Refactor dummy_block function in unit test
What changed, and why it matters
This commit is a harmless code cleanup inside the project's test suite. It moves the creation of a fake Bitcoin block into a reusable helper function and renames a few variables. There is no change to the actual library code that users rely on, and no security implications.
No action required; this is a non-security test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors primitives/src/block.rs test module only. It extracts the inline block construction from block_decode() into a new helper dummy_block(), renames original_block/decoded_block to original/decoded, and reorders the assert_eq! operands to (got, want). No production code, no feature changes, no test coverage change as stated.
Changed components
primitives/src/block.rs (test module only)Inspect captured patch +11 / −8
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index a384cd69..cc59e377 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -1322,10 +1322,8 @@ mod tests {
assert_eq!(header, parsed_upper);
}
- #[test]
#[cfg(feature = "alloc")]
- fn block_decode() {
- // Make a simple block, encode then decode. Verify equivalence.
+ fn dummy_block() -> Block {
let header = Header {
version: Version::ONE,
#[rustfmt::skip]
@@ -1363,13 +1361,18 @@ mod tests {
script_pubkey: crate::script::ScriptPubKeyBuf::new(),
}],
}];
- let original_block = Block::new_unchecked(header, transactions);
+ Block::new_unchecked(header, transactions)
+ }
+
+ #[test]
+ #[cfg(feature = "alloc")]
+ fn block_decode() {
+ let original = dummy_block();
- // Encode + decode the block
- let encoded = encoding::encode_to_vec(&original_block);
- let decoded_block = encoding::decode_from_slice(encoded.as_slice()).unwrap();
+ let encoded = encoding::encode_to_vec(&original);
+ let decoded: Block = encoding::decode_from_slice(encoded.as_slice()).unwrap();
- assert_eq!(original_block, decoded_block);
+ assert_eq!(decoded, original);
}
// Test vector provided by tm0 in issue #5023
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.