Skip to content

Commit

Permalink
evm types
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron1024 committed Mar 17, 2022
1 parent dff1e6b commit 1ccac0a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions proptest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,20 @@ atomic64bit = []
# passed (see https://github.com/AltSysrq/proptest/issues/124).
break-dead-code = []

evm = ["primitive-types"]

[dependencies]
bitflags = "1.0.1"

# [dependencies.hashmap_core]
# version = "0.1.5"
# optional = true

[dependencies.primitive-types]
version = "0.10.1"
optional = true
features = ["std"]

[dependencies.lazy_static]
version = "1.2"
optional = true
Expand Down
30 changes: 30 additions & 0 deletions proptest/src/arbitrary/evm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use primitive_types::{H128, H160, H256, H512, U128, U256, U512};

use crate::strategy::Map;

use super::Strategy;
use super::{any, Arbitrary, StrategyFor};

macro_rules! evm_impl {
($t:ty, $bytes:literal) => {
impl Arbitrary for &t {
type Parameters = ();
type Strategy =
Map<StrategyFor<[u8; $bytes]>, fn([u8; $bytes]) -> Self>;

fn arbitrary_with((): Self::Parameters) -> Self::Strategy {
any::<[u8; $bytes]>().prop_map(|bytes| $t::from_slice(&bytes))
}
}
};
}

evm_impl!(H128, 16);
evm_impl!(H160, 20);
evm_impl!(H256, 32);
evm_impl!(H512, 64);

evm_impl!(U128, 16);
evm_impl!(U256, 32);
evm_impl!(U512, 64);

3 changes: 3 additions & 0 deletions proptest/src/arbitrary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ mod _alloc;
#[cfg(feature = "std")]
mod _std;

#[cfg(feature = "evm")]
mod evm;

pub use self::traits::*;

//==============================================================================
Expand Down

0 comments on commit 1ccac0a

Please sign in to comment.