mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-13 01:11:09 +00:00
Add more context to errors
This commit is contained in:
@@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
|
||||
use tracing::{debug, info};
|
||||
|
||||
use crate::metadata::{Metadata, MetadataFile};
|
||||
use anyhow::Context as _;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
@@ -20,7 +21,13 @@ impl Corpus {
|
||||
pub fn try_from_path(file_path: impl AsRef<Path>) -> anyhow::Result<Self> {
|
||||
let mut corpus = File::open(file_path.as_ref())
|
||||
.map_err(anyhow::Error::from)
|
||||
.and_then(|file| serde_json::from_reader::<_, Corpus>(file).map_err(Into::into))?;
|
||||
.and_then(|file| serde_json::from_reader::<_, Corpus>(file).map_err(Into::into))
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to open and deserialize corpus file at {}",
|
||||
file_path.as_ref().display()
|
||||
)
|
||||
})?;
|
||||
|
||||
for path in corpus.paths_iter_mut() {
|
||||
*path = file_path
|
||||
@@ -28,12 +35,19 @@ impl Corpus {
|
||||
.parent()
|
||||
.ok_or_else(|| {
|
||||
anyhow::anyhow!("Corpus path '{}' does not point to a file", path.display())
|
||||
})
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed resolving parent directory for corpus path '{}'",
|
||||
file_path.as_ref().display()
|
||||
)
|
||||
})?
|
||||
.canonicalize()
|
||||
.map_err(|error| {
|
||||
anyhow::anyhow!(
|
||||
"Failed to canonicalize path to corpus '{}': {error}",
|
||||
path.display()
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to canonicalize path to corpus '{}': {}",
|
||||
path.display(),
|
||||
file_path.as_ref().display()
|
||||
)
|
||||
})?
|
||||
.join(path.as_path())
|
||||
|
||||
+38
-14
@@ -268,7 +268,11 @@ impl Input {
|
||||
) -> anyhow::Result<Bytes> {
|
||||
match self.method {
|
||||
Method::Deployer | Method::Fallback => {
|
||||
let calldata = self.calldata.calldata(resolver, context).await?;
|
||||
let calldata = self
|
||||
.calldata
|
||||
.calldata(resolver, context)
|
||||
.await
|
||||
.context("Failed to produce calldata for deployer/fallback method")?;
|
||||
|
||||
Ok(calldata.into())
|
||||
}
|
||||
@@ -283,14 +287,15 @@ impl Input {
|
||||
// Overloads are handled by providing the full function signature in the "function
|
||||
// name".
|
||||
// https://github.com/matter-labs/era-compiler-tester/blob/1dfa7d07cba0734ca97e24704f12dd57f6990c2c/compiler_tester/src/test/case/input/mod.rs#L158-L190
|
||||
let selector = if function_name.contains('(') && function_name.contains(')') {
|
||||
Function::parse(function_name)
|
||||
let selector =
|
||||
if function_name.contains('(') && function_name.contains(')') {
|
||||
Function::parse(function_name)
|
||||
.context(
|
||||
"Failed to parse the provided function name into a function signature",
|
||||
)?
|
||||
.selector()
|
||||
} else {
|
||||
abi.functions()
|
||||
} else {
|
||||
abi.functions()
|
||||
.find(|function| function.signature().starts_with(function_name))
|
||||
.ok_or_else(|| {
|
||||
anyhow::anyhow!(
|
||||
@@ -298,9 +303,13 @@ impl Input {
|
||||
function_name,
|
||||
&self.instance
|
||||
)
|
||||
})?
|
||||
})
|
||||
.with_context(|| format!(
|
||||
"Failed to resolve function selector for {:?} on instance {:?}",
|
||||
function_name, &self.instance
|
||||
))?
|
||||
.selector()
|
||||
};
|
||||
};
|
||||
|
||||
// Allocating a vector that we will be using for the calldata. The vector size will be:
|
||||
// 4 bytes for the function selector.
|
||||
@@ -312,7 +321,8 @@ impl Input {
|
||||
calldata.extend(selector.0);
|
||||
self.calldata
|
||||
.calldata_into_slice(&mut calldata, resolver, context)
|
||||
.await?;
|
||||
.await
|
||||
.context("Failed to append encoded argument to calldata buffer")?;
|
||||
|
||||
Ok(calldata.into())
|
||||
}
|
||||
@@ -325,7 +335,10 @@ impl Input {
|
||||
resolver: &impl ResolverApi,
|
||||
context: ResolutionContext<'_>,
|
||||
) -> anyhow::Result<TransactionRequest> {
|
||||
let input_data = self.encoded_input(resolver, context).await?;
|
||||
let input_data = self
|
||||
.encoded_input(resolver, context)
|
||||
.await
|
||||
.context("Failed to encode input bytes for transaction request")?;
|
||||
let transaction_request = TransactionRequest::default().from(self.caller).value(
|
||||
self.value
|
||||
.map(|value| value.into_inner())
|
||||
@@ -437,7 +450,8 @@ impl Calldata {
|
||||
})
|
||||
.buffered(0xFF)
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
.await
|
||||
.context("Failed to resolve one or more calldata arguments")?;
|
||||
|
||||
buffer.extend(resolved.into_iter().flatten());
|
||||
}
|
||||
@@ -478,7 +492,10 @@ impl Calldata {
|
||||
std::borrow::Cow::Borrowed(other)
|
||||
};
|
||||
|
||||
let this = this.resolve(resolver, context).await?;
|
||||
let this = this
|
||||
.resolve(resolver, context)
|
||||
.await
|
||||
.context("Failed to resolve calldata item during equivalence check")?;
|
||||
let other = U256::from_be_slice(&other);
|
||||
Ok(this == other)
|
||||
})
|
||||
@@ -664,17 +681,24 @@ impl<T: AsRef<str>> CalldataToken<T> {
|
||||
|
||||
let current_block_number = match context.tip_block_number() {
|
||||
Some(block_number) => *block_number,
|
||||
None => resolver.last_block_number().await?,
|
||||
None => resolver.last_block_number().await.context(
|
||||
"Failed to query last block number while resolving $BLOCK_HASH",
|
||||
)?,
|
||||
};
|
||||
let desired_block_number = current_block_number.saturating_sub(offset);
|
||||
|
||||
let block_hash = resolver.block_hash(desired_block_number.into()).await?;
|
||||
let block_hash = resolver
|
||||
.block_hash(desired_block_number.into())
|
||||
.await
|
||||
.context("Failed to resolve block hash for desired block number")?;
|
||||
|
||||
Ok(U256::from_be_bytes(block_hash.0))
|
||||
} else if item == Self::BLOCK_NUMBER_VARIABLE {
|
||||
let current_block_number = match context.tip_block_number() {
|
||||
Some(block_number) => *block_number,
|
||||
None => resolver.last_block_number().await?,
|
||||
None => resolver.last_block_number().await.context(
|
||||
"Failed to query last block number while resolving $BLOCK_NUMBER",
|
||||
)?,
|
||||
};
|
||||
Ok(U256::from(current_block_number))
|
||||
} else if item == Self::BLOCK_TIMESTAMP_VARIABLE {
|
||||
|
||||
@@ -132,7 +132,15 @@ impl Metadata {
|
||||
) in contracts
|
||||
{
|
||||
let alias = alias.clone();
|
||||
let absolute_path = directory.join(contract_source_path).canonicalize()?;
|
||||
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()
|
||||
)
|
||||
})?;
|
||||
let contract_ident = contract_ident.clone();
|
||||
|
||||
sources.insert(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use anyhow::Context;
|
||||
use regex::Regex;
|
||||
use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -44,21 +45,34 @@ impl FromStr for ParsedMode {
|
||||
};
|
||||
|
||||
let pipeline = match caps.name("pipeline") {
|
||||
Some(m) => Some(ModePipeline::from_str(m.as_str())?),
|
||||
Some(m) => Some(
|
||||
ModePipeline::from_str(m.as_str())
|
||||
.context("Failed to parse mode pipeline from string")?,
|
||||
),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let optimize_flag = caps.name("optimize_flag").map(|m| m.as_str() == "+");
|
||||
|
||||
let optimize_setting = match caps.name("optimize_setting") {
|
||||
Some(m) => Some(ModeOptimizerSetting::from_str(m.as_str())?),
|
||||
Some(m) => Some(
|
||||
ModeOptimizerSetting::from_str(m.as_str())
|
||||
.context("Failed to parse optimizer setting from string")?,
|
||||
),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let version = match caps.name("version") {
|
||||
Some(m) => Some(semver::VersionReq::parse(m.as_str()).map_err(|e| {
|
||||
anyhow::anyhow!("Cannot parse the version requirement '{}': {e}", m.as_str())
|
||||
})?),
|
||||
Some(m) => Some(
|
||||
semver::VersionReq::parse(m.as_str())
|
||||
.map_err(|e| {
|
||||
anyhow::anyhow!(
|
||||
"Cannot parse the version requirement '{}': {e}",
|
||||
m.as_str()
|
||||
)
|
||||
})
|
||||
.context("Failed to parse semver requirement from mode string")?,
|
||||
),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user