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

@ -819,7 +819,7 @@ mod tests {
fn load_accounts_with_fee_and_rent(
tx: Transaction,
ka: &Vec<(Pubkey, Account)>,
ka: &[(Pubkey, Account)],
fee_calculator: &FeeCalculator,
rent_collector: &RentCollector,
error_counters: &mut ErrorCounters,
@ -832,7 +832,7 @@ mod tests {
}
let ancestors = vec![(0, 0)].into_iter().collect();
let res = accounts.load_accounts(
accounts.load_accounts(
&ancestors,
&[tx],
None,
@ -840,13 +840,12 @@ mod tests {
&hash_queue,
error_counters,
rent_collector,
);
res
)
}
fn load_accounts_with_fee(
tx: Transaction,
ka: &Vec<(Pubkey, Account)>,
ka: &[(Pubkey, Account)],
fee_calculator: &FeeCalculator,
error_counters: &mut ErrorCounters,
) -> Vec<(Result<TransactionLoadResult>, Option<HashAgeKind>)> {
@ -856,7 +855,7 @@ mod tests {
fn load_accounts(
tx: Transaction,
ka: &Vec<(Pubkey, Account)>,
ka: &[(Pubkey, Account)],
error_counters: &mut ErrorCounters,
) -> Vec<(Result<TransactionLoadResult>, Option<HashAgeKind>)> {
let fee_calculator = FeeCalculator::default();
@ -1090,7 +1089,7 @@ mod tests {
// Fee leaves non-zero, but sub-min_balance balance fails
accounts[0].1.lamports = 3 * min_balance / 2;
let loaded_accounts = load_accounts_with_fee_and_rent(
tx.clone(),
tx,
&accounts,
&fee_calculator,
&rent_collector,
@ -1473,7 +1472,7 @@ mod tests {
accounts.bank_hash_at(1);
}
fn check_accounts(accounts: &Accounts, pubkeys: &Vec<Pubkey>, num: usize) {
fn check_accounts(accounts: &Accounts, pubkeys: &[Pubkey], num: usize) {
for _ in 1..num {
let idx = thread_rng().gen_range(0, num - 1);
let ancestors = vec![(0, 0)].into_iter().collect();
@ -1701,7 +1700,7 @@ mod tests {
}
}
});
let counter_clone = counter.clone();
let counter_clone = counter;
for _ in 0..5 {
let txs = vec![readonly_tx.clone()];
let results = accounts_arc.clone().lock_accounts(&txs, None);
@ -1768,7 +1767,7 @@ mod tests {
Some(HashAgeKind::Extant),
);
let transaction_accounts1 = vec![account1, account2.clone()];
let transaction_accounts1 = vec![account1, account2];
let transaction_loaders1 = vec![];
let transaction_rent1 = 0;
let loaded1 = (
@ -1804,12 +1803,10 @@ mod tests {
assert_eq!(collected_accounts.len(), 2);
assert!(collected_accounts
.iter()
.find(|(pubkey, _account)| *pubkey == &keypair0.pubkey())
.is_some());
.any(|(pubkey, _account)| *pubkey == &keypair0.pubkey()));
assert!(collected_accounts
.iter()
.find(|(pubkey, _account)| *pubkey == &keypair1.pubkey())
.is_some());
.any(|(pubkey, _account)| *pubkey == &keypair1.pubkey()));
// Ensure readonly_lock reflects lock
let readonly_locks = accounts.readonly_locks.read().unwrap();

View File

@ -2390,12 +2390,12 @@ pub mod tests {
}
}
fn update_accounts(accounts: &AccountsDB, pubkeys: &Vec<Pubkey>, slot: Slot, range: usize) {
fn update_accounts(accounts: &AccountsDB, pubkeys: &[Pubkey], slot: Slot, range: usize) {
for _ in 1..1000 {
let idx = thread_rng().gen_range(0, range);
let ancestors = vec![(slot, 0)].into_iter().collect();
if let Some((mut account, _)) = accounts.load_slow(&ancestors, &pubkeys[idx]) {
account.lamports = account.lamports + 1;
account.lamports += 1;
accounts.store(slot, &[(&pubkeys[idx], &account)]);
if account.lamports == 0 {
let ancestors = vec![(slot, 0)].into_iter().collect();
@ -2441,9 +2441,10 @@ pub mod tests {
}
}
#[allow(clippy::needless_range_loop)]
fn modify_accounts(
accounts: &AccountsDB,
pubkeys: &Vec<Pubkey>,
pubkeys: &[Pubkey],
slot: Slot,
num: usize,
count: usize,
@ -2979,7 +2980,7 @@ pub mod tests {
fn assert_no_stores(accounts: &AccountsDB, slot: Slot) {
let stores = accounts.storage.read().unwrap();
info!("{:?}", stores.0.get(&slot));
assert!(stores.0.get(&slot).is_none() || stores.0.get(&slot).unwrap().len() == 0);
assert!(stores.0.get(&slot).is_none() || stores.0.get(&slot).unwrap().is_empty());
}
#[test]
@ -3228,8 +3229,7 @@ pub mod tests {
solana_logger::setup();
with_chained_zero_lamport_accounts(|accounts, current_slot| {
accounts.clean_accounts();
let accounts = reconstruct_accounts_db_via_serialization(&accounts, current_slot);
accounts
reconstruct_accounts_db_via_serialization(&accounts, current_slot)
});
}
@ -3240,8 +3240,7 @@ pub mod tests {
let accounts = reconstruct_accounts_db_via_serialization(&accounts, current_slot);
print_accounts("after_reconstruct", &accounts);
accounts.clean_accounts();
let accounts = reconstruct_accounts_db_via_serialization(&accounts, current_slot);
accounts
reconstruct_accounts_db_via_serialization(&accounts, current_slot)
});
}
@ -3258,7 +3257,6 @@ pub mod tests {
db.add_root(slot);
let thread_hdls: Vec<_> = (0..num_threads)
.into_iter()
.map(|_| {
let db = db.clone();
std::thread::Builder::new()
@ -3271,9 +3269,11 @@ pub mod tests {
let account_bal = thread_rng().gen_range(1, 99);
account.lamports = account_bal;
db.store(slot, &[(&pubkey, &account)]);
let (account, slot) = db.load_slow(&HashMap::new(), &pubkey).expect(
&format!("Could not fetch stored account {}, iter {}", pubkey, i),
);
let (account, slot) =
db.load_slow(&HashMap::new(), &pubkey).unwrap_or_else(|| {
panic!("Could not fetch stored account {}, iter {}", pubkey, i)
});
assert_eq!(slot, slot);
assert_eq!(account.lamports, account_bal);
i += 1;
@ -3397,7 +3397,7 @@ pub mod tests {
);
// Executable may not be modified
let mut account_modified = account.clone();
let mut account_modified = account;
account_modified.executable = true;
assert_ne!(
hash,
@ -3641,7 +3641,7 @@ pub mod tests {
db.hash_accounts(some_slot, accounts);
// provide bogus account hashes
let some_hash = Hash::new(&[0xca; HASH_BYTES]);
db.store_with_hashes(some_slot, accounts, &vec![some_hash]);
db.store_with_hashes(some_slot, accounts, &[some_hash]);
db.add_root(some_slot);
assert_matches!(
db.verify_bank_hash(some_slot, &ancestors),
@ -3655,12 +3655,11 @@ pub mod tests {
let db = AccountsDB::new(Vec::new());
let some_slot: Slot = 0;
let ancestors = vec![(some_slot, 0)].into_iter().collect();
let ancestors: Ancestors = [(some_slot, 0)].iter().copied().collect();
for _ in 0..10_000 {
let num_accounts = thread_rng().gen_range(0, 100);
let accounts_keys: Vec<_> = (0..num_accounts)
.into_iter()
.map(|_| {
let key = Keypair::new().pubkey();
let lamports = thread_rng().gen_range(0, 100);
@ -3790,7 +3789,7 @@ pub mod tests {
let account = Account::new(old_lamport, no_data, &owner);
let account2 = Account::new(old_lamport + 100_001, no_data, &owner);
let account3 = Account::new(old_lamport + 100_002, no_data, &owner);
let dummy_account = Account::new(99999999, no_data, &owner);
let dummy_account = Account::new(99_999_999, no_data, &owner);
let zero_lamport_account = Account::new(zero_lamport, no_data, &owner);
let pubkey = Pubkey::new_rand();
@ -3846,7 +3845,7 @@ pub mod tests {
let old_lamport = 223;
let zero_lamport = 0;
let no_data = 0;
let dummy_lamport = 999999;
let dummy_lamport = 999_999;
let owner = Account::default().owner;
let account = Account::new(old_lamport, no_data, &owner);
@ -4124,12 +4123,12 @@ pub mod tests {
lamports: 0,
};
let mut reclaims = vec![];
accounts_index.insert(0, &key0, info0.clone(), &mut reclaims);
accounts_index.insert(0, &key0, info0, &mut reclaims);
accounts_index.insert(1, &key0, info1.clone(), &mut reclaims);
accounts_index.insert(1, &key1, info1.clone(), &mut reclaims);
accounts_index.insert(1, &key1, info1, &mut reclaims);
accounts_index.insert(2, &key1, info2.clone(), &mut reclaims);
accounts_index.insert(2, &key2, info2.clone(), &mut reclaims);
accounts_index.insert(3, &key2, info3.clone(), &mut reclaims);
accounts_index.insert(2, &key2, info2, &mut reclaims);
accounts_index.insert(3, &key2, info3, &mut reclaims);
accounts_index.add_root(0);
accounts_index.add_root(1);
accounts_index.add_root(2);

View File

@ -545,12 +545,12 @@ pub mod tests {
}
impl<'a> StoredAccount<'a> {
#[allow(clippy::cast_ref_to_mut)]
fn set_data_len_unsafe(&self, new_data_len: u64) {
let data_len: &u64 = &self.meta.data_len;
#[allow(mutable_transmutes)]
// UNSAFE: cast away & (= const ref) to &mut to force to mutate append-only (=read-only) AppendVec
let data_len: &mut u64 = unsafe { &mut *(data_len as *const u64 as *mut u64) };
*data_len = new_data_len;
unsafe {
*(&self.meta.data_len as *const u64 as *mut u64) = new_data_len;
}
}
fn get_executable_byte(&self) -> u8 {
@ -560,13 +560,12 @@ pub mod tests {
executable_byte
}
#[allow(clippy::cast_ref_to_mut)]
fn set_executable_as_byte(&self, new_executable_byte: u8) {
let executable_ref: &bool = &self.account_meta.executable;
#[allow(mutable_transmutes)]
// UNSAFE: Force to interpret mmap-backed &bool as &u8 to write some crafted value;
let executable_byte: &mut u8 =
unsafe { &mut *(executable_ref as *const bool as *mut u8) };
*executable_byte = new_executable_byte;
unsafe {
*(&self.account_meta.executable as *const bool as *mut u8) = new_executable_byte;
}
}
}
@ -597,31 +596,41 @@ pub mod tests {
#[test]
fn test_append_vec_sanitize_len_and_size_too_small() {
let result = AppendVec::sanitize_len_and_size(0, 0);
const LEN: usize = 0;
const SIZE: usize = 0;
let result = AppendVec::sanitize_len_and_size(LEN, SIZE);
assert_matches!(result, Err(ref message) if message.to_string() == *"too small file size 0 for AppendVec");
}
#[test]
fn test_append_vec_sanitize_len_and_size_maximum() {
let result = AppendVec::sanitize_len_and_size(0, 16 * 1024 * 1024 * 1024);
const LEN: usize = 0;
const SIZE: usize = 16 * 1024 * 1024 * 1024;
let result = AppendVec::sanitize_len_and_size(LEN, SIZE);
assert_matches!(result, Ok(_));
}
#[test]
fn test_append_vec_sanitize_len_and_size_too_large() {
let result = AppendVec::sanitize_len_and_size(0, 16 * 1024 * 1024 * 1024 + 1);
const LEN: usize = 0;
const SIZE: usize = 16 * 1024 * 1024 * 1024 + 1;
let result = AppendVec::sanitize_len_and_size(LEN, SIZE);
assert_matches!(result, Err(ref message) if message.to_string() == *"too large file size 17179869185 for AppendVec");
}
#[test]
fn test_append_vec_sanitize_len_and_size_full_and_same_as_current_len() {
let result = AppendVec::sanitize_len_and_size(1 * 1024 * 1024, 1 * 1024 * 1024);
const LEN: usize = 1024 * 1024;
const SIZE: usize = 1024 * 1024;
let result = AppendVec::sanitize_len_and_size(LEN, SIZE);
assert_matches!(result, Ok(_));
}
#[test]
fn test_append_vec_sanitize_len_and_size_larger_current_len() {
let result = AppendVec::sanitize_len_and_size(1 * 1024 * 1024 + 1, 1 * 1024 * 1024);
const LEN: usize = 1024 * 1024 + 1;
const SIZE: usize = 1024 * 1024;
let result = AppendVec::sanitize_len_and_size(LEN, SIZE);
assert_matches!(result, Err(ref message) if message.to_string() == *"current_len is larger than file size (1048576)");
}
@ -806,7 +815,8 @@ pub mod tests {
// Depending on use, *executable_bool can be truthy or falsy due to direct memory manipulation
// assert_eq! thinks *exeutable_bool is equal to false but the if condition thinks it's not, contradictly.
assert_eq!(*executable_bool, false);
if *executable_bool == false {
const FALSE: bool = false; // keep clippy happy
if *executable_bool == FALSE {
panic!("This didn't occur if this test passed.");
}
assert_eq!(*account.ref_executable_byte(), crafted_executable);

View File

@ -2679,6 +2679,7 @@ mod tests {
}
#[test]
#[allow(clippy::float_cmp)]
fn test_bank_new() {
let dummy_leader_pubkey = Pubkey::new_rand();
let dummy_leader_lamports = BOOTSTRAP_VALIDATOR_LAMPORTS;
@ -2728,13 +2729,13 @@ mod tests {
fn test_bank_update_epoch_stakes() {
impl Bank {
fn epoch_stake_keys(&self) -> Vec<Epoch> {
let mut keys: Vec<Epoch> = self.epoch_stakes.keys().map(|k| *k).collect();
let mut keys: Vec<Epoch> = self.epoch_stakes.keys().copied().collect();
keys.sort();
keys
}
fn epoch_stake_key_info(&self) -> (Epoch, Epoch, usize) {
let mut keys: Vec<Epoch> = self.epoch_stakes.keys().map(|k| *k).collect();
let mut keys: Vec<Epoch> = self.epoch_stakes.keys().copied().collect();
keys.sort();
(*keys.first().unwrap(), *keys.last().unwrap(), keys.len())
}
@ -2790,7 +2791,6 @@ mod tests {
fn test_bank_capitalization() {
let bank = Arc::new(Bank::new(&GenesisConfig {
accounts: (0..42)
.into_iter()
.map(|_| (Pubkey::new_rand(), Account::new(42, 0, &Pubkey::default())))
.collect(),
..GenesisConfig::default()
@ -2879,7 +2879,7 @@ mod tests {
let t3 =
system_transaction::transfer(&keypair5, &keypair6.pubkey(), 1, genesis_config.hash());
let res = bank.process_transactions(&vec![t1.clone(), t2.clone(), t3.clone()]);
let res = bank.process_transactions(&[t1.clone(), t2.clone(), t3]);
assert_eq!(res.len(), 3);
assert_eq!(res[0], Ok(()));
@ -2891,7 +2891,7 @@ mod tests {
let rwlockguard_bank_hash = bank.hash.read().unwrap();
let bank_hash = rwlockguard_bank_hash.as_ref();
let res = bank_with_success_txs.process_transactions(&vec![t2.clone(), t1.clone()]);
let res = bank_with_success_txs.process_transactions(&[t2, t1]);
assert_eq!(res.len(), 2);
assert_eq!(res[0], Ok(()));
@ -3294,7 +3294,7 @@ mod tests {
#[test]
fn test_rent_exempt_executable_account() {
let (mut genesis_config, mint_keypair) = create_genesis_config(100000);
let (mut genesis_config, mint_keypair) = create_genesis_config(100_000);
genesis_config.rent = Rent {
lamports_per_byte_year: 1,
exemption_threshold: 1000.0,
@ -3419,14 +3419,7 @@ mod tests {
genesis_config.hash(),
);
let res = bank.process_transactions(&[
t6.clone(),
t5.clone(),
t1.clone(),
t2.clone(),
t3.clone(),
t4.clone(),
]);
let res = bank.process_transactions(&[t6, t5, t1, t2, t3, t4]);
assert_eq!(res.len(), 6);
assert_eq!(res[0], Ok(()));
@ -3548,6 +3541,7 @@ mod tests {
}
#[test]
#[allow(clippy::cognitive_complexity)]
fn test_rent_eager_across_epoch_without_gap_under_multi_epoch_cycle() {
let leader_pubkey = Pubkey::new_rand();
let leader_lamports = 3;
@ -3561,32 +3555,32 @@ mod tests {
EpochSchedule::custom(SLOTS_PER_EPOCH, LEADER_SCHEDULE_SLOT_OFFSET, false);
let mut bank = Arc::new(Bank::new(&genesis_config));
assert_eq!(DEFAULT_SLOTS_PER_EPOCH, 432000);
assert_eq!(DEFAULT_SLOTS_PER_EPOCH, 432_000);
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (0, 0));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432_000)]);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (0, 1));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 432_000)]);
for _ in 2..32 {
bank = Arc::new(new_from_parent(&bank));
}
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (0, 31));
assert_eq!(bank.rent_collection_partitions(), vec![(30, 31, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(30, 31, 432_000)]);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (1, 0));
assert_eq!(bank.rent_collection_partitions(), vec![(31, 32, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(31, 32, 432_000)]);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (1, 1));
assert_eq!(bank.rent_collection_partitions(), vec![(32, 33, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(32, 33, 432_000)]);
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 1000));
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 1001));
@ -3594,27 +3588,27 @@ mod tests {
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (31, 9));
assert_eq!(
bank.rent_collection_partitions(),
vec![(1000, 1001, 432000)]
vec![(1000, 1001, 432_000)]
);
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 431998));
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 431999));
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 431_998));
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 431_999));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (13499, 31));
assert_eq!(
bank.rent_collection_partitions(),
vec![(431998, 431999, 432000)]
vec![(431_998, 431_999, 432_000)]
);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (13500, 0));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432_000)]);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (13500, 1));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 432_000)]);
}
#[test]
@ -3631,43 +3625,43 @@ mod tests {
EpochSchedule::custom(SLOTS_PER_EPOCH, LEADER_SCHEDULE_SLOT_OFFSET, false);
let mut bank = Arc::new(Bank::new(&genesis_config));
assert_eq!(DEFAULT_SLOTS_PER_EPOCH, 432000);
assert_eq!(DEFAULT_SLOTS_PER_EPOCH, 432_000);
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (0, 0));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432_000)]);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (0, 1));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 432_000)]);
for _ in 2..19 {
bank = Arc::new(new_from_parent(&bank));
}
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (0, 18));
assert_eq!(bank.rent_collection_partitions(), vec![(17, 18, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(17, 18, 432_000)]);
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 44));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (1, 12));
assert_eq!(
bank.rent_collection_partitions(),
vec![(18, 31, 432000), (31, 44, 432000)]
vec![(18, 31, 432_000), (31, 44, 432_000)]
);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (1, 13));
assert_eq!(bank.rent_collection_partitions(), vec![(44, 45, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(44, 45, 432_000)]);
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 431993));
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 432011));
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 431_993));
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 432_011));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (13500, 11));
assert_eq!(
bank.rent_collection_partitions(),
vec![(431993, 431999, 432000), (0, 11, 432000)]
vec![(431_993, 431_999, 432_000), (0, 11, 432_000)]
);
}
@ -3685,7 +3679,7 @@ mod tests {
EpochSchedule::custom(SLOTS_PER_EPOCH, LEADER_SCHEDULE_SLOT_OFFSET, true);
let mut bank = Arc::new(Bank::new(&genesis_config));
assert_eq!(DEFAULT_SLOTS_PER_EPOCH, 432000);
assert_eq!(DEFAULT_SLOTS_PER_EPOCH, 432_000);
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.first_normal_epoch(), 3);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (0, 0));
@ -3700,31 +3694,31 @@ mod tests {
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 256);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (3, 0));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 431872)]);
assert_eq!(431872 % bank.get_slots_in_epoch(bank.epoch()), 0);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 431_872)]);
assert_eq!(431_872 % bank.get_slots_in_epoch(bank.epoch()), 0);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 256);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (3, 1));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 431872)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 431_872)]);
bank = Arc::new(Bank::new_from_parent(
&bank,
&Pubkey::default(),
431872 + 223 - 1,
431_872 + 223 - 1,
));
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 256);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (1689, 255));
assert_eq!(
bank.rent_collection_partitions(),
vec![(431870, 431871, 431872)]
vec![(431_870, 431_871, 431_872)]
);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 256);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (1690, 0));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 431872)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 431_872)]);
}
#[test]
@ -3744,48 +3738,52 @@ mod tests {
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 32);
assert_eq!(bank.first_normal_epoch(), 3);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (0, 0));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432_000)]);
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 222));
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 128);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (2, 127));
assert_eq!(bank.rent_collection_partitions(), vec![(222, 223, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(222, 223, 432_000)]);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 256);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (3, 0));
assert_eq!(bank.rent_collection_partitions(), vec![(223, 224, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(223, 224, 432_000)]);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.get_slots_in_epoch(bank.epoch()), 256);
assert_eq!(bank.get_epoch_and_slot_index(bank.slot()), (3, 1));
assert_eq!(bank.rent_collection_partitions(), vec![(224, 225, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(224, 225, 432_000)]);
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 432000 - 2));
bank = Arc::new(Bank::new_from_parent(
&bank,
&Pubkey::default(),
432_000 - 2,
));
bank = Arc::new(new_from_parent(&bank));
assert_eq!(
bank.rent_collection_partitions(),
vec![(431998, 431999, 432000)]
vec![(431_998, 431_999, 432_000)]
);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 0, 432_000)]);
bank = Arc::new(new_from_parent(&bank));
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 432000)]);
assert_eq!(bank.rent_collection_partitions(), vec![(0, 1, 432_000)]);
bank = Arc::new(Bank::new_from_parent(
&bank,
&Pubkey::default(),
864000 - 20,
864_000 - 20,
));
bank = Arc::new(Bank::new_from_parent(
&bank,
&Pubkey::default(),
864000 + 39,
864_000 + 39,
));
assert_eq!(
bank.rent_collection_partitions(),
vec![(431980, 431999, 432000), (0, 39, 432000)]
vec![(431_980, 431_999, 432_000), (0, 39, 432_000)]
);
}
@ -3924,7 +3922,7 @@ mod tests {
let mut bank = Arc::new(Bank::new(&genesis_config));
let zero_lamports = 0;
let little_lamports = 1234;
let large_lamports = 123456789;
let large_lamports = 123_456_789;
let rent_collected = 22;
bank.store_account(
@ -4064,7 +4062,6 @@ mod tests {
// create a bank that ticks really slowly...
let bank = Arc::new(Bank::new(&GenesisConfig {
accounts: (0..42)
.into_iter()
.map(|_| {
(
Pubkey::new_rand(),
@ -4102,9 +4099,9 @@ mod tests {
// generate some rewards
let mut vote_state = Some(VoteState::from(&vote_account).unwrap());
for i in 0..MAX_LOCKOUT_HISTORY + 42 {
vote_state
.as_mut()
.map(|v| v.process_slot_vote_unchecked(i as u64));
if let Some(v) = vote_state.as_mut() {
v.process_slot_vote_unchecked(i as u64)
}
let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap()));
VoteState::to(&versioned, &mut vote_account).unwrap();
bank.store_account(&vote_id, &vote_account);
@ -4253,7 +4250,7 @@ mod tests {
let t1 = system_transaction::transfer(&mint_keypair, &key1, 1, genesis_config.hash());
let t2 = system_transaction::transfer(&mint_keypair, &key2, 1, genesis_config.hash());
let res = bank.process_transactions(&vec![t1.clone(), t2.clone()]);
let res = bank.process_transactions(&[t1.clone(), t2.clone()]);
assert_eq!(res.len(), 2);
assert_eq!(res[0], Ok(()));
@ -4642,7 +4639,7 @@ mod tests {
];
let initial_balance = bank.get_balance(&leader);
let results = bank.filter_program_errors_and_collect_fee(&vec![tx1, tx2], None, &results);
let results = bank.filter_program_errors_and_collect_fee(&[tx1, tx2], None, &results);
bank.freeze();
assert_eq!(
bank.get_balance(&leader),
@ -4737,7 +4734,7 @@ mod tests {
assert_eq!(results[0], Ok(()));
assert_eq!(results[1], Ok(()));
let ix0 = vote_instruction::vote(&vote_pubkey2, &authorized_voter.pubkey(), vote.clone());
let ix0 = vote_instruction::vote(&vote_pubkey2, &authorized_voter.pubkey(), vote);
let tx0 = Transaction::new_signed_with_payer(
&[ix0],
Some(&payer0.pubkey()),
@ -4873,7 +4870,7 @@ mod tests {
Err(TransactionError::SanitizeFailure)
);
let mut tx_invalid_account_index = tx.clone();
let mut tx_invalid_account_index = tx;
tx_invalid_account_index.message.instructions[0].accounts[0] = 42;
assert_eq!(
bank.process_transaction(&tx_invalid_account_index),
@ -5828,6 +5825,7 @@ mod tests {
}
#[test]
#[allow(clippy::float_cmp)]
fn test_check_point_value() {
let (genesis_config, _) = create_genesis_config(500);
let bank = Arc::new(Bank::new(&genesis_config));
@ -5881,7 +5879,7 @@ mod tests {
);
assert_eq!(
bank1.get_program_accounts(Some(&program_id)),
vec![(pubkey0, account0.clone())]
vec![(pubkey0, account0)]
);
assert_eq!(
bank1.get_program_accounts_modified_since_parent(&program_id),
@ -6056,7 +6054,7 @@ mod tests {
sysvar::recent_blockhashes::RecentBlockhashes::from_account(&bhq_account).unwrap();
// Check length
assert_eq!(recent_blockhashes.len(), i);
let most_recent_hash = recent_blockhashes.iter().nth(0).unwrap().blockhash;
let most_recent_hash = recent_blockhashes.iter().next().unwrap().blockhash;
// Check order
assert_eq!(Some(true), bank.check_hash_age(&most_recent_hash, 0));
goto_end_of_slot(Arc::get_mut(&mut bank).unwrap());
@ -6188,7 +6186,7 @@ mod tests {
&custodian_keypair.pubkey(),
custodian_lamports,
)];
let nonce_authority = nonce_authority.unwrap_or(nonce_keypair.pubkey());
let nonce_authority = nonce_authority.unwrap_or_else(|| nonce_keypair.pubkey());
setup_ixs.extend_from_slice(&system_instruction::create_nonce_account(
&custodian_keypair.pubkey(),
&nonce_keypair.pubkey(),
@ -6348,7 +6346,7 @@ mod tests {
let bank = Arc::new(Bank::new(&genesis_config));
let nonce = Keypair::new();
let nonce_account = Account::new_data(
42424242,
42_424_242,
&nonce::state::Versions::new_current(nonce::State::Initialized(
nonce::state::Data::default(),
)),
@ -6376,16 +6374,8 @@ mod tests {
#[test]
fn test_durable_nonce_transaction() {
let (mut bank, _mint_keypair, custodian_keypair, nonce_keypair) = setup_nonce_with_bank(
10_000_000,
|gc| {
gc.rent.lamports_per_byte_year;
},
5_000_000,
250_000,
None,
)
.unwrap();
let (mut bank, _mint_keypair, custodian_keypair, nonce_keypair) =
setup_nonce_with_bank(10_000_000, |_| {}, 5_000_000, 250_000, None).unwrap();
let alice_keypair = Keypair::new();
let alice_pubkey = alice_keypair.pubkey();
let custodian_pubkey = custodian_keypair.pubkey();
@ -6552,9 +6542,9 @@ mod tests {
let blockhash = bank0.last_blockhash();
let tx0 = system_transaction::transfer(&keypair0, &pubkey0, 2, blockhash.clone());
let tx1 = system_transaction::transfer(&Keypair::new(), &pubkey1, 2, blockhash.clone());
let tx2 = system_transaction::transfer(&keypair1, &pubkey2, 12, blockhash.clone());
let tx0 = system_transaction::transfer(&keypair0, &pubkey0, 2, blockhash);
let tx1 = system_transaction::transfer(&Keypair::new(), &pubkey1, 2, blockhash);
let tx2 = system_transaction::transfer(&keypair1, &pubkey2, 12, blockhash);
let txs = vec![tx0, tx1, tx2];
let lock_result = bank0.prepare_batch(&txs, None);
@ -6608,7 +6598,7 @@ mod tests {
let from_pubkey = Pubkey::new_rand();
let to_pubkey = Pubkey::new_rand();
let dup_pubkey = from_pubkey.clone();
let dup_pubkey = from_pubkey;
let from_account = Account::new(100, 1, &mock_program_id);
let to_account = Account::new(0, 1, &mock_program_id);
bank.store_account(&from_pubkey, &from_account);
@ -6651,7 +6641,7 @@ mod tests {
let from_pubkey = Pubkey::new_rand();
let to_pubkey = Pubkey::new_rand();
let dup_pubkey = from_pubkey.clone();
let dup_pubkey = from_pubkey;
let from_account = Account::new(100, 1, &mock_program_id);
let to_account = Account::new(0, 1, &mock_program_id);
bank.store_account(&from_pubkey, &from_account);
@ -6873,7 +6863,6 @@ mod tests {
let max_programs = 5;
let program_keys: Vec<_> = (0..max_programs)
.into_iter()
.enumerate()
.map(|i| {
let key = Pubkey::new_rand();
@ -6884,7 +6873,6 @@ mod tests {
.collect();
let max_keys = 100;
let keys: Vec<_> = (0..max_keys)
.into_iter()
.enumerate()
.map(|_| {
let key = Pubkey::new_rand();
@ -6916,7 +6904,6 @@ mod tests {
let mut account_keys: Vec<_> = if thread_rng().gen_ratio(1, 5) {
(0..num_keys)
.into_iter()
.map(|_| {
let idx = thread_rng().gen_range(0, keys.len());
keys[idx].0
@ -6926,7 +6913,6 @@ mod tests {
use std::collections::HashSet;
let mut inserted = HashSet::new();
(0..num_keys)
.into_iter()
.map(|_| {
let mut idx;
loop {
@ -6943,11 +6929,9 @@ mod tests {
let instructions: Vec<_> = if num_keys > 0 {
(0..num_instructions)
.into_iter()
.map(|_| {
let num_accounts_to_pass = thread_rng().gen_range(0, num_keys);
let account_indexes = (0..num_accounts_to_pass)
.into_iter()
.map(|_| thread_rng().gen_range(0, num_keys))
.collect();
let program_index: u8 = thread_rng().gen_range(0, num_keys) as u8;

View File

@ -595,8 +595,8 @@ mod tests {
// Check call depth increases and has a limit
let mut depth_reached = 1;
for i in 1..MAX_DEPTH {
if Err(InstructionError::CallDepth) == invoke_context.push(&program_ids[i]) {
for program_id in program_ids.iter().skip(1) {
if Err(InstructionError::CallDepth) == invoke_context.push(program_id) {
break;
}
depth_reached += 1;
@ -721,7 +721,7 @@ mod tests {
}
pub fn new_cross_program(owner: &Pubkey, program_id: &Pubkey, key: &Pubkey) -> Self {
let mut change = Change::new(owner, program_id);
change.pre.key = key.clone();
change.pre.key = *key;
change
}
pub fn read_only(mut self) -> Self {
@ -931,7 +931,7 @@ mod tests {
Change::new(&owner, &owner)
.executable(false, true)
.lamports(0, min_lamports - 1)
.data(data.clone(), data.clone())
.data(data.clone(), data)
.verify(),
Err(InstructionError::ExecutableAccountNotRentExempt),
"owner should not be able to change an account's data once its marked executable"
@ -968,7 +968,7 @@ mod tests {
assert_eq!(
Change::new_cross_program(&owner, &system_program_id, &key)
.signer(false, true, &[key.clone()])
.signer(false, true, &[key])
.verify_cross_program(),
Ok(()),
"account signed by a signer"
@ -1314,7 +1314,7 @@ mod tests {
let from_pubkey = Pubkey::new_rand();
let to_pubkey = Pubkey::new_rand();
let dup_pubkey = from_pubkey.clone();
let dup_pubkey = from_pubkey;
let account_metas = vec![
AccountMeta::new(from_pubkey, true),
AccountMeta::new(to_pubkey, false),

View File

@ -212,7 +212,7 @@ mod tests {
// New is in Uninitialzed state
assert_eq!(state, State::Uninitialized);
let recent_blockhashes = create_test_recent_blockhashes(0);
let authorized = nonce_account.unsigned_key().clone();
let authorized = nonce_account.unsigned_key();
nonce_account
.initialize_nonce_account(&authorized, &recent_blockhashes, &Rent::free())
.unwrap();
@ -242,7 +242,7 @@ mod tests {
// New is in Uninitialzed state
assert_eq!(state, State::Uninitialized);
let recent_blockhashes = create_test_recent_blockhashes(0);
let authorized = nonce_account.unsigned_key().clone();
let authorized = nonce_account.unsigned_key();
nonce_account
.initialize_nonce_account(&authorized, &recent_blockhashes, &Rent::free())
.unwrap();
@ -378,7 +378,7 @@ mod tests {
&post_account_pubkey,
&Err(transaction::TransactionError::InstructionError(
0,
InstructionError::InvalidArgument.into(),
InstructionError::InvalidArgument,
)),
Some((&pre_account_pubkey, &pre_account)),
&last_blockhash,

View File

@ -323,9 +323,9 @@ pub mod tests {
let mut vote_state = Some(VoteState::from(&vote_account).unwrap());
for i in 0..MAX_LOCKOUT_HISTORY + 42 {
vote_state
.as_mut()
.map(|v| v.process_slot_vote_unchecked(i as u64));
if let Some(v) = vote_state.as_mut() {
v.process_slot_vote_unchecked(i as u64)
}
let versioned = VoteStateVersions::Current(Box::new(vote_state.take().unwrap()));
VoteState::to(&versioned, &mut vote_account).unwrap();
match versioned {

View File

@ -456,6 +456,7 @@ mod tests {
}
#[test]
#[allow(clippy::assertions_on_constants)]
fn test_age_sanity() {
assert!(MAX_CACHE_ENTRIES <= MAX_RECENT_BLOCKHASHES);
}

View File

@ -497,7 +497,7 @@ mod tests {
let from_lamports = from_account.borrow().lamports;
let to_lamports = to_account.lamports;
let to_owner = to_account.owner;
let to_data = to_account.data.clone();
let to_data = to_account.data;
assert_eq!(from_lamports, 100);
assert_eq!(to_lamports, 0);
assert_eq!(to_owner, new_program_owner);

View File

@ -211,7 +211,7 @@ fn test_stake_account_lifetime() {
if let StakeState::Stake(_meta, stake) = stake_state {
assert_eq!(stake.delegation.stake, 1_000_000);
} else {
assert!(false, "wrong account type found")
panic!("wrong account type found")
}
// Test that we cannot withdraw anything until deactivation
@ -235,7 +235,7 @@ fn test_stake_account_lifetime() {
if let StakeState::Stake(_meta, stake) = stake_state {
assert_eq!(stake.delegation.stake, 1_000_000);
} else {
assert!(false, "wrong account type found")
panic!("wrong account type found")
}
loop {
@ -453,6 +453,6 @@ fn test_create_stake_account_from_seed() {
if let StakeState::Stake(_meta, stake) = stake_state {
assert_eq!(stake.delegation.stake, 1_000_000);
} else {
assert!(false, "wrong account type found")
panic!("wrong account type found")
}
}