test(p2p): Update deser tests for `AddrV2Payload`
What changed, and why it matters
This commit only adds new unit tests for serializing and deserializing Bitcoin peer-to-peer address messages. It does not change any production code, fix a bug, or alter behavior. There is no security relevance.
No action required; this is a test-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff extends an existing test in p2p/src/address.rs for AddrV2Payload by adding a round-trip deserialization/serialization check using encoding::decode_from_slice and encoding::encode_to_vec, plus assertions on the decoded structure. No implementation code is modified.
Changed components
p2p/src/address.rs (tests only)Inspect captured patch +24 / −0
diff --git a/p2p/src/address.rs b/p2p/src/address.rs
index 9c6a4758..477c73f8 100644
--- a/p2p/src/address.rs
+++ b/p2p/src/address.rs
@@ -1431,6 +1431,30 @@ mod test {
);
assert_eq!(serialize(&addresses), raw);
+
+ let addresses: AddrV2Payload = encoding::decode_from_slice(&raw).unwrap();
+
+ assert_eq!(
+ addresses.0,
+ vec![
+ AddrV2Message {
+ services: ServiceFlags::NETWORK,
+ time: 0x4966_bc61,
+ port: 8333,
+ addr: AddrV2::Unknown(153, hex!("abab").to_vec())
+ },
+ AddrV2Message {
+ services: ServiceFlags::NETWORK_LIMITED
+ | ServiceFlags::WITNESS
+ | ServiceFlags::COMPACT_FILTERS,
+ time: 0x8376_6279,
+ port: 8333,
+ addr: AddrV2::Ipv4(Ipv4Addr::new(9, 9, 9, 9))
+ },
+ ]
+ );
+
+ assert_eq!(encoding::encode_to_vec(&addresses), raw);
}
#[test]
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.