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

Adds --blockhash arg to Close #7456

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions token/cli/src/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,7 @@ pub fn app<'a>(
.arg(owner_address_arg())
.arg(multisig_signer_arg())
.nonce_args(true)
.offline_args(),
)
.subcommand(
SubCommand::with_name(CommandName::CloseMint.into())
Expand Down
56 changes: 46 additions & 10 deletions token/cli/tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3129,14 +3129,16 @@ async fn do_offline_multisig_transfer(
.await
.unwrap();

let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = Arc::new(
ProgramOfflineClient::new(blockhash, ProgramRpcClientSendTransaction),
);
let offline_program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> =
Arc::new(ProgramOfflineClient::new(
blockhash,
ProgramRpcClientSendTransaction,
));
let mut args = vec![
"spl-token".to_string(),
CommandName::Transfer.as_ref().to_string(),
token.to_string(),
"10".to_string(),
"100".to_string(),
destination.to_string(),
"--blockhash".to_string(),
blockhash.to_string(),
Expand Down Expand Up @@ -3166,7 +3168,7 @@ async fn do_offline_multisig_transfer(
args.push("--with-compute-unit-limit".to_string());
args.push(10_000.to_string());
}
config.program_client = program_client;
config.program_client = offline_program_client;
let result = exec_test_cmd(&config, &args).await.unwrap();
// the provided signer has a signature, denoted by the pubkey followed
// by "=" and the signature
Expand All @@ -3190,15 +3192,15 @@ async fn do_offline_multisig_transfer(
assert!(!absent_signers.contains(&token.to_string()));

// now send the transaction
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = Arc::new(
let rpc_program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = Arc::new(
ProgramRpcClient::new(config.rpc_client.clone(), ProgramRpcClientSendTransaction),
);
config.program_client = program_client;
config.program_client = rpc_program_client;
let mut args = vec![
"spl-token".to_string(),
CommandName::Transfer.as_ref().to_string(),
token.to_string(),
"10".to_string(),
"100".to_string(),
destination.to_string(),
"--blockhash".to_string(),
blockhash.to_string(),
Expand Down Expand Up @@ -3233,12 +3235,46 @@ async fn do_offline_multisig_transfer(

let account = config.rpc_client.get_account(&source).await.unwrap();
let token_account = StateWithExtensionsOwned::<Account>::unpack(account.data).unwrap();
let amount = spl_token::ui_amount_to_amount(90.0, TEST_DECIMALS);
let amount = spl_token::ui_amount_to_amount(0.0, TEST_DECIMALS);
assert_eq!(token_account.base.amount, amount);
let account = config.rpc_client.get_account(&destination).await.unwrap();
let token_account = StateWithExtensionsOwned::<Account>::unpack(account.data).unwrap();
let amount = spl_token::ui_amount_to_amount(10.0, TEST_DECIMALS);
let amount = spl_token::ui_amount_to_amount(100.0, TEST_DECIMALS);
assert_eq!(token_account.base.amount, amount);

// get new nonce
let nonce_account = config.rpc_client.get_account(&nonce).await.unwrap();
let blockhash = Hash::new(&nonce_account.data[start_hash_index..start_hash_index + 32]);
let mut args = vec![
"spl-token".to_string(),
CommandName::Close.as_ref().to_string(),
"--address".to_string(),
source.to_string(),
"--blockhash".to_string(),
blockhash.to_string(),
"--nonce".to_string(),
nonce.to_string(),
"--nonce-authority".to_string(),
fee_payer_keypair_file.path().to_str().unwrap().to_string(),
"--multisig-signer".to_string(),
multisig_paths[1].path().to_str().unwrap().to_string(),
"--multisig-signer".to_string(),
multisig_paths[2].path().to_str().unwrap().to_string(),
"--owner".to_string(),
multisig_pubkey.to_string(),
"--fee-payer".to_string(),
fee_payer_keypair_file.path().to_str().unwrap().to_string(),
"--program-id".to_string(),
program_id.to_string(),
];
if let Some(compute_unit_price) = compute_unit_price {
args.push("--with-compute-unit-price".to_string());
args.push(compute_unit_price.to_string());
args.push("--with-compute-unit-limit".to_string());
args.push(10_000.to_string());
}
exec_test_cmd(&config, &args).await.unwrap();
let _ = config.rpc_client.get_account(&source).await.unwrap_err();
}
}

Expand Down
Loading