mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-12 15:51:09 +00:00
fix lint
This commit is contained in:
+25
-19
@@ -54,33 +54,39 @@ pub struct Case {
|
||||
impl Case {
|
||||
pub fn steps_iterator(&self) -> impl Iterator<Item = Step> {
|
||||
let steps_len = self.steps.len();
|
||||
self.steps.clone().into_iter().enumerate().map(move |(idx, mut step)| {
|
||||
let Step::FunctionCall(ref mut input) = step else {
|
||||
return step;
|
||||
};
|
||||
self.steps
|
||||
.clone()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(move |(idx, mut step)| {
|
||||
let Step::FunctionCall(ref mut input) = step else {
|
||||
return step;
|
||||
};
|
||||
|
||||
if idx + 1 == steps_len {
|
||||
if input.expected.is_none() {
|
||||
input.expected = self.expected.clone();
|
||||
if idx + 1 == steps_len {
|
||||
if input.expected.is_none() {
|
||||
input.expected = self.expected.clone();
|
||||
}
|
||||
|
||||
// TODO: What does it mean for us to have an `expected` field on the case itself
|
||||
// but the final input also has an expected field that doesn't match the one on
|
||||
// the case? What are we supposed to do with that final expected field on the
|
||||
// case?
|
||||
|
||||
step
|
||||
} else {
|
||||
step
|
||||
}
|
||||
|
||||
// TODO: What does it mean for us to have an `expected` field on the case itself
|
||||
// but the final input also has an expected field that doesn't match the one on
|
||||
// the case? What are we supposed to do with that final expected field on the
|
||||
// case?
|
||||
|
||||
step
|
||||
} else {
|
||||
step
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn steps_iterator_for_benchmarks(
|
||||
&self,
|
||||
default_repeat_count: usize,
|
||||
) -> Box<dyn Iterator<Item = Step> + '_> {
|
||||
let contains_repeat = self.steps_iterator().any(|step| matches!(&step, Step::Repeat(..)));
|
||||
let contains_repeat = self
|
||||
.steps_iterator()
|
||||
.any(|step| matches!(&step, Step::Repeat(..)));
|
||||
if contains_repeat {
|
||||
Box::new(self.steps_iterator()) as Box<_>
|
||||
} else {
|
||||
|
||||
+22
-40
@@ -13,14 +13,8 @@ use anyhow::Context as _;
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Corpus {
|
||||
SinglePath {
|
||||
name: String,
|
||||
path: PathBuf,
|
||||
},
|
||||
MultiplePaths {
|
||||
name: String,
|
||||
paths: Vec<PathBuf>,
|
||||
},
|
||||
SinglePath { name: String, path: PathBuf },
|
||||
MultiplePaths { name: String, paths: Vec<PathBuf> },
|
||||
}
|
||||
|
||||
impl Corpus {
|
||||
@@ -92,58 +86,46 @@ impl Corpus {
|
||||
.collect::<Vec<_>>();
|
||||
tests.sort_by(|a, b| a.metadata_file_path.cmp(&b.metadata_file_path));
|
||||
tests.dedup_by(|a, b| a.metadata_file_path == b.metadata_file_path);
|
||||
info!(len = tests.len(), corpus_name = self.name(), "Found tests in Corpus");
|
||||
info!(
|
||||
len = tests.len(),
|
||||
corpus_name = self.name(),
|
||||
"Found tests in Corpus"
|
||||
);
|
||||
tests
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
match self {
|
||||
Corpus::SinglePath {
|
||||
name,
|
||||
..
|
||||
}
|
||||
| Corpus::MultiplePaths {
|
||||
name,
|
||||
..
|
||||
} => name.as_str(),
|
||||
Corpus::SinglePath { name, .. } | Corpus::MultiplePaths { name, .. } => name.as_str(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn paths_iter(&self) -> impl Iterator<Item = &Path> {
|
||||
match self {
|
||||
Corpus::SinglePath {
|
||||
path,
|
||||
..
|
||||
} => Box::new(std::iter::once(path.as_path())) as Box<dyn Iterator<Item = _>>,
|
||||
Corpus::MultiplePaths {
|
||||
paths,
|
||||
..
|
||||
} => Box::new(paths.iter().map(|path| path.as_path())) as Box<dyn Iterator<Item = _>>,
|
||||
Corpus::SinglePath { path, .. } => {
|
||||
Box::new(std::iter::once(path.as_path())) as Box<dyn Iterator<Item = _>>
|
||||
}
|
||||
Corpus::MultiplePaths { paths, .. } => {
|
||||
Box::new(paths.iter().map(|path| path.as_path())) as Box<dyn Iterator<Item = _>>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn paths_iter_mut(&mut self) -> impl Iterator<Item = &mut PathBuf> {
|
||||
match self {
|
||||
Corpus::SinglePath {
|
||||
path,
|
||||
..
|
||||
} => Box::new(std::iter::once(path)) as Box<dyn Iterator<Item = _>>,
|
||||
Corpus::MultiplePaths {
|
||||
paths,
|
||||
..
|
||||
} => Box::new(paths.iter_mut()) as Box<dyn Iterator<Item = _>>,
|
||||
Corpus::SinglePath { path, .. } => {
|
||||
Box::new(std::iter::once(path)) as Box<dyn Iterator<Item = _>>
|
||||
}
|
||||
Corpus::MultiplePaths { paths, .. } => {
|
||||
Box::new(paths.iter_mut()) as Box<dyn Iterator<Item = _>>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn path_count(&self) -> usize {
|
||||
match self {
|
||||
Corpus::SinglePath {
|
||||
..
|
||||
} => 1,
|
||||
Corpus::MultiplePaths {
|
||||
paths,
|
||||
..
|
||||
} => paths.len(),
|
||||
Corpus::SinglePath { .. } => 1,
|
||||
Corpus::MultiplePaths { paths, .. } => paths.len(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ impl MetadataFile {
|
||||
if self.corpus_file_path.is_file() {
|
||||
&self.corpus_file_path
|
||||
} else {
|
||||
self.metadata_file_path.strip_prefix(&self.corpus_file_path).unwrap()
|
||||
self.metadata_file_path
|
||||
.strip_prefix(&self.corpus_file_path)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,8 +167,10 @@ impl Metadata {
|
||||
) in contracts
|
||||
{
|
||||
let alias = alias.clone();
|
||||
let absolute_path =
|
||||
directory.join(contract_source_path).canonicalize().map_err(|error| {
|
||||
let absolute_path = directory
|
||||
.join(contract_source_path)
|
||||
.canonicalize()
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(
|
||||
"Failed to canonicalize contract source path '{}': {error}",
|
||||
directory.join(contract_source_path).display()
|
||||
@@ -331,7 +335,12 @@ pub struct ContractPathAndIdent {
|
||||
|
||||
impl Display for ContractPathAndIdent {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}:{}", self.contract_source_path.display(), self.contract_ident.as_ref())
|
||||
write!(
|
||||
f,
|
||||
"{}:{}",
|
||||
self.contract_source_path.display(),
|
||||
self.contract_ident.as_ref()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,7 +596,10 @@ mod test {
|
||||
|
||||
// Assert
|
||||
let identifier = identifier.expect("Failed to parse");
|
||||
assert_eq!(identifier.contract_source_path.display().to_string(), "ERC20/ERC20.sol");
|
||||
assert_eq!(
|
||||
identifier.contract_source_path.display().to_string(),
|
||||
"ERC20/ERC20.sol"
|
||||
);
|
||||
assert_eq!(identifier.contract_ident, "ERC20".to_owned().into());
|
||||
|
||||
// Act
|
||||
|
||||
+12
-11
@@ -93,11 +93,7 @@ impl Display for ParsedMode {
|
||||
if let Some(pipeline) = self.pipeline {
|
||||
pipeline.fmt(f)?;
|
||||
if let Some(optimize_flag) = self.optimize_flag {
|
||||
f.write_str(if optimize_flag {
|
||||
"+"
|
||||
} else {
|
||||
"-"
|
||||
})?;
|
||||
f.write_str(if optimize_flag { "+" } else { "-" })?;
|
||||
}
|
||||
has_written = true;
|
||||
}
|
||||
@@ -161,11 +157,13 @@ impl ParsedMode {
|
||||
);
|
||||
|
||||
pipeline_iter.flat_map(move |pipeline| {
|
||||
optimize_settings_iter.clone().map(move |optimize_setting| Mode {
|
||||
pipeline,
|
||||
optimize_setting,
|
||||
version: self.version.clone(),
|
||||
})
|
||||
optimize_settings_iter
|
||||
.clone()
|
||||
.map(move |optimize_setting| Mode {
|
||||
pipeline,
|
||||
optimize_setting,
|
||||
version: self.version.clone(),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -237,7 +235,10 @@ mod tests {
|
||||
("Y+", vec!["Y M3"]),
|
||||
("Y-", vec!["Y M0"]),
|
||||
("Y <=0.8", vec!["Y M0 <=0.8", "Y M3 <=0.8"]),
|
||||
("<=0.8", vec!["Y M0 <=0.8", "Y M3 <=0.8", "E M0 <=0.8", "E M3 <=0.8"]),
|
||||
(
|
||||
"<=0.8",
|
||||
vec!["Y M0 <=0.8", "Y M3 <=0.8", "E M0 <=0.8", "E M3 <=0.8"],
|
||||
),
|
||||
];
|
||||
|
||||
for (actual, expected) in strings {
|
||||
|
||||
+102
-23
@@ -78,7 +78,12 @@ impl StepPath {
|
||||
|
||||
impl Display for StepPath {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.0.iter().map(|idx| idx.to_string()).collect::<Vec<_>>().join(".").fmt(f)
|
||||
self.0
|
||||
.iter()
|
||||
.map(|idx| idx.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(".")
|
||||
.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +91,10 @@ impl FromStr for StepPath {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
s.split(".").map(StepIdx::from_str).collect::<anyhow::Result<Vec<_>>>().map(Self)
|
||||
s.split(".")
|
||||
.map(StepIdx::from_str)
|
||||
.collect::<anyhow::Result<Vec<_>>>()
|
||||
.map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,7 +456,9 @@ impl StepAddress {
|
||||
|
||||
impl FunctionCallStep {
|
||||
pub const fn default_caller_address() -> Address {
|
||||
Address(FixedBytes(alloy::hex!("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1")))
|
||||
Address(FixedBytes(alloy::hex!(
|
||||
"0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"
|
||||
)))
|
||||
}
|
||||
|
||||
pub const fn default_caller() -> StepAddress {
|
||||
@@ -538,9 +548,11 @@ impl FunctionCallStep {
|
||||
.await
|
||||
.context("Failed to encode input bytes for transaction request")?;
|
||||
let caller = self.caller.resolve_address(resolver, context).await?;
|
||||
let transaction_request = TransactionRequest::default()
|
||||
.from(caller)
|
||||
.value(self.value.map(|value| value.into_inner()).unwrap_or_default());
|
||||
let transaction_request = TransactionRequest::default().from(caller).value(
|
||||
self.value
|
||||
.map(|value| value.into_inner())
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
match self.method {
|
||||
Method::Deployer => Ok(transaction_request.with_deploy_code(input_data)),
|
||||
_ => Ok(transaction_request
|
||||
@@ -596,7 +608,11 @@ impl Calldata {
|
||||
|
||||
pub fn new_compound(items: impl IntoIterator<Item = impl AsRef<str>>) -> Self {
|
||||
Self::Compound(
|
||||
items.into_iter().map(|item| item.as_ref().to_owned()).map(CalldataItem::new).collect(),
|
||||
items
|
||||
.into_iter()
|
||||
.map(|item| item.as_ref().to_owned())
|
||||
.map(CalldataItem::new)
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -618,7 +634,8 @@ impl Calldata {
|
||||
context: ResolutionContext<'_>,
|
||||
) -> anyhow::Result<Vec<u8>> {
|
||||
let mut buffer = Vec::<u8>::with_capacity(self.size_requirement());
|
||||
self.calldata_into_slice(&mut buffer, resolver, context).await?;
|
||||
self.calldata_into_slice(&mut buffer, resolver, context)
|
||||
.await?;
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
@@ -709,7 +726,10 @@ impl CalldataItem {
|
||||
) -> anyhow::Result<U256> {
|
||||
let mut stack = Vec::<CalldataToken<U256>>::new();
|
||||
|
||||
for token in self.calldata_tokens().map(|token| token.resolve(resolver, context)) {
|
||||
for token in self
|
||||
.calldata_tokens()
|
||||
.map(|token| token.resolve(resolver, context))
|
||||
{
|
||||
let token = token.await?;
|
||||
let new_token = match token {
|
||||
CalldataToken::Item(_) => token,
|
||||
@@ -750,7 +770,9 @@ impl CalldataItem {
|
||||
// Empty stack means that we got an empty compound calldata which we resolve to zero.
|
||||
[] => Ok(U256::ZERO),
|
||||
[CalldataToken::Item(item)] => Ok(*item),
|
||||
_ => Err(anyhow::anyhow!("Invalid calldata arithmetic operation - Invalid stack")),
|
||||
_ => Err(anyhow::anyhow!(
|
||||
"Invalid calldata arithmetic operation - Invalid stack"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -894,7 +916,10 @@ impl<T: AsRef<str>> CalldataToken<T> {
|
||||
.await
|
||||
.map(U256::from)
|
||||
} else if let Some(variable_name) = item.strip_prefix(Self::VARIABLE_PREFIX) {
|
||||
context.variable(variable_name).context("Variable lookup failed").copied()
|
||||
context
|
||||
.variable(variable_name)
|
||||
.context("Variable lookup failed")
|
||||
.copied()
|
||||
} else {
|
||||
U256::from_str_radix(item, 10)
|
||||
.map_err(|error| anyhow::anyhow!("Invalid decimal literal: {}", error))
|
||||
@@ -1024,7 +1049,13 @@ mod tests {
|
||||
"#;
|
||||
|
||||
let parsed_abi: JsonAbi = serde_json::from_str(raw_metadata).unwrap();
|
||||
let selector = parsed_abi.function("store").unwrap().first().unwrap().selector().0;
|
||||
let selector = parsed_abi
|
||||
.function("store")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.selector()
|
||||
.0;
|
||||
|
||||
let input = FunctionCallStep {
|
||||
instance: ContractInstance::new("Contract"),
|
||||
@@ -1062,7 +1093,13 @@ mod tests {
|
||||
]"#;
|
||||
|
||||
let parsed_abi: JsonAbi = serde_json::from_str(raw_abi).unwrap();
|
||||
let selector = parsed_abi.function("send").unwrap().first().unwrap().selector().0;
|
||||
let selector = parsed_abi
|
||||
.function("send")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.selector()
|
||||
.0;
|
||||
|
||||
let input: FunctionCallStep = FunctionCallStep {
|
||||
instance: "Contract".to_owned().into(),
|
||||
@@ -1084,7 +1121,10 @@ mod tests {
|
||||
|
||||
type T = (alloy::primitives::Address,);
|
||||
let decoded: T = T::abi_decode(&encoded.0[4..]).unwrap();
|
||||
assert_eq!(decoded.0, address!("0x1000000000000000000000000000000000000001"));
|
||||
assert_eq!(
|
||||
decoded.0,
|
||||
address!("0x1000000000000000000000000000000000000001")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1100,7 +1140,13 @@ mod tests {
|
||||
]"#;
|
||||
|
||||
let parsed_abi: JsonAbi = serde_json::from_str(raw_abi).unwrap();
|
||||
let selector = parsed_abi.function("send").unwrap().first().unwrap().selector().0;
|
||||
let selector = parsed_abi
|
||||
.function("send")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.selector()
|
||||
.0;
|
||||
|
||||
let input: FunctionCallStep = FunctionCallStep {
|
||||
instance: ContractInstance::new("Contract"),
|
||||
@@ -1122,7 +1168,10 @@ mod tests {
|
||||
|
||||
type T = (alloy::primitives::Address,);
|
||||
let decoded: T = T::abi_decode(&encoded.0[4..]).unwrap();
|
||||
assert_eq!(decoded.0, address!("0x1000000000000000000000000000000000000001"));
|
||||
assert_eq!(
|
||||
decoded.0,
|
||||
address!("0x1000000000000000000000000000000000000001")
|
||||
);
|
||||
}
|
||||
|
||||
async fn resolve_calldata_item(
|
||||
@@ -1159,7 +1208,12 @@ mod tests {
|
||||
let resolved = resolved.expect("Failed to resolve argument");
|
||||
assert_eq!(
|
||||
resolved,
|
||||
U256::from(MockResolver.block_gas_limit(Default::default()).await.unwrap())
|
||||
U256::from(
|
||||
MockResolver
|
||||
.block_gas_limit(Default::default())
|
||||
.await
|
||||
.unwrap()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1176,7 +1230,11 @@ mod tests {
|
||||
assert_eq!(
|
||||
resolved,
|
||||
U256::from_be_slice(
|
||||
MockResolver.block_coinbase(Default::default()).await.unwrap().as_ref()
|
||||
MockResolver
|
||||
.block_coinbase(Default::default())
|
||||
.await
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1191,7 +1249,13 @@ mod tests {
|
||||
|
||||
// Assert
|
||||
let resolved = resolved.expect("Failed to resolve argument");
|
||||
assert_eq!(resolved, MockResolver.block_difficulty(Default::default()).await.unwrap())
|
||||
assert_eq!(
|
||||
resolved,
|
||||
MockResolver
|
||||
.block_difficulty(Default::default())
|
||||
.await
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1206,7 +1270,11 @@ mod tests {
|
||||
let resolved = resolved.expect("Failed to resolve argument");
|
||||
assert_eq!(
|
||||
resolved,
|
||||
MockResolver.block_base_fee(Default::default()).await.map(U256::from).unwrap()
|
||||
MockResolver
|
||||
.block_base_fee(Default::default())
|
||||
.await
|
||||
.map(U256::from)
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1236,7 +1304,10 @@ mod tests {
|
||||
|
||||
// Assert
|
||||
let resolved = resolved.expect("Failed to resolve argument");
|
||||
assert_eq!(resolved, U256::from(MockResolver.last_block_number().await.unwrap()))
|
||||
assert_eq!(
|
||||
resolved,
|
||||
U256::from(MockResolver.last_block_number().await.unwrap())
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1251,7 +1322,12 @@ mod tests {
|
||||
let resolved = resolved.expect("Failed to resolve argument");
|
||||
assert_eq!(
|
||||
resolved,
|
||||
U256::from(MockResolver.block_timestamp(Default::default()).await.unwrap())
|
||||
U256::from(
|
||||
MockResolver
|
||||
.block_timestamp(Default::default())
|
||||
.await
|
||||
.unwrap()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1329,7 +1405,10 @@ mod tests {
|
||||
|
||||
// Assert
|
||||
let resolved = resolved.expect("Failed to resolve argument");
|
||||
assert_eq!(resolved, U256::from(MockResolver.last_block_number().await.unwrap() + 10));
|
||||
assert_eq!(
|
||||
resolved,
|
||||
U256::from(MockResolver.last_block_number().await.unwrap() + 10)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -149,7 +149,8 @@ impl<'a> ResolutionContext<'a> {
|
||||
&self,
|
||||
instance: &ContractInstance,
|
||||
) -> Option<&(ContractIdent, Address, JsonAbi)> {
|
||||
self.deployed_contracts.and_then(|deployed_contracts| deployed_contracts.get(instance))
|
||||
self.deployed_contracts
|
||||
.and_then(|deployed_contracts| deployed_contracts.get(instance))
|
||||
}
|
||||
|
||||
pub fn deployed_contract_address(&self, instance: &ContractInstance) -> Option<&Address> {
|
||||
@@ -161,7 +162,8 @@ impl<'a> ResolutionContext<'a> {
|
||||
}
|
||||
|
||||
pub fn variable(&self, name: impl AsRef<str>) -> Option<&U256> {
|
||||
self.variables.and_then(|variables| variables.get(name.as_ref()))
|
||||
self.variables
|
||||
.and_then(|variables| variables.get(name.as_ref()))
|
||||
}
|
||||
|
||||
pub fn tip_block_number(&self) -> Option<&'a BlockNumber> {
|
||||
|
||||
Reference in New Issue
Block a user