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

Commit fb4d8e1

Browse files
authored
cleanup clippy tests (#10172)
automerge
1 parent a71833c commit fb4d8e1

File tree

10 files changed

+46
-46
lines changed

10 files changed

+46
-46
lines changed

core/src/cluster_info.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,8 +2425,7 @@ mod tests {
24252425

24262426
fn test_crds_values(pubkey: Pubkey) -> Vec<CrdsValue> {
24272427
let entrypoint = ContactInfo::new_localhost(&pubkey, timestamp());
2428-
let entrypoint_crdsvalue =
2429-
CrdsValue::new_unsigned(CrdsData::ContactInfo(entrypoint.clone()));
2428+
let entrypoint_crdsvalue = CrdsValue::new_unsigned(CrdsData::ContactInfo(entrypoint));
24302429
vec![entrypoint_crdsvalue]
24312430
}
24322431

core/src/cluster_info_vote_listener.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ mod tests {
957957
&exit,
958958
Arc::new(RwLock::new(bank_forks)),
959959
Arc::new(RwLock::new(BlockCommitmentCache::default_with_blockstore(
960-
blockstore.clone(),
960+
blockstore,
961961
))),
962962
));
963963

@@ -1072,7 +1072,7 @@ mod tests {
10721072
&exit,
10731073
Arc::new(RwLock::new(bank_forks)),
10741074
Arc::new(RwLock::new(BlockCommitmentCache::default_with_blockstore(
1075-
blockstore.clone(),
1075+
blockstore,
10761076
))),
10771077
));
10781078

core/src/commitment.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ mod tests {
551551
cache2.increase_confirmation_stake(2, 5);
552552

553553
let mut block_commitment = HashMap::new();
554-
block_commitment.entry(1).or_insert(cache0.clone()); // Slot 1, conf 2
555-
block_commitment.entry(2).or_insert(cache1.clone()); // Slot 2, conf 1
556-
block_commitment.entry(3).or_insert(cache2.clone()); // Slot 3, conf 0
554+
block_commitment.entry(1).or_insert_with(|| cache0.clone()); // Slot 1, conf 2
555+
block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1
556+
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
557557
let block_commitment_cache = BlockCommitmentCache::new(
558558
block_commitment,
559559
0,
@@ -568,9 +568,9 @@ mod tests {
568568

569569
// Build map with multiple slots at conf 1
570570
let mut block_commitment = HashMap::new();
571-
block_commitment.entry(1).or_insert(cache1.clone()); // Slot 1, conf 1
572-
block_commitment.entry(2).or_insert(cache1.clone()); // Slot 2, conf 1
573-
block_commitment.entry(3).or_insert(cache2.clone()); // Slot 3, conf 0
571+
block_commitment.entry(1).or_insert_with(|| cache1.clone()); // Slot 1, conf 1
572+
block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1
573+
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
574574
let block_commitment_cache = BlockCommitmentCache::new(
575575
block_commitment,
576576
0,
@@ -585,9 +585,9 @@ mod tests {
585585

586586
// Build map with slot gaps
587587
let mut block_commitment = HashMap::new();
588-
block_commitment.entry(1).or_insert(cache1.clone()); // Slot 1, conf 1
589-
block_commitment.entry(3).or_insert(cache1.clone()); // Slot 3, conf 1
590-
block_commitment.entry(5).or_insert(cache2.clone()); // Slot 5, conf 0
588+
block_commitment.entry(1).or_insert_with(|| cache1.clone()); // Slot 1, conf 1
589+
block_commitment.entry(3).or_insert(cache1); // Slot 3, conf 1
590+
block_commitment.entry(5).or_insert_with(|| cache2.clone()); // Slot 5, conf 0
591591
let block_commitment_cache = BlockCommitmentCache::new(
592592
block_commitment,
593593
0,
@@ -602,9 +602,9 @@ mod tests {
602602

603603
// Build map with no conf 1 slots, but one higher
604604
let mut block_commitment = HashMap::new();
605-
block_commitment.entry(1).or_insert(cache0.clone()); // Slot 1, conf 2
606-
block_commitment.entry(2).or_insert(cache2.clone()); // Slot 2, conf 0
607-
block_commitment.entry(3).or_insert(cache2.clone()); // Slot 3, conf 0
605+
block_commitment.entry(1).or_insert(cache0); // Slot 1, conf 2
606+
block_commitment.entry(2).or_insert_with(|| cache2.clone()); // Slot 2, conf 0
607+
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
608608
let block_commitment_cache = BlockCommitmentCache::new(
609609
block_commitment,
610610
0,
@@ -619,15 +619,15 @@ mod tests {
619619

620620
// Build map with no conf 1 or higher slots
621621
let mut block_commitment = HashMap::new();
622-
block_commitment.entry(1).or_insert(cache2.clone()); // Slot 1, conf 0
623-
block_commitment.entry(2).or_insert(cache2.clone()); // Slot 2, conf 0
624-
block_commitment.entry(3).or_insert(cache2.clone()); // Slot 3, conf 0
622+
block_commitment.entry(1).or_insert_with(|| cache2.clone()); // Slot 1, conf 0
623+
block_commitment.entry(2).or_insert_with(|| cache2.clone()); // Slot 2, conf 0
624+
block_commitment.entry(3).or_insert(cache2); // Slot 3, conf 0
625625
let block_commitment_cache = BlockCommitmentCache::new(
626626
block_commitment,
627627
0,
628628
total_stake,
629-
bank_slot_5.clone(),
630-
blockstore.clone(),
629+
bank_slot_5,
630+
blockstore,
631631
0,
632632
0,
633633
);

core/src/replay_stage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,7 @@ pub(crate) mod tests {
26182618

26192619
let exit = Arc::new(AtomicBool::new(false));
26202620
let block_commitment_cache = Arc::new(RwLock::new(
2621-
BlockCommitmentCache::default_with_blockstore(blockstore.clone()),
2621+
BlockCommitmentCache::default_with_blockstore(blockstore),
26222622
));
26232623
let subscriptions = Arc::new(RpcSubscriptions::new(
26242624
&exit,

core/src/rpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ pub mod tests {
23212321
r#"{{"jsonrpc":"2.0","id":1,"method":"simulateTransaction","params":["{}"]}}"#,
23222322
tx_serialized_encoded,
23232323
);
2324-
let res = io.handle_request_sync(&req, meta.clone());
2324+
let res = io.handle_request_sync(&req, meta);
23252325
let expected = json!({
23262326
"jsonrpc": "2.0",
23272327
"result": {
@@ -2361,7 +2361,7 @@ pub mod tests {
23612361
);
23622362

23632363
// should panic because `bank` is not frozen
2364-
let _ = io.handle_request_sync(&req, meta.clone());
2364+
let _ = io.handle_request_sync(&req, meta);
23652365
}
23662366

23672367
#[test]

core/src/rpc_pubsub.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,11 @@ mod tests {
745745
);
746746
let exit = Arc::new(AtomicBool::new(false));
747747
let block_commitment_cache = Arc::new(RwLock::new(
748-
BlockCommitmentCache::new_for_tests_with_blockstore(blockstore.clone()),
748+
BlockCommitmentCache::new_for_tests_with_blockstore(blockstore),
749749
));
750750

751751
let subscriptions =
752-
RpcSubscriptions::new(&exit, bank_forks.clone(), block_commitment_cache.clone());
752+
RpcSubscriptions::new(&exit, bank_forks.clone(), block_commitment_cache);
753753
rpc.subscriptions = Arc::new(subscriptions);
754754
let session = create_session();
755755
let (subscriber, _id_receiver, receiver) = Subscriber::new_test("accountNotification");
@@ -895,8 +895,7 @@ mod tests {
895895
let (subscriber, _id_receiver, receiver) = Subscriber::new_test("voteNotification");
896896

897897
// Setup Subscriptions
898-
let subscriptions =
899-
RpcSubscriptions::new(&exit, bank_forks.clone(), block_commitment_cache.clone());
898+
let subscriptions = RpcSubscriptions::new(&exit, bank_forks, block_commitment_cache);
900899
rpc.subscriptions = Arc::new(subscriptions);
901900
rpc.vote_subscribe(session, subscriber);
902901

@@ -922,6 +921,8 @@ mod tests {
922921
});
923922

924923
// Process votes and check they were notified.
924+
// FIX-ME-BETTER-LATER - clone below is required for testcase to pass
925+
#[allow(clippy::redundant_clone)]
925926
ClusterInfoVoteListener::get_and_process_votes_for_tests(
926927
&votes_receiver,
927928
&vote_tracker,

ledger/src/blockstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4922,7 +4922,7 @@ pub mod tests {
49224922
// Trying to insert value into slot <= than last root should fail
49234923
{
49244924
let mut coding_shred =
4925-
Shred::new_empty_from_header(shred.clone(), DataShredHeader::default(), coding);
4925+
Shred::new_empty_from_header(shred, DataShredHeader::default(), coding);
49264926
let index = index_cf.get(coding_shred.slot()).unwrap().unwrap();
49274927
coding_shred.set_slot(*last_root.read().unwrap());
49284928
assert!(!Blockstore::should_insert_coding_shred(

ledger/tests/shred.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use std::{
1515
sync::Arc,
1616
};
1717

18+
type IndexShredsMap = BTreeMap<u32, Vec<Shred>>;
19+
1820
#[test]
1921
fn test_multi_fec_block_coding() {
2022
let keypair = Arc::new(Keypair::new());
@@ -123,9 +125,9 @@ fn test_multi_fec_block_different_size_coding() {
123125
let num_data = fec_data_shreds.len();
124126
let num_coding = fec_coding_shreds.len();
125127
let all_shreds: Vec<Shred> = fec_data_shreds
126-
.into_iter()
128+
.iter()
127129
.step_by(2)
128-
.chain(fec_coding_shreds.into_iter().step_by(2))
130+
.chain(fec_coding_shreds.iter().step_by(2))
129131
.cloned()
130132
.collect();
131133

@@ -162,8 +164,8 @@ fn test_multi_fec_block_different_size_coding() {
162164
fn sort_data_coding_into_fec_sets(
163165
data_shreds: Vec<Shred>,
164166
coding_shreds: Vec<Shred>,
165-
fec_data: &mut BTreeMap<u32, Vec<Shred>>,
166-
fec_coding: &mut BTreeMap<u32, Vec<Shred>>,
167+
fec_data: &mut IndexShredsMap,
168+
fec_coding: &mut IndexShredsMap,
167169
data_slot_and_index: &mut HashSet<(Slot, u32)>,
168170
coding_slot_and_index: &mut HashSet<(Slot, u32)>,
169171
) {
@@ -175,7 +177,7 @@ fn sort_data_coding_into_fec_sets(
175177
data_slot_and_index.insert(key);
176178
let fec_entry = fec_data
177179
.entry(shred.common_header.fec_set_index)
178-
.or_insert(vec![]);
180+
.or_insert_with(|| vec![]);
179181
fec_entry.push(shred);
180182
}
181183
for shred in coding_shreds {
@@ -186,16 +188,17 @@ fn sort_data_coding_into_fec_sets(
186188
coding_slot_and_index.insert(key);
187189
let fec_entry = fec_coding
188190
.entry(shred.common_header.fec_set_index)
189-
.or_insert(vec![]);
191+
.or_insert_with(|| vec![]);
190192
fec_entry.push(shred);
191193
}
192194
}
193195

196+
#[allow(clippy::assertions_on_constants)]
194197
fn setup_different_sized_fec_blocks(
195198
slot: Slot,
196199
parent_slot: Slot,
197200
keypair: Arc<Keypair>,
198-
) -> (BTreeMap<u32, Vec<Shred>>, BTreeMap<u32, Vec<Shred>>, usize) {
201+
) -> (IndexShredsMap, IndexShredsMap, usize) {
199202
let shredder =
200203
Shredder::new(slot, parent_slot, 1.0, keypair, 0, 0).expect("Failed in creating shredder");
201204
let keypair0 = Keypair::new();

sdk/src/signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ mod tests {
561561
}
562562

563563
fn pubkeys(signers: &[&dyn Signer]) -> Vec<Pubkey> {
564-
signers.into_iter().map(|x| x.pubkey()).collect()
564+
signers.iter().map(|x| x.pubkey()).collect()
565565
}
566566

567567
#[test]

sdk/src/slot_history.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ mod tests {
9999
slot_history.add(MAX_ENTRIES);
100100
assert_eq!(slot_history.check(0), Check::TooOld);
101101
assert_eq!(slot_history.check(1), Check::NotFound);
102-
assert_eq!(slot_history.check(2), Check::Found);
103-
assert_eq!(slot_history.check(20), Check::Found);
104-
assert_eq!(slot_history.check(MAX_ENTRIES), Check::Found);
102+
for i in &[2, 20, MAX_ENTRIES] {
103+
assert_eq!(slot_history.check(*i), Check::Found);
104+
}
105105
for i in 3..20 {
106106
assert_eq!(slot_history.check(i), Check::NotFound, "i: {}", i);
107107
}
@@ -113,12 +113,9 @@ mod tests {
113113
info!("add max_entries + 3");
114114
let slot = 3 * MAX_ENTRIES + 3;
115115
slot_history.add(slot);
116-
assert_eq!(slot_history.check(0), Check::TooOld);
117-
assert_eq!(slot_history.check(1), Check::TooOld);
118-
assert_eq!(slot_history.check(2), Check::TooOld);
119-
assert_eq!(slot_history.check(20), Check::TooOld);
120-
assert_eq!(slot_history.check(21), Check::TooOld);
121-
assert_eq!(slot_history.check(MAX_ENTRIES), Check::TooOld);
116+
for i in &[0, 1, 2, 20, 21, MAX_ENTRIES] {
117+
assert_eq!(slot_history.check(*i), Check::TooOld);
118+
}
122119
let start = slot - MAX_ENTRIES + 1;
123120
let end = slot;
124121
for i in start..end {

0 commit comments

Comments
 (0)