|
| 1 | +use solana_program::hash::Hash; |
| 2 | +use solana_program_test::{processor, BanksClient, ProgramTest}; |
| 3 | +use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction}; |
| 4 | +use steel_api::prelude::*; |
| 5 | + |
| 6 | +async fn setup() -> (BanksClient, Keypair, Hash) { |
| 7 | + let mut program_test = ProgramTest::new( |
| 8 | + "steel_program", |
| 9 | + steel_api::ID, |
| 10 | + processor!(steel_program::process_instruction), |
| 11 | + ); |
| 12 | + program_test.prefer_bpf(true); |
| 13 | + program_test.start().await |
| 14 | +} |
| 15 | + |
| 16 | +#[tokio::test] |
| 17 | +async fn run_test() { |
| 18 | + // Setup test |
| 19 | + let (mut banks, payer, blockhash) = setup().await; |
| 20 | + |
| 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()); |
| 41 | + |
| 42 | + // Submit check_accounts transaction. |
| 43 | + let ix = check_accounts( |
| 44 | + payer.pubkey(), |
| 45 | + account_to_create.pubkey(), |
| 46 | + account_to_change.pubkey(), |
| 47 | + ); |
| 48 | + let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); |
| 49 | + let res = banks.process_transaction(tx).await; |
| 50 | + assert!(res.is_ok()); |
| 51 | +} |
0 commit comments