Skip to content

Commit 93e1636

Browse files
committed
Tidy up
1 parent 0a64761 commit 93e1636

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

program/tests/processor.rs

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,24 @@
22

33
//! Program state processor tests
44
5-
use std::collections::HashSet;
6-
7-
use mollusk_svm::{
8-
result::{Check, InstructionResult},
9-
Mollusk,
10-
};
11-
use solana_sdk::{
12-
account::{create_account_for_test, Account as SolanaAccount, AccountSharedData},
13-
instruction::Instruction,
14-
program_pack::Pack,
15-
pubkey::Pubkey,
16-
rent::Rent,
5+
use {
6+
mollusk_svm::{
7+
result::{Check, InstructionResult},
8+
Mollusk,
9+
},
10+
solana_sdk::{
11+
account::{create_account_for_test, Account as SolanaAccount, AccountSharedData},
12+
instruction::Instruction,
13+
program_pack::Pack,
14+
pubkey::Pubkey,
15+
rent::Rent,
16+
},
17+
spl_token::{error::TokenError, instruction::initialize_mint, state::Mint},
18+
std::collections::HashSet,
1719
};
18-
use spl_token::{error::TokenError, instruction::initialize_mint, state::Mint};
1920

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

22-
fn do_process_instruction(
23-
instruction: Instruction,
24-
accounts: Vec<&SolanaAccount>,
25-
checks: &[Check],
26-
) -> InstructionResult {
27-
let accounts = instruction
28-
.accounts
29-
.iter()
30-
.zip(accounts)
31-
.map(|(account_meta, account)| {
32-
(
33-
account_meta.pubkey,
34-
AccountSharedData::from(account.clone()),
35-
)
36-
})
37-
.collect::<Vec<_>>();
38-
39-
let mollusk = Mollusk::new(&spl_token::id(), "spl_token");
40-
mollusk.process_and_validate_instruction(&instruction, accounts.as_slice(), checks)
41-
}
42-
4323
fn do_process_instructions(
4424
instructions: &[InstructionPack],
4525
checks: &[Check],
@@ -96,18 +76,22 @@ fn test_initialize_mint() {
9676
let rent_sysvar = rent_sysvar();
9777

9878
// mint is not rent exempt
99-
do_process_instruction(
100-
initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(),
101-
vec![&mint_account, &rent_sysvar],
79+
do_process_instructions(
80+
&[(
81+
initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(),
82+
vec![&mint_account, &rent_sysvar],
83+
)],
10284
&[Check::err(TokenError::NotRentExempt.into())],
10385
);
10486

10587
mint_account.lamports = mint_minimum_balance();
10688

10789
// create new mint
108-
do_process_instruction(
109-
initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(),
110-
vec![&mint_account, &rent_sysvar],
90+
do_process_instructions(
91+
&[(
92+
initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(),
93+
vec![&mint_account, &rent_sysvar],
94+
)],
11195
&[Check::success()],
11296
);
11397

@@ -127,9 +111,11 @@ fn test_initialize_mint() {
127111
);
128112

129113
// create another mint that can freeze
130-
do_process_instruction(
131-
initialize_mint(&program_id, &mint2_key, &owner_key, Some(&owner_key), 2).unwrap(),
132-
vec![&mint2_account, &rent_sysvar],
114+
do_process_instructions(
115+
&[(
116+
initialize_mint(&program_id, &mint2_key, &owner_key, Some(&owner_key), 2).unwrap(),
117+
vec![&mint2_account, &rent_sysvar],
118+
)],
133119
&[
134120
// Account successfully re-initialized.
135121
Check::success(),

0 commit comments

Comments
 (0)