@@ -5,7 +5,7 @@ mod setup;
55use {
66 mollusk_svm:: { result:: Check , Mollusk } ,
77 solana_sdk:: {
8- account:: { AccountSharedData , ReadableAccount } ,
8+ account:: { Account as SolanaAccount , ReadableAccount } ,
99 program_error:: ProgramError ,
1010 program_pack:: Pack ,
1111 pubkey:: Pubkey ,
@@ -24,44 +24,53 @@ fn success_init_after_close_account() {
2424 let destination = Pubkey :: new_unique ( ) ;
2525 let decimals = 9 ;
2626
27- let owner_account = AccountSharedData :: new ( 1_000_000_000 , 0 , & system_program:: id ( ) ) ;
27+ let owner_account = SolanaAccount :: new ( 1_000_000_000 , 0 , & system_program:: id ( ) ) ;
2828 let mint_account = setup:: setup_mint_account ( None , None , 0 , decimals) ;
2929 let token_account = setup:: setup_token_account ( & mint, & owner, 0 ) ;
3030
3131 let expected_destination_lamports = token_account. lamports ( ) ;
3232
3333 mollusk. process_and_validate_instruction_chain (
3434 & [
35- instruction:: close_account ( & spl_token:: id ( ) , & account, & destination, & owner, & [ ] )
36- . unwrap ( ) ,
37- system_instruction:: create_account (
38- & owner,
39- & account,
40- 1_000_000_000 ,
41- Account :: LEN as u64 ,
42- & spl_token:: id ( ) ,
35+ (
36+ & instruction:: close_account ( & spl_token:: id ( ) , & account, & destination, & owner, & [ ] )
37+ . unwrap ( ) ,
38+ & [ Check :: success ( ) ] ,
39+ ) ,
40+ (
41+ & system_instruction:: create_account (
42+ & owner,
43+ & account,
44+ 1_000_000_000 ,
45+ Account :: LEN as u64 ,
46+ & spl_token:: id ( ) ,
47+ ) ,
48+ & [ Check :: success ( ) ] ,
49+ ) ,
50+ (
51+ & instruction:: initialize_account ( & spl_token:: id ( ) , & account, & mint, & owner)
52+ . unwrap ( ) ,
53+ & [
54+ Check :: success ( ) ,
55+ // Account successfully re-initialized.
56+ Check :: account ( & account)
57+ . data ( setup:: setup_token_account ( & mint, & owner, 0 ) . data ( ) )
58+ . owner ( & spl_token:: id ( ) )
59+ . build ( ) ,
60+ // The destination should have the lamports from the closed account.
61+ Check :: account ( & destination)
62+ . lamports ( expected_destination_lamports)
63+ . build ( ) ,
64+ ] ,
4365 ) ,
44- instruction:: initialize_account ( & spl_token:: id ( ) , & account, & mint, & owner) . unwrap ( ) ,
4566 ] ,
4667 & [
4768 ( mint, mint_account) ,
4869 ( account, token_account) ,
4970 ( owner, owner_account) ,
50- ( destination, AccountSharedData :: default ( ) ) ,
71+ ( destination, SolanaAccount :: default ( ) ) ,
5172 mollusk. sysvars . keyed_account_for_rent_sysvar ( ) ,
5273 ] ,
53- & [
54- Check :: success ( ) ,
55- // Account successfully re-initialized.
56- Check :: account ( & account)
57- . data ( setup:: setup_token_account ( & mint, & owner, 0 ) . data ( ) )
58- . owner ( & spl_token:: id ( ) )
59- . build ( ) ,
60- // The destination should have the lamports from the closed account.
61- Check :: account ( & destination)
62- . lamports ( expected_destination_lamports)
63- . build ( ) ,
64- ] ,
6574 ) ;
6675}
6776
@@ -75,37 +84,46 @@ fn fail_init_after_close_account() {
7584 let destination = Pubkey :: new_unique ( ) ;
7685 let decimals = 9 ;
7786
78- let owner_account = AccountSharedData :: new ( 1_000_000_000 , 0 , & system_program:: id ( ) ) ;
87+ let owner_account = SolanaAccount :: new ( 1_000_000_000 , 0 , & system_program:: id ( ) ) ;
7988 let mint_account = setup:: setup_mint_account ( None , None , 0 , decimals) ;
8089 let token_account = setup:: setup_token_account ( & mint, & owner, 0 ) ;
8190
8291 let expected_destination_lamports = token_account. lamports ( ) ;
8392
8493 mollusk. process_and_validate_instruction_chain (
8594 & [
86- instruction:: close_account ( & spl_token:: id ( ) , & account, & destination, & owner, & [ ] )
87- . unwrap ( ) ,
88- system_instruction:: transfer ( & owner, & account, 1_000_000_000 ) ,
89- instruction:: initialize_account ( & spl_token:: id ( ) , & account, & mint, & owner) . unwrap ( ) ,
95+ (
96+ & instruction:: close_account ( & spl_token:: id ( ) , & account, & destination, & owner, & [ ] )
97+ . unwrap ( ) ,
98+ & [ Check :: success ( ) ] ,
99+ ) ,
100+ (
101+ & system_instruction:: transfer ( & owner, & account, 1_000_000_000 ) ,
102+ & [ Check :: success ( ) ] ,
103+ ) ,
104+ (
105+ & instruction:: initialize_account ( & spl_token:: id ( ) , & account, & mint, & owner)
106+ . unwrap ( ) ,
107+ & [
108+ Check :: err ( ProgramError :: InvalidAccountData ) ,
109+ // Account not re-initialized.
110+ Check :: account ( & account)
111+ . lamports ( 1_000_000_000 )
112+ . owner ( & system_program:: id ( ) )
113+ . build ( ) ,
114+ // The destination should have the lamports from the closed account.
115+ Check :: account ( & destination)
116+ . lamports ( expected_destination_lamports)
117+ . build ( ) ,
118+ ] ,
119+ ) ,
90120 ] ,
91121 & [
92122 ( mint, mint_account) ,
93123 ( account, token_account) ,
94124 ( owner, owner_account) ,
95- ( destination, AccountSharedData :: default ( ) ) ,
125+ ( destination, SolanaAccount :: default ( ) ) ,
96126 mollusk. sysvars . keyed_account_for_rent_sysvar ( ) ,
97127 ] ,
98- & [
99- Check :: err ( ProgramError :: InvalidAccountData ) ,
100- // Account not re-initialized.
101- Check :: account ( & account)
102- . lamports ( 1_000_000_000 )
103- . owner ( & system_program:: id ( ) )
104- . build ( ) ,
105- // The destination should have the lamports from the closed account.
106- Check :: account ( & destination)
107- . lamports ( expected_destination_lamports)
108- . build ( ) ,
109- ] ,
110128 ) ;
111129}
0 commit comments