diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 9ffb705ce0a27d..1b59bbad862979 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -2292,7 +2292,7 @@ mod tests { system_program, transaction::TransactionError, }; - use std::{collections::HashMap, path::PathBuf}; + use std::{collections::HashMap, path::PathBuf, rc::Rc}; fn make_tmp_path(name: &str) -> String { let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string()); @@ -2819,7 +2819,7 @@ mod tests { let keypair = Keypair::new(); let pubkey = keypair.pubkey().to_string(); - config.keypair = keypair; + config.keypair = keypair.into(); config.command = CliCommand::Address; assert_eq!(process_command(&config).unwrap(), pubkey); @@ -2879,7 +2879,7 @@ mod tests { let bob_pubkey = bob_keypair.pubkey(); let custodian = Pubkey::new_rand(); config.command = CliCommand::CreateStakeAccount { - stake_account: bob_keypair.into(), + stake_account: Rc::new(bob_keypair.into()), seed: None, staker: None, withdrawer: None, @@ -2937,7 +2937,7 @@ mod tests { blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, - split_stake_account: split_stake_account.into(), + split_stake_account: Rc::new(split_stake_account.into()), seed: None, lamports: 1234, fee_payer: None, diff --git a/cli/src/nonce.rs b/cli/src/nonce.rs index 92d2fefc370911..d62663c7937c5f 100644 --- a/cli/src/nonce.rs +++ b/cli/src/nonce.rs @@ -615,9 +615,10 @@ mod tests { account::Account, hash::hash, nonce_state::{Meta as NonceMeta, NonceState}, - signature::{read_keypair_file, write_keypair}, + signature::{read_keypair_file, write_keypair, Keypair}, system_program, }; + use std::rc::Rc; use tempfile::NamedTempFile; fn make_tmp_file() -> (String, NamedTempFile) { @@ -692,7 +693,7 @@ mod tests { parse_command(&test_create_nonce_account).unwrap(), CliCommandInfo { command: CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&keypair_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&keypair_file).unwrap().into()), seed: None, nonce_authority: None, lamports: 50, @@ -715,7 +716,7 @@ mod tests { parse_command(&test_create_nonce_account).unwrap(), CliCommandInfo { command: CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&keypair_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&keypair_file).unwrap().into()), seed: None, nonce_authority: Some( read_keypair_file(&authority_keypair_file).unwrap().pubkey() diff --git a/cli/src/stake.rs b/cli/src/stake.rs index 25f31b86df1a6a..1d674369f21bea 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -1448,8 +1448,11 @@ mod tests { use solana_sdk::{ fee_calculator::FeeCalculator, hash::Hash, - signature::{keypair_from_seed, read_keypair_file, write_keypair, KeypairUtil, Presigner}, + signature::{ + keypair_from_seed, read_keypair_file, write_keypair, Keypair, KeypairUtil, Presigner, + }, }; + use std::rc::Rc; use tempfile::NamedTempFile; fn make_tmp_file() -> (String, NamedTempFile) { @@ -1798,7 +1801,7 @@ mod tests { parse_command(&test_create_stake_account).unwrap(), CliCommandInfo { command: CliCommand::CreateStakeAccount { - stake_account: stake_account_keypair.into(), + stake_account: Rc::new(stake_account_keypair.into()), seed: None, staker: Some(authorized), withdrawer: Some(authorized), @@ -1837,7 +1840,7 @@ mod tests { parse_command(&test_create_stake_account2).unwrap(), CliCommandInfo { command: CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&keypair_file).unwrap().into()), seed: None, staker: None, withdrawer: None, @@ -1888,7 +1891,7 @@ mod tests { parse_command(&test_create_stake_account2).unwrap(), CliCommandInfo { command: CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&keypair_file).unwrap().into()), seed: None, staker: None, withdrawer: None, @@ -2125,8 +2128,6 @@ mod tests { let (fee_payer_keypair_file, mut fee_payer_tmp_file) = make_tmp_file(); let fee_payer_keypair = Keypair::new(); write_keypair(&fee_payer_keypair, fee_payer_tmp_file.as_file_mut()).unwrap(); - let fee_payer_pubkey = fee_payer_keypair.pubkey(); - let fee_payer_string = fee_payer_pubkey.to_string(); let test_delegate_stake = test_commands.clone().get_matches_from(vec![ "test", "delegate-stake", @@ -2477,9 +2478,11 @@ mod tests { blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, - split_stake_account: read_keypair_file(&split_stake_account_keypair_file) - .unwrap() - .into(), + split_stake_account: Rc::new( + read_keypair_file(&split_stake_account_keypair_file) + .unwrap() + .into(), + ), seed: None, lamports: 50, fee_payer: None, @@ -2536,9 +2539,11 @@ mod tests { blockhash_query: BlockhashQuery::FeeCalculator(nonce_hash), nonce_account: Some(nonce_account.into()), nonce_authority: Some(Presigner::new(&nonce_auth_pubkey, &nonce_sig).into()), - split_stake_account: read_keypair_file(&split_stake_account_keypair_file) - .unwrap() - .into(), + split_stake_account: Rc::new( + read_keypair_file(&split_stake_account_keypair_file) + .unwrap() + .into(), + ), seed: None, lamports: 50, fee_payer: Some(Presigner::new(&nonce_auth_pubkey, &nonce_sig).into()), diff --git a/cli/tests/nonce.rs b/cli/tests/nonce.rs index ce7856bac84d52..f5ae4a074546c8 100644 --- a/cli/tests/nonce.rs +++ b/cli/tests/nonce.rs @@ -1,6 +1,4 @@ -use solana_cli::cli::{ - process_command, request_and_confirm_airdrop, CliCommand, CliConfig, SigningAuthority, -}; +use solana_cli::cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig}; use solana_client::rpc_client::RpcClient; use solana_faucet::faucet::run_local_faucet; use solana_sdk::{ @@ -15,6 +13,7 @@ use std::sync::mpsc::channel; #[cfg(test)] use solana_core::validator::new_validator_for_tests; +use std::rc::Rc; use std::thread::sleep; use std::time::Duration; @@ -141,7 +140,7 @@ fn test_nonce_with_authority() { remove_dir_all(ledger_path).unwrap(); } -fn read_keypair_from_option(keypair_file: &Option<&str>) -> Option { +fn read_keypair_from_option(keypair_file: &Option<&str>) -> Option> { keypair_file.map(|akf| read_keypair_file(&akf).unwrap().into()) } @@ -172,10 +171,9 @@ fn full_battery_tests( // Create nonce account config_payer.command = CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&nonce_keypair_file).unwrap().into()), seed, - nonce_authority: read_keypair_from_option(&authority_keypair_file) - .map(|na: SigningAuthority| na.pubkey()), + nonce_authority: read_keypair_from_option(&authority_keypair_file), lamports: 1000, }; diff --git a/cli/tests/pay.rs b/cli/tests/pay.rs index eda6a073aeda54..e2131f95041a11 100644 --- a/cli/tests/pay.rs +++ b/cli/tests/pay.rs @@ -18,6 +18,7 @@ use std::sync::mpsc::channel; #[cfg(test)] use solana_core::validator::new_validator_for_tests; +use std::rc::Rc; use std::thread::sleep; use std::time::Duration; use tempfile::NamedTempFile; @@ -303,11 +304,10 @@ fn test_offline_pay_tx() { check_balance(50, &rpc_client, &config_online.keypair.pubkey()); check_balance(0, &rpc_client, &bob_pubkey); - let (blockhash, signers) = parse_sign_only_reply_string(&sig_response); + let (blockhash, _signers) = parse_sign_only_reply_string(&sig_response); config_online.command = CliCommand::Pay(PayCommand { lamports: 10, to: bob_pubkey, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), ..PayCommand::default() }); @@ -357,7 +357,7 @@ fn test_nonced_pay_tx() { let (nonce_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&nonce_account, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&nonce_keypair_file).unwrap().into()), seed: None, nonce_authority: Some(config.keypair.pubkey()), lamports: minimum_nonce_balance, diff --git a/cli/tests/request_airdrop.rs b/cli/tests/request_airdrop.rs index 3a4b278c0e3545..10b076dd9c0032 100644 --- a/cli/tests/request_airdrop.rs +++ b/cli/tests/request_airdrop.rs @@ -2,7 +2,6 @@ use solana_cli::cli::{process_command, CliCommand, CliConfig}; use solana_client::rpc_client::RpcClient; use solana_core::validator::new_validator_for_tests; use solana_faucet::faucet::run_local_faucet; -use solana_sdk::signature::KeypairUtil; use std::fs::remove_dir_all; use std::sync::mpsc::channel; diff --git a/cli/tests/stake.rs b/cli/tests/stake.rs index 890a97a01a9163..5303edfe817352 100644 --- a/cli/tests/stake.rs +++ b/cli/tests/stake.rs @@ -1,3 +1,4 @@ +use solana_clap_utils::keypair::presigner_from_pubkey_sigs; use solana_cli::{ cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig}, offline::{parse_sign_only_reply_string, BlockhashQuery}, @@ -20,6 +21,7 @@ use std::sync::mpsc::channel; use solana_core::validator::{ new_validator_for_tests, new_validator_for_tests_ex, new_validator_for_tests_with_vote_pubkey, }; +use std::rc::Rc; use std::thread::sleep; use std::time::Duration; @@ -77,14 +79,13 @@ fn test_stake_delegation_force() { let (stake_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&stake_keypair, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&stake_keypair_file).unwrap().into()), seed: None, staker: None, withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -100,7 +101,6 @@ fn test_stake_delegation_force() { stake_authority: None, force: false, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -115,7 +115,6 @@ fn test_stake_delegation_force() { stake_authority: None, force: true, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -169,14 +168,13 @@ fn test_seed_stake_delegation_and_deactivation() { // Create stake account with a seed, uses the validator config as the base, // which is nice ;) config_validator.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&validator_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&validator_keypair_file).unwrap().into()), seed: Some("hi there".to_string()), staker: None, withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -192,7 +190,6 @@ fn test_seed_stake_delegation_and_deactivation() { stake_authority: None, force: false, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -205,7 +202,6 @@ fn test_seed_stake_delegation_and_deactivation() { stake_account_pubkey: stake_address, stake_authority: None, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -250,14 +246,13 @@ fn test_stake_delegation_and_deactivation() { // Create stake account config_validator.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&stake_keypair_file).unwrap().into()), seed: None, staker: None, withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -273,7 +268,6 @@ fn test_stake_delegation_and_deactivation() { stake_authority: None, force: false, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -286,7 +280,6 @@ fn test_stake_delegation_and_deactivation() { stake_account_pubkey: config_stake.keypair.pubkey(), stake_authority: None, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -350,14 +343,13 @@ fn test_offline_stake_delegation_and_deactivation() { // Create stake account config_validator.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&stake_keypair_file).unwrap().into()), seed: None, staker: Some(config_offline.keypair.pubkey().into()), withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -374,7 +366,6 @@ fn test_offline_stake_delegation_and_deactivation() { stake_authority: None, force: false, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()), nonce_account: None, nonce_authority: None, @@ -382,17 +373,18 @@ fn test_offline_stake_delegation_and_deactivation() { }; let sig_response = process_command(&config_offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sig_response); + let offline_presigner = + presigner_from_pubkey_sigs(&config_offline.keypair.pubkey(), &signers).unwrap(); config_payer.command = CliCommand::DelegateStake { stake_account_pubkey: config_stake.keypair.pubkey(), vote_account_pubkey: vote_pubkey, - stake_authority: Some(config_offline.keypair.pubkey().into()), + stake_authority: Some(offline_presigner.clone().into()), force: false, sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()), nonce_account: None, nonce_authority: None, - fee_payer: Some(config_offline.keypair.pubkey().into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config_payer).unwrap(); @@ -402,7 +394,6 @@ fn test_offline_stake_delegation_and_deactivation() { stake_account_pubkey: config_stake.keypair.pubkey(), stake_authority: None, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()), nonce_account: None, nonce_authority: None, @@ -410,15 +401,16 @@ fn test_offline_stake_delegation_and_deactivation() { }; let sig_response = process_command(&config_offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sig_response); + let offline_presigner = + presigner_from_pubkey_sigs(&config_offline.keypair.pubkey(), &signers).unwrap(); config_payer.command = CliCommand::DeactivateStake { stake_account_pubkey: config_stake.keypair.pubkey(), - stake_authority: Some(config_offline.keypair.pubkey().into()), + stake_authority: Some(offline_presigner.clone().into()), sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: None, nonce_authority: None, - fee_payer: Some(config_offline.keypair.pubkey().into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config_payer).unwrap(); @@ -439,6 +431,8 @@ fn test_nonced_stake_delegation_and_deactivation() { let rpc_client = RpcClient::new_socket(leader_data.rpc); let mut config = CliConfig::default(); + let (config_keypair_file, mut tmp_file) = make_tmp_file(); + write_keypair(&config.keypair, tmp_file.as_file_mut()).unwrap(); config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port()); let minimum_nonce_balance = rpc_client @@ -453,14 +447,13 @@ fn test_nonced_stake_delegation_and_deactivation() { let (stake_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&stake_keypair, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&stake_keypair_file).unwrap().into()), seed: None, staker: None, withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -474,7 +467,7 @@ fn test_nonced_stake_delegation_and_deactivation() { let (nonce_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&nonce_account, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&nonce_keypair_file).unwrap().into()), seed: None, nonce_authority: Some(config.keypair.pubkey()), lamports: minimum_nonce_balance, @@ -496,7 +489,6 @@ fn test_nonced_stake_delegation_and_deactivation() { stake_authority: None, force: false, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()), nonce_account: Some(nonce_account.pubkey()), nonce_authority: None, @@ -513,15 +505,13 @@ fn test_nonced_stake_delegation_and_deactivation() { }; // Deactivate stake - let config_keypair = Keypair::from_bytes(&config.keypair.to_bytes()).unwrap(); config.command = CliCommand::DeactivateStake { stake_account_pubkey: stake_keypair.pubkey(), stake_authority: None, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::FeeCalculator(nonce_hash), nonce_account: Some(nonce_account.pubkey()), - nonce_authority: Some(config_keypair.into()), + nonce_authority: Some(read_keypair_file(&config_keypair_file).unwrap().into()), fee_payer: None, }; process_command(&config).unwrap(); @@ -567,14 +557,13 @@ fn test_stake_authorize() { let (stake_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&stake_keypair, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&stake_keypair_file).unwrap().into()), seed: None, staker: None, withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -594,7 +583,6 @@ fn test_stake_authorize() { stake_authorize: StakeAuthorize::Staker, authority: None, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -619,7 +607,6 @@ fn test_stake_authorize() { stake_authorize: StakeAuthorize::Staker, authority: Some(read_keypair_file(&online_authority_file).unwrap().into()), sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -646,7 +633,6 @@ fn test_stake_authorize() { stake_authorize: StakeAuthorize::Staker, authority: Some(read_keypair_file(&offline_authority_file).unwrap().into()), sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()), nonce_account: None, nonce_authority: None, @@ -654,17 +640,18 @@ fn test_stake_authorize() { }; let sign_reply = process_command(&config_offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sign_reply); + let offline_presigner = + presigner_from_pubkey_sigs(&offline_authority_pubkey, &signers).unwrap(); config.command = CliCommand::StakeAuthorize { stake_account_pubkey, new_authorized_pubkey: nonced_authority_pubkey, stake_authorize: StakeAuthorize::Staker, - authority: Some(offline_authority_pubkey.into()), + authority: Some(offline_presigner.clone().into()), sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: None, nonce_authority: None, - fee_payer: Some(offline_authority_pubkey.into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config).unwrap(); let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap(); @@ -683,7 +670,7 @@ fn test_stake_authorize() { let (nonce_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&nonce_account, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&nonce_keypair_file).unwrap().into()), seed: None, nonce_authority: Some(config_offline.keypair.pubkey()), lamports: minimum_nonce_balance, @@ -709,7 +696,6 @@ fn test_stake_authorize() { stake_authorize: StakeAuthorize::Staker, authority: Some(read_keypair_file(&nonced_authority_file).unwrap().into()), sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()), nonce_account: Some(nonce_account.pubkey()), nonce_authority: None, @@ -718,17 +704,20 @@ fn test_stake_authorize() { let sign_reply = process_command(&config_offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sign_reply); assert_eq!(blockhash, nonce_hash); + let offline_presigner = + presigner_from_pubkey_sigs(&offline_authority_pubkey, &signers).unwrap(); + let nonced_authority_presigner = + presigner_from_pubkey_sigs(&nonced_authority_pubkey, &signers).unwrap(); config.command = CliCommand::StakeAuthorize { stake_account_pubkey, new_authorized_pubkey: online_authority_pubkey, stake_authorize: StakeAuthorize::Staker, - authority: Some(nonced_authority_pubkey.into()), + authority: Some(nonced_authority_presigner.clone().into()), sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: Some(nonce_account.pubkey()), - nonce_authority: Some(offline_authority_pubkey.into()), - fee_payer: Some(offline_authority_pubkey.into()), + nonce_authority: Some(offline_presigner.clone().into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config).unwrap(); let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap(); @@ -797,14 +786,13 @@ fn test_stake_authorize_with_fee_payer() { let (stake_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&stake_keypair, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&stake_keypair_file).unwrap().into()), seed: None, staker: None, withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -826,7 +814,6 @@ fn test_stake_authorize_with_fee_payer() { stake_authorize: StakeAuthorize::Staker, authority: None, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -855,7 +842,6 @@ fn test_stake_authorize_with_fee_payer() { stake_authorize: StakeAuthorize::Staker, authority: None, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()), nonce_account: None, nonce_authority: None, @@ -863,17 +849,17 @@ fn test_stake_authorize_with_fee_payer() { }; let sign_reply = process_command(&config_offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sign_reply); + let offline_presigner = presigner_from_pubkey_sigs(&offline_pubkey, &signers).unwrap(); config.command = CliCommand::StakeAuthorize { stake_account_pubkey, new_authorized_pubkey: payer_pubkey, stake_authorize: StakeAuthorize::Staker, - authority: Some(offline_pubkey.into()), + authority: Some(offline_presigner.clone().into()), sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: None, nonce_authority: None, - fee_payer: Some(offline_pubkey.into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config).unwrap(); // `config`'s balance again has not changed @@ -928,19 +914,18 @@ fn test_stake_split() { let minimum_stake_balance = rpc_client .get_minimum_balance_for_rent_exemption(std::mem::size_of::()) .unwrap(); - let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap(); + let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap().into(); let stake_account_pubkey = stake_keypair.pubkey(); let (stake_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&stake_keypair, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&stake_keypair_file).unwrap().into()), seed: None, staker: Some(offline_pubkey), withdrawer: Some(offline_pubkey), lockup: Lockup::default(), lamports: 10 * minimum_stake_balance, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -958,12 +943,12 @@ fn test_stake_split() { let minimum_nonce_balance = rpc_client .get_minimum_balance_for_rent_exemption(NonceState::size()) .unwrap(); - let nonce_account = keypair_from_seed(&[1u8; 32]).unwrap(); + let nonce_account = keypair_from_seed(&[1u8; 32]).unwrap().into(); let nonce_account_pubkey = nonce_account.pubkey(); let (nonce_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&nonce_account, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&nonce_keypair_file).unwrap().into()), seed: None, nonce_authority: Some(offline_pubkey), lamports: minimum_nonce_balance, @@ -980,7 +965,7 @@ fn test_stake_split() { }; // Nonced offline split - let split_account = keypair_from_seed(&[2u8; 32]).unwrap(); + let split_account = keypair_from_seed(&[2u8; 32]).unwrap().into(); let (split_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&split_account, tmp_file.as_file_mut()).unwrap(); check_balance(0, &rpc_client, &split_account.pubkey()); @@ -988,29 +973,28 @@ fn test_stake_split() { stake_account_pubkey: stake_account_pubkey, stake_authority: None, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()), nonce_account: Some(nonce_account_pubkey), nonce_authority: None, - split_stake_account: read_keypair_file(&split_keypair_file).unwrap().into(), + split_stake_account: Rc::new(read_keypair_file(&split_keypair_file).unwrap().into()), seed: None, lamports: 2 * minimum_stake_balance, fee_payer: None, }; let sig_response = process_command(&config_offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sig_response); + let offline_presigner = presigner_from_pubkey_sigs(&offline_pubkey, &signers).unwrap(); config.command = CliCommand::SplitStake { stake_account_pubkey: stake_account_pubkey, - stake_authority: Some(offline_pubkey.into()), + stake_authority: Some(offline_presigner.clone().into()), sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: Some(nonce_account_pubkey), - nonce_authority: Some(offline_pubkey.into()), - split_stake_account: read_keypair_file(&split_keypair_file).unwrap().into(), + nonce_authority: Some(offline_presigner.clone().into()), + split_stake_account: Rc::new(read_keypair_file(&split_keypair_file).unwrap().into()), seed: None, lamports: 2 * minimum_stake_balance, - fee_payer: Some(offline_pubkey.into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config).unwrap(); check_balance( @@ -1063,7 +1047,7 @@ fn test_stake_set_lockup() { .get_minimum_balance_for_rent_exemption(std::mem::size_of::()) .unwrap(); - let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap(); + let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap().into(); let stake_account_pubkey = stake_keypair.pubkey(); let (stake_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&stake_keypair, tmp_file.as_file_mut()).unwrap(); @@ -1072,14 +1056,13 @@ fn test_stake_set_lockup() { lockup.custodian = config.keypair.pubkey(); config.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&stake_keypair_file).unwrap().into()), seed: None, staker: Some(offline_pubkey), withdrawer: Some(offline_pubkey), lockup, lamports: 10 * minimum_stake_balance, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -1104,7 +1087,6 @@ fn test_stake_set_lockup() { lockup, custodian: None, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -1136,7 +1118,6 @@ fn test_stake_set_lockup() { lockup, custodian: None, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -1154,7 +1135,6 @@ fn test_stake_set_lockup() { lockup, custodian: Some(read_keypair_file(&online_custodian_file).unwrap().into()), sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -1181,7 +1161,6 @@ fn test_stake_set_lockup() { lockup, custodian: Some(online_custodian.into()), sign_only: false, - signers: None, blockhash_query: BlockhashQuery::default(), nonce_account: None, nonce_authority: None, @@ -1193,12 +1172,12 @@ fn test_stake_set_lockup() { let minimum_nonce_balance = rpc_client .get_minimum_balance_for_rent_exemption(NonceState::size()) .unwrap(); - let nonce_account = keypair_from_seed(&[1u8; 32]).unwrap(); + let nonce_account = keypair_from_seed(&[1u8; 32]).unwrap().into(); let nonce_account_pubkey = nonce_account.pubkey(); let (nonce_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&nonce_account, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&nonce_keypair_file).unwrap().into()), seed: None, nonce_authority: Some(offline_pubkey), lamports: minimum_nonce_balance, @@ -1225,7 +1204,6 @@ fn test_stake_set_lockup() { lockup, custodian: None, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()), nonce_account: Some(nonce_account_pubkey), nonce_authority: None, @@ -1233,16 +1211,16 @@ fn test_stake_set_lockup() { }; let sig_response = process_command(&config_offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sig_response); + let offline_presigner = presigner_from_pubkey_sigs(&offline_pubkey, &signers).unwrap(); config.command = CliCommand::StakeSetLockup { stake_account_pubkey, lockup, - custodian: Some(offline_pubkey.into()), + custodian: Some(offline_presigner.clone().into()), sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: Some(nonce_account_pubkey), - nonce_authority: Some(offline_pubkey.into()), - fee_payer: Some(offline_pubkey.into()), + nonce_authority: Some(offline_presigner.clone().into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config).unwrap(); let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap(); @@ -1269,11 +1247,11 @@ fn test_offline_nonced_create_stake_account_and_withdraw() { let rpc_client = RpcClient::new_socket(leader_data.rpc); let mut config = CliConfig::default(); - config.keypair = keypair_from_seed(&[1u8; 32]).unwrap(); + config.keypair = keypair_from_seed(&[1u8; 32]).unwrap().into(); config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port()); let mut config_offline = CliConfig::default(); - config_offline.keypair = keypair_from_seed(&[2u8; 32]).unwrap(); + config_offline.keypair = keypair_from_seed(&[2u8; 32]).unwrap().into(); let offline_pubkey = config_offline.keypair.pubkey(); let (offline_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&config_offline.keypair, tmp_file.as_file_mut()).unwrap(); @@ -1299,12 +1277,12 @@ fn test_offline_nonced_create_stake_account_and_withdraw() { let minimum_nonce_balance = rpc_client .get_minimum_balance_for_rent_exemption(NonceState::size()) .unwrap(); - let nonce_account = keypair_from_seed(&[3u8; 32]).unwrap(); + let nonce_account = keypair_from_seed(&[3u8; 32]).unwrap().into(); let nonce_pubkey = nonce_account.pubkey(); let (nonce_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&nonce_account, tmp_file.as_file_mut()).unwrap(); config.command = CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&nonce_keypair_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&nonce_keypair_file).unwrap().into()), seed: None, nonce_authority: Some(offline_pubkey), lamports: minimum_nonce_balance, @@ -1320,19 +1298,18 @@ fn test_offline_nonced_create_stake_account_and_withdraw() { }; // Create stake account offline - let stake_keypair = keypair_from_seed(&[4u8; 32]).unwrap(); + let stake_keypair = keypair_from_seed(&[4u8; 32]).unwrap().into(); let stake_pubkey = stake_keypair.pubkey(); let (stake_keypair_file, mut tmp_file) = make_tmp_file(); write_keypair(&stake_keypair, tmp_file.as_file_mut()).unwrap(); config_offline.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(read_keypair_file(&stake_keypair_file).unwrap().into()), seed: None, staker: None, withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()), nonce_account: Some(nonce_pubkey), nonce_authority: None, @@ -1341,20 +1318,22 @@ fn test_offline_nonced_create_stake_account_and_withdraw() { }; let sig_response = process_command(&config_offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sig_response); + let offline_presigner = presigner_from_pubkey_sigs(&offline_pubkey, &signers).unwrap(); config.command = CliCommand::CreateStakeAccount { - stake_account: stake_pubkey.into(), + stake_account: presigner_from_pubkey_sigs(&stake_pubkey, &signers) + .map(|p| Rc::new(p.into())) + .unwrap(), seed: None, - staker: Some(offline_pubkey.into()), + staker: Some(offline_pubkey), withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: Some(nonce_pubkey), - nonce_authority: Some(offline_pubkey.into()), - fee_payer: Some(offline_pubkey.into()), - from: Some(offline_pubkey.into()), + nonce_authority: Some(offline_presigner.clone().into()), + fee_payer: Some(offline_presigner.clone().into()), + from: Some(offline_presigner.clone().into()), }; process_command(&config).unwrap(); check_balance(50_000, &rpc_client, &stake_pubkey); @@ -1368,7 +1347,7 @@ fn test_offline_nonced_create_stake_account_and_withdraw() { }; // Offline, nonced stake-withdraw - let recipient = keypair_from_seed(&[5u8; 32]).unwrap(); + let recipient = keypair_from_seed(&[5u8; 32]).unwrap().into(); let recipient_pubkey = recipient.pubkey(); config_offline.command = CliCommand::WithdrawStake { stake_account_pubkey: stake_pubkey, @@ -1376,7 +1355,6 @@ fn test_offline_nonced_create_stake_account_and_withdraw() { lamports: 42, withdraw_authority: None, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()), nonce_account: Some(nonce_pubkey), nonce_authority: None, @@ -1384,36 +1362,35 @@ fn test_offline_nonced_create_stake_account_and_withdraw() { }; let sig_response = process_command(&config_offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sig_response); + let offline_presigner = presigner_from_pubkey_sigs(&offline_pubkey, &signers).unwrap(); config.command = CliCommand::WithdrawStake { stake_account_pubkey: stake_pubkey, destination_account_pubkey: recipient_pubkey, lamports: 42, - withdraw_authority: Some(offline_pubkey.into()), + withdraw_authority: Some(offline_presigner.clone().into()), sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: Some(nonce_pubkey), - nonce_authority: Some(offline_pubkey.into()), - fee_payer: Some(offline_pubkey.into()), + nonce_authority: Some(offline_presigner.clone().into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config).unwrap(); check_balance(42, &rpc_client, &recipient_pubkey); // Test that offline derived addresses fail config_offline.command = CliCommand::CreateStakeAccount { - stake_account: read_keypair_file(&stake_keypair_file).unwrap().into(), + stake_account: Rc::new(Box::new(read_keypair_file(&stake_keypair_file).unwrap())), seed: Some("fail".to_string()), staker: None, withdrawer: None, lockup: Lockup::default(), lamports: 50_000, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()), nonce_account: Some(nonce_pubkey), - nonce_authority: Some(read_keypair_file(&offline_keypair_file).unwrap().into()), - fee_payer: Some(read_keypair_file(&offline_keypair_file).unwrap().into()), - from: Some(read_keypair_file(&offline_keypair_file).unwrap().into()), + nonce_authority: None, + fee_payer: None, + from: None, }; process_command(&config_offline).unwrap_err(); diff --git a/cli/tests/transfer.rs b/cli/tests/transfer.rs index ecf21aada8fb9c..4ed9c100ae1ac3 100644 --- a/cli/tests/transfer.rs +++ b/cli/tests/transfer.rs @@ -1,3 +1,4 @@ +use solana_clap_utils::keypair::presigner_from_pubkey_sigs; use solana_cli::{ cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig}, offline::{parse_sign_only_reply_string, BlockhashQuery}, @@ -16,6 +17,7 @@ use std::sync::mpsc::channel; #[cfg(test)] use solana_core::validator::new_validator_for_tests_ex; +use std::rc::Rc; use std::thread::sleep; use std::time::Duration; use tempfile::NamedTempFile; @@ -66,7 +68,6 @@ fn test_transfer() { to: recipient_pubkey, from: None, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::All, nonce_account: None, nonce_authority: None, @@ -94,7 +95,6 @@ fn test_transfer() { to: recipient_pubkey, from: None, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(blockhash, FeeCalculator::default()), nonce_account: None, nonce_authority: None, @@ -102,16 +102,16 @@ fn test_transfer() { }; let sign_only_reply = process_command(&offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sign_only_reply); + let offline_presigner = presigner_from_pubkey_sigs(&offline_pubkey, &signers).unwrap(); config.command = CliCommand::Transfer { lamports: 10, to: recipient_pubkey, - from: Some(offline_pubkey.into()), + from: Some(offline_presigner.clone().into()), sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: None, nonce_authority: None, - fee_payer: Some(offline_pubkey.into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config).unwrap(); check_balance(39, &rpc_client, &offline_pubkey); @@ -125,7 +125,7 @@ fn test_transfer() { .get_minimum_balance_for_rent_exemption(NonceState::size()) .unwrap(); config.command = CliCommand::CreateNonceAccount { - nonce_account: read_keypair_file(&nonce_account_file).unwrap().into(), + nonce_account: Rc::new(read_keypair_file(&nonce_account_file).unwrap().into()), seed: None, nonce_authority: None, lamports: minimum_nonce_balance, @@ -147,7 +147,6 @@ fn test_transfer() { to: recipient_pubkey, from: None, sign_only: false, - signers: None, blockhash_query: BlockhashQuery::FeeCalculator(nonce_hash), nonce_account: Some(nonce_account.pubkey()), nonce_authority: None, @@ -187,7 +186,6 @@ fn test_transfer() { to: recipient_pubkey, from: None, sign_only: true, - signers: None, blockhash_query: BlockhashQuery::None(nonce_hash, FeeCalculator::default()), nonce_account: Some(nonce_account.pubkey()), nonce_authority: None, @@ -195,16 +193,16 @@ fn test_transfer() { }; let sign_only_reply = process_command(&offline).unwrap(); let (blockhash, signers) = parse_sign_only_reply_string(&sign_only_reply); + let offline_presigner = presigner_from_pubkey_sigs(&offline_pubkey, &signers).unwrap(); config.command = CliCommand::Transfer { lamports: 10, to: recipient_pubkey, - from: Some(offline_pubkey.into()), + from: Some(offline_presigner.clone().into()), sign_only: false, - signers: Some(signers), blockhash_query: BlockhashQuery::FeeCalculator(blockhash), nonce_account: Some(nonce_account.pubkey()), - nonce_authority: Some(offline_pubkey.into()), - fee_payer: Some(offline_pubkey.into()), + nonce_authority: Some(offline_presigner.clone().into()), + fee_payer: Some(offline_presigner.clone().into()), }; process_command(&config).unwrap(); check_balance(28, &rpc_client, &offline_pubkey);