From 3e750d7ba1469540e057ad763b31b6a725a6f397 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Fri, 7 Mar 2025 16:04:10 +0000 Subject: [PATCH] Create test helper function to create a header Move the header creation to the helper function so it can be used in further tests. --- primitives/src/block.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/primitives/src/block.rs b/primitives/src/block.rs index 3b4925610..3ac68ad74 100644 --- a/primitives/src/block.rs +++ b/primitives/src/block.rs @@ -361,6 +361,17 @@ impl<'a> Arbitrary<'a> for Version { mod tests { use super::*; + fn dummy_header() -> Header { + Header { + version: Version::ONE, + prev_blockhash: BlockHash::from_byte_array([0x99; 32]), + merkle_root: TxMerkleNode::from_byte_array([0x77; 32]), + time: Timestamp::from(2), + bits: CompactTarget::from_consensus(3), + nonce: 4, + } + } + #[test] fn version_is_not_signalling_with_invalid_bit() { let arbitrary_version = Version::from_consensus(1_234_567_890); @@ -398,14 +409,7 @@ mod tests { // Check that the size of the header consensus serialization matches the const SIZE value #[test] fn header_size() { - let header = Header { - version: Version::ONE, - prev_blockhash: BlockHash::from_byte_array([0x99; 32]), - merkle_root: TxMerkleNode::from_byte_array([0x77; 32]), - time: Timestamp::from(2), - bits: CompactTarget::from_consensus(3), - nonce: 4, - }; + let header = dummy_header(); // Calculate the size of the block header in bytes from the sum of the serialized lengths // it's fields: version, prev_blockhash, merkle_root, time, bits, nonce.