From ba25d6d6b3f0523c0dbad653a3b7835461089721 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sat, 15 Jul 2023 23:38:26 +0200 Subject: [PATCH] chore: replace `ruint2` with `ruint` --- Cargo.toml | 4 ++-- crates/dyn-abi/src/arbitrary.rs | 35 ++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1bc33c178..7eae47d58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,6 +56,6 @@ itoa = "1" once_cell = "1" proptest = "1" proptest-derive = "0.3" -ruint = { version = "1.9.0", package = "ruint2", default-features = false } -ruint-macro = { version = "1.0.3", package = "ruint2-macro", default-features = false } +ruint = { version = "1.9.0", default-features = false } +ruint-macro = { version = "1.1.0", default-features = false } tiny-keccak = "2.0" diff --git a/crates/dyn-abi/src/arbitrary.rs b/crates/dyn-abi/src/arbitrary.rs index d62f11d36..7baa07032 100644 --- a/crates/dyn-abi/src/arbitrary.rs +++ b/crates/dyn-abi/src/arbitrary.rs @@ -3,7 +3,10 @@ //! These implementations are guaranteed to be valid, including `CustomStruct` //! identifiers. -// TODO: remove this after updating `ruint2`. +// TODO: Maybe make array sizes configurable? Also change parameters type from +// tuple to a struct + +// `prop_oneof!` / `TupleUnion` uses `Arc`s for cheap cloning #![allow(clippy::arc_with_non_send_sync)] use crate::{DynSolType, DynSolValue}; @@ -274,7 +277,8 @@ type TypeRecurseStrategy = TupleUnion< >; type TypeStrategy = Rec; -type ValueArrayStrategy = Flat, VecStrategy>>; +type ValueArrayStrategy = + Flat, VecStrategy>>; type ValueRecurseStrategy = TupleUnion< tuple_type_cfg![ @@ -400,36 +404,35 @@ impl DynSolValue { } } - // TODO: make this `SBoxedStrategy` after updating `ruint2`. /// Create a [proptest strategy][Strategy] to generate [`DynSolValue`]s from /// the given type. - pub fn type_strategy(ty: &DynSolType) -> BoxedStrategy { + pub fn type_strategy(ty: &DynSolType) -> SBoxedStrategy { match ty { - DynSolType::Bool => any::().prop_map(Self::Bool).boxed(), - DynSolType::Address => any::
().prop_map(Self::Address).boxed(), - &DynSolType::Int(sz) => any::().prop_map(move |x| Self::Int(x, sz)).boxed(), - &DynSolType::Uint(sz) => any::().prop_map(move |x| Self::Uint(x, sz)).boxed(), + DynSolType::Bool => any::().prop_map(Self::Bool).sboxed(), + DynSolType::Address => any::
().prop_map(Self::Address).sboxed(), + &DynSolType::Int(sz) => any::().prop_map(move |x| Self::Int(x, sz)).sboxed(), + &DynSolType::Uint(sz) => any::().prop_map(move |x| Self::Uint(x, sz)).sboxed(), &DynSolType::FixedBytes(sz) => any::() .prop_map(move |x| Self::FixedBytes(x, sz)) - .boxed(), - DynSolType::Bytes => any::>().prop_map(Self::Bytes).boxed(), - DynSolType::String => any::().prop_map(Self::String).boxed(), + .sboxed(), + DynSolType::Bytes => any::>().prop_map(Self::Bytes).sboxed(), + DynSolType::String => any::().prop_map(Self::String).sboxed(), DynSolType::Array(ty) => { let element = Self::type_strategy(ty); - vec_strategy(element, 1..=16).prop_map(Self::Array).boxed() + vec_strategy(element, 1..=16).prop_map(Self::Array).sboxed() } DynSolType::FixedArray(ty, sz) => { let element = Self::type_strategy(ty); vec_strategy(element, *sz) .prop_map(Self::FixedArray) - .boxed() + .sboxed() } DynSolType::Tuple(tys) => tys .iter() .map(Self::type_strategy) .collect::>() .prop_map(Self::Tuple) - .boxed(), + .sboxed(), #[cfg(feature = "eip712")] DynSolType::CustomStruct { tuple, .. } => { let types = tuple.iter().map(Self::type_strategy).collect::>(); @@ -440,7 +443,7 @@ impl DynSolValue { prop_names, tuple, }) - .boxed() + .sboxed() } } } @@ -448,7 +451,7 @@ impl DynSolValue { /// Create a [proptest strategy][Strategy] to generate [`DynSolValue`]s from /// the given value's type. #[inline] - pub fn value_strategy(&self) -> BoxedStrategy { + pub fn value_strategy(&self) -> SBoxedStrategy { Self::type_strategy(&self.as_type().unwrap()) }