22
33mod setup;
44
5- use std:: {
6- collections:: { BTreeMap , HashMap } ,
7- println,
8- } ;
9-
10- use pinocchio:: instruction;
11- use setup:: { account, mint, TOKEN_PROGRAM_ID } ;
125use solana_program_test:: { tokio, ProgramTest } ;
136use solana_sdk:: {
147 instruction:: { AccountMeta , Instruction } ,
158 program_error:: ProgramError ,
169 program_pack:: Pack ,
1710 pubkey:: Pubkey ,
1811 signature:: { Keypair , Signer } ,
19- system_instruction, system_program ,
12+ system_instruction,
2013 transaction:: Transaction ,
2114} ;
2215
2316fn batch_instruction ( instructions : Vec < Instruction > ) -> Result < Instruction , ProgramError > {
24- // Create a Vector of ordered, AccountMetas
17+ // Create a `Vec` of ordered `AccountMeta`s
2518 let mut accounts: Vec < AccountMeta > = vec ! [ ] ;
26- // Start with the batch discriminator and a length byte
27-
19+ // Start with the batch discriminator
2820 let mut data: Vec < u8 > = vec ! [ 0xff ] ;
21+
2922 for instruction in instructions {
30- // Error out on non-token IX
23+ // Error out on non-token IX.
3124 if instruction. program_id . ne ( & spl_token:: ID ) {
3225 return Err ( ProgramError :: IncorrectProgramId ) ;
3326 }
3427
35- data. extend_from_slice ( & [ instruction. accounts . len ( ) as u8 ] ) ;
36- data. extend_from_slice ( & [ instruction. data . len ( ) as u8 ] ) ;
28+ data. push ( instruction. accounts . len ( ) as u8 ) ;
29+ data. push ( instruction. data . len ( ) as u8 ) ;
30+
3731 data. extend_from_slice ( & instruction. data ) ;
3832 accounts. extend_from_slice ( & instruction. accounts ) ;
3933 }
34+
4035 Ok ( Instruction {
4136 program_id : spl_token:: ID ,
4237 data,
@@ -102,7 +97,6 @@ async fn batch(token_program: Pubkey) {
10297 let owner_a = Keypair :: new ( ) ;
10398 let owner_b = Keypair :: new ( ) ;
10499 let owner_a_ta_a = Keypair :: new ( ) ;
105- let owner_a_ta_b = Keypair :: new ( ) ;
106100 let owner_b_ta_a = Keypair :: new ( ) ;
107101
108102 let create_owner_a_ta_a = system_instruction:: create_account (
@@ -126,13 +120,6 @@ async fn batch(token_program: Pubkey) {
126120 & owner_a. pubkey ( ) ,
127121 )
128122 . unwrap ( ) ;
129- let intialize_owner_a_ta_b = spl_token:: instruction:: initialize_account3 (
130- & token_program,
131- & owner_a_ta_b. pubkey ( ) ,
132- & mint_b. pubkey ( ) ,
133- & owner_a. pubkey ( ) ,
134- )
135- . unwrap ( ) ;
136123 let intialize_owner_b_ta_a = spl_token:: instruction:: initialize_account3 (
137124 & token_program,
138125 & owner_b_ta_a. pubkey ( ) ,
0 commit comments