From 159d96760c957fc34d923ec42a0b0053df1c0279 Mon Sep 17 00:00:00 2001 From: brooks Date: Mon, 4 Nov 2024 15:15:30 -0500 Subject: [PATCH 1/2] Adds --blockhash arg to Close --- token/cli/src/clap_app.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 83183d88aa5..a57b4c93e68 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -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()) From bb7437b785aab7ff908b3c56697c04e0449a1e53 Mon Sep 17 00:00:00 2001 From: Jon C Date: Mon, 11 Nov 2024 20:34:50 +0100 Subject: [PATCH 2/2] Add test for closing account with nonce blockhash --- token/cli/tests/command.rs | 56 +++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/token/cli/tests/command.rs b/token/cli/tests/command.rs index 64b4b33e1ce..34bd1e7f9f7 100644 --- a/token/cli/tests/command.rs +++ b/token/cli/tests/command.rs @@ -3129,14 +3129,16 @@ async fn do_offline_multisig_transfer( .await .unwrap(); - let program_client: Arc> = Arc::new( - ProgramOfflineClient::new(blockhash, ProgramRpcClientSendTransaction), - ); + let offline_program_client: Arc> = + 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(), @@ -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 @@ -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> = Arc::new( + let rpc_program_client: Arc> = 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(), @@ -3233,12 +3235,46 @@ async fn do_offline_multisig_transfer( let account = config.rpc_client.get_account(&source).await.unwrap(); let token_account = StateWithExtensionsOwned::::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::::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(); } }