Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
febo committed Dec 20, 2024
1 parent 0a64761 commit 3eb2121
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions program/tests/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@ use spl_token::{error::TokenError, instruction::initialize_mint, state::Mint};

type InstructionPack<'a> = (Instruction, Vec<&'a SolanaAccount>);

fn do_process_instruction(
instruction: Instruction,
accounts: Vec<&SolanaAccount>,
checks: &[Check],
) -> InstructionResult {
let accounts = instruction
.accounts
.iter()
.zip(accounts)
.map(|(account_meta, account)| {
(
account_meta.pubkey,
AccountSharedData::from(account.clone()),
)
})
.collect::<Vec<_>>();

let mollusk = Mollusk::new(&spl_token::id(), "spl_token");
mollusk.process_and_validate_instruction(&instruction, accounts.as_slice(), checks)
}

fn do_process_instructions(
instructions: &[InstructionPack],
checks: &[Check],
Expand Down Expand Up @@ -96,18 +75,22 @@ fn test_initialize_mint() {
let rent_sysvar = rent_sysvar();

// mint is not rent exempt
do_process_instruction(
initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(),
vec![&mint_account, &rent_sysvar],
do_process_instructions(
&[(
initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(),
vec![&mint_account, &rent_sysvar],
)],
&[Check::err(TokenError::NotRentExempt.into())],
);

mint_account.lamports = mint_minimum_balance();

// create new mint
do_process_instruction(
initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(),
vec![&mint_account, &rent_sysvar],
do_process_instructions(
&[(
initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(),
vec![&mint_account, &rent_sysvar],
)],
&[Check::success()],
);

Expand All @@ -127,9 +110,11 @@ fn test_initialize_mint() {
);

// create another mint that can freeze
do_process_instruction(
initialize_mint(&program_id, &mint2_key, &owner_key, Some(&owner_key), 2).unwrap(),
vec![&mint2_account, &rent_sysvar],
do_process_instructions(
&[(
initialize_mint(&program_id, &mint2_key, &owner_key, Some(&owner_key), 2).unwrap(),
vec![&mint2_account, &rent_sysvar],
)],
&[
// Account successfully re-initialized.
Check::success(),
Expand Down

0 comments on commit 3eb2121

Please sign in to comment.