diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index f100093d661606..22ed1ca03f9951 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -2425,8 +2425,7 @@ mod tests { fn test_crds_values(pubkey: Pubkey) -> Vec { let entrypoint = ContactInfo::new_localhost(&pubkey, timestamp()); - let entrypoint_crdsvalue = - CrdsValue::new_unsigned(CrdsData::ContactInfo(entrypoint.clone())); + let entrypoint_crdsvalue = CrdsValue::new_unsigned(CrdsData::ContactInfo(entrypoint)); vec![entrypoint_crdsvalue] } diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index e674a3431e6c06..fc1f1f3c884138 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -957,7 +957,7 @@ mod tests { &exit, Arc::new(RwLock::new(bank_forks)), Arc::new(RwLock::new(BlockCommitmentCache::default_with_blockstore( - blockstore.clone(), + blockstore, ))), )); @@ -1072,7 +1072,7 @@ mod tests { &exit, Arc::new(RwLock::new(bank_forks)), Arc::new(RwLock::new(BlockCommitmentCache::default_with_blockstore( - blockstore.clone(), + blockstore, ))), )); diff --git a/core/src/commitment.rs b/core/src/commitment.rs index 5e18dbe5a77dd6..a26be76655e9fd 100644 --- a/core/src/commitment.rs +++ b/core/src/commitment.rs @@ -551,9 +551,9 @@ mod tests { cache2.increase_confirmation_stake(2, 5); let mut block_commitment = HashMap::new(); - block_commitment.entry(1).or_insert(cache0.clone()); // Slot 1, conf 2 - block_commitment.entry(2).or_insert(cache1.clone()); // Slot 2, conf 1 - block_commitment.entry(3).or_insert(cache2.clone()); // Slot 3, conf 0 + block_commitment.entry(1).or_insert_with(|| cache0.clone()); // Slot 1, conf 2 + block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1 + block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0 let block_commitment_cache = BlockCommitmentCache::new( block_commitment, 0, @@ -568,9 +568,9 @@ mod tests { // Build map with multiple slots at conf 1 let mut block_commitment = HashMap::new(); - block_commitment.entry(1).or_insert(cache1.clone()); // Slot 1, conf 1 - block_commitment.entry(2).or_insert(cache1.clone()); // Slot 2, conf 1 - block_commitment.entry(3).or_insert(cache2.clone()); // Slot 3, conf 0 + block_commitment.entry(1).or_insert_with(|| cache1.clone()); // Slot 1, conf 1 + block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1 + block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0 let block_commitment_cache = BlockCommitmentCache::new( block_commitment, 0, @@ -585,9 +585,9 @@ mod tests { // Build map with slot gaps let mut block_commitment = HashMap::new(); - block_commitment.entry(1).or_insert(cache1.clone()); // Slot 1, conf 1 - block_commitment.entry(3).or_insert(cache1.clone()); // Slot 3, conf 1 - block_commitment.entry(5).or_insert(cache2.clone()); // Slot 5, conf 0 + block_commitment.entry(1).or_insert_with(|| cache1.clone()); // Slot 1, conf 1 + block_commitment.entry(3).or_insert(cache1); // Slot 3, conf 1 + block_commitment.entry(5).or_insert_with(|| cache2.clone()); // Slot 5, conf 0 let block_commitment_cache = BlockCommitmentCache::new( block_commitment, 0, @@ -602,9 +602,9 @@ mod tests { // Build map with no conf 1 slots, but one higher let mut block_commitment = HashMap::new(); - block_commitment.entry(1).or_insert(cache0.clone()); // Slot 1, conf 2 - block_commitment.entry(2).or_insert(cache2.clone()); // Slot 2, conf 0 - block_commitment.entry(3).or_insert(cache2.clone()); // Slot 3, conf 0 + block_commitment.entry(1).or_insert(cache0); // Slot 1, conf 2 + block_commitment.entry(2).or_insert_with(|| cache2.clone()); // Slot 2, conf 0 + block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0 let block_commitment_cache = BlockCommitmentCache::new( block_commitment, 0, @@ -619,15 +619,15 @@ mod tests { // Build map with no conf 1 or higher slots let mut block_commitment = HashMap::new(); - block_commitment.entry(1).or_insert(cache2.clone()); // Slot 1, conf 0 - block_commitment.entry(2).or_insert(cache2.clone()); // Slot 2, conf 0 - block_commitment.entry(3).or_insert(cache2.clone()); // Slot 3, conf 0 + block_commitment.entry(1).or_insert_with(|| cache2.clone()); // Slot 1, conf 0 + block_commitment.entry(2).or_insert_with(|| cache2.clone()); // Slot 2, conf 0 + block_commitment.entry(3).or_insert(cache2); // Slot 3, conf 0 let block_commitment_cache = BlockCommitmentCache::new( block_commitment, 0, total_stake, - bank_slot_5.clone(), - blockstore.clone(), + bank_slot_5, + blockstore, 0, 0, ); diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 97a7614f5c2586..20d99ccb881d4c 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -2618,7 +2618,7 @@ pub(crate) mod tests { let exit = Arc::new(AtomicBool::new(false)); let block_commitment_cache = Arc::new(RwLock::new( - BlockCommitmentCache::default_with_blockstore(blockstore.clone()), + BlockCommitmentCache::default_with_blockstore(blockstore), )); let subscriptions = Arc::new(RpcSubscriptions::new( &exit, diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 4933354c46c7c4..116fed56556fcd 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -2321,7 +2321,7 @@ pub mod tests { r#"{{"jsonrpc":"2.0","id":1,"method":"simulateTransaction","params":["{}"]}}"#, tx_serialized_encoded, ); - let res = io.handle_request_sync(&req, meta.clone()); + let res = io.handle_request_sync(&req, meta); let expected = json!({ "jsonrpc": "2.0", "result": { @@ -2361,7 +2361,7 @@ pub mod tests { ); // should panic because `bank` is not frozen - let _ = io.handle_request_sync(&req, meta.clone()); + let _ = io.handle_request_sync(&req, meta); } #[test] diff --git a/core/src/rpc_pubsub.rs b/core/src/rpc_pubsub.rs index 2bb505a704af02..80c429f69d436b 100644 --- a/core/src/rpc_pubsub.rs +++ b/core/src/rpc_pubsub.rs @@ -745,11 +745,11 @@ mod tests { ); let exit = Arc::new(AtomicBool::new(false)); let block_commitment_cache = Arc::new(RwLock::new( - BlockCommitmentCache::new_for_tests_with_blockstore(blockstore.clone()), + BlockCommitmentCache::new_for_tests_with_blockstore(blockstore), )); let subscriptions = - RpcSubscriptions::new(&exit, bank_forks.clone(), block_commitment_cache.clone()); + RpcSubscriptions::new(&exit, bank_forks.clone(), block_commitment_cache); rpc.subscriptions = Arc::new(subscriptions); let session = create_session(); let (subscriber, _id_receiver, receiver) = Subscriber::new_test("accountNotification"); @@ -895,8 +895,7 @@ mod tests { let (subscriber, _id_receiver, receiver) = Subscriber::new_test("voteNotification"); // Setup Subscriptions - let subscriptions = - RpcSubscriptions::new(&exit, bank_forks.clone(), block_commitment_cache.clone()); + let subscriptions = RpcSubscriptions::new(&exit, bank_forks, block_commitment_cache); rpc.subscriptions = Arc::new(subscriptions); rpc.vote_subscribe(session, subscriber); @@ -922,6 +921,8 @@ mod tests { }); // Process votes and check they were notified. + // FIX-ME-BETTER-LATER - clone below is required for testcase to pass + #[allow(clippy::redundant_clone)] ClusterInfoVoteListener::get_and_process_votes_for_tests( &votes_receiver, &vote_tracker, diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 24eb427a86cd25..199eacfbaeb855 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -4922,7 +4922,7 @@ pub mod tests { // Trying to insert value into slot <= than last root should fail { let mut coding_shred = - Shred::new_empty_from_header(shred.clone(), DataShredHeader::default(), coding); + Shred::new_empty_from_header(shred, DataShredHeader::default(), coding); let index = index_cf.get(coding_shred.slot()).unwrap().unwrap(); coding_shred.set_slot(*last_root.read().unwrap()); assert!(!Blockstore::should_insert_coding_shred( diff --git a/ledger/tests/shred.rs b/ledger/tests/shred.rs index 3077cc187919ed..9494729b5b78e9 100644 --- a/ledger/tests/shred.rs +++ b/ledger/tests/shred.rs @@ -15,6 +15,8 @@ use std::{ sync::Arc, }; +type IndexShredsMap = BTreeMap>; + #[test] fn test_multi_fec_block_coding() { let keypair = Arc::new(Keypair::new()); @@ -123,9 +125,9 @@ fn test_multi_fec_block_different_size_coding() { let num_data = fec_data_shreds.len(); let num_coding = fec_coding_shreds.len(); let all_shreds: Vec = fec_data_shreds - .into_iter() + .iter() .step_by(2) - .chain(fec_coding_shreds.into_iter().step_by(2)) + .chain(fec_coding_shreds.iter().step_by(2)) .cloned() .collect(); @@ -162,8 +164,8 @@ fn test_multi_fec_block_different_size_coding() { fn sort_data_coding_into_fec_sets( data_shreds: Vec, coding_shreds: Vec, - fec_data: &mut BTreeMap>, - fec_coding: &mut BTreeMap>, + fec_data: &mut IndexShredsMap, + fec_coding: &mut IndexShredsMap, data_slot_and_index: &mut HashSet<(Slot, u32)>, coding_slot_and_index: &mut HashSet<(Slot, u32)>, ) { @@ -175,7 +177,7 @@ fn sort_data_coding_into_fec_sets( data_slot_and_index.insert(key); let fec_entry = fec_data .entry(shred.common_header.fec_set_index) - .or_insert(vec![]); + .or_insert_with(|| vec![]); fec_entry.push(shred); } for shred in coding_shreds { @@ -186,16 +188,17 @@ fn sort_data_coding_into_fec_sets( coding_slot_and_index.insert(key); let fec_entry = fec_coding .entry(shred.common_header.fec_set_index) - .or_insert(vec![]); + .or_insert_with(|| vec![]); fec_entry.push(shred); } } +#[allow(clippy::assertions_on_constants)] fn setup_different_sized_fec_blocks( slot: Slot, parent_slot: Slot, keypair: Arc, -) -> (BTreeMap>, BTreeMap>, usize) { +) -> (IndexShredsMap, IndexShredsMap, usize) { let shredder = Shredder::new(slot, parent_slot, 1.0, keypair, 0, 0).expect("Failed in creating shredder"); let keypair0 = Keypair::new(); diff --git a/sdk/src/signature.rs b/sdk/src/signature.rs index 84bf86e0ab6941..d360471f6ac834 100644 --- a/sdk/src/signature.rs +++ b/sdk/src/signature.rs @@ -561,7 +561,7 @@ mod tests { } fn pubkeys(signers: &[&dyn Signer]) -> Vec { - signers.into_iter().map(|x| x.pubkey()).collect() + signers.iter().map(|x| x.pubkey()).collect() } #[test] diff --git a/sdk/src/slot_history.rs b/sdk/src/slot_history.rs index 3fa97392b0f31e..bdee200a4576b5 100644 --- a/sdk/src/slot_history.rs +++ b/sdk/src/slot_history.rs @@ -99,9 +99,9 @@ mod tests { slot_history.add(MAX_ENTRIES); assert_eq!(slot_history.check(0), Check::TooOld); assert_eq!(slot_history.check(1), Check::NotFound); - assert_eq!(slot_history.check(2), Check::Found); - assert_eq!(slot_history.check(20), Check::Found); - assert_eq!(slot_history.check(MAX_ENTRIES), Check::Found); + for i in &[2, 20, MAX_ENTRIES] { + assert_eq!(slot_history.check(*i), Check::Found); + } for i in 3..20 { assert_eq!(slot_history.check(i), Check::NotFound, "i: {}", i); } @@ -113,12 +113,9 @@ mod tests { info!("add max_entries + 3"); let slot = 3 * MAX_ENTRIES + 3; slot_history.add(slot); - assert_eq!(slot_history.check(0), Check::TooOld); - assert_eq!(slot_history.check(1), Check::TooOld); - assert_eq!(slot_history.check(2), Check::TooOld); - assert_eq!(slot_history.check(20), Check::TooOld); - assert_eq!(slot_history.check(21), Check::TooOld); - assert_eq!(slot_history.check(MAX_ENTRIES), Check::TooOld); + for i in &[0, 1, 2, 20, 21, MAX_ENTRIES] { + assert_eq!(slot_history.check(*i), Check::TooOld); + } let start = slot - MAX_ENTRIES + 1; let end = slot; for i in start..end {