Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
9951 clippy errors in the test suite (#10030)
Browse files Browse the repository at this point in the history
automerge
  • Loading branch information
svenski123 authored May 15, 2020
1 parent 1da1667 commit 58ef02f
Show file tree
Hide file tree
Showing 106 changed files with 713 additions and 827 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions clap-utils/src/input_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,16 @@ mod tests {
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "50"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(50000000000));
assert_eq!(lamports_of_sol(&matches, "single"), Some(50_000_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "1.5"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(1500000000));
assert_eq!(lamports_of_sol(&matches, "single"), Some(1_500_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "0.03"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(30000000));
assert_eq!(lamports_of_sol(&matches, "single"), Some(30_000_000));
}
}
40 changes: 15 additions & 25 deletions cli/src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ mod tests {
let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetBalance, account_balance_response.clone());
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
assert_eq!(
check_account_for_fee(&rpc_client, &pubkey, &fee_calculator, &message0).unwrap(),
()
);
check_account_for_fee(&rpc_client, &pubkey, &fee_calculator, &message0)
.expect("unexpected result");

let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetBalance, account_balance_response.clone());
Expand Down Expand Up @@ -128,16 +126,13 @@ mod tests {
mocks.insert(RpcRequest::GetBalance, account_balance_response);
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);

assert_eq!(
check_account_for_multiple_fees(
&rpc_client,
&pubkey,
&fee_calculator,
&[&message0, &message0]
)
.unwrap(),
()
);
check_account_for_multiple_fees(
&rpc_client,
&pubkey,
&fee_calculator,
&[&message0, &message0],
)
.expect("unexpected result");
}

#[test]
Expand Down Expand Up @@ -194,19 +189,14 @@ mod tests {
#[test]
fn test_check_unique_pubkeys() {
let pubkey0 = Pubkey::new_rand();
let pubkey_clone = pubkey0.clone();
let pubkey_clone = pubkey0;
let pubkey1 = Pubkey::new_rand();

assert_eq!(
check_unique_pubkeys((&pubkey0, "foo".to_string()), (&pubkey1, "bar".to_string()))
.unwrap(),
()
);
assert_eq!(
check_unique_pubkeys((&pubkey0, "foo".to_string()), (&pubkey1, "foo".to_string()))
.unwrap(),
()
);
check_unique_pubkeys((&pubkey0, "foo".to_string()), (&pubkey1, "bar".to_string()))
.expect("unexpected result");
check_unique_pubkeys((&pubkey0, "foo".to_string()), (&pubkey1, "foo".to_string()))
.expect("unexpected result");

assert!(check_unique_pubkeys(
(&pubkey0, "foo".to_string()),
(&pubkey_clone, "bar".to_string())
Expand Down
6 changes: 4 additions & 2 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2703,6 +2703,7 @@ mod tests {
}

#[test]
#[allow(clippy::cognitive_complexity)]
fn test_cli_parse_command() {
let test_commands = app("test", "desc", "version");

Expand Down Expand Up @@ -2800,7 +2801,7 @@ mod tests {
);

// Test Confirm Subcommand
let signature = Signature::new(&vec![1; 64]);
let signature = Signature::new(&[1; 64]);
let signature_string = format!("{:?}", signature);
let test_confirm =
test_commands
Expand Down Expand Up @@ -3235,6 +3236,7 @@ mod tests {
}

#[test]
#[allow(clippy::cognitive_complexity)]
fn test_cli_process_command() {
// Success cases
let mut config = CliConfig::default();
Expand Down Expand Up @@ -3774,7 +3776,7 @@ mod tests {
blockhash_query::Source::NonceAccount(nonce_address),
blockhash
),
nonce_account: Some(nonce_address.into()),
nonce_account: Some(nonce_address),
nonce_authority: 1,
fee_payer: 0,
},
Expand Down
12 changes: 6 additions & 6 deletions cli/src/offline/blockhash_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,19 @@ mod tests {
);
mocks.insert(
RpcRequest::GetFeeCalculatorForBlockhash,
get_fee_calculator_for_blockhash_response.clone(),
get_fee_calculator_for_blockhash_response,
);
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
assert_eq!(
BlockhashQuery::FeeCalculator(Source::Cluster, test_blockhash)
.get_blockhash_and_fee_calculator(&rpc_client)
.unwrap(),
(test_blockhash, rpc_fee_calc.clone()),
(test_blockhash, rpc_fee_calc),
);
let mut mocks = HashMap::new();
mocks.insert(
RpcRequest::GetRecentBlockhash,
get_recent_blockhash_response.clone(),
get_recent_blockhash_response,
);
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
assert_eq!(
Expand Down Expand Up @@ -347,7 +347,7 @@ mod tests {
let rpc_nonce_account = RpcAccount::encode(nonce_account);
let get_account_response = json!(Response {
context: RpcResponseContext { slot: 1 },
value: json!(Some(rpc_nonce_account.clone())),
value: json!(Some(rpc_nonce_account)),
});

let mut mocks = HashMap::new();
Expand All @@ -366,7 +366,7 @@ mod tests {
BlockhashQuery::FeeCalculator(Source::NonceAccount(nonce_pubkey), nonce_blockhash)
.get_blockhash_and_fee_calculator(&rpc_client)
.unwrap(),
(nonce_blockhash, nonce_fee_calc.clone()),
(nonce_blockhash, nonce_fee_calc),
);
let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetAccountInfo, get_account_response.clone());
Expand All @@ -377,7 +377,7 @@ mod tests {
.is_err()
);
let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetAccountInfo, get_account_response.clone());
mocks.insert(RpcRequest::GetAccountInfo, get_account_response);
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
assert_eq!(
BlockhashQuery::None(nonce_blockhash)
Expand Down
3 changes: 2 additions & 1 deletion cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,7 @@ mod tests {
}

#[test]
#[allow(clippy::cognitive_complexity)]
fn test_parse_command() {
let test_commands = app("test", "desc", "version");
let default_keypair = Keypair::new();
Expand Down Expand Up @@ -2861,7 +2862,7 @@ mod tests {
blockhash_query::Source::NonceAccount(nonce_account),
nonce_hash
),
nonce_account: Some(nonce_account.into()),
nonce_account: Some(nonce_account),
nonce_authority: 1,
split_stake_account: 2,
seed: None,
Expand Down
8 changes: 2 additions & 6 deletions cli/src/validator_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,7 @@ mod tests {
let mut info = Map::new();
info.insert("name".to_string(), Value::String("Alice".to_string()));
let info_string = serde_json::to_string(&Value::Object(info.clone())).unwrap();
let validator_info = ValidatorInfo {
info: info_string.clone(),
};
let validator_info = ValidatorInfo { info: info_string };
let data = serialize(&(config, validator_info)).unwrap();

assert_eq!(
Expand Down Expand Up @@ -547,9 +545,7 @@ mod tests {
info.insert("details".to_string(), Value::String(max_long_string));
let info_string = serde_json::to_string(&Value::Object(info)).unwrap();

let validator_info = ValidatorInfo {
info: info_string.clone(),
};
let validator_info = ValidatorInfo { info: info_string };

assert_eq!(
serialized_size(&validator_info).unwrap(),
Expand Down
20 changes: 10 additions & 10 deletions cli/tests/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ fn test_offline_stake_delegation_and_deactivation() {
config_validator.command = CliCommand::CreateStakeAccount {
stake_account: 1,
seed: None,
staker: Some(config_offline.signers[0].pubkey().into()),
staker: Some(config_offline.signers[0].pubkey()),
withdrawer: None,
lockup: Lockup::default(),
amount: SpendAmount::Some(50_000),
Expand Down Expand Up @@ -1033,7 +1033,7 @@ fn test_stake_split() {
check_balance(0, &rpc_client, &split_account.pubkey());
config_offline.signers.push(&split_account);
config_offline.command = CliCommand::SplitStake {
stake_account_pubkey: stake_account_pubkey,
stake_account_pubkey,
stake_authority: 0,
sign_only: true,
blockhash_query: BlockhashQuery::None(nonce_hash),
Expand All @@ -1051,7 +1051,7 @@ fn test_stake_split() {
let offline_presigner = sign_only.presigner_of(&offline_pubkey).unwrap();
config.signers = vec![&offline_presigner, &split_account];
config.command = CliCommand::SplitStake {
stake_account_pubkey: stake_account_pubkey,
stake_account_pubkey,
stake_authority: 0,
sign_only: false,
blockhash_query: BlockhashQuery::FeeCalculator(
Expand Down Expand Up @@ -1165,7 +1165,7 @@ fn test_stake_set_lockup() {

// Online set lockup
let lockup = LockupArgs {
unix_timestamp: Some(1581534570),
unix_timestamp: Some(1_581_534_570),
epoch: Some(200),
custodian: None,
};
Expand Down Expand Up @@ -1199,7 +1199,7 @@ fn test_stake_set_lockup() {
let online_custodian_pubkey = online_custodian.pubkey();

let lockup = LockupArgs {
unix_timestamp: Some(1581534571),
unix_timestamp: Some(1_581_534_571),
epoch: Some(201),
custodian: Some(online_custodian_pubkey),
};
Expand All @@ -1216,7 +1216,7 @@ fn test_stake_set_lockup() {
process_command(&config).unwrap();

let lockup = LockupArgs {
unix_timestamp: Some(1581534572),
unix_timestamp: Some(1_581_534_572),
epoch: Some(202),
custodian: None,
};
Expand Down Expand Up @@ -1247,7 +1247,7 @@ fn test_stake_set_lockup() {

// Set custodian to offline pubkey
let lockup = LockupArgs {
unix_timestamp: Some(1581534573),
unix_timestamp: Some(1_581_534_573),
epoch: Some(203),
custodian: Some(offline_pubkey),
};
Expand Down Expand Up @@ -1287,7 +1287,7 @@ fn test_stake_set_lockup() {

// Nonced offline set lockup
let lockup = LockupArgs {
unix_timestamp: Some(1581534576),
unix_timestamp: Some(1_581_534_576),
epoch: Some(222),
custodian: None,
};
Expand Down Expand Up @@ -1524,8 +1524,8 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
config.command = CliCommand::CreateStakeAccount {
stake_account: 1,
seed: Some(seed.to_string()),
staker: Some(offline_pubkey.into()),
withdrawer: Some(offline_pubkey.into()),
staker: Some(offline_pubkey),
withdrawer: Some(offline_pubkey),
lockup: Lockup::default(),
amount: SpendAmount::Some(50_000),
sign_only: false,
Expand Down
1 change: 0 additions & 1 deletion client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,6 @@ mod tests {
use jsonrpc_core::{Error, IoHandler, Params};
use jsonrpc_http_server::{AccessControlAllowOrigin, DomainsValidation, ServerBuilder};
use serde_json::Number;
use solana_logger;
use solana_sdk::{
instruction::InstructionError, signature::Keypair, system_transaction,
transaction::TransactionError,
Expand Down
2 changes: 1 addition & 1 deletion client/src/rpc_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ mod tests {
assert_eq!(request["method"], "getRecentBlockhash");

let test_request = RpcRequest::GetFeeCalculatorForBlockhash;
let request = test_request.build_request_json(1, json!([addr.clone()]));
let request = test_request.build_request_json(1, json!([addr]));
assert_eq!(request["method"], "getFeeCalculatorForBlockhash");

let test_request = RpcRequest::GetFeeRateGovernor;
Expand Down
2 changes: 1 addition & 1 deletion core/src/accounts_hash_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ mod tests {
trusted_validators.insert(validator1.pubkey());
assert!(AccountsHashVerifier::should_halt(
&cluster_info,
&Some(trusted_validators.clone()),
&Some(trusted_validators),
&mut slot_to_hash,
));
}
Expand Down
Loading

0 comments on commit 58ef02f

Please sign in to comment.