From a8514d78adf5f59124244b0ffcc3ea67e7206d3a Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Wed, 18 Sep 2024 12:53:02 +0900 Subject: [PATCH] chore(proto): remove OldKeyPrint variants Only used for one test arbitrarily testing itself... --- sn_protocol/src/lib.rs | 54 +----------------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/sn_protocol/src/lib.rs b/sn_protocol/src/lib.rs index a5aa364e25..4d3b92628d 100644 --- a/sn_protocol/src/lib.rs +++ b/sn_protocol/src/lib.rs @@ -394,62 +394,10 @@ impl<'a> std::fmt::Debug for PrettyPrintRecordKey<'a> { #[cfg(test)] mod tests { - use crate::{NetworkAddress, PrettyPrintRecordKey}; + use crate::NetworkAddress; use bls::rand::thread_rng; - use bytes::Bytes; - use libp2p::kad::{KBucketKey, RecordKey}; use sn_transfers::SpendAddress; - // A struct that implements hex representation of RecordKey using `bytes::Bytes` - struct OldRecordKeyPrint(RecordKey); - - // old impl using Bytes - impl std::fmt::Display for OldRecordKeyPrint { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let b: Vec = self.0.as_ref().to_vec(); - let record_key_b = Bytes::from(b); - let record_key_str = &format!("{record_key_b:64x}")[0..6]; // only the first 6 chars are logged - write!( - f, - "{record_key_str}({:?})", - OldKBucketKeyPrint(NetworkAddress::from_record_key(&self.0).as_kbucket_key()) - ) - } - } - - impl std::fmt::Debug for OldRecordKeyPrint { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{self}") - } - } - - // A struct that implements hex representation of KBucketKey using `bytes::Bytes` - pub struct OldKBucketKeyPrint(KBucketKey>); - - // old impl using Bytes - impl std::fmt::Display for OldKBucketKeyPrint { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let kbucket_key_b = Bytes::from(self.0.hashed_bytes().to_vec()); - write!(f, "{kbucket_key_b:64x}") - } - } - - impl std::fmt::Debug for OldKBucketKeyPrint { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{self}") - } - } - - #[test] - fn verify_custom_hex_representation() { - let random = xor_name::XorName::random(&mut thread_rng()); - let key = RecordKey::new(&random.0); - let pretty_key = PrettyPrintRecordKey::from(&key).into_owned(); - let old_record_key = OldRecordKeyPrint(key); - - assert_eq!(format!("{pretty_key:?}"), format!("{old_record_key:?}")); - } - #[test] fn verify_spend_addr_is_actionable() { let xorname = xor_name::XorName::random(&mut thread_rng());