test: add roundtrip test for encoding and decoding an Address
What changed, and why it matters
This commit adds a new automated test that checks an Address object can be encoded to bytes and then decoded back to the same object. It does not change any production code, fix any bug, or alter behavior visible to users.
No security action needed; this is a routine test addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds one unit test, encode_decode_address_roundtrip, in p2p/src/address.rs. The test constructs a local SocketAddr, wraps it in an Address with NETWORK and WITNESS service flags, encodes via encoding::encode_to_vec, decodes via encoding::decode_from_slice, and asserts equality. No library code is modified.
Changed components
p2p/src/address.rs (test module only)Inspect captured patch +10 / −0
diff --git a/p2p/src/address.rs b/p2p/src/address.rs
index 1c502d5d..5047c886 100644
--- a/p2p/src/address.rs
+++ b/p2p/src/address.rs
@@ -977,6 +977,16 @@ mod test {
use super::*;
use crate::message::AddrV2Payload;
+ #[test]
+ fn encode_decode_address_roundtrip() {
+ let sock = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8333);
+ let addr = Address::new(&sock, ServiceFlags::NETWORK | ServiceFlags::WITNESS);
+ let encoded_addr = encoding::encode_to_vec(&addr);
+ let decoded_addr = encoding::decode_from_slice::<Address>(&encoded_addr).unwrap();
+
+ assert_eq!(decoded_addr, addr);
+ }
+
#[test]
fn serialize_address() {
assert_eq!(
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.