diff --git a/zebra-chain/src/work/difficulty.rs b/zebra-chain/src/work/difficulty.rs index d7204c3cf..45e654a19 100644 --- a/zebra-chain/src/work/difficulty.rs +++ b/zebra-chain/src/work/difficulty.rs @@ -123,9 +123,9 @@ impl fmt::Debug for ExpandedDifficulty { #[derive(Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd)] pub struct Work(u128); -impl From for u128 { - fn from(work: Work) -> Self { - work.0 +impl Work { + pub fn as_u128(self) -> u128 { + self.0 } } diff --git a/zebra-chain/src/work/difficulty/arbitrary.rs b/zebra-chain/src/work/difficulty/arbitrary.rs index 586ad83ea..1e6c93032 100644 --- a/zebra-chain/src/work/difficulty/arbitrary.rs +++ b/zebra-chain/src/work/difficulty/arbitrary.rs @@ -51,15 +51,7 @@ impl Arbitrary for Work { // In the Zcash protocol, a Work is converted from an ExpandedDifficulty. // But some randomised difficulties are impractically large, and will // never appear in any real-world block. So we just use a random Work value. - (any::()) - .prop_filter_map("zero Work values are invalid", |w| { - if w == 0 { - None - } else { - Some(Work(w)) - } - }) - .boxed() + (1..std::u128::MAX).prop_map(Work).boxed() } type Strategy = BoxedStrategy; diff --git a/zebra-state/src/tests.rs b/zebra-state/src/tests.rs index f4c027df2..f90c98a6b 100644 --- a/zebra-state/src/tests.rs +++ b/zebra-state/src/tests.rs @@ -84,11 +84,11 @@ use proptest::prelude::*; fn round_trip_work_expanded() { zebra_test::init(); - proptest!(|(work in 1..std::u128::MAX)| { - let work: U256 = work.into(); + proptest!(|(work in any::())| { + let work: U256 = work.as_u128().into(); let expanded = work_to_expanded(work); let work_after = Work::try_from(expanded).unwrap(); - let work_after = u128::from(work_after); + let work_after = work_after.as_u128(); let work_after = U256::from(work_after); prop_assert_eq!(work, work_after); });