9951 clippy errors in the test suite (#10030)

automerge
This commit is contained in:
Kristofer Peterson
2020-05-15 17:35:43 +01:00
committed by GitHub
parent 1da1667920
commit 58ef02f02b
106 changed files with 713 additions and 827 deletions

View File

@ -319,7 +319,7 @@ mod tests {
Err(InstructionError::NotEnoughAccountKeys),
process_instruction(
&bpf_loader::id(),
&vec![],
&[],
&instruction_data,
&mut MockInvokeContext::default()
)
@ -385,7 +385,7 @@ mod tests {
Err(InstructionError::NotEnoughAccountKeys),
process_instruction(
&bpf_loader::id(),
&vec![],
&[],
&instruction_data,
&mut MockInvokeContext::default()
)
@ -453,8 +453,8 @@ mod tests {
Err(InstructionError::NotEnoughAccountKeys),
process_instruction(
&bpf_loader::id(),
&vec![],
&vec![],
&[],
&[],
&mut MockInvokeContext::default()
)
);
@ -465,7 +465,7 @@ mod tests {
process_instruction(
&bpf_loader::id(),
&keyed_accounts,
&vec![],
&[],
&mut MockInvokeContext::default()
)
);
@ -477,7 +477,7 @@ mod tests {
process_instruction(
&bpf_loader::id(),
&keyed_accounts,
&vec![],
&[],
&mut MockInvokeContext::default()
)
);
@ -491,7 +491,7 @@ mod tests {
process_instruction(
&bpf_loader::id(),
&keyed_accounts,
&vec![],
&[],
&mut MockInvokeContext::default()
)
);
@ -507,7 +507,7 @@ mod tests {
process_instruction(
&bpf_loader::id(),
&keyed_accounts,
&vec![],
&[],
&mut MockInvokeContext::default()
)
);
@ -568,7 +568,7 @@ mod tests {
let _result = process_instruction(
&bpf_loader::id(),
&keyed_accounts,
&vec![],
&[],
&mut MockInvokeContext::default(),
);
},

View File

@ -775,9 +775,10 @@ mod tests {
(true, START + LENGTH / 2, LENGTH / 2, addr + LENGTH / 2),
];
for (ok, start, length, value) in cases {
match ok {
true => assert_eq!(translate!(start, length, &regions).unwrap(), value),
false => assert!(translate!(start, length, &regions).is_err()),
if ok {
assert_eq!(translate!(start, length, &regions).unwrap(), value)
} else {
assert!(translate!(start, length, &regions).is_err())
}
}
}

View File

@ -106,7 +106,7 @@ mod test {
assert_eq!(106, value_a);
assert_eq!(550, value_b);
assert_eq!(998000, value_c);
assert_eq!(998_000, value_c);
}
#[test]

View File

@ -119,7 +119,7 @@ mod tests {
}
impl Default for MyConfig {
fn default() -> Self {
Self { item: 123456789 }
Self { item: 123_456_789 }
}
}
impl MyConfig {
@ -172,7 +172,7 @@ mod tests {
fn test_process_create_ok() {
solana_logger::setup();
let keys = vec![];
let (_, config_account) = create_config_account(keys.clone());
let (_, config_account) = create_config_account(keys);
assert_eq!(
Some(MyConfig::default()),
deserialize(get_config_data(&config_account.borrow().data).unwrap()).ok()
@ -187,7 +187,7 @@ mod tests {
let config_pubkey = config_keypair.pubkey();
let my_config = MyConfig::new(42);
let instruction = config_instruction::store(&config_pubkey, true, keys.clone(), &my_config);
let instruction = config_instruction::store(&config_pubkey, true, keys, &my_config);
let accounts = vec![(&config_pubkey, true, &config_account)];
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
assert_eq!(
@ -208,8 +208,7 @@ mod tests {
let config_pubkey = config_keypair.pubkey();
let my_config = MyConfig::new(42);
let mut instruction =
config_instruction::store(&config_pubkey, true, keys.clone(), &my_config);
let mut instruction = config_instruction::store(&config_pubkey, true, keys, &my_config);
instruction.data = vec![0; 123]; // <-- Replace data with a vector that's too large
let accounts = vec![(&config_pubkey, true, &config_account)];
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
@ -223,7 +222,7 @@ mod tests {
fn test_process_store_fail_account0_not_signer() {
solana_logger::setup();
let keys = vec![];
let (config_keypair, config_account) = create_config_account(keys.clone());
let (config_keypair, config_account) = create_config_account(keys);
let config_pubkey = config_keypair.pubkey();
let my_config = MyConfig::new(42);
@ -283,8 +282,7 @@ mod tests {
let config_pubkey = config_keypair.pubkey();
let my_config = MyConfig::new(42);
let instruction =
config_instruction::store(&config_pubkey, false, keys.clone(), &my_config);
let instruction = config_instruction::store(&config_pubkey, false, keys, &my_config);
let signer0_account = RefCell::new(Account::default());
let accounts = vec![(&signer0_pubkey, true, &signer0_account)];
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
@ -306,7 +304,7 @@ mod tests {
let config_pubkey = config_keypair.pubkey();
let my_config = MyConfig::new(42);
let instruction = config_instruction::store(&config_pubkey, true, keys.clone(), &my_config);
let instruction = config_instruction::store(&config_pubkey, true, keys, &my_config);
// Config-data pubkey doesn't match signer
let accounts = vec![
@ -385,8 +383,7 @@ mod tests {
// Attempt update with incomplete signatures
let keys = vec![(pubkey, false), (signer0_pubkey, true)];
let instruction =
config_instruction::store(&config_pubkey, false, keys.clone(), &my_config);
let instruction = config_instruction::store(&config_pubkey, false, keys, &my_config);
let accounts = vec![
(&config_pubkey, false, &config_account),
(&signer0_pubkey, true, &signer0_account),
@ -404,8 +401,7 @@ mod tests {
(signer0_pubkey, true),
(signer2_pubkey, true),
];
let instruction =
config_instruction::store(&config_pubkey, false, keys.clone(), &my_config);
let instruction = config_instruction::store(&config_pubkey, false, keys, &my_config);
let accounts = vec![
(&config_pubkey, false, &config_account),
(&signer0_pubkey, true, &signer0_account),
@ -429,7 +425,7 @@ mod tests {
(signer0_pubkey, true),
(signer0_pubkey, true),
]; // Dummy keys for account sizing
let (config_keypair, config_account) = create_config_account(keys.clone());
let (config_keypair, config_account) = create_config_account(keys);
let config_pubkey = config_keypair.pubkey();
let my_config = MyConfig::new(42);
@ -472,7 +468,7 @@ mod tests {
// Attempt update with incomplete signatures
let keys = vec![(pubkey, false), (config_keypair.pubkey(), true)];
let instruction = config_instruction::store(&config_pubkey, true, keys.clone(), &my_config);
let instruction = config_instruction::store(&config_pubkey, true, keys, &my_config);
let accounts = vec![(&config_pubkey, true, &config_account)];
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
assert_eq!(

View File

@ -497,6 +497,7 @@ mod test {
use solana_sdk::system_instruction;
use std::mem;
#[allow(clippy::too_many_arguments)]
fn try_calc(
scaler: u64,
primary_tokens: u64,
@ -604,7 +605,7 @@ mod test {
client
.send_message(&[owner, &new], Message::new(&[instruction]))
.expect(&format!("{}:{}", line!(), file!()));
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
new.pubkey()
}
@ -613,7 +614,7 @@ mod test {
let instruction = exchange_instruction::account_request(&owner.pubkey(), &new);
client
.send_instruction(owner, instruction)
.expect(&format!("{}:{}", line!(), file!()));
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
new
}
@ -627,7 +628,7 @@ mod test {
);
client
.send_instruction(owner, instruction)
.expect(&format!("{}:{}", line!(), file!()));
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
}
fn trade(
@ -655,7 +656,7 @@ mod test {
);
client
.send_instruction(owner, instruction)
.expect(&format!("{}:{}", line!(), file!()));
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
(trade, src)
}
@ -708,7 +709,7 @@ mod test {
);
client
.send_instruction(&owner, instruction)
.expect(&format!("{}:{}", line!(), file!()));
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
let new_account_data = client.get_account_data(&new).unwrap().unwrap();
@ -795,7 +796,7 @@ mod test {
exchange_instruction::swap_request(&owner.pubkey(), &to_trade, &from_trade, &profit);
client
.send_instruction(&owner, instruction)
.expect(&format!("{}:{}", line!(), file!()));
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
let to_trade_account_data = client.get_account_data(&to_trade).unwrap().unwrap();
let from_trade_account_data = client.get_account_data(&from_trade).unwrap().unwrap();
@ -862,7 +863,7 @@ mod test {
exchange_instruction::swap_request(&owner.pubkey(), &to_trade, &from_trade, &profit);
client
.send_instruction(&owner, instruction)
.expect(&format!("{}:{}", line!(), file!()));
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
let new = create_token_account(&client, &owner);
@ -870,13 +871,13 @@ mod test {
exchange_instruction::transfer_request(&owner.pubkey(), &new, &to_trade, Token::B, 1);
client
.send_instruction(&owner, instruction)
.expect(&format!("{}:{}", line!(), file!()));
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
let instruction =
exchange_instruction::transfer_request(&owner.pubkey(), &new, &from_trade, Token::A, 1);
client
.send_instruction(&owner, instruction)
.expect(&format!("{}:{}", line!(), file!()));
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
let new_account_data = client.get_account_data(&new).unwrap().unwrap();

View File

@ -78,10 +78,10 @@ mod tests {
#[test]
fn test() {
let mut account = RefCell::new(create_account(0, &Config::default()));
let account = RefCell::new(create_account(0, &Config::default()));
assert_eq!(Config::from(&account.borrow()), Some(Config::default()));
assert_eq!(
from_keyed_account(&KeyedAccount::new(&Pubkey::default(), false, &mut account)),
from_keyed_account(&KeyedAccount::new(&Pubkey::default(), false, &account)),
Err(InstructionError::InvalidArgument)
);
}

View File

@ -1044,7 +1044,6 @@ mod tests {
..Delegation::default()
},
credits_observed: vote_state_credits,
..Stake::default()
}
);
@ -1092,7 +1091,6 @@ mod tests {
..Delegation::default()
},
credits_observed: vote_state_credits,
..Stake::default()
}
);
@ -1150,7 +1148,7 @@ mod tests {
};
// save this off so stake.config.warmup_rate changes don't break this test
let increment = (1_000 as f64 * stake.warmup_cooldown_rate) as u64;
let increment = (1_000_f64 * stake.warmup_cooldown_rate) as u64;
let mut stake_history = StakeHistory::default();
// assert that this stake follows step function if there's no history
@ -1707,7 +1705,7 @@ mod tests {
assert_eq!(lockup.epoch, 1);
assert_eq!(lockup.custodian, custodian);
} else {
assert!(false);
panic!();
}
assert_eq!(
@ -1729,7 +1727,7 @@ mod tests {
assert_eq!(lockup.epoch, 3);
assert_eq!(lockup.custodian, custodian);
} else {
assert!(false);
panic!();
}
let new_custodian = Pubkey::new_rand();
@ -1752,7 +1750,7 @@ mod tests {
assert_eq!(lockup.epoch, 3);
assert_eq!(lockup.custodian, new_custodian);
} else {
assert!(false);
panic!();
}
assert_eq!(
@ -2173,7 +2171,7 @@ mod tests {
stake.credits_observed = 1;
// this one should be able to collect exactly 1 (already observed one)
assert_eq!(
Some((0, stake.delegation.stake * 1, 2)),
Some((0, stake.delegation.stake, 2)),
stake.calculate_rewards(1.0, &vote_state, None)
);
@ -2183,7 +2181,7 @@ mod tests {
stake.credits_observed = 2;
// this one should be able to collect the one just added
assert_eq!(
Some((0, stake.delegation.stake * 1, 3)),
Some((0, stake.delegation.stake, 3)),
stake.calculate_rewards(1.0, &vote_state, None)
);
@ -2202,8 +2200,8 @@ mod tests {
Some((
0,
stake.delegation.stake * 2 // epoch 0
+ stake.delegation.stake * 1 // epoch 1
+ stake.delegation.stake * 1, // epoch 2
+ stake.delegation.stake // epoch 1
+ stake.delegation.stake, // epoch 2
4
)),
stake.calculate_rewards(1.0, &vote_state, None)
@ -2278,7 +2276,7 @@ mod tests {
assert_eq!(authorized.staker, stake_pubkey0);
assert_eq!(authorized.withdrawer, stake_pubkey0);
} else {
assert!(false);
panic!();
}
// A second authorization signed by the stake_keyed_account should fail

View File

@ -280,7 +280,7 @@ mod tests {
assert_eq!(
verify_signed_account(&keyed_account, &date_pubkey).unwrap_err(),
InstructionError::MissingRequiredSignature.into()
InstructionError::MissingRequiredSignature
);
}

View File

@ -1353,13 +1353,11 @@ mod tests {
let mut vote_state_b = VoteState::new_for_test(&account_b);
// process some votes on account a
(0..5)
.into_iter()
.for_each(|i| vote_state_a.process_slot_vote_unchecked(i as u64));
(0..5).for_each(|i| vote_state_a.process_slot_vote_unchecked(i as u64));
assert_ne!(recent_votes(&vote_state_a), recent_votes(&vote_state_b));
// as long as b has missed less than "NUM_RECENT" votes both accounts should be in sync
let slots = (0u64..MAX_RECENT_VOTES as u64).into_iter().collect();
let slots = (0u64..MAX_RECENT_VOTES as u64).collect();
let vote = Vote::new(slots, Hash::default());
let slot_hashes: Vec<_> = vote.slots.iter().rev().map(|x| (*x, vote.hash)).collect();
@ -1389,7 +1387,7 @@ mod tests {
let vote = Vote::new(vec![0], Hash::default());
assert_eq!(
vote_state.check_slots_are_valid(&vote, &vec![]),
vote_state.check_slots_are_valid(&vote, &[]),
Err(VoteError::VoteTooOld)
);
}
@ -1642,7 +1640,7 @@ mod tests {
#[test]
fn test_vote_process_timestamp() {
let (slot, timestamp) = (15, 1575412285);
let (slot, timestamp) = (15, 1_575_412_285);
let mut vote_state = VoteState::default();
vote_state.last_timestamp = BlockTimestamp { slot, timestamp };
@ -1767,13 +1765,13 @@ mod tests {
let new_voter = Pubkey::new_rand();
// Set a new authorized voter
vote_state
.set_new_authorized_voter(&new_voter, 0, 0 + epoch_offset, |_| Ok(()))
.set_new_authorized_voter(&new_voter, 0, epoch_offset, |_| Ok(()))
.unwrap();
assert_eq!(vote_state.prior_voters.idx, 0);
assert_eq!(
vote_state.prior_voters.last(),
Some(&(original_voter, 0, 0 + epoch_offset))
Some(&(original_voter, 0, epoch_offset))
);
// Trying to set authorized voter for same epoch again should fail