use solana_program_test::*; use solana_sdk::{ program_pack::Pack, pubkey::Pubkey, signature::Signer, signer::keypair::Keypair, system_instruction, transaction::Transaction, transport, }; use spl_associated_token_account::create_associated_token_account; pub async fn create_mint( context: &mut ProgramTestContext, mint: &Keypair, manager: &Pubkey, decimals: u8, freeze_authority: Option<&Pubkey>, ) -> transport::Result<()> { let rent = context.banks_client.get_rent().await.unwrap(); let tx = Transaction::new_signed_with_payer( &[ system_instruction::create_account( &context.payer.pubkey(), &mint.pubkey(), rent.minimum_balance(spl_token::state::Mint::LEN), spl_token::state::Mint::LEN as u64, &spl_token::id(), ), spl_token::instruction::initialize_mint( &spl_token::id(), &mint.pubkey(), &manager, freeze_authority, decimals, ) .unwrap(), ], Some(&context.payer.pubkey()), &[&context.payer, &mint], context.last_blockhash, ); context.banks_client.process_transaction(tx).await } pub async fn mint_tokens( context: &mut ProgramTestContext, mint: &Pubkey, account: &Pubkey, amount: u64, owner: &Pubkey, additional_signer: Option<&Keypair>, ) -> transport::Result<()> { let mut signing_keypairs = vec![&context.payer]; if let Some(signer) = additional_signer { signing_keypairs.push(signer); } let tx = Transaction::new_signed_with_payer( &[ spl_token::instruction::mint_to(&spl_token::id(), mint, account, owner, &[], amount) .unwrap(), ], Some(&context.payer.pubkey()), &signing_keypairs, context.last_blockhash, ); context.banks_client.process_transaction(tx).await } pub async fn create_associated_account( context: &mut ProgramTestContext, wallet_address: &Pubkey, mint_address: &Pubkey, ) -> transport::Result<()> { let tx = Transaction::new_signed_with_payer( &[ create_associated_token_account( &context.payer.pubkey(), &wallet_address, &mint_address, ) ], Some(&context.payer.pubkey()), &[&context.payer], context.last_blockhash, ); context.banks_client.process_transaction(tx).await }