Skip to content

Commit f5a58b1

Browse files
authored
Upgrade to Anchor 0.15.0 (#7)
1 parent c4bce19 commit f5a58b1

File tree

5 files changed

+52
-71
lines changed

5 files changed

+52
-71
lines changed

Cargo.lock

Lines changed: 44 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ edition = "2018"
1010
exclude = ["images/"]
1111

1212
[dependencies]
13-
anchor-lang = "0.13.2"
14-
anchor-spl = "0.13.2"
13+
anchor-lang = "0.15.0"
14+
anchor-spl = "0.15.0"
1515
spl-associated-token-account = { version = "1.0.3", features = [
1616
"no-entrypoint"
1717
] }

src/assert.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,24 +229,23 @@ mod tests {
229229

230230
#[test]
231231
fn test_assert_owner() -> ProgramResult {
232-
let key = Pubkey::new_unique();
233232
let mut lamports: u64 = 8 + (TestData::default().try_to_vec().unwrap().len() as u64);
234233

235234
let mut buffer: [u8; 16] = [0; 16];
236235
let mut buf: &mut [u8] = &mut buffer;
237236
TestData::default().try_serialize(&mut buf)?;
238237

239-
let info: CpiAccount<TestData> = CpiAccount::try_from(&AccountInfo::new(
240-
&key,
238+
let info: Account<TestData> = Account::try_from(&AccountInfo::new(
239+
&crate::ID,
241240
false,
242241
false,
243242
&mut lamports,
244243
&mut buffer,
245-
&key,
244+
&crate::ID,
246245
false,
247246
0,
248247
))?;
249-
assert_owner!(info, key);
248+
assert_owner!(info, crate::ID);
250249

251250
Ok(())
252251
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub mod validate;
99

1010
use anchor_lang::prelude::*;
1111

12+
declare_id!("VipersTest111111111111111111111111111111111");
13+
1214
/// Validates a derived program address.
1315
pub fn validate_derived_address(
1416
derived_address: &Pubkey,

src/validate.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
11
//! Validations for accounts.
22
33
use anchor_lang::prelude::*;
4-
use anchor_spl::token::{Mint, TokenAccount};
5-
6-
use crate::assert_owner;
74

85
/// Validates the contents of a variable. Generally used for [Accounts] structs and struct members.
96
pub trait Validate<'info> {
107
/// Validates the account struct.
118
fn validate(&self) -> ProgramResult;
129
}
13-
14-
/// Represents an account owned by a program.
15-
pub trait ProgramOwned: AccountDeserialize + Clone {
16-
/// Gets the expected owner of the program owned account.
17-
fn expected_owner(&self) -> &'static Pubkey;
18-
}
19-
20-
impl<'info, T: ProgramOwned> Validate<'info> for CpiAccount<'info, T> {
21-
fn validate(&self) -> ProgramResult {
22-
assert_owner!(*self, *self.expected_owner());
23-
Ok(())
24-
}
25-
}
26-
27-
impl ProgramOwned for TokenAccount {
28-
fn expected_owner(&self) -> &'static Pubkey {
29-
&crate::program_ids::token::ID
30-
}
31-
}
32-
33-
impl ProgramOwned for Mint {
34-
fn expected_owner(&self) -> &'static Pubkey {
35-
&crate::program_ids::token::ID
36-
}
37-
}

0 commit comments

Comments
 (0)