From 89f495c5bc33ae62e78fc8c5fa7af41cf011beaa Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Fri, 4 Oct 2024 14:59:19 +0200 Subject: [PATCH] Manual impl Arbitrary for Sealed --- crates/primitives/src/sealed.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/primitives/src/sealed.rs b/crates/primitives/src/sealed.rs index a93f8e7ac..c03864248 100644 --- a/crates/primitives/src/sealed.rs +++ b/crates/primitives/src/sealed.rs @@ -6,7 +6,7 @@ use crate::B256; /// implement the [`Sealable`] trait to provide define their own hash. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "arbitrary", derive(derive_arbitrary::Arbitrary, proptest_derive::Arbitrary))] +#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] pub struct Sealed { /// The inner item inner: T, @@ -68,6 +68,16 @@ impl Sealed { } } +#[cfg(any(test, feature = "arbitrary"))] +impl<'a, T> arbitrary::Arbitrary<'a> for Sealed +where + T: for<'b> arbitrary::Arbitrary<'b> + Sealable, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(T::arbitrary(u)?.seal_slow()) + } +} + /// Sealeable objects. pub trait Sealable: Sized { /// Calculate the seal hash, this may be slow.