Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: update rustfmt config #406

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions crates/dyn-abi/benches/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,8 @@ fn encode_struct_input_tokens() -> [ethabi::Token; 8] {
ethabi::Token::Address(input.tokenOut.0 .0.into()),
ethabi::Token::Uint(input.fee.into()),
ethabi::Token::Address(input.recipient.0 .0.into()),
ethabi::Token::Uint(ethabi::Uint::from_big_endian(
&input.deadline.to_be_bytes_vec(),
)),
ethabi::Token::Uint(ethabi::Uint::from_big_endian(
&input.amountIn.to_be_bytes_vec(),
)),
ethabi::Token::Uint(ethabi::Uint::from_big_endian(&input.deadline.to_be_bytes_vec())),
ethabi::Token::Uint(ethabi::Uint::from_big_endian(&input.amountIn.to_be_bytes_vec())),
ethabi::Token::Uint(ethabi::Uint::from_big_endian(
&input.amountOutMinimum.to_be_bytes_vec(),
)),
Expand Down
28 changes: 9 additions & 19 deletions crates/dyn-abi/benches/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use criterion::{
use rand::seq::SliceRandom;
use std::{hint::black_box, time::Duration};

const KEYWORDS: &[&str] = &[
"address", "bool", "string", "bytes", "bytes32", "uint", "uint256", "int", "int256",
];
const KEYWORDS: &[&str] =
&["address", "bool", "string", "bytes", "bytes32", "uint", "uint256", "int", "int256"];
const COMPLEX: &[&str] = &[
"((uint104,bytes,bytes8,bytes7,address,bool,address,int256,int32,bytes1,uint56,int136),uint80,uint104,address,bool,bytes14,int16,address,string,uint176,uint72,(uint120,uint192,uint256,int232,bool,bool,bool,bytes5,int56,address,uint224,int248,bytes10,int48,int8),string,string,bool,bool)",
"(address,string,(bytes,int48,bytes30,bool,address,bytes30,int48,address,bytes17,bool,uint32),bool,address,bytes28,bytes25,uint136)",
Expand Down Expand Up @@ -40,21 +39,16 @@ fn resolve(c: &mut Criterion) {
let rng = &mut rand::thread_rng();

g.bench_function("keywords", |b| {
let parsed_keywords = KEYWORDS
.iter()
.map(|s| TypeSpecifier::parse(s).unwrap())
.collect::<Vec<_>>();
let parsed_keywords =
KEYWORDS.iter().map(|s| TypeSpecifier::parse(s).unwrap()).collect::<Vec<_>>();
let parsed_keywords = parsed_keywords.as_slice();
b.iter(|| {
let kw = parsed_keywords.choose(rng).unwrap();
black_box(kw).resolve().unwrap()
});
});
g.bench_function("complex", |b| {
let complex = COMPLEX
.iter()
.map(|s| TypeSpecifier::parse(s).unwrap())
.collect::<Vec<_>>();
let complex = COMPLEX.iter().map(|s| TypeSpecifier::parse(s).unwrap()).collect::<Vec<_>>();
let complex = complex.as_slice();
b.iter(|| {
let complex = complex.choose(rng).unwrap();
Expand All @@ -70,21 +64,17 @@ fn format(c: &mut Criterion) {
let rng = &mut rand::thread_rng();

g.bench_function("keywords", |b| {
let keyword_types = KEYWORDS
.iter()
.map(|s| DynSolType::parse(s).unwrap())
.collect::<Vec<_>>();
let keyword_types =
KEYWORDS.iter().map(|s| DynSolType::parse(s).unwrap()).collect::<Vec<_>>();
let keyword_types = keyword_types.as_slice();
b.iter(|| {
let kw = unsafe { keyword_types.choose(rng).unwrap_unchecked() };
black_box(kw).sol_type_name()
});
});
g.bench_function("complex", |b| {
let complex_types = COMPLEX
.iter()
.map(|s| DynSolType::parse(s).unwrap())
.collect::<Vec<_>>();
let complex_types =
COMPLEX.iter().map(|s| DynSolType::parse(s).unwrap()).collect::<Vec<_>>();
let complex_types = complex_types.as_slice();
b.iter(|| {
let complex = unsafe { complex_types.choose(rng).unwrap_unchecked() };
Expand Down
65 changes: 20 additions & 45 deletions crates/dyn-abi/src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,9 @@ impl<'a> arbitrary::Arbitrary<'a> for DynSolType {
#[cfg(feature = "eip712")]
Choice::CustomStruct => {
let name = u.arbitrary::<AString>()?.0;
let (prop_names, tuple) = u
.arbitrary_iter::<(AString, Self)>()?
.flatten()
.map(|(a, b)| (a.0, b))
.unzip();
Ok(Self::CustomStruct {
name,
prop_names,
tuple,
})
let (prop_names, tuple) =
u.arbitrary_iter::<(AString, Self)>()?.flatten().map(|(a, b)| (a.0, b)).unzip();
Ok(Self::CustomStruct { name, prop_names, tuple })
}
}
}
Expand All @@ -193,11 +186,7 @@ impl<'a> arbitrary::Arbitrary<'a> for DynSolValue {
match u.arbitrary::<DynSolType>()? {
// re-use name and prop_names
#[cfg(feature = "eip712")]
DynSolType::CustomStruct {
name,
prop_names,
tuple,
} => Ok(Self::CustomStruct {
DynSolType::CustomStruct { name, prop_names, tuple } => Ok(Self::CustomStruct {
name,
prop_names,
tuple: tuple
Expand Down Expand Up @@ -255,11 +244,7 @@ macro_rules! custom_struct_strategy {
vec_strategy(elem.clone(), sz..=sz),
)
})
.prop_map(|(name, prop_names, tuple)| Self::CustomStruct {
name,
prop_names,
tuple,
})
.prop_map(|(name, prop_names, tuple)| Self::CustomStruct { name, prop_names, tuple })
.boxed();
strat
}};
Expand Down Expand Up @@ -377,9 +362,9 @@ impl DynSolValue {
DynSolType::Function => u.arbitrary().map(Self::Function),
&DynSolType::Int(sz) => u.arbitrary().map(|x| Self::Int(adjust_int(x, sz), sz)),
&DynSolType::Uint(sz) => u.arbitrary().map(|x| Self::Uint(adjust_uint(x, sz), sz)),
&DynSolType::FixedBytes(sz) => u
.arbitrary()
.map(|x| Self::FixedBytes(adjust_fb(x, sz), sz)),
&DynSolType::FixedBytes(sz) => {
u.arbitrary().map(|x| Self::FixedBytes(adjust_fb(x, sz), sz))
}
DynSolType::Bytes => u.arbitrary().map(Self::Bytes),
DynSolType::String => u.arbitrary().map(Self::String),
DynSolType::Array(ty) => {
Expand Down Expand Up @@ -413,11 +398,7 @@ impl DynSolValue {
let prop_names = (0..sz)
.map(|_| u.arbitrary::<AString>().map(|s| s.0))
.collect::<Result<Vec<_>, _>>()?;
Ok(Self::CustomStruct {
name,
prop_names,
tuple,
})
Ok(Self::CustomStruct { name, prop_names, tuple })
}
}
}
Expand All @@ -429,15 +410,15 @@ impl DynSolValue {
DynSolType::Bool => any::<bool>().prop_map(Self::Bool).sboxed(),
DynSolType::Address => any::<Address>().prop_map(Self::Address).sboxed(),
DynSolType::Function => any::<Function>().prop_map(Self::Function).sboxed(),
&DynSolType::Int(sz) => any::<I256>()
.prop_map(move |x| Self::Int(adjust_int(x, sz), sz))
.sboxed(),
&DynSolType::Uint(sz) => any::<U256>()
.prop_map(move |x| Self::Uint(adjust_uint(x, sz), sz))
.sboxed(),
&DynSolType::FixedBytes(sz) => any::<B256>()
.prop_map(move |x| Self::FixedBytes(adjust_fb(x, sz), sz))
.sboxed(),
&DynSolType::Int(sz) => {
any::<I256>().prop_map(move |x| Self::Int(adjust_int(x, sz), sz)).sboxed()
}
&DynSolType::Uint(sz) => {
any::<U256>().prop_map(move |x| Self::Uint(adjust_uint(x, sz), sz)).sboxed()
}
&DynSolType::FixedBytes(sz) => {
any::<B256>().prop_map(move |x| Self::FixedBytes(adjust_fb(x, sz), sz)).sboxed()
}
DynSolType::Bytes => any::<Vec<u8>>().prop_map(Self::Bytes).sboxed(),
DynSolType::String => any::<String>().prop_map(Self::String).sboxed(),
DynSolType::Array(ty) => {
Expand All @@ -446,9 +427,7 @@ impl DynSolValue {
}
DynSolType::FixedArray(ty, sz) => {
let element = Self::type_strategy(ty);
vec_strategy(element, *sz)
.prop_map(Self::FixedArray)
.sboxed()
vec_strategy(element, *sz).prop_map(Self::FixedArray).sboxed()
}
DynSolType::Tuple(tys) => tys
.iter()
Expand Down Expand Up @@ -707,11 +686,7 @@ mod tests {
);
}
#[cfg(feature = "eip712")]
DynSolValue::CustomStruct {
name,
prop_names,
tuple,
} => {
DynSolValue::CustomStruct { name, prop_names, tuple } => {
prop_assert!(is_valid_identifier(name));
prop_assert!(prop_names.iter().all(|s| is_valid_identifier(s)));
prop_assert_eq!(prop_names.len(), tuple.len());
Expand Down
Loading