Skip to content

Commit 24e3454

Browse files
committed
move account_to_change creation to test
1 parent 66c6f8f commit 24e3454

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

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

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

33
use crate::prelude::*;
44

5-
pub fn check_accounts(signer: Pubkey, account_to_create: Pubkey) -> Instruction {
5+
pub fn check_accounts(
6+
signer: Pubkey,
7+
account_to_create: Pubkey,
8+
account_to_change: Pubkey,
9+
) -> Instruction {
610
Instruction {
711
program_id: crate::ID,
812
accounts: vec![
913
AccountMeta::new(signer, true),
1014
AccountMeta::new(account_to_create, false),
11-
AccountMeta::new(account_to_change_pda().0, false),
15+
AccountMeta::new(account_to_change, false),
1216
AccountMeta::new_readonly(system_program::ID, false),
1317
],
1418
data: CheckAccounts {}.to_bytes(),

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

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

54
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-
95
// Load accounts.
106
// You can verify the list has the correct number of accounts.
117
let [signer_info, account_to_create_info, account_to_change_info, system_program] = accounts
@@ -30,13 +26,6 @@ pub fn process_check_accounts(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Pro
3026
return Err(ProgramError::AccountAlreadyInitialized);
3127
};
3228
// (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-
)?;
4029

4130
// You can also make sure an account has been initialized.
4231
msg!("Account to change: {}", account_to_change_info.key);

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use solana_program::hash::Hash;
22
use solana_program_test::{processor, BanksClient, ProgramTest};
33
use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction};
4-
use steel::*;
54
use steel_api::prelude::*;
65

76
async fn setup() -> (BanksClient, Keypair, Hash) {
@@ -19,10 +18,33 @@ async fn run_test() {
1918
// Setup test
2019
let (mut banks, payer, blockhash) = setup().await;
2120

22-
let account_to_create = Pubkey::new_unique();
21+
let account_to_create = Keypair::new();
22+
let account_to_change = Keypair::new();
23+
24+
let account_to_change_ix = solana_sdk::system_instruction::create_account(
25+
&payer.pubkey(),
26+
&account_to_change.pubkey(),
27+
solana_sdk::native_token::LAMPORTS_PER_SOL,
28+
0,
29+
&steel_api::ID,
30+
);
31+
32+
let tx = Transaction::new_signed_with_payer(
33+
&[account_to_change_ix],
34+
Some(&payer.pubkey()),
35+
&[&payer, &account_to_change],
36+
blockhash,
37+
);
38+
39+
let res = banks.process_transaction(tx).await;
40+
assert!(res.is_ok());
2341

2442
// Submit check_accounts transaction.
25-
let ix = check_accounts(payer.pubkey(), account_to_create);
43+
let ix = check_accounts(
44+
payer.pubkey(),
45+
account_to_create.pubkey(),
46+
account_to_change.pubkey(),
47+
);
2648
let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
2749
let res = banks.process_transaction(tx).await;
2850
assert!(res.is_ok());

0 commit comments

Comments
 (0)