test(p2p): Replace encoding logic in `bip152`
What changed, and why it matters
This is a small test-only change that swaps one internal encoding helper for another inside the BIP152 test module. It does not touch production code, network handling, or consensus logic, and there is no indication it fixes or introduces a security issue.
No security action required. Treat as routine test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit updates p2p/src/bip152.rs test code to replace calls to bitcoin::consensus::encode::{deserialize, serialize} with equivalent encoding::{decode_from_slice, encode_to_vec} helpers. The change is purely a refactoring of test utilities; no runtime behavior, serialization format, or validation rules are altered.
Changed components
p2p/src/bip152.rs (test module only)Inspect captured patch +5 / −6
diff --git a/p2p/src/bip152.rs b/p2p/src/bip152.rs
index 67ff5786..c7d6afde 100644
--- a/p2p/src/bip152.rs
+++ b/p2p/src/bip152.rs
@@ -1040,7 +1040,6 @@ impl<'a> Arbitrary<'a> for BlockTransactionsRequest {
mod test {
use alloc::vec;
- use bitcoin::consensus::encode::{deserialize, serialize};
use bitcoin::merkle_tree::TxMerkleNode;
use primitives::locktime::absolute;
use primitives::{
@@ -1105,11 +1104,11 @@ mod test {
let raw_block = hex::decode_to_vec("000000206c750a364035aefd5f81508a08769975116d9195312ee4520dceac39e1fdc62c4dc67473b8e354358c1e610afeaff7410858bd45df43e2940f8a62bd3d5e3ac943c2975cffff7f200000000002020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff04016b0101ffffffff020006062a0100000001510000000000000000266a24aa21a9ed4a3d9f3343dafcc0d6f6d4310f2ee5ce273ed34edca6c75db3a73e7f368734200120000000000000000000000000000000000000000000000000000000000000000000000000020000000001021fc20ba2bd745507b8e00679e3b362558f9457db374ca28ffa5243f4c23a4d5f00000000171600147c9dea14ffbcaec4b575e03f05ceb7a81cd3fcbffdffffff915d689be87b43337f42e26033df59807b768223368f189a023d0242d837768900000000171600147c9dea14ffbcaec4b575e03f05ceb7a81cd3fcbffdffffff0200cdf5050000000017a9146803c72d9154a6a20f404bed6d3dcee07986235a8700e1f5050000000017a9144e6a4c7cb5b5562904843bdf816342f4db9f5797870247304402205e9bf6e70eb0e4b495bf483fd8e6e02da64900f290ef8aaa64bb32600d973c450220670896f5d0e5f33473e5f399ab680cc1d25c2d2afd15abd722f04978f28be887012103e4e4d9312b2261af508b367d8ba9be4f01b61d6d6e78bec499845b4f410bcf2702473044022045ac80596a6ac9c8c572f94708709adaf106677221122e08daf8b9741a04f66a022003ccd52a3b78f8fd08058fc04fc0cffa5f4c196c84eae9e37e2a85babe731b57012103e4e4d9312b2261af508b367d8ba9be4f01b61d6d6e78bec499845b4f410bcf276a000000").unwrap();
let raw_compact = hex::decode_to_vec("000000206c750a364035aefd5f81508a08769975116d9195312ee4520dceac39e1fdc62c4dc67473b8e354358c1e610afeaff7410858bd45df43e2940f8a62bd3d5e3ac943c2975cffff7f2000000000a4df3c3744da89fa010a6979e971450100020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff04016b0101ffffffff020006062a0100000001510000000000000000266a24aa21a9ed4a3d9f3343dafcc0d6f6d4310f2ee5ce273ed34edca6c75db3a73e7f368734200120000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
- let block: Block = deserialize(&raw_block).unwrap();
+ let block: Block = encoding::decode_from_slice(&raw_block).unwrap();
let block = block.assume_checked(None);
let nonce = 18_053_200_567_810_711_460;
let compact = HeaderAndShortIds::from_block(&block, nonce, 2, &[]).unwrap();
- let compact_expected = deserialize(&raw_compact).unwrap();
+ let compact_expected = encoding::decode_from_slice(&raw_compact).unwrap();
assert_eq!(compact, compact_expected);
}
@@ -1133,12 +1132,12 @@ mod test {
// test deserialization
let mut raw: Vec<u8> = vec![0u8; 32];
raw.extend(testcase.0.clone());
- let btr: BlockTransactionsRequest = deserialize(&raw.clone()).unwrap();
+ let btr: BlockTransactionsRequest = encoding::decode_from_slice(&raw.clone()).unwrap();
assert_eq!(testcase.1, btr.indices().unwrap());
}
{
// test serialization
- let raw: Vec<u8> = serialize(&&BlockTransactionsRequest::from_indices_unchecked(
+ let raw: Vec<u8> = encoding::encode_to_vec(&BlockTransactionsRequest::from_indices_unchecked(
BlockHash::from_byte_array([0; 32]),
testcase.1,
));
@@ -1152,7 +1151,7 @@ mod test {
// test that we return Err() if deserialization fails (and don't panic)
let mut raw: Vec<u8> = [0u8; 32].to_vec();
raw.extend(errorcase);
- assert!(deserialize::<BlockTransactionsRequest>(&raw).is_err());
+ assert!(encoding::decode_from_slice::<BlockTransactionsRequest>(&raw).is_err());
}
}
}
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.