|
| 1 | +use litesvm::LiteSVM; |
| 2 | +use solana_keypair::{Keypair, Signer}; |
| 3 | +use solana_native_token::LAMPORTS_PER_SOL; |
| 4 | +use solana_pubkey::Pubkey; |
| 5 | +use solana_system_interface::instruction::create_account; |
| 6 | +use solana_transaction::{AccountMeta, Instruction, Transaction}; |
| 7 | + |
| 8 | +#[test] |
| 9 | +fn test_checking_accounts() { |
| 10 | + let mut svm = LiteSVM::new(); |
| 11 | + |
| 12 | + let payer = Keypair::new(); |
| 13 | + let account_to_change = Keypair::new(); |
| 14 | + let account_to_create = Keypair::new(); |
| 15 | + |
| 16 | + svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap(); |
| 17 | + |
| 18 | + let program_id = Pubkey::new_unique(); |
| 19 | + let program_bytes = |
| 20 | + include_bytes!("../../../../../target/deploy/checking_accounts_native_program.so"); |
| 21 | + |
| 22 | + svm.add_program(program_id, program_bytes).unwrap(); |
| 23 | + |
| 24 | + let create_account_ix = create_account( |
| 25 | + &payer.pubkey(), |
| 26 | + &account_to_change.pubkey(), |
| 27 | + LAMPORTS_PER_SOL, |
| 28 | + 0, |
| 29 | + &program_id, |
| 30 | + ); |
| 31 | + |
| 32 | + let tx = Transaction::new_signed_with_payer( |
| 33 | + &[create_account_ix], |
| 34 | + Some(&payer.pubkey()), |
| 35 | + &[&payer, &account_to_change], |
| 36 | + svm.latest_blockhash(), |
| 37 | + ); |
| 38 | + |
| 39 | + // verify tx was sent successfully |
| 40 | + let _ = svm.send_transaction(tx).is_ok(); |
| 41 | + |
| 42 | + let ix = Instruction { |
| 43 | + program_id, |
| 44 | + accounts: vec![ |
| 45 | + AccountMeta::new(payer.pubkey(), true), |
| 46 | + AccountMeta::new(account_to_create.pubkey(), true), |
| 47 | + AccountMeta::new(account_to_change.pubkey(), true), |
| 48 | + AccountMeta::new(solana_system_interface::program::ID, false), |
| 49 | + ], |
| 50 | + data: vec![0], |
| 51 | + }; |
| 52 | + |
| 53 | + let tx = Transaction::new_signed_with_payer( |
| 54 | + &[ix], |
| 55 | + Some(&payer.pubkey()), |
| 56 | + &[payer, account_to_change, account_to_create], |
| 57 | + svm.latest_blockhash(), |
| 58 | + ); |
| 59 | + |
| 60 | + // verify tx was sent successfully |
| 61 | + let _ = svm.send_transaction(tx).is_ok(); |
| 62 | +} |
0 commit comments