From ed87229cec5f8e30a9a94a20bbf1ff8e386e6530 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Tue, 11 Feb 2020 22:48:04 -0700 Subject: [PATCH] CLI: Don't hide errors when fees are disabled (#8204) automerge --- cli/src/cli.rs | 12 +++++------- cli/tests/transfer.rs | 14 ++++++++------ client/src/mock_rpc_client_request.rs | 11 ++++------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 05e4793d8..66e58192b 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -806,12 +806,11 @@ fn check_account_for_multiple_fees( ) -> Result<(), Box> { let balance = rpc_client.retry_get_balance(account_pubkey, 5)?; if let Some(lamports) = balance { - if lamports - >= messages - .iter() - .map(|message| fee_calculator.calculate_fee(message)) - .sum() - { + let fee = messages + .iter() + .map(|message| fee_calculator.calculate_fee(message)) + .sum(); + if lamports != 0 && lamports >= fee { return Ok(()); } } @@ -3199,7 +3198,6 @@ mod tests { }; assert!(process_command(&config).is_ok()); - config.rpc_client = Some(RpcClient::new_mock("airdrop".to_string())); config.command = CliCommand::TimeElapsed(bob_pubkey, process_id, dt); let signature = process_command(&config); assert_eq!(signature.unwrap(), SIGNATURE.to_string()); diff --git a/cli/tests/transfer.rs b/cli/tests/transfer.rs index 22b2115b9..ecf21aada 100644 --- a/cli/tests/transfer.rs +++ b/cli/tests/transfer.rs @@ -15,7 +15,7 @@ use std::fs::remove_dir_all; use std::sync::mpsc::channel; #[cfg(test)] -use solana_core::validator::new_validator_for_tests; +use solana_core::validator::new_validator_for_tests_ex; use std::thread::sleep; use std::time::Duration; use tempfile::NamedTempFile; @@ -40,7 +40,7 @@ fn check_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey) { #[test] fn test_transfer() { - let (server, leader_data, mint_keypair, ledger_path) = new_validator_for_tests(); + let (server, leader_data, mint_keypair, ledger_path, _) = new_validator_for_tests_ex(1, 42_000); let (sender, receiver) = channel(); run_local_faucet(mint_keypair, sender, None); @@ -73,7 +73,7 @@ fn test_transfer() { fee_payer: None, }; process_command(&config).unwrap(); - check_balance(49_990, &rpc_client, &sender_pubkey); + check_balance(49_989, &rpc_client, &sender_pubkey); check_balance(10, &rpc_client, &recipient_pubkey); let mut offline = CliConfig::default(); @@ -114,7 +114,7 @@ fn test_transfer() { fee_payer: Some(offline_pubkey.into()), }; process_command(&config).unwrap(); - check_balance(40, &rpc_client, &offline_pubkey); + check_balance(39, &rpc_client, &offline_pubkey); check_balance(20, &rpc_client, &recipient_pubkey); // Create nonce account @@ -131,6 +131,7 @@ fn test_transfer() { lamports: minimum_nonce_balance, }; process_command(&config).unwrap(); + check_balance(49_987 - minimum_nonce_balance, &rpc_client, &sender_pubkey); // Fetch nonce hash let account = rpc_client.get_account(&nonce_account.pubkey()).unwrap(); @@ -153,7 +154,7 @@ fn test_transfer() { fee_payer: None, }; process_command(&config).unwrap(); - check_balance(49_980 - minimum_nonce_balance, &rpc_client, &sender_pubkey); + check_balance(49_976 - minimum_nonce_balance, &rpc_client, &sender_pubkey); check_balance(30, &rpc_client, &recipient_pubkey); let account = rpc_client.get_account(&nonce_account.pubkey()).unwrap(); let nonce_state: NonceState = account.state().unwrap(); @@ -170,6 +171,7 @@ fn test_transfer() { new_authority: offline_pubkey, }; process_command(&config).unwrap(); + check_balance(49_975 - minimum_nonce_balance, &rpc_client, &sender_pubkey); // Fetch nonce hash let account = rpc_client.get_account(&nonce_account.pubkey()).unwrap(); @@ -205,7 +207,7 @@ fn test_transfer() { fee_payer: Some(offline_pubkey.into()), }; process_command(&config).unwrap(); - check_balance(30, &rpc_client, &offline_pubkey); + check_balance(28, &rpc_client, &offline_pubkey); check_balance(40, &rpc_client, &recipient_pubkey); server.close().unwrap(); diff --git a/client/src/mock_rpc_client_request.rs b/client/src/mock_rpc_client_request.rs index d80152651..372c38dda 100644 --- a/client/src/mock_rpc_client_request.rs +++ b/client/src/mock_rpc_client_request.rs @@ -60,13 +60,10 @@ impl GenericRpcClientRequest for MockRpcClientRequest { Value::Null } } - RpcRequest::GetBalance => { - let n = if self.url == "airdrop" { 0 } else { 50 }; - serde_json::to_value(Response { - context: RpcResponseContext { slot: 1 }, - value: Value::Number(Number::from(n)), - })? - } + RpcRequest::GetBalance => serde_json::to_value(Response { + context: RpcResponseContext { slot: 1 }, + value: Value::Number(Number::from(50)), + })?, RpcRequest::GetRecentBlockhash => serde_json::to_value(Response { context: RpcResponseContext { slot: 1 }, value: (