2
2
3
3
//! Program state processor tests
4
4
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 ,
17
19
} ;
18
- use spl_token:: { error:: TokenError , instruction:: initialize_mint, state:: Mint } ;
19
20
20
21
type InstructionPack < ' a > = ( Instruction , Vec < & ' a SolanaAccount > ) ;
21
22
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
-
43
23
fn do_process_instructions (
44
24
instructions : & [ InstructionPack ] ,
45
25
checks : & [ Check ] ,
@@ -96,18 +76,22 @@ fn test_initialize_mint() {
96
76
let rent_sysvar = rent_sysvar ( ) ;
97
77
98
78
// 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
+ ) ] ,
102
84
& [ Check :: err ( TokenError :: NotRentExempt . into ( ) ) ] ,
103
85
) ;
104
86
105
87
mint_account. lamports = mint_minimum_balance ( ) ;
106
88
107
89
// 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
+ ) ] ,
111
95
& [ Check :: success ( ) ] ,
112
96
) ;
113
97
@@ -127,9 +111,11 @@ fn test_initialize_mint() {
127
111
) ;
128
112
129
113
// 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
+ ) ] ,
133
119
& [
134
120
// Account successfully re-initialized.
135
121
Check :: success ( ) ,
0 commit comments