From 4c45f354846f9c085f13f91aa5713fa824c8bbd8 Mon Sep 17 00:00:00 2001 From: febo Date: Tue, 14 Jan 2025 15:35:34 +0000 Subject: [PATCH] Update mollusk git reference --- Cargo.lock | 6 +- program/tests/assert_instruction_count.rs | 16 ++-- program/tests/close_account.rs | 102 +++++++++++++--------- program/tests/processor.rs | 15 ++-- program/tests/setup.rs | 17 ++-- 5 files changed, 83 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e98547a..0213a0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1559,7 +1559,7 @@ dependencies = [ [[package]] name = "mollusk-svm" version = "0.0.13" -source = "git+https://github.com/buffalojoec/mollusk.git#c01523016195c315870bd9e4bfa3a64a6cffa659" +source = "git+https://github.com/buffalojoec/mollusk.git#f01db9074f90405b5e5109a1845a1a643d9e0dc5" dependencies = [ "bincode", "mollusk-svm-error", @@ -1576,7 +1576,7 @@ dependencies = [ [[package]] name = "mollusk-svm-error" version = "0.0.13" -source = "git+https://github.com/buffalojoec/mollusk.git#c01523016195c315870bd9e4bfa3a64a6cffa659" +source = "git+https://github.com/buffalojoec/mollusk.git#f01db9074f90405b5e5109a1845a1a643d9e0dc5" dependencies = [ "solana-sdk", "thiserror 1.0.69", @@ -1585,7 +1585,7 @@ dependencies = [ [[package]] name = "mollusk-svm-keys" version = "0.0.13" -source = "git+https://github.com/buffalojoec/mollusk.git#c01523016195c315870bd9e4bfa3a64a6cffa659" +source = "git+https://github.com/buffalojoec/mollusk.git#f01db9074f90405b5e5109a1845a1a643d9e0dc5" dependencies = [ "mollusk-svm-error", "solana-sdk", diff --git a/program/tests/assert_instruction_count.rs b/program/tests/assert_instruction_count.rs index ab5de7c..0143a11 100644 --- a/program/tests/assert_instruction_count.rs +++ b/program/tests/assert_instruction_count.rs @@ -5,7 +5,7 @@ mod setup; use { mollusk_svm::{result::Check, Mollusk}, solana_sdk::{ - account::{AccountSharedData, ReadableAccount}, + account::{Account as SolanaAccount, ReadableAccount}, program_pack::Pack, pubkey::Pubkey, }, @@ -29,7 +29,7 @@ fn initialize_mint() { let mint_account = { let space = Mint::LEN; let lamports = mollusk.sysvars.rent.minimum_balance(space); - AccountSharedData::new(lamports, space, &id()) + SolanaAccount::new(lamports, space, &id()) }; mollusk.process_and_validate_instruction( @@ -61,7 +61,7 @@ fn initialize_account() { let token_account = { let space = Account::LEN; let lamports = mollusk.sysvars.rent.minimum_balance(space); - AccountSharedData::new(lamports, space, &id()) + SolanaAccount::new(lamports, space, &id()) }; mollusk.process_and_validate_instruction( @@ -69,7 +69,7 @@ fn initialize_account() { &[ (account, token_account), (mint, mint_account), - (owner, AccountSharedData::default()), + (owner, SolanaAccount::default()), mollusk.sysvars.keyed_account_for_rent_sysvar(), ], &[ @@ -99,7 +99,7 @@ fn mint_to() { &[ (mint, mint_account), (account, token_account), - (owner, AccountSharedData::default()), + (owner, SolanaAccount::default()), ], &[ Check::success(), @@ -133,7 +133,7 @@ fn transfer() { &[ (source, source_token_account), (destination, destination_token_account), - (owner, AccountSharedData::default()), + (owner, SolanaAccount::default()), ], &[ Check::success(), @@ -165,7 +165,7 @@ fn burn() { &[ (mint, mint_account), (account, token_account), - (owner, AccountSharedData::default()), + (owner, SolanaAccount::default()), ], &[ Check::success(), @@ -194,7 +194,7 @@ fn close_account() { &[ (mint, mint_account), (account, token_account), - (owner, AccountSharedData::default()), + (owner, SolanaAccount::default()), ], &[Check::success(), Check::account(&account).closed().build()], ); diff --git a/program/tests/close_account.rs b/program/tests/close_account.rs index 7cfbb06..cb1ac55 100644 --- a/program/tests/close_account.rs +++ b/program/tests/close_account.rs @@ -5,7 +5,7 @@ mod setup; use { mollusk_svm::{result::Check, Mollusk}, solana_sdk::{ - account::{AccountSharedData, ReadableAccount}, + account::{Account as SolanaAccount, ReadableAccount}, program_error::ProgramError, program_pack::Pack, pubkey::Pubkey, @@ -24,7 +24,7 @@ fn success_init_after_close_account() { let destination = Pubkey::new_unique(); let decimals = 9; - let owner_account = AccountSharedData::new(1_000_000_000, 0, &system_program::id()); + let owner_account = SolanaAccount::new(1_000_000_000, 0, &system_program::id()); let mint_account = setup::setup_mint_account(None, None, 0, decimals); let token_account = setup::setup_token_account(&mint, &owner, 0); @@ -32,36 +32,45 @@ fn success_init_after_close_account() { mollusk.process_and_validate_instruction_chain( &[ - instruction::close_account(&spl_token::id(), &account, &destination, &owner, &[]) - .unwrap(), - system_instruction::create_account( - &owner, - &account, - 1_000_000_000, - Account::LEN as u64, - &spl_token::id(), + ( + &instruction::close_account(&spl_token::id(), &account, &destination, &owner, &[]) + .unwrap(), + &[Check::success()], + ), + ( + &system_instruction::create_account( + &owner, + &account, + 1_000_000_000, + Account::LEN as u64, + &spl_token::id(), + ), + &[Check::success()], + ), + ( + &instruction::initialize_account(&spl_token::id(), &account, &mint, &owner) + .unwrap(), + &[ + Check::success(), + // Account successfully re-initialized. + Check::account(&account) + .data(setup::setup_token_account(&mint, &owner, 0).data()) + .owner(&spl_token::id()) + .build(), + // The destination should have the lamports from the closed account. + Check::account(&destination) + .lamports(expected_destination_lamports) + .build(), + ], ), - instruction::initialize_account(&spl_token::id(), &account, &mint, &owner).unwrap(), ], &[ (mint, mint_account), (account, token_account), (owner, owner_account), - (destination, AccountSharedData::default()), + (destination, SolanaAccount::default()), mollusk.sysvars.keyed_account_for_rent_sysvar(), ], - &[ - Check::success(), - // Account successfully re-initialized. - Check::account(&account) - .data(setup::setup_token_account(&mint, &owner, 0).data()) - .owner(&spl_token::id()) - .build(), - // The destination should have the lamports from the closed account. - Check::account(&destination) - .lamports(expected_destination_lamports) - .build(), - ], ); } @@ -75,7 +84,7 @@ fn fail_init_after_close_account() { let destination = Pubkey::new_unique(); let decimals = 9; - let owner_account = AccountSharedData::new(1_000_000_000, 0, &system_program::id()); + let owner_account = SolanaAccount::new(1_000_000_000, 0, &system_program::id()); let mint_account = setup::setup_mint_account(None, None, 0, decimals); let token_account = setup::setup_token_account(&mint, &owner, 0); @@ -83,29 +92,38 @@ fn fail_init_after_close_account() { mollusk.process_and_validate_instruction_chain( &[ - instruction::close_account(&spl_token::id(), &account, &destination, &owner, &[]) - .unwrap(), - system_instruction::transfer(&owner, &account, 1_000_000_000), - instruction::initialize_account(&spl_token::id(), &account, &mint, &owner).unwrap(), + ( + &instruction::close_account(&spl_token::id(), &account, &destination, &owner, &[]) + .unwrap(), + &[Check::success()], + ), + ( + &system_instruction::transfer(&owner, &account, 1_000_000_000), + &[Check::success()], + ), + ( + &instruction::initialize_account(&spl_token::id(), &account, &mint, &owner) + .unwrap(), + &[ + Check::err(ProgramError::InvalidAccountData), + // Account not re-initialized. + Check::account(&account) + .lamports(1_000_000_000) + .owner(&system_program::id()) + .build(), + // The destination should have the lamports from the closed account. + Check::account(&destination) + .lamports(expected_destination_lamports) + .build(), + ], + ), ], &[ (mint, mint_account), (account, token_account), (owner, owner_account), - (destination, AccountSharedData::default()), + (destination, SolanaAccount::default()), mollusk.sysvars.keyed_account_for_rent_sysvar(), ], - &[ - Check::err(ProgramError::InvalidAccountData), - // Account not re-initialized. - Check::account(&account) - .lamports(1_000_000_000) - .owner(&system_program::id()) - .build(), - // The destination should have the lamports from the closed account. - Check::account(&destination) - .lamports(expected_destination_lamports) - .build(), - ], ); } diff --git a/program/tests/processor.rs b/program/tests/processor.rs index e4c75e0..d7ccb0f 100644 --- a/program/tests/processor.rs +++ b/program/tests/processor.rs @@ -9,7 +9,7 @@ use { }, serial_test::serial, solana_sdk::{ - account::{create_account_for_test, Account as SolanaAccount, AccountSharedData}, + account::{create_account_for_test, Account as SolanaAccount}, account_info::{AccountInfo, IntoAccountInfo}, entrypoint::ProgramResult, instruction::Instruction, @@ -54,12 +54,7 @@ fn do_process_instruction( .accounts .iter() .zip(&accounts) - .map(|(account_meta, account)| { - ( - account_meta.pubkey, - AccountSharedData::from((*account).clone()), - ) - }) + .map(|(account_meta, account)| (account_meta.pubkey, (*account).clone())) .for_each(|(pubkey, account)| { instruction_accounts.push((pubkey, account)); }); @@ -70,7 +65,7 @@ fn do_process_instruction( // Update accounts after the instruction is processed. for (original, (_, updated)) in accounts.iter_mut().zip(result.resulting_accounts.iter()) { - let account = SolanaAccount::from(updated.clone()); + let account = updated.clone(); original.data = account.data; original.lamports = account.lamports; original.owner = account.owner; @@ -101,7 +96,7 @@ fn do_process_instruction_dups( executable: account_info.executable, rent_epoch: account_info.rent_epoch, }; - dedup_accounts.push((*account_info.key, AccountSharedData::from(account))); + dedup_accounts.push((*account_info.key, account)); cached_accounts.insert(account_info.key, account_info); } }); @@ -114,7 +109,7 @@ fn do_process_instruction_dups( .resulting_accounts .iter() .for_each(|(pubkey, account)| { - let account = SolanaAccount::from(account.clone()); + let account = account.clone(); let account_info = cached_accounts.get(pubkey).unwrap(); if account.data.is_empty() { // When the account is closed, the tests expect the data to diff --git a/program/tests/setup.rs b/program/tests/setup.rs index df79381..4365dea 100644 --- a/program/tests/setup.rs +++ b/program/tests/setup.rs @@ -2,10 +2,7 @@ use { solana_sdk::{ - account::{Account as SolanaAccount, AccountSharedData}, - program_pack::Pack, - pubkey::Pubkey, - rent::Rent, + account::Account as SolanaAccount, program_pack::Pack, pubkey::Pubkey, rent::Rent, }, spl_token::state::{Account, AccountState, Mint}, }; @@ -15,7 +12,7 @@ pub fn setup_mint_account( freeze_authority: Option<&Pubkey>, supply: u64, decimals: u8, -) -> AccountSharedData { +) -> SolanaAccount { let data = { let mut data = vec![0; Mint::LEN]; let state = Mint { @@ -32,15 +29,15 @@ pub fn setup_mint_account( let space = data.len(); let lamports = Rent::default().minimum_balance(space); - AccountSharedData::from(SolanaAccount { + SolanaAccount { lamports, data, owner: spl_token::id(), ..Default::default() - }) + } } -pub fn setup_token_account(mint: &Pubkey, owner: &Pubkey, amount: u64) -> AccountSharedData { +pub fn setup_token_account(mint: &Pubkey, owner: &Pubkey, amount: u64) -> SolanaAccount { let data = { let mut data = vec![0; Account::LEN]; let state = Account { @@ -60,10 +57,10 @@ pub fn setup_token_account(mint: &Pubkey, owner: &Pubkey, amount: u64) -> Accoun let space = data.len(); let lamports = Rent::default().minimum_balance(space); - AccountSharedData::from(SolanaAccount { + SolanaAccount { lamports, data, owner: spl_token::id(), ..Default::default() - }) + } }