From 4f71ca4a0a0b55bd36f07fe245e5bb54d7447a02 Mon Sep 17 00:00:00 2001 From: refcell Date: Sun, 1 Sep 2024 08:57:21 -0400 Subject: [PATCH] feat(primitives): arbitrary impl --- crates/primitives/src/block.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 0b2033e..0dbe92b 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -7,6 +7,7 @@ use core::fmt::Display; #[derive(Debug, Clone, Copy, Eq, Hash, PartialEq, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))] +#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] pub struct BlockID { /// Block hash pub hash: B256, @@ -23,3 +24,18 @@ impl Display for BlockID { ) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_block_id_display() { + let block_id = BlockID { + hash: B256::from([0; 32]), + number: 0, + }; + let expected = "BlockID { hash: 0x0000000000000000000000000000000000000000000000000000000000000000, number: 0 }"; + assert_eq!(block_id.to_string(), expected); + } +}