33//! Program state processor tests
44
55use {
6- mollusk_svm:: { result :: ProgramResult as MolluskResult , Mollusk } ,
6+ mollusk_svm:: Mollusk ,
77 serial_test:: serial,
88 solana_sdk:: {
9- account:: { create_account_for_test, Account as SolanaAccount , AccountSharedData } ,
9+ account:: {
10+ create_account_for_test, Account as SolanaAccount , AccountSharedData , ReadableAccount ,
11+ } ,
1012 account_info:: { AccountInfo , IntoAccountInfo } ,
1113 entrypoint:: ProgramResult ,
1214 instruction:: Instruction ,
@@ -43,10 +45,8 @@ fn do_process_instruction(
4345 instruction : Instruction ,
4446 mut accounts : Vec < & mut SolanaAccount > ,
4547) -> ProgramResult {
46- let mut instruction_accounts = Vec :: new ( ) ;
47-
4848 // Prepare accounts for mollusk.
49- instruction
49+ let instruction_accounts : Vec < ( Pubkey , AccountSharedData ) > = instruction
5050 . accounts
5151 . iter ( )
5252 . zip ( & accounts)
@@ -56,26 +56,24 @@ fn do_process_instruction(
5656 AccountSharedData :: from ( ( * account) . clone ( ) ) ,
5757 )
5858 } )
59- . for_each ( |( pubkey, account) | {
60- instruction_accounts. push ( ( pubkey, account) ) ;
61- } ) ;
59+ . collect ( ) ;
6260
6361 let mollusk = Mollusk :: new ( & spl_token:: ID , "spl_token" ) ;
64- let result = mollusk. process_and_validate_instruction ( & instruction, & instruction_accounts, & [ ] ) ;
62+ let result = mollusk. process_instruction ( & instruction, & instruction_accounts) ;
6563
6664 // Update accounts after the instruction is processed.
67- for ( original, ( _, updated) ) in accounts. iter_mut ( ) . zip ( result. resulting_accounts . iter ( ) ) {
68- let account = SolanaAccount :: from ( updated. clone ( ) ) ;
69- original. data = account. data ;
70- original. lamports = account. lamports ;
71- original. owner = account. owner ;
65+ for ( original, ( _, updated) ) in accounts
66+ . iter_mut ( )
67+ . zip ( result. resulting_accounts . into_iter ( ) )
68+ {
69+ original. data = updated. data ( ) . to_vec ( ) ;
70+ original. lamports = updated. lamports ( ) ;
71+ original. owner = * updated. owner ( ) ;
7272 }
7373
74- match result. program_result {
75- MolluskResult :: Success => Ok ( ( ) ) ,
76- MolluskResult :: Failure ( err) => Err ( err) ,
77- MolluskResult :: UnknownError ( err) => panic ! ( "Unknown error: {:?}" , err) ,
78- }
74+ result
75+ . raw_result
76+ . map_err ( |e| ProgramError :: try_from ( e) . unwrap ( ) )
7977}
8078
8179fn do_process_instruction_dups (
@@ -101,34 +99,31 @@ fn do_process_instruction_dups(
10199 } ) ;
102100
103101 let mollusk = Mollusk :: new ( & spl_token:: ID , "spl_token" ) ;
104- let result = mollusk. process_and_validate_instruction ( & instruction, & dedup_accounts, & [ ] ) ;
102+ let result = mollusk. process_instruction ( & instruction, & dedup_accounts) ;
105103
106104 // Update accounts after the instruction is processed.
107105 result
108106 . resulting_accounts
109- . iter ( )
107+ . into_iter ( )
110108 . for_each ( |( pubkey, account) | {
111- let account = SolanaAccount :: from ( account. clone ( ) ) ;
112- let account_info = cached_accounts. get ( pubkey) . unwrap ( ) ;
113- if account. data . is_empty ( ) {
109+ let account_info = cached_accounts. get ( & pubkey) . unwrap ( ) ;
110+ if account. data ( ) . is_empty ( ) {
114111 // When the account is closed, the tests expect the data to
115112 // be zeroed.
116113 account_info. try_borrow_mut_data ( ) . unwrap ( ) . fill ( 0 ) ;
117114 } else {
118115 account_info
119116 . try_borrow_mut_data ( )
120117 . unwrap ( )
121- . copy_from_slice ( & account. data ) ;
118+ . copy_from_slice ( account. data ( ) ) ;
122119 }
123- * * account_info. try_borrow_mut_lamports ( ) . unwrap ( ) = account. lamports ;
124- account_info. assign ( & account. owner ) ;
120+ * * account_info. try_borrow_mut_lamports ( ) . unwrap ( ) = account. lamports ( ) ;
121+ account_info. assign ( account. owner ( ) ) ;
125122 } ) ;
126123
127- match result. program_result {
128- MolluskResult :: Success => Ok ( ( ) ) ,
129- MolluskResult :: Failure ( err) => Err ( err) ,
130- MolluskResult :: UnknownError ( err) => panic ! ( "Unknown error: {:?}" , err) ,
131- }
124+ result
125+ . raw_result
126+ . map_err ( |e| ProgramError :: try_from ( e) . unwrap ( ) )
132127}
133128
134129fn set_expected_data ( expected_data : Vec < u8 > ) {
0 commit comments