use super::*;
use proptest::{collection::vec, prelude::*};
impl Arbitrary for CompactDifficulty {
type Parameters = ();
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
(vec(any::<u8>(), 32))
.prop_filter_map("zero CompactDifficulty values are invalid", |v| {
let mut bytes = [0; 32];
bytes.copy_from_slice(v.as_slice());
if bytes == [0; 32] {
return None;
}
Some(ExpandedDifficulty::from_hash(&block::Hash(bytes)).to_compact())
})
.boxed()
}
type Strategy = BoxedStrategy<Self>;
}
impl Arbitrary for ExpandedDifficulty {
type Parameters = ();
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
any::<CompactDifficulty>()
.prop_map(|d| {
d.to_expanded()
.expect("arbitrary CompactDifficulty is valid")
})
.boxed()
}
type Strategy = BoxedStrategy<Self>;
}
impl Arbitrary for Work {
type Parameters = ();
fn arbitrary_with(_args: ()) -> Self::Strategy {
(1..u128::MAX).prop_map(Work).boxed()
}
type Strategy = BoxedStrategy<Self>;
}
impl Arbitrary for PartialCumulativeWork {
type Parameters = ();
fn arbitrary_with(_args: ()) -> Self::Strategy {
(any::<Work>())
.prop_map(PartialCumulativeWork::from)
.boxed()
}
type Strategy = BoxedStrategy<Self>;
}