|
| 1 | +use litesvm::LiteSVM; |
| 2 | +use pda_rent_payer_program::instructions::InitRentVaultArgs; |
| 3 | +use pda_rent_payer_program::processor::MyInstruction; |
| 4 | +use solana_instruction::{AccountMeta, Instruction}; |
| 5 | +use solana_keypair::{Keypair, Signer}; |
| 6 | +use solana_native_token::LAMPORTS_PER_SOL; |
| 7 | +use solana_pubkey::Pubkey; |
| 8 | +use solana_transaction::Transaction; |
| 9 | + |
| 10 | +#[test] |
| 11 | +fn test_pda_rent_payer() { |
| 12 | + let program_id = Pubkey::new_unique(); |
| 13 | + let program_bytes = include_bytes!("../../tests/fixtures/pda_rent_payer_program.so"); |
| 14 | + |
| 15 | + let mut svm = LiteSVM::new(); |
| 16 | + svm.add_program(program_id, program_bytes).unwrap(); |
| 17 | + |
| 18 | + let payer = Keypair::new(); |
| 19 | + svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap(); |
| 20 | + |
| 21 | + let rent_value_pda = Pubkey::find_program_address(&[b"rent_vault"], &program_id).0; |
| 22 | + |
| 23 | + let args = InitRentVaultArgs { |
| 24 | + fund_lamports: 1000000000, |
| 25 | + }; |
| 26 | + |
| 27 | + let data = borsh::to_vec(&MyInstruction::InitRentVault(args)).unwrap(); |
| 28 | + |
| 29 | + let ix = Instruction { |
| 30 | + program_id, |
| 31 | + accounts: vec![ |
| 32 | + AccountMeta::new(rent_value_pda, false), |
| 33 | + AccountMeta::new(payer.pubkey(), true), |
| 34 | + AccountMeta::new(solana_system_interface::program::ID, false), |
| 35 | + ], |
| 36 | + data, |
| 37 | + }; |
| 38 | + |
| 39 | + let tx = Transaction::new_signed_with_payer( |
| 40 | + &[ix], |
| 41 | + Some(&payer.pubkey()), |
| 42 | + &[&payer], |
| 43 | + svm.latest_blockhash(), |
| 44 | + ); |
| 45 | + |
| 46 | + let _ = svm.send_transaction(tx).is_ok(); |
| 47 | + |
| 48 | + let new_account = Keypair::new(); |
| 49 | + |
| 50 | + let data = borsh::to_vec(&MyInstruction::CreateNewAccount).unwrap(); |
| 51 | + |
| 52 | + let ix = Instruction { |
| 53 | + program_id, |
| 54 | + accounts: vec![ |
| 55 | + AccountMeta::new(new_account.pubkey(), true), |
| 56 | + AccountMeta::new(rent_value_pda, false), |
| 57 | + AccountMeta::new(solana_system_interface::program::ID, false), |
| 58 | + ], |
| 59 | + data, |
| 60 | + }; |
| 61 | + |
| 62 | + let tx = Transaction::new_signed_with_payer( |
| 63 | + &[ix], |
| 64 | + Some(&payer.pubkey()), |
| 65 | + &[&payer, &new_account], |
| 66 | + svm.latest_blockhash(), |
| 67 | + ); |
| 68 | + |
| 69 | + let _ = svm.send_transaction(tx).is_ok(); |
| 70 | +} |
0 commit comments