Compare commits

..

2 Commits

Author SHA1 Message Date
Omar Abdulla 59f439b5f8 Update the kitchensink tests 2025-08-25 18:12:01 +03:00
Omar Abdulla 8d1523fd77 Configure kitchensink to use devnode by default 2025-08-25 17:43:52 +03:00
22 changed files with 269 additions and 779 deletions
-2
View File
@@ -9,5 +9,3 @@ node_modules
*.log *.log
profile.json.gz profile.json.gz
resolc-compiler-tests
workdir
+5 -14
View File
@@ -3,28 +3,19 @@ use std::{
path::Path, path::Path,
}; };
use anyhow::{Context, Result}; use anyhow::Result;
/// This method clears the passed directory of all of the files and directories contained within /// This method clears the passed directory of all of the files and directories contained within
/// without deleting the directory. /// without deleting the directory.
pub fn clear_directory(path: impl AsRef<Path>) -> Result<()> { pub fn clear_directory(path: impl AsRef<Path>) -> Result<()> {
for entry in read_dir(path.as_ref()) for entry in read_dir(path.as_ref())? {
.with_context(|| format!("Failed to read directory: {}", path.as_ref().display()))? let entry = entry?;
{
let entry = entry.with_context(|| {
format!(
"Failed to read an entry in directory: {}",
path.as_ref().display()
)
})?;
let entry_path = entry.path(); let entry_path = entry.path();
if entry_path.is_file() { if entry_path.is_file() {
remove_file(&entry_path) remove_file(entry_path)?
.with_context(|| format!("Failed to remove file: {}", entry_path.display()))?
} else { } else {
remove_dir_all(&entry_path) remove_dir_all(entry_path)?
.with_context(|| format!("Failed to remove directory: {}", entry_path.display()))?
} }
} }
Ok(()) Ok(())
+2 -5
View File
@@ -1,7 +1,7 @@
use std::ops::ControlFlow; use std::ops::ControlFlow;
use std::time::Duration; use std::time::Duration;
use anyhow::{Context as _, Result, anyhow}; use anyhow::{Result, anyhow};
const EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION: Duration = Duration::from_secs(60); const EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION: Duration = Duration::from_secs(60);
@@ -38,10 +38,7 @@ where
)); ));
} }
match future() match future().await? {
.await
.context("Polled future returned an error during polling loop")?
{
ControlFlow::Continue(()) => { ControlFlow::Continue(()) => {
let next_wait_duration = match polling_wait_behavior { let next_wait_duration = match polling_wait_behavior {
PollingWaitBehavior::Constant(duration) => duration, PollingWaitBehavior::Constant(duration) => duration,
+3 -5
View File
@@ -13,7 +13,6 @@ use std::{
use alloy::json_abi::JsonAbi; use alloy::json_abi::JsonAbi;
use alloy_primitives::Address; use alloy_primitives::Address;
use anyhow::Context;
use semver::Version; use semver::Version;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -137,10 +136,9 @@ where
} }
pub fn with_source(mut self, path: impl AsRef<Path>) -> anyhow::Result<Self> { pub fn with_source(mut self, path: impl AsRef<Path>) -> anyhow::Result<Self> {
self.input.sources.insert( self.input
path.as_ref().to_path_buf(), .sources
read_to_string(path.as_ref()).context("Failed to read the contract source")?, .insert(path.as_ref().to_path_buf(), read_to_string(path.as_ref())?);
);
Ok(self) Ok(self)
} }
+25 -72
View File
@@ -119,28 +119,18 @@ impl SolidityCompiler for Resolc {
.join(","), .join(","),
); );
} }
let mut child = command let mut child = command.spawn()?;
.spawn()
.with_context(|| format!("Failed to spawn resolc at {}", self.resolc_path.display()))?;
let stdin_pipe = child.stdin.as_mut().expect("stdin must be piped"); let stdin_pipe = child.stdin.as_mut().expect("stdin must be piped");
let serialized_input = serde_json::to_vec(&input) let serialized_input = serde_json::to_vec(&input)?;
.context("Failed to serialize Standard JSON input for resolc")?; stdin_pipe.write_all(&serialized_input).await?;
stdin_pipe
.write_all(&serialized_input)
.await
.context("Failed to write Standard JSON to resolc stdin")?;
let output = child let output = child.wait_with_output().await?;
.wait_with_output()
.await
.context("Failed while waiting for resolc process to finish")?;
let stdout = output.stdout; let stdout = output.stdout;
let stderr = output.stderr; let stderr = output.stderr;
if !output.status.success() { if !output.status.success() {
let json_in = serde_json::to_string_pretty(&input) let json_in = serde_json::to_string_pretty(&input)?;
.context("Failed to pretty-print Standard JSON input for logging")?;
let message = String::from_utf8_lossy(&stderr); let message = String::from_utf8_lossy(&stderr);
tracing::error!( tracing::error!(
status = %output.status, status = %output.status,
@@ -151,14 +141,12 @@ impl SolidityCompiler for Resolc {
anyhow::bail!("Compilation failed with an error: {message}"); anyhow::bail!("Compilation failed with an error: {message}");
} }
let parsed = serde_json::from_slice::<SolcStandardJsonOutput>(&stdout) let parsed = serde_json::from_slice::<SolcStandardJsonOutput>(&stdout).map_err(|e| {
.map_err(|e| {
anyhow::anyhow!( anyhow::anyhow!(
"failed to parse resolc JSON output: {e}\nstderr: {}", "failed to parse resolc JSON output: {e}\nstderr: {}",
String::from_utf8_lossy(&stderr) String::from_utf8_lossy(&stderr)
) )
}) })?;
.context("Failed to parse resolc standard JSON output")?;
tracing::debug!( tracing::debug!(
output = %serde_json::to_string(&parsed).unwrap(), output = %serde_json::to_string(&parsed).unwrap(),
@@ -185,10 +173,7 @@ impl SolidityCompiler for Resolc {
let mut compiler_output = CompilerOutput::default(); let mut compiler_output = CompilerOutput::default();
for (source_path, contracts) in contracts.into_iter() { for (source_path, contracts) in contracts.into_iter() {
let src_for_msg = source_path.clone(); let source_path = PathBuf::from(source_path).canonicalize()?;
let source_path = PathBuf::from(source_path)
.canonicalize()
.with_context(|| format!("Failed to canonicalize path {src_for_msg}"))?;
let map = compiler_output.contracts.entry(source_path).or_default(); let map = compiler_output.contracts.entry(source_path).or_default();
for (contract_name, contract_information) in contracts.into_iter() { for (contract_name, contract_information) in contracts.into_iter() {
@@ -196,41 +181,23 @@ impl SolidityCompiler for Resolc {
.evm .evm
.and_then(|evm| evm.bytecode.clone()) .and_then(|evm| evm.bytecode.clone())
.context("Unexpected - Contract compiled with resolc has no bytecode")?; .context("Unexpected - Contract compiled with resolc has no bytecode")?;
let abi = { let abi = contract_information
let metadata = contract_information
.metadata .metadata
.as_ref() .as_ref()
.context("No metadata found for the contract")?; .and_then(|metadata| metadata.as_object())
let solc_metadata_str = match metadata { .and_then(|metadata| metadata.get("solc_metadata"))
serde_json::Value::String(solc_metadata_str) => solc_metadata_str.as_str(), .and_then(|solc_metadata| solc_metadata.as_str())
serde_json::Value::Object(metadata_object) => { .and_then(|metadata| serde_json::from_str::<serde_json::Value>(metadata).ok())
let solc_metadata_value = metadata_object .and_then(|metadata| {
.get("solc_metadata") metadata.get("output").and_then(|output| {
.context("Contract doesn't have a 'solc_metadata' field")?; output
solc_metadata_value
.as_str()
.context("The 'solc_metadata' field is not a string")?
}
serde_json::Value::Null
| serde_json::Value::Bool(_)
| serde_json::Value::Number(_)
| serde_json::Value::Array(_) => {
anyhow::bail!("Unsupported type of metadata {metadata:?}")
}
};
let solc_metadata =
serde_json::from_str::<serde_json::Value>(solc_metadata_str).context(
"Failed to deserialize the solc_metadata as a serde_json generic value",
)?;
let output_value = solc_metadata
.get("output")
.context("solc_metadata doesn't have an output field")?;
let abi_value = output_value
.get("abi") .get("abi")
.context("solc_metadata output doesn't contain an abi field")?; .and_then(|abi| serde_json::from_value::<JsonAbi>(abi.clone()).ok())
serde_json::from_value::<JsonAbi>(abi_value.clone()) })
.context("ABI found in solc_metadata output is not valid ABI")? })
}; .context(
"Unexpected - Failed to get the ABI for a contract compiled with resolc",
)?;
map.insert(contract_name, (bytecode.object, abi)); map.insert(contract_name, (bytecode.object, abi));
} }
} }
@@ -266,20 +233,8 @@ impl SolidityCompiler for Resolc {
let output = Command::new(self.resolc_path.as_path()) let output = Command::new(self.resolc_path.as_path())
.arg("--version") .arg("--version")
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.spawn() .spawn()?
.with_context(|| { .wait_with_output()?
format!(
"Failed to spawn resolc at {} to get version",
self.resolc_path.display()
)
})?
.wait_with_output()
.with_context(|| {
format!(
"Failed waiting for resolc at {} to finish --version",
self.resolc_path.display()
)
})?
.stdout; .stdout;
let output = String::from_utf8_lossy(&output); let output = String::from_utf8_lossy(&output);
@@ -291,9 +246,7 @@ impl SolidityCompiler for Resolc {
.next() .next()
.context("Version parsing failed")?; .context("Version parsing failed")?;
let version = Version::parse(version_string).with_context(|| { let version = Version::parse(version_string)?;
format!("Failed to parse resolc semver from '{version_string}'")
})?;
vacant_entry.insert(version.clone()); vacant_entry.insert(version.clone());
+13 -49
View File
@@ -49,11 +49,7 @@ impl SolidityCompiler for Solc {
}: CompilerInput, }: CompilerInput,
_: Self::Options, _: Self::Options,
) -> anyhow::Result<CompilerOutput> { ) -> anyhow::Result<CompilerOutput> {
let compiler_supports_via_ir = self let compiler_supports_via_ir = self.version().await? >= SOLC_VERSION_SUPPORTING_VIA_YUL_IR;
.version()
.await
.context("Failed to query solc version to determine via-ir support")?
>= SOLC_VERSION_SUPPORTING_VIA_YUL_IR;
// Be careful to entirely omit the viaIR field if the compiler does not support it, // Be careful to entirely omit the viaIR field if the compiler does not support it,
// as it will error if you provide fields it does not know about. Because // as it will error if you provide fields it does not know about. Because
@@ -138,25 +134,15 @@ impl SolidityCompiler for Solc {
.join(","), .join(","),
); );
} }
let mut child = command let mut child = command.spawn()?;
.spawn()
.with_context(|| format!("Failed to spawn solc at {}", self.solc_path.display()))?;
let stdin = child.stdin.as_mut().expect("should be piped"); let stdin = child.stdin.as_mut().expect("should be piped");
let serialized_input = serde_json::to_vec(&input) let serialized_input = serde_json::to_vec(&input)?;
.context("Failed to serialize Standard JSON input for solc")?; stdin.write_all(&serialized_input).await?;
stdin let output = child.wait_with_output().await?;
.write_all(&serialized_input)
.await
.context("Failed to write Standard JSON to solc stdin")?;
let output = child
.wait_with_output()
.await
.context("Failed while waiting for solc process to finish")?;
if !output.status.success() { if !output.status.success() {
let json_in = serde_json::to_string_pretty(&input) let json_in = serde_json::to_string_pretty(&input)?;
.context("Failed to pretty-print Standard JSON input for logging")?;
let message = String::from_utf8_lossy(&output.stderr); let message = String::from_utf8_lossy(&output.stderr);
tracing::error!( tracing::error!(
status = %output.status, status = %output.status,
@@ -167,14 +153,12 @@ impl SolidityCompiler for Solc {
anyhow::bail!("Compilation failed with an error: {message}"); anyhow::bail!("Compilation failed with an error: {message}");
} }
let parsed = serde_json::from_slice::<SolcOutput>(&output.stdout) let parsed = serde_json::from_slice::<SolcOutput>(&output.stdout).map_err(|e| {
.map_err(|e| {
anyhow::anyhow!( anyhow::anyhow!(
"failed to parse resolc JSON output: {e}\nstderr: {}", "failed to parse resolc JSON output: {e}\nstderr: {}",
String::from_utf8_lossy(&output.stdout) String::from_utf8_lossy(&output.stdout)
) )
}) })?;
.context("Failed to parse solc standard JSON output")?;
// Detecting if the compiler output contained errors and reporting them through logs and // Detecting if the compiler output contained errors and reporting them through logs and
// errors instead of returning the compiler output that might contain errors. // errors instead of returning the compiler output that might contain errors.
@@ -194,12 +178,7 @@ impl SolidityCompiler for Solc {
for (contract_path, contracts) in parsed.contracts { for (contract_path, contracts) in parsed.contracts {
let map = compiler_output let map = compiler_output
.contracts .contracts
.entry(contract_path.canonicalize().with_context(|| { .entry(contract_path.canonicalize()?)
format!(
"Failed to canonicalize contract path {}",
contract_path.display()
)
})?)
.or_default(); .or_default();
for (contract_name, contract_info) in contracts.into_iter() { for (contract_name, contract_info) in contracts.into_iter() {
let source_code = contract_info let source_code = contract_info
@@ -228,9 +207,7 @@ impl SolidityCompiler for Solc {
config: &Arguments, config: &Arguments,
version: impl Into<VersionOrRequirement>, version: impl Into<VersionOrRequirement>,
) -> anyhow::Result<PathBuf> { ) -> anyhow::Result<PathBuf> {
let path = download_solc(config.directory(), version, config.wasm) let path = download_solc(config.directory(), version, config.wasm).await?;
.await
.context("Failed to download/get path to solc binary")?;
Ok(path) Ok(path)
} }
@@ -253,19 +230,8 @@ impl SolidityCompiler for Solc {
let child = Command::new(self.solc_path.as_path()) let child = Command::new(self.solc_path.as_path())
.arg("--version") .arg("--version")
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.spawn() .spawn()?;
.with_context(|| { let output = child.wait_with_output()?;
format!(
"Failed to spawn solc at {} to get version",
self.solc_path.display()
)
})?;
let output = child.wait_with_output().with_context(|| {
format!(
"Failed waiting for solc at {} to finish --version",
self.solc_path.display()
)
})?;
let output = String::from_utf8_lossy(&output.stdout); let output = String::from_utf8_lossy(&output.stdout);
let version_line = output let version_line = output
.split("Version: ") .split("Version: ")
@@ -276,9 +242,7 @@ impl SolidityCompiler for Solc {
.next() .next()
.context("Version parsing failed")?; .context("Version parsing failed")?;
let version = Version::parse(version_string).with_context(|| { let version = Version::parse(version_string)?;
format!("Failed to parse solc semver from '{version_string}'")
})?;
vacant_entry.insert(version.clone()); vacant_entry.insert(version.clone());
+15 -36
View File
@@ -14,7 +14,7 @@ use revive_dt_config::Arguments;
use revive_dt_format::metadata::{ContractIdent, ContractInstance, Metadata}; use revive_dt_format::metadata::{ContractIdent, ContractInstance, Metadata};
use alloy::{hex::ToHexExt, json_abi::JsonAbi, primitives::Address}; use alloy::{hex::ToHexExt, json_abi::JsonAbi, primitives::Address};
use anyhow::{Context as _, Error, Result}; use anyhow::{Error, Result};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use semver::Version; use semver::Version;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -29,10 +29,7 @@ impl CachedCompiler {
pub async fn new(path: impl AsRef<Path>, invalidate_cache: bool) -> Result<Self> { pub async fn new(path: impl AsRef<Path>, invalidate_cache: bool) -> Result<Self> {
let mut cache = ArtifactsCache::new(path); let mut cache = ArtifactsCache::new(path);
if invalidate_cache { if invalidate_cache {
cache = cache cache = cache.with_invalidated_cache().await?;
.with_invalidated_cache()
.await
.context("Failed to invalidate compilation cache directory")?;
} }
Ok(Self(cache)) Ok(Self(cache))
} }
@@ -79,8 +76,9 @@ impl CachedCompiler {
compiler_version_or_requirement, compiler_version_or_requirement,
) )
.await .await
.inspect_err(|err| compilation_failure_report_callback(None, None, None, err.to_string())) .inspect_err(|err| {
.context("Failed to obtain compiler executable path")?; compilation_failure_report_callback(None, None, None, err.to_string())
})?;
let compiler_version = <P::Compiler as SolidityCompiler>::new(compiler_path.clone()) let compiler_version = <P::Compiler as SolidityCompiler>::new(compiler_path.clone())
.version() .version()
.await .await
@@ -91,8 +89,7 @@ impl CachedCompiler {
None, None,
err.to_string(), err.to_string(),
) )
}) })?;
.context("Failed to query compiler version")?;
let cache_key = CacheKey { let cache_key = CacheKey {
platform_key: P::config_id().to_string(), platform_key: P::config_id().to_string(),
@@ -107,14 +104,10 @@ impl CachedCompiler {
let compilation_success_report_callback = compilation_success_report_callback.clone(); let compilation_success_report_callback = compilation_success_report_callback.clone();
async move { async move {
compile_contracts::<P>( compile_contracts::<P>(
metadata metadata.directory()?,
.directory()
.context("Failed to get metadata directory while preparing compilation")?,
compiler_path, compiler_path,
compiler_version, compiler_version,
metadata metadata.files_to_compile()?,
.files_to_compile()
.context("Failed to enumerate files to compile from metadata")?,
mode, mode,
deployed_libraries, deployed_libraries,
compilation_success_report_callback, compilation_success_report_callback,
@@ -138,10 +131,7 @@ impl CachedCompiler {
Some(_) => { Some(_) => {
debug!("Deployed libraries defined, recompilation must take place"); debug!("Deployed libraries defined, recompilation must take place");
debug!("Cache miss"); debug!("Cache miss");
compilation_callback() compilation_callback().await?.compiler_output
.await
.context("Compilation callback for deployed libraries failed")?
.compiler_output
} }
// If no deployed libraries are specified then we can follow the cached flow and attempt // If no deployed libraries are specified then we can follow the cached flow and attempt
// to lookup the compilation artifacts in the cache. // to lookup the compilation artifacts in the cache.
@@ -177,12 +167,7 @@ impl CachedCompiler {
); );
cache_value.compiler_output cache_value.compiler_output
} }
None => { None => compilation_callback().await?.compiler_output,
compilation_callback()
.await
.context("Compilation callback failed (cache miss path)")?
.compiler_output
}
} }
} }
}; };
@@ -262,8 +247,7 @@ async fn compile_contracts<P: Platform>(
Some(compiler_input.clone()), Some(compiler_input.clone()),
err.to_string(), err.to_string(),
) )
}) })?;
.context("Failed to configure compiler with sources and options")?;
compilation_success_report_callback( compilation_success_report_callback(
compiler_version, compiler_version,
compiler_path.as_ref().to_path_buf(), compiler_path.as_ref().to_path_buf(),
@@ -289,20 +273,15 @@ impl ArtifactsCache {
pub async fn with_invalidated_cache(self) -> Result<Self> { pub async fn with_invalidated_cache(self) -> Result<Self> {
cacache::clear(self.path.as_path()) cacache::clear(self.path.as_path())
.await .await
.map_err(Into::<Error>::into) .map_err(Into::<Error>::into)?;
.with_context(|| format!("Failed to clear cache at {}", self.path.display()))?;
Ok(self) Ok(self)
} }
#[instrument(level = "debug", skip_all, err)] #[instrument(level = "debug", skip_all, err)]
pub async fn insert(&self, key: &CacheKey, value: &CacheValue) -> Result<()> { pub async fn insert(&self, key: &CacheKey, value: &CacheValue) -> Result<()> {
let key = bson::to_vec(key).context("Failed to serialize cache key (bson)")?; let key = bson::to_vec(key)?;
let value = bson::to_vec(value).context("Failed to serialize cache value (bson)")?; let value = bson::to_vec(value)?;
cacache::write(self.path.as_path(), key.encode_hex(), value) cacache::write(self.path.as_path(), key.encode_hex(), value).await?;
.await
.with_context(|| {
format!("Failed to write cache entry under {}", self.path.display())
})?;
Ok(()) Ok(())
} }
+20 -41
View File
@@ -86,22 +86,18 @@ where
) -> anyhow::Result<StepOutput> { ) -> anyhow::Result<StepOutput> {
match step { match step {
Step::FunctionCall(input) => { Step::FunctionCall(input) => {
let (receipt, geth_trace, diff_mode) = self let (receipt, geth_trace, diff_mode) =
.handle_input(metadata, input, node) self.handle_input(metadata, input, node).await?;
.await
.context("Failed to handle function call step")?;
Ok(StepOutput::FunctionCall(receipt, geth_trace, diff_mode)) Ok(StepOutput::FunctionCall(receipt, geth_trace, diff_mode))
} }
Step::BalanceAssertion(balance_assertion) => { Step::BalanceAssertion(balance_assertion) => {
self.handle_balance_assertion(metadata, balance_assertion, node) self.handle_balance_assertion(metadata, balance_assertion, node)
.await .await?;
.context("Failed to handle balance assertion step")?;
Ok(StepOutput::BalanceAssertion) Ok(StepOutput::BalanceAssertion)
} }
Step::StorageEmptyAssertion(storage_empty) => { Step::StorageEmptyAssertion(storage_empty) => {
self.handle_storage_empty(metadata, storage_empty, node) self.handle_storage_empty(metadata, storage_empty, node)
.await .await?;
.context("Failed to handle storage empty assertion step")?;
Ok(StepOutput::StorageEmptyAssertion) Ok(StepOutput::StorageEmptyAssertion)
} }
} }
@@ -117,23 +113,18 @@ where
) -> anyhow::Result<(TransactionReceipt, GethTrace, DiffMode)> { ) -> anyhow::Result<(TransactionReceipt, GethTrace, DiffMode)> {
let deployment_receipts = self let deployment_receipts = self
.handle_input_contract_deployment(metadata, input, node) .handle_input_contract_deployment(metadata, input, node)
.await .await?;
.context("Failed during contract deployment phase of input handling")?;
let execution_receipt = self let execution_receipt = self
.handle_input_execution(input, deployment_receipts, node) .handle_input_execution(input, deployment_receipts, node)
.await .await?;
.context("Failed during transaction execution phase of input handling")?;
let tracing_result = self let tracing_result = self
.handle_input_call_frame_tracing(&execution_receipt, node) .handle_input_call_frame_tracing(&execution_receipt, node)
.await .await?;
.context("Failed during callframe tracing phase of input handling")?; self.handle_input_variable_assignment(input, &tracing_result)?;
self.handle_input_variable_assignment(input, &tracing_result)
.context("Failed to assign variables from callframe output")?;
let (_, (geth_trace, diff_mode)) = try_join!( let (_, (geth_trace, diff_mode)) = try_join!(
self.handle_input_expectations(input, &execution_receipt, node, &tracing_result), self.handle_input_expectations(input, &execution_receipt, node, &tracing_result),
self.handle_input_diff(&execution_receipt, node) self.handle_input_diff(&execution_receipt, node)
) )?;
.context("Failed while evaluating expectations and diffs in parallel")?;
Ok((execution_receipt, geth_trace, diff_mode)) Ok((execution_receipt, geth_trace, diff_mode))
} }
@@ -145,11 +136,9 @@ where
node: &T::Blockchain, node: &T::Blockchain,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.handle_balance_assertion_contract_deployment(metadata, balance_assertion, node) self.handle_balance_assertion_contract_deployment(metadata, balance_assertion, node)
.await .await?;
.context("Failed to deploy contract for balance assertion")?;
self.handle_balance_assertion_execution(balance_assertion, node) self.handle_balance_assertion_execution(balance_assertion, node)
.await .await?;
.context("Failed to execute balance assertion")?;
Ok(()) Ok(())
} }
@@ -161,11 +150,9 @@ where
node: &T::Blockchain, node: &T::Blockchain,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.handle_storage_empty_assertion_contract_deployment(metadata, storage_empty, node) self.handle_storage_empty_assertion_contract_deployment(metadata, storage_empty, node)
.await .await?;
.context("Failed to deploy contract for storage empty assertion")?;
self.handle_storage_empty_assertion_execution(storage_empty, node) self.handle_storage_empty_assertion_execution(storage_empty, node)
.await .await?;
.context("Failed to execute storage empty assertion")?;
Ok(()) Ok(())
} }
@@ -204,8 +191,7 @@ where
value, value,
node, node,
) )
.await .await?
.context("Failed to get or deploy contract instance during input execution")?
{ {
receipts.insert(instance.clone(), receipt); receipts.insert(instance.clone(), receipt);
} }
@@ -227,7 +213,7 @@ where
// lookup the transaction receipt in this case and continue on. // lookup the transaction receipt in this case and continue on.
Method::Deployer => deployment_receipts Method::Deployer => deployment_receipts
.remove(&input.instance) .remove(&input.instance)
.context("Failed to find deployment receipt for constructor call"), .context("Failed to find deployment receipt"),
Method::Fallback | Method::FunctionName(_) => { Method::Fallback | Method::FunctionName(_) => {
let tx = match input let tx = match input
.legacy_transaction(node, self.default_resolution_context()) .legacy_transaction(node, self.default_resolution_context())
@@ -399,8 +385,7 @@ where
let actual = &tracing_result.output.as_ref().unwrap_or_default(); let actual = &tracing_result.output.as_ref().unwrap_or_default();
if !expected if !expected
.is_equivalent(actual, resolver, resolution_context) .is_equivalent(actual, resolver, resolution_context)
.await .await?
.context("Failed to resolve calldata equivalence for return data assertion")?
{ {
tracing::error!( tracing::error!(
?execution_receipt, ?execution_receipt,
@@ -463,8 +448,7 @@ where
let expected = Calldata::new_compound([expected]); let expected = Calldata::new_compound([expected]);
if !expected if !expected
.is_equivalent(&actual.0, resolver, resolution_context) .is_equivalent(&actual.0, resolver, resolution_context)
.await .await?
.context("Failed to resolve event topic equivalence")?
{ {
tracing::error!( tracing::error!(
event_idx, event_idx,
@@ -484,8 +468,7 @@ where
let actual = &actual_event.data().data; let actual = &actual_event.data().data;
if !expected if !expected
.is_equivalent(&actual.0, resolver, resolution_context) .is_equivalent(&actual.0, resolver, resolution_context)
.await .await?
.context("Failed to resolve event value equivalence")?
{ {
tracing::error!( tracing::error!(
event_idx, event_idx,
@@ -518,12 +501,8 @@ where
let trace = node let trace = node
.trace_transaction(execution_receipt, trace_options) .trace_transaction(execution_receipt, trace_options)
.await .await?;
.context("Failed to obtain geth prestate tracer output")?; let diff = node.state_diff(execution_receipt).await?;
let diff = node
.state_diff(execution_receipt)
.await
.context("Failed to obtain state diff for transaction")?;
Ok((trace, diff)) Ok((trace, diff))
} }
+19 -46
View File
@@ -60,7 +60,7 @@ struct Test<'a> {
} }
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
let (args, _guard) = init_cli().context("Failed to initialize CLI and tracing subscriber")?; let (args, _guard) = init_cli()?;
info!( info!(
leader = args.leader.to_string(), leader = args.leader.to_string(),
follower = args.follower.to_string(), follower = args.follower.to_string(),
@@ -74,8 +74,7 @@ fn main() -> anyhow::Result<()> {
let number_of_threads = args.number_of_threads; let number_of_threads = args.number_of_threads;
let body = async move { let body = async move {
let tests = collect_corpora(&args) let tests = collect_corpora(&args)?
.context("Failed to collect corpus files from provided arguments")?
.into_iter() .into_iter()
.inspect(|(corpus, _)| { .inspect(|(corpus, _)| {
reporter reporter
@@ -97,9 +96,7 @@ fn main() -> anyhow::Result<()> {
Some(platform) => { Some(platform) => {
compile_corpus(&args, &tests, platform, reporter, report_aggregator_task).await compile_corpus(&args, &tests, platform, reporter, report_aggregator_task).await
} }
None => execute_corpus(&args, &tests, reporter, report_aggregator_task) None => execute_corpus(&args, &tests, reporter, report_aggregator_task).await?,
.await
.context("Failed to execute corpus")?,
} }
Ok(()) Ok(())
}; };
@@ -186,9 +183,7 @@ where
F::Blockchain: revive_dt_node::Node + Send + Sync + 'static, F::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
{ {
let tests = prepare_tests::<L, F>(args, metadata_files, reporter.clone()); let tests = prepare_tests::<L, F>(args, metadata_files, reporter.clone());
let driver_task = start_driver_task::<L, F>(args, tests) let driver_task = start_driver_task::<L, F>(args, tests).await?;
.await
.context("Failed to start driver task")?;
let cli_reporting_task = start_cli_reporting_task(reporter); let cli_reporting_task = start_cli_reporting_task(reporter);
let (_, _, rtn) = tokio::join!(cli_reporting_task, driver_task, report_aggregator_task); let (_, _, rtn) = tokio::join!(cli_reporting_task, driver_task, report_aggregator_task);
@@ -424,13 +419,9 @@ async fn does_compiler_support_mode<P: Platform>(
mode: &Mode, mode: &Mode,
) -> anyhow::Result<bool> { ) -> anyhow::Result<bool> {
let compiler_version_or_requirement = mode.compiler_version_to_use(args.solc.clone()); let compiler_version_or_requirement = mode.compiler_version_to_use(args.solc.clone());
let compiler_path = P::Compiler::get_compiler_executable(args, compiler_version_or_requirement) let compiler_path =
.await P::Compiler::get_compiler_executable(args, compiler_version_or_requirement).await?;
.context("Failed to obtain compiler executable path")?; let compiler_version = P::Compiler::new(compiler_path.clone()).version().await?;
let compiler_version = P::Compiler::new(compiler_path.clone())
.version()
.await
.context("Failed to query compiler version")?;
Ok(P::Compiler::supports_mode( Ok(P::Compiler::supports_mode(
&compiler_version, &compiler_version,
@@ -451,20 +442,15 @@ where
{ {
info!("Starting driver task"); info!("Starting driver task");
let leader_nodes = Arc::new( let leader_nodes = Arc::new(NodePool::<L::Blockchain>::new(args)?);
NodePool::<L::Blockchain>::new(args).context("Failed to initialize leader node pool")?, let follower_nodes = Arc::new(NodePool::<F::Blockchain>::new(args)?);
);
let follower_nodes = Arc::new(
NodePool::<F::Blockchain>::new(args).context("Failed to initialize follower node pool")?,
);
let number_concurrent_tasks = args.number_of_concurrent_tasks(); let number_concurrent_tasks = args.number_of_concurrent_tasks();
let cached_compiler = Arc::new( let cached_compiler = Arc::new(
CachedCompiler::new( CachedCompiler::new(
args.directory().join("compilation_cache"), args.directory().join("compilation_cache"),
args.invalidate_compilation_cache, args.invalidate_compilation_cache,
) )
.await .await?,
.context("Failed to initialize cached compiler")?,
); );
Ok(tests.for_each_concurrent( Ok(tests.for_each_concurrent(
@@ -560,30 +546,22 @@ async fn start_cli_reporting_task(reporter: Reporter) {
number_of_successes += 1; number_of_successes += 1;
writeln!( writeln!(
buf, buf,
"{}{}Case Succeeded{} - Steps Executed: {}{}", "{}{}Case Succeeded{}{} - Steps Executed: {}",
GREEN, BOLD, BOLD_RESET, steps_executed, COLOR_RESET GREEN, BOLD, BOLD_RESET, COLOR_RESET, steps_executed
) )
} }
TestCaseStatus::Failed { reason } => { TestCaseStatus::Failed { reason } => {
number_of_failures += 1; number_of_failures += 1;
writeln!( writeln!(
buf, buf,
"{}{}Case Failed{} - Reason: {}{}", "{}{}Case Failed{}{} - Reason: {}",
RED, RED, BOLD, BOLD_RESET, COLOR_RESET, reason
BOLD,
BOLD_RESET,
reason.trim(),
COLOR_RESET,
) )
} }
TestCaseStatus::Ignored { reason, .. } => writeln!( TestCaseStatus::Ignored { reason, .. } => writeln!(
buf, buf,
"{}{}Case Ignored{} - Reason: {}{}", "{}{}Case Ignored{}{} - Reason: {}",
GREY, GREY, BOLD, BOLD_RESET, COLOR_RESET, reason
BOLD,
BOLD_RESET,
reason.trim(),
COLOR_RESET,
), ),
}; };
} }
@@ -709,15 +687,11 @@ where
.expect("Can't fail") .expect("Can't fail")
} }
) )
) )?;
.context("Failed to compile pre-link contracts for leader/follower in parallel")?;
let mut leader_deployed_libraries = None::<HashMap<_, _>>; let mut leader_deployed_libraries = None::<HashMap<_, _>>;
let mut follower_deployed_libraries = None::<HashMap<_, _>>; let mut follower_deployed_libraries = None::<HashMap<_, _>>;
let mut contract_sources = test let mut contract_sources = test.metadata.contract_sources()?;
.metadata
.contract_sources()
.context("Failed to retrieve contract sources from metadata")?;
for library_instance in test for library_instance in test
.metadata .metadata
.libraries .libraries
@@ -908,8 +882,7 @@ where
.expect("Can't fail") .expect("Can't fail")
} }
) )
) )?;
.context("Failed to compile post-link contracts for leader/follower in parallel")?;
let leader_state = CaseState::<L>::new( let leader_state = CaseState::<L>::new(
leader_compiler_version, leader_compiler_version,
+15 -17
View File
@@ -8,7 +8,6 @@ use serde::{Deserialize, Serialize};
use tracing::{debug, info}; use tracing::{debug, info};
use crate::metadata::{Metadata, MetadataFile}; use crate::metadata::{Metadata, MetadataFile};
use anyhow::Context as _;
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(untagged)] #[serde(untagged)]
@@ -21,24 +20,23 @@ impl Corpus {
pub fn try_from_path(file_path: impl AsRef<Path>) -> anyhow::Result<Self> { pub fn try_from_path(file_path: impl AsRef<Path>) -> anyhow::Result<Self> {
let mut corpus = File::open(file_path.as_ref()) let mut corpus = File::open(file_path.as_ref())
.map_err(anyhow::Error::from) .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()
)
})?;
let corpus_directory = file_path
.as_ref()
.canonicalize()
.context("Failed to canonicalize the path to the corpus file")?
.parent()
.context("Corpus file has no parent")?
.to_path_buf();
for path in corpus.paths_iter_mut() { for path in corpus.paths_iter_mut() {
*path = corpus_directory.join(path.as_path()) *path = file_path
.as_ref()
.parent()
.ok_or_else(|| {
anyhow::anyhow!("Corpus path '{}' does not point to a file", path.display())
})?
.canonicalize()
.map_err(|error| {
anyhow::anyhow!(
"Failed to canonicalize path to corpus '{}': {error}",
path.display()
)
})?
.join(path.as_path())
} }
Ok(corpus) Ok(corpus)
+10 -34
View File
@@ -268,11 +268,7 @@ impl Input {
) -> anyhow::Result<Bytes> { ) -> anyhow::Result<Bytes> {
match self.method { match self.method {
Method::Deployer | Method::Fallback => { Method::Deployer | Method::Fallback => {
let calldata = self let calldata = self.calldata.calldata(resolver, context).await?;
.calldata
.calldata(resolver, context)
.await
.context("Failed to produce calldata for deployer/fallback method")?;
Ok(calldata.into()) Ok(calldata.into())
} }
@@ -287,8 +283,7 @@ impl Input {
// Overloads are handled by providing the full function signature in the "function // Overloads are handled by providing the full function signature in the "function
// name". // name".
// https://github.com/matter-labs/era-compiler-tester/blob/1dfa7d07cba0734ca97e24704f12dd57f6990c2c/compiler_tester/src/test/case/input/mod.rs#L158-L190 // https://github.com/matter-labs/era-compiler-tester/blob/1dfa7d07cba0734ca97e24704f12dd57f6990c2c/compiler_tester/src/test/case/input/mod.rs#L158-L190
let selector = let selector = if function_name.contains('(') && function_name.contains(')') {
if function_name.contains('(') && function_name.contains(')') {
Function::parse(function_name) Function::parse(function_name)
.context( .context(
"Failed to parse the provided function name into a function signature", "Failed to parse the provided function name into a function signature",
@@ -303,11 +298,7 @@ impl Input {
function_name, function_name,
&self.instance &self.instance
) )
}) })?
.with_context(|| format!(
"Failed to resolve function selector for {:?} on instance {:?}",
function_name, &self.instance
))?
.selector() .selector()
}; };
@@ -321,8 +312,7 @@ impl Input {
calldata.extend(selector.0); calldata.extend(selector.0);
self.calldata self.calldata
.calldata_into_slice(&mut calldata, resolver, context) .calldata_into_slice(&mut calldata, resolver, context)
.await .await?;
.context("Failed to append encoded argument to calldata buffer")?;
Ok(calldata.into()) Ok(calldata.into())
} }
@@ -335,10 +325,7 @@ impl Input {
resolver: &impl ResolverApi, resolver: &impl ResolverApi,
context: ResolutionContext<'_>, context: ResolutionContext<'_>,
) -> anyhow::Result<TransactionRequest> { ) -> anyhow::Result<TransactionRequest> {
let input_data = self let input_data = self.encoded_input(resolver, context).await?;
.encoded_input(resolver, context)
.await
.context("Failed to encode input bytes for transaction request")?;
let transaction_request = TransactionRequest::default().from(self.caller).value( let transaction_request = TransactionRequest::default().from(self.caller).value(
self.value self.value
.map(|value| value.into_inner()) .map(|value| value.into_inner())
@@ -450,8 +437,7 @@ impl Calldata {
}) })
.buffered(0xFF) .buffered(0xFF)
.try_collect::<Vec<_>>() .try_collect::<Vec<_>>()
.await .await?;
.context("Failed to resolve one or more calldata arguments")?;
buffer.extend(resolved.into_iter().flatten()); buffer.extend(resolved.into_iter().flatten());
} }
@@ -492,10 +478,7 @@ impl Calldata {
std::borrow::Cow::Borrowed(other) std::borrow::Cow::Borrowed(other)
}; };
let this = this let this = this.resolve(resolver, context).await?;
.resolve(resolver, context)
.await
.context("Failed to resolve calldata item during equivalence check")?;
let other = U256::from_be_slice(&other); let other = U256::from_be_slice(&other);
Ok(this == other) Ok(this == other)
}) })
@@ -681,24 +664,17 @@ impl<T: AsRef<str>> CalldataToken<T> {
let current_block_number = match context.tip_block_number() { let current_block_number = match context.tip_block_number() {
Some(block_number) => *block_number, Some(block_number) => *block_number,
None => resolver.last_block_number().await.context( None => resolver.last_block_number().await?,
"Failed to query last block number while resolving $BLOCK_HASH",
)?,
}; };
let desired_block_number = current_block_number.saturating_sub(offset); let desired_block_number = current_block_number.saturating_sub(offset);
let block_hash = resolver let block_hash = resolver.block_hash(desired_block_number.into()).await?;
.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)) Ok(U256::from_be_bytes(block_hash.0))
} else if item == Self::BLOCK_NUMBER_VARIABLE { } else if item == Self::BLOCK_NUMBER_VARIABLE {
let current_block_number = match context.tip_block_number() { let current_block_number = match context.tip_block_number() {
Some(block_number) => *block_number, Some(block_number) => *block_number,
None => resolver.last_block_number().await.context( None => resolver.last_block_number().await?,
"Failed to query last block number while resolving $BLOCK_NUMBER",
)?,
}; };
Ok(U256::from(current_block_number)) Ok(U256::from(current_block_number))
} else if item == Self::BLOCK_TIMESTAMP_VARIABLE { } else if item == Self::BLOCK_TIMESTAMP_VARIABLE {
+1 -9
View File
@@ -132,15 +132,7 @@ impl Metadata {
) in contracts ) in contracts
{ {
let alias = alias.clone(); let alias = alias.clone();
let absolute_path = directory let absolute_path = directory.join(contract_source_path).canonicalize()?;
.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(); let contract_ident = contract_ident.clone();
sources.insert( sources.insert(
+5 -19
View File
@@ -1,4 +1,3 @@
use anyhow::Context;
use regex::Regex; use regex::Regex;
use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline}; use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -45,34 +44,21 @@ impl FromStr for ParsedMode {
}; };
let pipeline = match caps.name("pipeline") { let pipeline = match caps.name("pipeline") {
Some(m) => Some( Some(m) => Some(ModePipeline::from_str(m.as_str())?),
ModePipeline::from_str(m.as_str())
.context("Failed to parse mode pipeline from string")?,
),
None => None, None => None,
}; };
let optimize_flag = caps.name("optimize_flag").map(|m| m.as_str() == "+"); let optimize_flag = caps.name("optimize_flag").map(|m| m.as_str() == "+");
let optimize_setting = match caps.name("optimize_setting") { let optimize_setting = match caps.name("optimize_setting") {
Some(m) => Some( Some(m) => Some(ModeOptimizerSetting::from_str(m.as_str())?),
ModeOptimizerSetting::from_str(m.as_str())
.context("Failed to parse optimizer setting from string")?,
),
None => None, None => None,
}; };
let version = match caps.name("version") { let version = match caps.name("version") {
Some(m) => Some( Some(m) => Some(semver::VersionReq::parse(m.as_str()).map_err(|e| {
semver::VersionReq::parse(m.as_str()) anyhow::anyhow!("Cannot parse the version requirement '{}': {e}", 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, None => None,
}; };
+45 -104
View File
@@ -101,13 +101,10 @@ impl GethNode {
let _ = clear_directory(&self.base_directory); let _ = clear_directory(&self.base_directory);
let _ = clear_directory(&self.logs_directory); let _ = clear_directory(&self.logs_directory);
create_dir_all(&self.base_directory) create_dir_all(&self.base_directory)?;
.context("Failed to create base directory for geth node")?; create_dir_all(&self.logs_directory)?;
create_dir_all(&self.logs_directory)
.context("Failed to create logs directory for geth node")?;
let mut genesis = serde_json::from_str::<Genesis>(&genesis) let mut genesis = serde_json::from_str::<Genesis>(&genesis)?;
.context("Failed to deserialize geth genesis JSON")?;
for signer_address in for signer_address in
<EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet) <EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet)
{ {
@@ -119,11 +116,7 @@ impl GethNode {
.or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE))); .or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE)));
} }
let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE); let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE);
serde_json::to_writer( serde_json::to_writer(File::create(&genesis_path)?, &genesis)?;
File::create(&genesis_path).context("Failed to create geth genesis file")?,
&genesis,
)
.context("Failed to serialize geth genesis JSON to file")?;
let mut child = Command::new(&self.geth) let mut child = Command::new(&self.geth)
.arg("--state.scheme") .arg("--state.scheme")
@@ -134,22 +127,16 @@ impl GethNode {
.arg(genesis_path) .arg(genesis_path)
.stderr(Stdio::piped()) .stderr(Stdio::piped())
.stdout(Stdio::null()) .stdout(Stdio::null())
.spawn() .spawn()?;
.context("Failed to spawn geth --init process")?;
let mut stderr = String::new(); let mut stderr = String::new();
child child
.stderr .stderr
.take() .take()
.expect("should be piped") .expect("should be piped")
.read_to_string(&mut stderr) .read_to_string(&mut stderr)?;
.context("Failed to read geth --init stderr")?;
if !child if !child.wait()?.success() {
.wait()
.context("Failed waiting for geth --init process to finish")?
.success()
{
anyhow::bail!("failed to initialize geth node #{:?}: {stderr}", &self.id); anyhow::bail!("failed to initialize geth node #{:?}: {stderr}", &self.id);
} }
@@ -174,11 +161,8 @@ impl GethNode {
let stdout_logs_file = open_options let stdout_logs_file = open_options
.clone() .clone()
.open(self.geth_stdout_log_file_path()) .open(self.geth_stdout_log_file_path())?;
.context("Failed to open geth stdout logs file")?; let stderr_logs_file = open_options.open(self.geth_stderr_log_file_path())?;
let stderr_logs_file = open_options
.open(self.geth_stderr_log_file_path())
.context("Failed to open geth stderr logs file")?;
self.handle = Command::new(&self.geth) self.handle = Command::new(&self.geth)
.arg("--dev") .arg("--dev")
.arg("--datadir") .arg("--datadir")
@@ -198,24 +182,14 @@ impl GethNode {
.arg("full") .arg("full")
.arg("--gcmode") .arg("--gcmode")
.arg("archive") .arg("archive")
.stderr( .stderr(stderr_logs_file.try_clone()?)
stderr_logs_file .stdout(stdout_logs_file.try_clone()?)
.try_clone() .spawn()?
.context("Failed to clone geth stderr log file handle")?,
)
.stdout(
stdout_logs_file
.try_clone()
.context("Failed to clone geth stdout log file handle")?,
)
.spawn()
.context("Failed to spawn geth node process")?
.into(); .into();
if let Err(error) = self.wait_ready() { if let Err(error) = self.wait_ready() {
tracing::error!(?error, "Failed to start geth, shutting down gracefully"); tracing::error!(?error, "Failed to start geth, shutting down gracefully");
self.shutdown() self.shutdown()?;
.context("Failed to gracefully shutdown after geth start error")?;
return Err(error); return Err(error);
} }
@@ -237,8 +211,7 @@ impl GethNode {
.write(false) .write(false)
.append(false) .append(false)
.truncate(false) .truncate(false)
.open(self.geth_stderr_log_file_path()) .open(self.geth_stderr_log_file_path())?;
.context("Failed to open geth stderr logs file for readiness check")?;
let maximum_wait_time = Duration::from_millis(self.start_timeout); let maximum_wait_time = Duration::from_millis(self.start_timeout);
let mut stderr = BufReader::new(logs_file).lines(); let mut stderr = BufReader::new(logs_file).lines();
@@ -304,18 +277,11 @@ impl EthereumNode for GethNode {
&self, &self,
transaction: TransactionRequest, transaction: TransactionRequest,
) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> { ) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> {
let provider = self let provider = self.provider().await?;
.provider()
.await
.context("Failed to create provider for transaction submission")?;
let pending_transaction = provider let pending_transaction = provider.send_transaction(transaction).await.inspect_err(
.send_transaction(transaction)
.await
.inspect_err(
|err| tracing::error!(%err, "Encountered an error when submitting the transaction"), |err| tracing::error!(%err, "Encountered an error when submitting the transaction"),
) )?;
.context("Failed to submit transaction to geth node")?;
let transaction_hash = *pending_transaction.tx_hash(); let transaction_hash = *pending_transaction.tx_hash();
// The following is a fix for the "transaction indexing is in progress" error that we used // The following is a fix for the "transaction indexing is in progress" error that we used
@@ -369,11 +335,7 @@ impl EthereumNode for GethNode {
transaction: &TransactionReceipt, transaction: &TransactionReceipt,
trace_options: GethDebugTracingOptions, trace_options: GethDebugTracingOptions,
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> { ) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
let provider = Arc::new( let provider = Arc::new(self.provider().await?);
self.provider()
.await
.context("Failed to create provider for tracing")?,
);
poll( poll(
Self::TRACE_POLLING_DURATION, Self::TRACE_POLLING_DURATION,
PollingWaitBehavior::Constant(Duration::from_millis(200)), PollingWaitBehavior::Constant(Duration::from_millis(200)),
@@ -409,10 +371,8 @@ impl EthereumNode for GethNode {
}); });
match self match self
.trace_transaction(transaction, trace_options) .trace_transaction(transaction, trace_options)
.await .await?
.context("Failed to trace transaction for prestate diff")? .try_into_pre_state_frame()?
.try_into_pre_state_frame()
.context("Failed to convert trace into pre-state frame")?
{ {
PreStateFrame::Diff(diff) => Ok(diff), PreStateFrame::Diff(diff) => Ok(diff),
_ => anyhow::bail!("expected a diff mode trace"), _ => anyhow::bail!("expected a diff mode trace"),
@@ -422,8 +382,7 @@ impl EthereumNode for GethNode {
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn balance_of(&self, address: Address) -> anyhow::Result<U256> { async fn balance_of(&self, address: Address) -> anyhow::Result<U256> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_balance(address) .get_balance(address)
.await .await
.map_err(Into::into) .map_err(Into::into)
@@ -436,8 +395,7 @@ impl EthereumNode for GethNode {
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
) -> anyhow::Result<EIP1186AccountProofResponse> { ) -> anyhow::Result<EIP1186AccountProofResponse> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_proof(address, keys) .get_proof(address, keys)
.latest() .latest()
.await .await
@@ -449,8 +407,7 @@ impl ResolverApi for GethNode {
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn chain_id(&self) -> anyhow::Result<alloy::primitives::ChainId> { async fn chain_id(&self) -> anyhow::Result<alloy::primitives::ChainId> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_chain_id() .get_chain_id()
.await .await
.map_err(Into::into) .map_err(Into::into)
@@ -459,8 +416,7 @@ impl ResolverApi for GethNode {
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn transaction_gas_price(&self, tx_hash: &TxHash) -> anyhow::Result<u128> { async fn transaction_gas_price(&self, tx_hash: &TxHash) -> anyhow::Result<u128> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_transaction_receipt(*tx_hash) .get_transaction_receipt(*tx_hash)
.await? .await?
.context("Failed to get the transaction receipt") .context("Failed to get the transaction receipt")
@@ -470,48 +426,40 @@ impl ResolverApi for GethNode {
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> { async fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the geth block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Geth block, perhaps there are no blocks?")
.map(|block| block.header.gas_limit as _) .map(|block| block.header.gas_limit as _)
} }
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> { async fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the geth block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Geth block, perhaps there are no blocks?")
.map(|block| block.header.beneficiary) .map(|block| block.header.beneficiary)
} }
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> { async fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the geth block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Geth block, perhaps there are no blocks?")
.map(|block| U256::from_be_bytes(block.header.mix_hash.0)) .map(|block| U256::from_be_bytes(block.header.mix_hash.0))
} }
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn block_base_fee(&self, number: BlockNumberOrTag) -> anyhow::Result<u64> { async fn block_base_fee(&self, number: BlockNumberOrTag) -> anyhow::Result<u64> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the geth block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Geth block, perhaps there are no blocks?")
.and_then(|block| { .and_then(|block| {
block block
.header .header
@@ -523,32 +471,27 @@ impl ResolverApi for GethNode {
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> { async fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the geth block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Geth block, perhaps there are no blocks?")
.map(|block| block.header.hash) .map(|block| block.header.hash)
} }
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> { async fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the geth block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Geth block, perhaps there are no blocks?")
.map(|block| block.header.timestamp) .map(|block| block.header.timestamp)
} }
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))] #[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
async fn last_block_number(&self) -> anyhow::Result<BlockNumber> { async fn last_block_number(&self) -> anyhow::Result<BlockNumber> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Geth provider")?
.get_block_number() .get_block_number()
.await .await
.map_err(Into::into) .map_err(Into::into)
@@ -633,10 +576,8 @@ impl Node for GethNode {
.stdin(Stdio::null()) .stdin(Stdio::null())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::null()) .stderr(Stdio::null())
.spawn() .spawn()?
.context("Failed to spawn geth --version process")? .wait_with_output()?
.wait_with_output()
.context("Failed to wait for geth --version output")?
.stdout; .stdout;
Ok(String::from_utf8_lossy(&output).into()) Ok(String::from_utf8_lossy(&output).into())
} }
+52 -108
View File
@@ -96,10 +96,8 @@ impl KitchensinkNode {
let _ = clear_directory(&self.base_directory); let _ = clear_directory(&self.base_directory);
let _ = clear_directory(&self.logs_directory); let _ = clear_directory(&self.logs_directory);
create_dir_all(&self.base_directory) create_dir_all(&self.base_directory)?;
.context("Failed to create base directory for kitchensink node")?; create_dir_all(&self.logs_directory)?;
create_dir_all(&self.logs_directory)
.context("Failed to create logs directory for kitchensink node")?;
let template_chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE); let template_chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE);
@@ -128,10 +126,8 @@ impl KitchensinkNode {
); );
} }
let content = String::from_utf8(output.stdout) let content = String::from_utf8(output.stdout)?;
.context("Failed to decode substrate export-chain-spec output as UTF-8")?; let mut chainspec_json: JsonValue = serde_json::from_str(&content)?;
let mut chainspec_json: JsonValue =
serde_json::from_str(&content).context("Failed to parse substrate chain spec JSON")?;
let existing_chainspec_balances = let existing_chainspec_balances =
chainspec_json["genesis"]["runtimeGenesis"]["patch"]["balances"]["balances"] chainspec_json["genesis"]["runtimeGenesis"]["patch"]["balances"]["balances"]
@@ -153,8 +149,7 @@ impl KitchensinkNode {
}) })
.collect(); .collect();
let mut eth_balances = { let mut eth_balances = {
let mut genesis = serde_json::from_str::<Genesis>(genesis) let mut genesis = serde_json::from_str::<Genesis>(genesis)?;
.context("Failed to deserialize EVM genesis JSON for kitchensink")?;
for signer_address in for signer_address in
<EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet) <EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet)
{ {
@@ -165,8 +160,7 @@ impl KitchensinkNode {
.entry(signer_address) .entry(signer_address)
.or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE))); .or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE)));
} }
self.extract_balance_from_genesis_file(&genesis) self.extract_balance_from_genesis_file(&genesis)?
.context("Failed to extract balances from EVM genesis JSON")?
}; };
merged_balances.append(&mut eth_balances); merged_balances.append(&mut eth_balances);
@@ -174,11 +168,9 @@ impl KitchensinkNode {
json!(merged_balances); json!(merged_balances);
serde_json::to_writer_pretty( serde_json::to_writer_pretty(
std::fs::File::create(&template_chainspec_path) std::fs::File::create(&template_chainspec_path)?,
.context("Failed to create kitchensink template chainspec file")?,
&chainspec_json, &chainspec_json,
) )?;
.context("Failed to write kitchensink template chainspec JSON")?;
Ok(self) Ok(self)
} }
@@ -204,12 +196,10 @@ impl KitchensinkNode {
// Start Substrate node // Start Substrate node
let kitchensink_stdout_logs_file = open_options let kitchensink_stdout_logs_file = open_options
.clone() .clone()
.open(self.kitchensink_stdout_log_file_path()) .open(self.kitchensink_stdout_log_file_path())?;
.context("Failed to open kitchensink stdout logs file")?;
let kitchensink_stderr_logs_file = open_options let kitchensink_stderr_logs_file = open_options
.clone() .clone()
.open(self.kitchensink_stderr_log_file_path()) .open(self.kitchensink_stderr_log_file_path())?;
.context("Failed to open kitchensink stderr logs file")?;
let node_binary_path = if self.use_kitchensink_not_dev_node { let node_binary_path = if self.use_kitchensink_not_dev_node {
self.substrate_binary.as_path() self.substrate_binary.as_path()
} else { } else {
@@ -233,18 +223,9 @@ impl KitchensinkNode {
.arg("--rpc-max-connections") .arg("--rpc-max-connections")
.arg(u32::MAX.to_string()) .arg(u32::MAX.to_string())
.env("RUST_LOG", Self::SUBSTRATE_LOG_ENV) .env("RUST_LOG", Self::SUBSTRATE_LOG_ENV)
.stdout( .stdout(kitchensink_stdout_logs_file.try_clone()?)
kitchensink_stdout_logs_file .stderr(kitchensink_stderr_logs_file.try_clone()?)
.try_clone() .spawn()?
.context("Failed to clone kitchensink stdout log file handle")?,
)
.stderr(
kitchensink_stderr_logs_file
.try_clone()
.context("Failed to clone kitchensink stderr log file handle")?,
)
.spawn()
.context("Failed to spawn substrate node process")?
.into(); .into();
// Give the node a moment to boot // Give the node a moment to boot
@@ -253,18 +234,14 @@ impl KitchensinkNode {
Self::SUBSTRATE_READY_MARKER, Self::SUBSTRATE_READY_MARKER,
Duration::from_secs(60), Duration::from_secs(60),
) { ) {
self.shutdown() self.shutdown()?;
.context("Failed to gracefully shutdown after substrate start error")?;
return Err(error); return Err(error);
}; };
let eth_proxy_stdout_logs_file = open_options let eth_proxy_stdout_logs_file = open_options
.clone() .clone()
.open(self.proxy_stdout_log_file_path()) .open(self.proxy_stdout_log_file_path())?;
.context("Failed to open eth-proxy stdout logs file")?; let eth_proxy_stderr_logs_file = open_options.open(self.proxy_stderr_log_file_path())?;
let eth_proxy_stderr_logs_file = open_options
.open(self.proxy_stderr_log_file_path())
.context("Failed to open eth-proxy stderr logs file")?;
self.process_proxy = Command::new(&self.eth_proxy_binary) self.process_proxy = Command::new(&self.eth_proxy_binary)
.arg("--dev") .arg("--dev")
.arg("--rpc-port") .arg("--rpc-port")
@@ -274,18 +251,9 @@ impl KitchensinkNode {
.arg("--rpc-max-connections") .arg("--rpc-max-connections")
.arg(u32::MAX.to_string()) .arg(u32::MAX.to_string())
.env("RUST_LOG", Self::PROXY_LOG_ENV) .env("RUST_LOG", Self::PROXY_LOG_ENV)
.stdout( .stdout(eth_proxy_stdout_logs_file.try_clone()?)
eth_proxy_stdout_logs_file .stderr(eth_proxy_stderr_logs_file.try_clone()?)
.try_clone() .spawn()?
.context("Failed to clone eth-proxy stdout log file handle")?,
)
.stderr(
eth_proxy_stderr_logs_file
.try_clone()
.context("Failed to clone eth-proxy stderr log file handle")?,
)
.spawn()
.context("Failed to spawn eth-proxy process")?
.into(); .into();
if let Err(error) = Self::wait_ready( if let Err(error) = Self::wait_ready(
@@ -293,8 +261,7 @@ impl KitchensinkNode {
Self::ETH_PROXY_READY_MARKER, Self::ETH_PROXY_READY_MARKER,
Duration::from_secs(60), Duration::from_secs(60),
) { ) {
self.shutdown() self.shutdown()?;
.context("Failed to gracefully shutdown after eth-proxy start error")?;
return Err(error); return Err(error);
}; };
@@ -419,14 +386,11 @@ impl EthereumNode for KitchensinkNode {
) -> anyhow::Result<TransactionReceipt> { ) -> anyhow::Result<TransactionReceipt> {
let receipt = self let receipt = self
.provider() .provider()
.await .await?
.context("Failed to create provider for transaction submission")?
.send_transaction(transaction) .send_transaction(transaction)
.await .await?
.context("Failed to submit transaction to kitchensink proxy")?
.get_receipt() .get_receipt()
.await .await?;
.context("Failed to fetch transaction receipt from kitchensink proxy")?;
Ok(receipt) Ok(receipt)
} }
@@ -436,12 +400,11 @@ impl EthereumNode for KitchensinkNode {
trace_options: GethDebugTracingOptions, trace_options: GethDebugTracingOptions,
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> { ) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
let tx_hash = transaction.transaction_hash; let tx_hash = transaction.transaction_hash;
self.provider() Ok(self
.await .provider()
.context("Failed to create provider for debug tracing")? .await?
.debug_trace_transaction(tx_hash, trace_options) .debug_trace_transaction(tx_hash, trace_options)
.await .await?)
.context("Failed to obtain debug trace from kitchensink proxy")
} }
async fn state_diff(&self, transaction: &TransactionReceipt) -> anyhow::Result<DiffMode> { async fn state_diff(&self, transaction: &TransactionReceipt) -> anyhow::Result<DiffMode> {
@@ -462,8 +425,7 @@ impl EthereumNode for KitchensinkNode {
async fn balance_of(&self, address: Address) -> anyhow::Result<U256> { async fn balance_of(&self, address: Address) -> anyhow::Result<U256> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_balance(address) .get_balance(address)
.await .await
.map_err(Into::into) .map_err(Into::into)
@@ -475,8 +437,7 @@ impl EthereumNode for KitchensinkNode {
keys: Vec<StorageKey>, keys: Vec<StorageKey>,
) -> anyhow::Result<EIP1186AccountProofResponse> { ) -> anyhow::Result<EIP1186AccountProofResponse> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_proof(address, keys) .get_proof(address, keys)
.latest() .latest()
.await .await
@@ -487,8 +448,7 @@ impl EthereumNode for KitchensinkNode {
impl ResolverApi for KitchensinkNode { impl ResolverApi for KitchensinkNode {
async fn chain_id(&self) -> anyhow::Result<alloy::primitives::ChainId> { async fn chain_id(&self) -> anyhow::Result<alloy::primitives::ChainId> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_chain_id() .get_chain_id()
.await .await
.map_err(Into::into) .map_err(Into::into)
@@ -496,8 +456,7 @@ impl ResolverApi for KitchensinkNode {
async fn transaction_gas_price(&self, tx_hash: &TxHash) -> anyhow::Result<u128> { async fn transaction_gas_price(&self, tx_hash: &TxHash) -> anyhow::Result<u128> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_transaction_receipt(*tx_hash) .get_transaction_receipt(*tx_hash)
.await? .await?
.context("Failed to get the transaction receipt") .context("Failed to get the transaction receipt")
@@ -506,45 +465,37 @@ impl ResolverApi for KitchensinkNode {
async fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> { async fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the kitchensink block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
.map(|block| block.header.gas_limit as _) .map(|block| block.header.gas_limit as _)
} }
async fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> { async fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the kitchensink block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
.map(|block| block.header.beneficiary) .map(|block| block.header.beneficiary)
} }
async fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> { async fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the kitchensink block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
.map(|block| U256::from_be_bytes(block.header.mix_hash.0)) .map(|block| U256::from_be_bytes(block.header.mix_hash.0))
} }
async fn block_base_fee(&self, number: BlockNumberOrTag) -> anyhow::Result<u64> { async fn block_base_fee(&self, number: BlockNumberOrTag) -> anyhow::Result<u64> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the kitchensink block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
.and_then(|block| { .and_then(|block| {
block block
.header .header
@@ -555,30 +506,25 @@ impl ResolverApi for KitchensinkNode {
async fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> { async fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the kitchensink block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
.map(|block| block.header.hash) .map(|block| block.header.hash)
} }
async fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> { async fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_block_by_number(number) .get_block_by_number(number)
.await .await?
.context("Failed to get the kitchensink block")? .ok_or(anyhow::Error::msg("Blockchain has no blocks"))
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
.map(|block| block.header.timestamp) .map(|block| block.header.timestamp)
} }
async fn last_block_number(&self) -> anyhow::Result<BlockNumber> { async fn last_block_number(&self) -> anyhow::Result<BlockNumber> {
self.provider() self.provider()
.await .await?
.context("Failed to get the Kitchensink provider")?
.get_block_number() .get_block_number()
.await .await
.map_err(Into::into) .map_err(Into::into)
@@ -665,10 +611,8 @@ impl Node for KitchensinkNode {
.stdin(Stdio::null()) .stdin(Stdio::null())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::null()) .stderr(Stdio::null())
.spawn() .spawn()?
.context("Failed to spawn kitchensink --version")? .wait_with_output()?
.wait_with_output()
.context("Failed to wait for kitchensink --version")?
.stdout; .stdout;
Ok(String::from_utf8_lossy(&output).into()) Ok(String::from_utf8_lossy(&output).into())
} }
+3 -6
View File
@@ -44,10 +44,8 @@ where
nodes.push( nodes.push(
handle handle
.join() .join()
.map_err(|error| anyhow::anyhow!("failed to spawn node: {:?}", error)) .map_err(|error| anyhow::anyhow!("failed to spawn node: {:?}", error))?
.context("Failed to join node spawn thread")? .map_err(|error| anyhow::anyhow!("node failed to spawn: {error}"))?,
.map_err(|error| anyhow::anyhow!("node failed to spawn: {error}"))
.context("Node failed to spawn")?,
); );
} }
@@ -71,8 +69,7 @@ fn spawn_node<T: Node + Send>(args: &Arguments, genesis: String) -> anyhow::Resu
connection_string = node.connection_string(), connection_string = node.connection_string(),
"Spawning node" "Spawning node"
); );
node.spawn(genesis) node.spawn(genesis)?;
.context("Failed to spawn node process")?;
info!( info!(
id = node.id(), id = node.id(),
connection_string = node.connection_string(), connection_string = node.connection_string(),
+4 -15
View File
@@ -9,7 +9,7 @@ use std::{
}; };
use alloy_primitives::Address; use alloy_primitives::Address;
use anyhow::{Context as _, Result}; use anyhow::Result;
use indexmap::IndexMap; use indexmap::IndexMap;
use revive_dt_compiler::{CompilerInput, CompilerOutput, Mode}; use revive_dt_compiler::{CompilerInput, CompilerOutput, Mode};
use revive_dt_config::{Arguments, TestingPlatform}; use revive_dt_config::{Arguments, TestingPlatform};
@@ -113,10 +113,7 @@ impl ReportAggregator {
debug!("Report aggregation completed"); debug!("Report aggregation completed");
let file_name = { let file_name = {
let current_timestamp = SystemTime::now() let current_timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
.duration_since(UNIX_EPOCH)
.context("System clock is before UNIX_EPOCH; cannot compute report timestamp")?
.as_secs();
let mut file_name = current_timestamp.to_string(); let mut file_name = current_timestamp.to_string();
file_name.push_str(".json"); file_name.push_str(".json");
file_name file_name
@@ -127,16 +124,8 @@ impl ReportAggregator {
.write(true) .write(true)
.truncate(true) .truncate(true)
.read(false) .read(false)
.open(&file_path) .open(file_path)?;
.with_context(|| { serde_json::to_writer_pretty(file, &self.report)?;
format!(
"Failed to open report file for writing: {}",
file_path.display()
)
})?;
serde_json::to_writer_pretty(&file, &self.report).with_context(|| {
format!("Failed to serialize report JSON to {}", file_path.display())
})?;
Ok(()) Ok(())
} }
+1 -3
View File
@@ -4,7 +4,6 @@
use std::{collections::BTreeMap, path::PathBuf, sync::Arc}; use std::{collections::BTreeMap, path::PathBuf, sync::Arc};
use alloy_primitives::Address; use alloy_primitives::Address;
use anyhow::Context as _;
use indexmap::IndexMap; use indexmap::IndexMap;
use revive_dt_compiler::{CompilerInput, CompilerOutput}; use revive_dt_compiler::{CompilerInput, CompilerOutput};
use revive_dt_config::TestingPlatform; use revive_dt_config::TestingPlatform;
@@ -631,8 +630,7 @@ define_event! {
impl RunnerEventReporter { impl RunnerEventReporter {
pub async fn subscribe(&self) -> anyhow::Result<broadcast::Receiver<ReporterEvent>> { pub async fn subscribe(&self) -> anyhow::Result<broadcast::Receiver<ReporterEvent>> {
let (tx, rx) = oneshot::channel::<broadcast::Receiver<ReporterEvent>>(); let (tx, rx) = oneshot::channel::<broadcast::Receiver<ReporterEvent>>();
self.report_subscribe_to_events_event(tx) self.report_subscribe_to_events_event(tx)?;
.context("Failed to send subscribe request to reporter task")?;
rx.await.map_err(Into::into) rx.await.map_err(Into::into)
} }
} }
+8 -45
View File
@@ -12,7 +12,6 @@ use std::{
use tokio::sync::Mutex; use tokio::sync::Mutex;
use crate::download::SolcDownloader; use crate::download::SolcDownloader;
use anyhow::Context;
pub const SOLC_CACHE_DIRECTORY: &str = "solc"; pub const SOLC_CACHE_DIRECTORY: &str = "solc";
pub(crate) static SOLC_CACHER: LazyLock<Mutex<HashSet<PathBuf>>> = LazyLock::new(Default::default); pub(crate) static SOLC_CACHER: LazyLock<Mutex<HashSet<PathBuf>>> = LazyLock::new(Default::default);
@@ -32,20 +31,8 @@ pub(crate) async fn get_or_download(
return Ok(target_file); return Ok(target_file);
} }
create_dir_all(&target_directory).with_context(|| { create_dir_all(target_directory)?;
format!( download_to_file(&target_file, downloader).await?;
"Failed to create solc cache directory: {}",
target_directory.display()
)
})?;
download_to_file(&target_file, downloader)
.await
.with_context(|| {
format!(
"Failed to write downloaded solc to {}",
target_file.display()
)
})?;
cache.insert(target_file.clone()); cache.insert(target_file.clone());
Ok(target_file) Ok(target_file)
@@ -58,26 +45,14 @@ async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::R
#[cfg(unix)] #[cfg(unix)]
{ {
let mut permissions = file let mut permissions = file.metadata()?.permissions();
.metadata()
.with_context(|| format!("Failed to read metadata for {}", path.display()))?
.permissions();
permissions.set_mode(permissions.mode() | 0o111); permissions.set_mode(permissions.mode() | 0o111);
file.set_permissions(permissions).with_context(|| { file.set_permissions(permissions)?;
format!("Failed to set executable permissions on {}", path.display())
})?;
} }
let mut file = BufWriter::new(file); let mut file = BufWriter::new(file);
file.write_all( file.write_all(&downloader.download().await?)?;
&downloader file.flush()?;
.download()
.await
.context("Failed to download solc binary bytes")?,
)
.with_context(|| format!("Failed to write solc binary to {}", path.display()))?;
file.flush()
.with_context(|| format!("Failed to flush file {}", path.display()))?;
drop(file); drop(file);
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
@@ -88,20 +63,8 @@ async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::R
.stderr(std::process::Stdio::null()) .stderr(std::process::Stdio::null())
.stdout(std::process::Stdio::null()) .stdout(std::process::Stdio::null())
.stdout(std::process::Stdio::null()) .stdout(std::process::Stdio::null())
.spawn() .spawn()?
.with_context(|| { .wait()?;
format!(
"Failed to spawn xattr to remove quarantine attribute on {}",
path.display()
)
})?
.wait()
.with_context(|| {
format!(
"Failed waiting for xattr operation to complete on {}",
path.display()
)
})?;
Ok(()) Ok(())
} }
+5 -27
View File
@@ -11,7 +11,6 @@ use semver::Version;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
use crate::list::List; use crate::list::List;
use anyhow::Context;
pub static LIST_CACHE: LazyLock<Mutex<HashMap<&'static str, List>>> = pub static LIST_CACHE: LazyLock<Mutex<HashMap<&'static str, List>>> =
LazyLock::new(Default::default); LazyLock::new(Default::default);
@@ -31,12 +30,7 @@ impl List {
return Ok(list.clone()); return Ok(list.clone());
} }
let body: List = reqwest::get(url) let body: List = reqwest::get(url).await?.json().await?;
.await
.with_context(|| format!("Failed to GET solc list from {url}"))?
.json()
.await
.with_context(|| format!("Failed to deserialize solc list JSON from {url}"))?;
LIST_CACHE.lock().unwrap().insert(url, body.clone()); LIST_CACHE.lock().unwrap().insert(url, body.clone());
@@ -74,8 +68,7 @@ impl SolcDownloader {
}), }),
VersionOrRequirement::Requirement(requirement) => { VersionOrRequirement::Requirement(requirement) => {
let Some(version) = List::download(list) let Some(version) = List::download(list)
.await .await?
.with_context(|| format!("Failed to download solc builds list from {list}"))?
.builds .builds
.into_iter() .into_iter()
.map(|build| build.version) .map(|build| build.version)
@@ -114,20 +107,11 @@ impl SolcDownloader {
/// Errors out if the download fails or the digest of the downloaded file /// Errors out if the download fails or the digest of the downloaded file
/// mismatches the expected digest from the release [List]. /// mismatches the expected digest from the release [List].
pub async fn download(&self) -> anyhow::Result<Vec<u8>> { pub async fn download(&self) -> anyhow::Result<Vec<u8>> {
let builds = List::download(self.list) let builds = List::download(self.list).await?.builds;
.await
.with_context(|| format!("Failed to download solc builds list from {}", self.list))?
.builds;
let build = builds let build = builds
.iter() .iter()
.find(|build| build.version == self.version) .find(|build| build.version == self.version)
.ok_or_else(|| anyhow::anyhow!("solc v{} not found builds", self.version)) .ok_or_else(|| anyhow::anyhow!("solc v{} not found builds", self.version))?;
.with_context(|| {
format!(
"Requested solc version {} was not found in builds list fetched from {}",
self.version, self.list
)
})?;
let path = build.path.clone(); let path = build.path.clone();
let expected_digest = build let expected_digest = build
@@ -137,13 +121,7 @@ impl SolcDownloader {
.to_string(); .to_string();
let url = format!("{}/{}/{}", Self::BASE_URL, self.target, path.display()); let url = format!("{}/{}/{}", Self::BASE_URL, self.target, path.display());
let file = reqwest::get(&url) let file = reqwest::get(url).await?.bytes().await?.to_vec();
.await
.with_context(|| format!("Failed to GET solc binary from {url}"))?
.bytes()
.await
.with_context(|| format!("Failed to read solc binary bytes from {url}"))?
.to_vec();
if hex::encode(Sha256::digest(&file)) != expected_digest { if hex::encode(Sha256::digest(&file)) != expected_digest {
anyhow::bail!("sha256 mismatch for solc version {}", self.version); anyhow::bail!("sha256 mismatch for solc version {}", self.version);
+1 -3
View File
@@ -5,7 +5,6 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use anyhow::Context;
use cache::get_or_download; use cache::get_or_download;
use download::SolcDownloader; use download::SolcDownloader;
@@ -35,8 +34,7 @@ pub async fn download_solc(
SolcDownloader::windows(version).await SolcDownloader::windows(version).await
} else { } else {
unimplemented!() unimplemented!()
} }?;
.context("Failed to initialize the Solc Downloader")?;
get_or_download(cache_directory, &downloader).await get_or_download(cache_directory, &downloader).await
} }
-102
View File
@@ -1,102 +0,0 @@
#!/bin/bash
# Revive Differential Tests - Quick Start Script
# This script clones the test repository, sets up the corpus file, and runs the tool
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
TEST_REPO_URL="https://github.com/paritytech/resolc-compiler-tests"
TEST_REPO_DIR="resolc-compiler-tests"
CORPUS_FILE="./corpus.json"
WORKDIR="workdir"
# Optional positional argument: path to polkadot-sdk directory
POLKADOT_SDK_DIR="${1:-}"
# Binary paths (default to names in $PATH)
REVIVE_DEV_NODE_BIN="revive-dev-node"
ETH_RPC_BIN="eth-rpc"
SUBSTRATE_NODE_BIN="substrate-node"
echo -e "${GREEN}=== Revive Differential Tests Quick Start ===${NC}"
echo ""
# Check if test repo already exists
if [ -d "$TEST_REPO_DIR" ]; then
echo -e "${YELLOW}Test repository already exists. Pulling latest changes...${NC}"
cd "$TEST_REPO_DIR"
git pull
cd ..
else
echo -e "${GREEN}Cloning test repository...${NC}"
git clone "$TEST_REPO_URL"
fi
# If polkadot-sdk path is provided, verify and use binaries from there; build if needed
if [ -n "$POLKADOT_SDK_DIR" ]; then
if [ ! -d "$POLKADOT_SDK_DIR" ]; then
echo -e "${RED}Provided polkadot-sdk directory does not exist: $POLKADOT_SDK_DIR${NC}"
exit 1
fi
POLKADOT_SDK_DIR=$(realpath "$POLKADOT_SDK_DIR")
echo -e "${GREEN}Using polkadot-sdk at: $POLKADOT_SDK_DIR${NC}"
REVIVE_DEV_NODE_BIN="$POLKADOT_SDK_DIR/target/release/revive-dev-node"
ETH_RPC_BIN="$POLKADOT_SDK_DIR/target/release/eth-rpc"
SUBSTRATE_NODE_BIN="$POLKADOT_SDK_DIR/target/release/substrate-node"
if [ ! -x "$REVIVE_DEV_NODE_BIN" ] || [ ! -x "$ETH_RPC_BIN" ] || [ ! -x "$SUBSTRATE_NODE_BIN" ]; then
echo -e "${YELLOW}Required binaries not found in release target. Building...${NC}"
(cd "$POLKADOT_SDK_DIR" && cargo build --release --package revive-dev-node --package eth-rpc --package substrate-node)
fi
for bin in "$REVIVE_DEV_NODE_BIN" "$ETH_RPC_BIN" "$SUBSTRATE_NODE_BIN"; do
if [ ! -x "$bin" ]; then
echo -e "${RED}Expected binary not found after build: $bin${NC}"
exit 1
fi
done
else
echo -e "${YELLOW}No polkadot-sdk path provided. Using binaries from $PATH.${NC}"
fi
# Create corpus file with absolute path resolved at runtime
echo -e "${GREEN}Creating corpus file...${NC}"
ABSOLUTE_PATH=$(realpath "$TEST_REPO_DIR/fixtures/solidity/")
cat > "$CORPUS_FILE" << EOF
{
"name": "MatterLabs Solidity Simple, Complex, and Semantic Tests",
"path": "$ABSOLUTE_PATH"
}
EOF
echo -e "${GREEN}Corpus file created: $CORPUS_FILE${NC}"
# Create workdir if it doesn't exist
mkdir -p "$WORKDIR"
echo -e "${GREEN}Starting differential tests...${NC}"
echo "This may take a while..."
echo ""
# Run the tool
RUST_LOG="error" cargo run --release -- \
--corpus "$CORPUS_FILE" \
--workdir "$WORKDIR" \
--number-of-nodes 5 \
--kitchensink "$SUBSTRATE_NODE_BIN" \
--revive-dev-node "$REVIVE_DEV_NODE_BIN" \
--eth_proxy "$ETH_RPC_BIN" \
> logs.log \
2> output.log
echo -e "${GREEN}=== Test run completed! ===${NC}"