Skip to content

Commit acde5e7

Browse files
committed
add destination checks
1 parent 6bcb378 commit acde5e7

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

program/tests/close_account.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg(feature = "test-sbf")]
1+
// #![cfg(feature = "test-sbf")]
22

33
mod setup;
44

@@ -21,15 +21,19 @@ fn success_init_after_close_account() {
2121
let owner = Pubkey::new_unique();
2222
let mint = Pubkey::new_unique();
2323
let account = Pubkey::new_unique();
24+
let destination = Pubkey::new_unique();
2425
let decimals = 9;
2526

2627
let owner_account = AccountSharedData::new(1_000_000_000, 0, &system_program::id());
2728
let mint_account = setup::setup_mint_account(None, None, 0, decimals);
2829
let token_account = setup::setup_token_account(&mint, &owner, 0);
2930

31+
let expected_destination_lamports = token_account.lamports();
32+
3033
mollusk.process_and_validate_instruction_chain(
3134
&[
32-
instruction::close_account(&spl_token::id(), &account, &owner, &owner, &[]).unwrap(),
35+
instruction::close_account(&spl_token::id(), &account, &destination, &owner, &[])
36+
.unwrap(),
3337
system_instruction::create_account(
3438
&owner,
3539
&account,
@@ -43,15 +47,20 @@ fn success_init_after_close_account() {
4347
(mint, mint_account),
4448
(account, token_account),
4549
(owner, owner_account),
50+
(destination, AccountSharedData::default()),
4651
mollusk.sysvars.keyed_account_for_rent_sysvar(),
4752
],
4853
&[
4954
Check::success(),
50-
// Account successfully initialized.
55+
// Account successfully re-initialized.
5156
Check::account(&account)
5257
.data(setup::setup_token_account(&mint, &owner, 0).data())
5358
.owner(&spl_token::id())
5459
.build(),
60+
// The destination should have the lamports from the closed account.
61+
Check::account(&destination)
62+
.lamports(expected_destination_lamports)
63+
.build(),
5564
],
5665
);
5766
}
@@ -63,31 +72,40 @@ fn fail_init_after_close_account() {
6372
let owner = Pubkey::new_unique();
6473
let mint = Pubkey::new_unique();
6574
let account = Pubkey::new_unique();
75+
let destination = Pubkey::new_unique();
6676
let decimals = 9;
6777

6878
let owner_account = AccountSharedData::new(1_000_000_000, 0, &system_program::id());
6979
let mint_account = setup::setup_mint_account(None, None, 0, decimals);
7080
let token_account = setup::setup_token_account(&mint, &owner, 0);
7181

82+
let expected_destination_lamports = token_account.lamports();
83+
7284
mollusk.process_and_validate_instruction_chain(
7385
&[
74-
instruction::close_account(&spl_token::id(), &account, &owner, &owner, &[]).unwrap(),
86+
instruction::close_account(&spl_token::id(), &account, &destination, &owner, &[])
87+
.unwrap(),
7588
system_instruction::transfer(&owner, &account, 1_000_000_000),
7689
instruction::initialize_account(&spl_token::id(), &account, &mint, &owner).unwrap(),
7790
],
7891
&[
7992
(mint, mint_account),
8093
(account, token_account),
8194
(owner, owner_account),
95+
(destination, AccountSharedData::default()),
8296
mollusk.sysvars.keyed_account_for_rent_sysvar(),
8397
],
8498
&[
8599
Check::err(ProgramError::InvalidAccountData),
86-
// Account not initialized.
100+
// Account not re-initialized.
87101
Check::account(&account)
88102
.lamports(1_000_000_000)
89103
.owner(&system_program::id())
90104
.build(),
105+
// The destination should have the lamports from the closed account.
106+
Check::account(&destination)
107+
.lamports(expected_destination_lamports)
108+
.build(),
91109
],
92110
);
93111
}

0 commit comments

Comments
 (0)