Skip to content

Commit 66c6f8f

Browse files
committed
fix tests
1 parent 9f361fe commit 66c6f8f

File tree

7 files changed

+59
-64
lines changed

7 files changed

+59
-64
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// Seed of the account_to_change account PDA.
2+
pub const ACCOUNT_TO_CHANGE: &[u8] = b"account_to_change";

basics/checking-accounts/steel/api/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
pub mod consts;
12
pub mod instruction;
23
pub mod sdk;
4+
pub mod state;
35

46
pub mod prelude {
7+
pub use crate::consts::*;
58
pub use crate::instruction::*;
69
pub use crate::sdk::*;
10+
pub use crate::state::*;
711
}
812

913
use steel::*;

basics/checking-accounts/steel/api/src/sdk.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ use steel::*;
22

33
use crate::prelude::*;
44

5-
pub fn check_accounts(
6-
signer: Pubkey,
7-
account_to_create: Pubkey,
8-
account_to_change: Pubkey,
9-
) -> Instruction {
5+
pub fn check_accounts(signer: Pubkey, account_to_create: Pubkey) -> Instruction {
106
Instruction {
117
program_id: crate::ID,
128
accounts: vec![
139
AccountMeta::new(signer, true),
1410
AccountMeta::new(account_to_create, false),
15-
AccountMeta::new(account_to_change, false),
11+
AccountMeta::new(account_to_change_pda().0, false),
1612
AccountMeta::new_readonly(system_program::ID, false),
1713
],
1814
data: CheckAccounts {}.to_bytes(),
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use steel::*;
2+
3+
use super::SteelAccount;
4+
5+
#[repr(C)]
6+
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
7+
pub struct AccountToChange {}
8+
9+
account!(SteelAccount, AccountToChange);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
mod account_to_change;
2+
3+
pub use account_to_change::*;
4+
5+
use steel::*;
6+
7+
use crate::consts::*;
8+
9+
#[repr(u8)]
10+
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
11+
pub enum SteelAccount {
12+
AccountToChange = 0,
13+
}
14+
15+
/// Fetch PDA of the account_to_change account.
16+
pub fn account_to_change_pda() -> (Pubkey, u8) {
17+
Pubkey::find_program_address(&[ACCOUNT_TO_CHANGE], &crate::id())
18+
}

basics/checking-accounts/steel/program/src/check_accounts.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use solana_program::msg;
22
use steel::*;
3+
use steel_api::prelude::*;
34

45
pub fn process_check_accounts(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
6+
// Get expected pda bump.
7+
let account_to_change_bump = account_to_change_pda().1;
8+
59
// Load accounts.
610
// You can verify the list has the correct number of accounts.
711
let [signer_info, account_to_create_info, account_to_change_info, system_program] = accounts
@@ -26,19 +30,26 @@ pub fn process_check_accounts(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Pro
2630
return Err(ProgramError::AccountAlreadyInitialized);
2731
};
2832
// (Create account...)
33+
create_account::<AccountToChange>(
34+
account_to_change_info,
35+
&steel_api::ID,
36+
&[ACCOUNT_TO_CHANGE, &[account_to_change_bump]],
37+
system_program,
38+
signer_info,
39+
)?;
2940

3041
// You can also make sure an account has been initialized.
31-
// msg!("Account to change: {}", account_to_change_info.key);
32-
// if account_to_change_info.lamports() == 0 {
33-
// msg!("The program expected the account to change to be initialized.");
34-
// return Err(ProgramError::UninitializedAccount);
35-
// };
36-
37-
// // If we want to modify an account's data, it must be owned by our program.
38-
// if account_to_change_info.owner != &steel_api::ID {
39-
// msg!("Account to change does not have the correct program id.");
40-
// return Err(ProgramError::IncorrectProgramId);
41-
// };
42+
msg!("Account to change: {}", account_to_change_info.key);
43+
if account_to_change_info.lamports() == 0 {
44+
msg!("The program expected the account to change to be initialized.");
45+
return Err(ProgramError::UninitializedAccount);
46+
};
47+
48+
// If we want to modify an account's data, it must be owned by our program.
49+
if account_to_change_info.owner != &steel_api::ID {
50+
msg!("Account to change does not have the correct program id.");
51+
return Err(ProgramError::IncorrectProgramId);
52+
};
4253

4354
// You can also check pubkeys against constants.
4455
if system_program.key != &system_program::ID {

basics/checking-accounts/steel/program/tests/test.rs

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,55 +20,10 @@ async fn run_test() {
2020
let (mut banks, payer, blockhash) = setup().await;
2121

2222
let account_to_create = Pubkey::new_unique();
23-
let account_to_change = Pubkey::new_unique();
2423

25-
// AccountInfo::new(
26-
// &account_to_change,
27-
// payer.pubkey(),
28-
// true,
29-
// 0,
30-
// data,
31-
// owner,
32-
// true,
33-
// rent_epoch,
34-
// );
35-
// getminu
36-
37-
// create_account(account_to_change., owner, seeds, system_program, payer);
38-
39-
// account!()
40-
// ToAccount
41-
42-
// // Initialize proof.
43-
// create_account::<Proof>(
44-
// proof_info,
45-
// &ore_api::ID,
46-
// &[PROOF, signer_info.key.as_ref(), &[args.bump]],
47-
// system_program,
48-
// payer_info,
49-
// )?;
50-
51-
// Submit initialize transaction.
52-
let ix = check_accounts(payer.pubkey(), account_to_create, account_to_change);
24+
// Submit check_accounts transaction.
25+
let ix = check_accounts(payer.pubkey(), account_to_create);
5326
let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
5427
let res = banks.process_transaction(tx).await;
5528
assert!(res.is_ok());
56-
57-
// Verify counter was initialized.
58-
// let counter_address = counter_pda().0;
59-
// let counter_account = banks.get_account(counter_address).await.unwrap().unwrap();
60-
// let counter = Counter::try_from_bytes(&counter_account.data).unwrap();
61-
// assert_eq!(counter_account.owner, steel_api::ID);
62-
// assert_eq!(counter.value, 0);
63-
64-
// Submit add transaction.
65-
// let ix = add(payer.pubkey(), 42);
66-
// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
67-
// let res = banks.process_transaction(tx).await;
68-
// assert!(res.is_ok());
69-
70-
// // Verify counter was incremented.
71-
// let counter_account = banks.get_account(counter_address).await.unwrap().unwrap();
72-
// let counter = Counter::try_from_bytes(&counter_account.data).unwrap();
73-
// assert_eq!(counter.value, 42);
7429
}

0 commit comments

Comments
 (0)