|
| 1 | +use { |
| 2 | + solana_program::{ |
| 3 | + instruction::{AccountMeta, Instruction}, |
| 4 | + pubkey::Pubkey, |
| 5 | + rent::Rent, |
| 6 | + system_program, |
| 7 | + }, |
| 8 | + solana_program_rosetta_cpi::{process_instruction, SIZE}, |
| 9 | + solana_program_test::*, |
| 10 | + solana_sdk::{account::Account, signature::Signer, transaction::Transaction}, |
| 11 | + std::str::FromStr, |
| 12 | +}; |
| 13 | + |
| 14 | +#[tokio::test] |
| 15 | +async fn test_cross_program_invocation() { |
| 16 | + let program_id = Pubkey::from_str("invoker111111111111111111111111111111111111").unwrap(); |
| 17 | + let (allocated_pubkey, bump_seed) = |
| 18 | + Pubkey::find_program_address(&[b"You pass butter"], &program_id); |
| 19 | + let mut program_test = ProgramTest::new( |
| 20 | + "solana_program_rosetta_cpi", |
| 21 | + program_id, |
| 22 | + processor!(process_instruction), |
| 23 | + ); |
| 24 | + program_test.add_account( |
| 25 | + allocated_pubkey, |
| 26 | + Account { |
| 27 | + lamports: Rent::default().minimum_balance(SIZE), |
| 28 | + ..Account::default() |
| 29 | + }, |
| 30 | + ); |
| 31 | + |
| 32 | + let (mut banks_client, payer, recent_blockhash) = program_test.start().await; |
| 33 | + |
| 34 | + let mut transaction = Transaction::new_with_payer( |
| 35 | + &[Instruction::new_with_bincode( |
| 36 | + program_id, |
| 37 | + &[bump_seed], |
| 38 | + vec![ |
| 39 | + AccountMeta::new(allocated_pubkey, false), |
| 40 | + AccountMeta::new_readonly(system_program::id(), false), |
| 41 | + ], |
| 42 | + )], |
| 43 | + Some(&payer.pubkey()), |
| 44 | + ); |
| 45 | + transaction.sign(&[&payer], recent_blockhash); |
| 46 | + banks_client.process_transaction(transaction).await.unwrap(); |
| 47 | + |
| 48 | + // Associated account now exists |
| 49 | + let allocated_account = banks_client |
| 50 | + .get_account(allocated_pubkey) |
| 51 | + .await |
| 52 | + .expect("get_account") |
| 53 | + .expect("associated_account not none"); |
| 54 | + assert_eq!(allocated_account.data.len(), SIZE); |
| 55 | +} |
0 commit comments