Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 0ddbd71

Browse files
committed
token-cli: test close account
1 parent 086b115 commit 0ddbd71

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

token/cli/src/main.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5171,6 +5171,73 @@ mod tests {
51715171
assert_eq!(ui_account.token_amount.amount, "90");
51725172
}
51735173

5174+
#[tokio::test]
5175+
#[serial]
5176+
async fn close_account() {
5177+
let (test_validator, payer) = new_validator_for_test().await;
5178+
for program_id in VALID_TOKEN_PROGRAM_IDS.iter() {
5179+
let config = test_config_with_default_signer(&test_validator, &payer, program_id);
5180+
5181+
let native_mint = Token::new_native(
5182+
config.program_client.clone(),
5183+
program_id,
5184+
config.fee_payer().unwrap().clone(),
5185+
);
5186+
do_create_native_mint(&config, program_id, &payer).await;
5187+
native_mint
5188+
.get_or_create_associated_account_info(&payer.pubkey())
5189+
.await
5190+
.unwrap();
5191+
5192+
let token = create_token(&config, &payer).await;
5193+
5194+
let system_recipient = Keypair::new().pubkey();
5195+
let wsol_recipient = native_mint.get_associated_token_address(&payer.pubkey());
5196+
5197+
let token_rent_amount = config
5198+
.rpc_client
5199+
.get_account(&create_auxiliary_account(&config, &payer, token).await)
5200+
.await
5201+
.unwrap()
5202+
.lamports;
5203+
5204+
for recipient in [system_recipient, wsol_recipient] {
5205+
let base_balance = config
5206+
.rpc_client
5207+
.get_account(&recipient)
5208+
.await
5209+
.map(|account| account.lamports)
5210+
.unwrap_or(0);
5211+
5212+
let source = create_auxiliary_account(&config, &payer, token).await;
5213+
5214+
process_test_command(
5215+
&config,
5216+
&payer,
5217+
&[
5218+
"spl-token",
5219+
CommandName::Close.into(),
5220+
"--address",
5221+
&source.to_string(),
5222+
"--recipient",
5223+
&recipient.to_string(),
5224+
],
5225+
)
5226+
.await
5227+
.unwrap();
5228+
5229+
let recipient_data = config.rpc_client.get_account(&recipient).await.unwrap();
5230+
5231+
assert_eq!(recipient_data.lamports, base_balance + token_rent_amount);
5232+
if recipient == wsol_recipient {
5233+
let recipient_account =
5234+
StateWithExtensionsOwned::<Account>::unpack(recipient_data.data).unwrap();
5235+
assert_eq!(recipient_account.base.amount, token_rent_amount);
5236+
}
5237+
}
5238+
}
5239+
}
5240+
51745241
#[tokio::test]
51755242
#[serial]
51765243
async fn close_wrapped_sol_account() {

0 commit comments

Comments
 (0)