Skip to content

Commit

Permalink
test: use concrete type for arbitrary strategy (paradigmxyz#3632)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jul 6, 2023
1 parent bfa84bb commit 5d904eb
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions crates/storage/db/src/tables/utils.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
//! Small database table utilities and helper functions
//! Small database table utilities and helper functions.
use crate::{
table::{Decode, Decompress, Table},
DatabaseError,
};

use std::borrow::Cow;

#[macro_export]
/// Implements the `Arbitrary` trait for types with fixed array
/// types.
/// Implements the `Arbitrary` trait for types with fixed array types.
macro_rules! impl_fixed_arbitrary {
($name:tt, $size:tt) => {
($name:ident, $size:tt) => {
#[cfg(any(test, feature = "arbitrary"))]
use arbitrary::{Arbitrary, Unstructured};

Expand All @@ -24,17 +22,18 @@ macro_rules! impl_fixed_arbitrary {
}
}

#[cfg(any(test, feature = "arbitrary"))]
use proptest::strategy::Strategy;
#[cfg(any(test, feature = "arbitrary"))]
impl proptest::prelude::Arbitrary for $name {
type Parameters = ();
type Strategy = proptest::prelude::BoxedStrategy<$name>;
type Strategy = proptest::strategy::Map<
proptest::collection::VecStrategy<<u8 as proptest::arbitrary::Arbitrary>::Strategy>,
fn(Vec<u8>) -> Self,
>;

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
use proptest::strategy::Strategy;
proptest::collection::vec(proptest::arbitrary::any_with::<u8>(args), $size)
.prop_map(move |vec| Decode::decode(vec).unwrap())
.boxed()
}
}
};
Expand Down

0 comments on commit 5d904eb

Please sign in to comment.