Skip to content

Commit

Permalink
CLI: Fix tests #1
Browse files Browse the repository at this point in the history
what to do about write_keypair outstanding
  • Loading branch information
t-nelson committed Feb 17, 2020
1 parent c17dfd0 commit 7c66acc
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 143 deletions.
8 changes: 4 additions & 4 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions cli/src/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down
29 changes: 17 additions & 12 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()),
Expand Down
12 changes: 5 additions & 7 deletions cli/tests/nonce.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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;

Expand Down Expand Up @@ -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<SigningAuthority> {
fn read_keypair_from_option(keypair_file: &Option<&str>) -> Option<Box<dyn KeypairUtil>> {
keypair_file.map(|akf| read_keypair_file(&akf).unwrap().into())
}

Expand Down Expand Up @@ -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,
};

Expand Down
6 changes: 3 additions & 3 deletions cli/tests/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
});
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion cli/tests/request_airdrop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 7c66acc

Please sign in to comment.