diff --git a/gossip/src/crds.rs b/gossip/src/crds.rs index 046c52104b820f..087ce66a7455b6 100644 --- a/gossip/src/crds.rs +++ b/gossip/src/crds.rs @@ -1341,15 +1341,17 @@ mod tests { let mut node = ContactInfo::new_rand(&mut rng, Some(pubkey)); let wallclock = node.wallclock(); node.set_shred_version(42); - let node = CrdsData::ContactInfo(node); - let node = CrdsValue::new_unsigned(node); - assert_eq!( - crds.insert(node, timestamp(), GossipRoute::LocalMessage), - Ok(()) - ); + { + let node = CrdsData::ContactInfo(node.clone()); + let node = CrdsValue::new_unsigned(node); + assert_eq!( + crds.insert(node, timestamp(), GossipRoute::LocalMessage), + Ok(()) + ); + } assert_eq!(crds.get_shred_version(&pubkey), Some(42)); // An outdated value should not update shred-version: - let mut node = ContactInfo::new_rand(&mut rng, Some(pubkey)); + let mut node = node.clone(); node.set_wallclock(wallclock - 1); // outdated. node.set_shred_version(8); let node = CrdsData::ContactInfo(node); @@ -1488,20 +1490,17 @@ mod tests { #[test] #[allow(clippy::neg_cmp_op_on_partial_ord)] fn test_hash_order() { + let mut node = ContactInfo::new_localhost(&Pubkey::default(), 0); let v1 = VersionedCrdsValue::new( - CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost( - &Pubkey::default(), - 0, - ))), + CrdsValue::new_unsigned(CrdsData::ContactInfo(node.clone())), Cursor::default(), 1, // local_timestamp GossipRoute::LocalMessage, ); let v2 = VersionedCrdsValue::new( { - let mut contact_info = ContactInfo::new_localhost(&Pubkey::default(), 0); - contact_info.set_rpc((Ipv4Addr::LOCALHOST, 1244)).unwrap(); - CrdsValue::new_unsigned(CrdsData::ContactInfo(contact_info)) + node.set_rpc((Ipv4Addr::LOCALHOST, 1244)).unwrap(); + CrdsValue::new_unsigned(CrdsData::ContactInfo(node)) }, Cursor::default(), 1, // local_timestamp @@ -1524,20 +1523,16 @@ mod tests { #[test] #[allow(clippy::neg_cmp_op_on_partial_ord)] fn test_wallclock_order() { + let mut node = ContactInfo::new_localhost(&Pubkey::default(), 1); let v1 = VersionedCrdsValue::new( - CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost( - &Pubkey::default(), - 1, - ))), + CrdsValue::new_unsigned(CrdsData::ContactInfo(node.clone())), Cursor::default(), 1, // local_timestamp GossipRoute::LocalMessage, ); + node.set_wallclock(0); let v2 = VersionedCrdsValue::new( - CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost( - &Pubkey::default(), - 0, - ))), + CrdsValue::new_unsigned(CrdsData::ContactInfo(node)), Cursor::default(), 1, // local_timestamp GossipRoute::LocalMessage, diff --git a/gossip/src/crds_gossip_pull.rs b/gossip/src/crds_gossip_pull.rs index c708f595343968..b227ed99734e1b 100644 --- a/gossip/src/crds_gossip_pull.rs +++ b/gossip/src/crds_gossip_pull.rs @@ -1148,6 +1148,7 @@ pub(crate) mod tests { let mut dest_crds = Crds::default(); let new_id = solana_sdk::pubkey::new_rand(); + let same_key = ContactInfo::new_localhost(&new_id, 0); let new = ContactInfo::new_localhost(&new_id, 1); ping_cache.mock_pong(*new.pubkey(), new.gossip().unwrap(), Instant::now()); let new = CrdsValue::new_unsigned(CrdsData::ContactInfo(new)); @@ -1157,7 +1158,6 @@ pub(crate) mod tests { let dest_crds = RwLock::new(dest_crds); // node contains a key from the dest node, but at an older local timestamp - let same_key = ContactInfo::new_localhost(&new_id, 0); ping_cache.mock_pong( *same_key.pubkey(), same_key.gossip().unwrap(),