Compare commits

...

1 Commits

Author SHA1 Message Date
Cyrill Leutwiler 12fdd9b4d1 test
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-10-08 13:04:03 +02:00
55 changed files with 12787 additions and 12039 deletions
-25
View File
@@ -1,25 +0,0 @@
# Basic
edition = "2024"
hard_tabs = true
max_width = 100
use_small_heuristics = "Max"
# Imports
imports_granularity = "Crate"
reorder_imports = true
# Consistency
newline_style = "Unix"
# Misc
chain_width = 80
spaces_around_ranges = false
binop_separator = "Back"
reorder_impl_items = false
match_arm_leading_pipes = "Preserve"
match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
# Format comments
comment_width = 100
wrap_comments = true
+6 -3
View File
@@ -20,14 +20,17 @@ pub fn read(path: impl AsRef<Path>) -> Result<Vec<u8>> {
let content = fs::read(path.as_path())?; let content = fs::read(path.as_path())?;
READ_CACHE.insert(path, content.clone()); READ_CACHE.insert(path, content.clone());
Ok(content) Ok(content)
}, }
} }
} }
pub fn read_to_string(path: impl AsRef<Path>) -> Result<String> { pub fn read_to_string(path: impl AsRef<Path>) -> Result<String> {
let content = read(path)?; let content = read(path)?;
String::from_utf8(content).map_err(|_| { String::from_utf8(content).map_err(|_| {
Error::new(std::io::ErrorKind::InvalidData, "The contents of the file are not valid UTF8") Error::new(
std::io::ErrorKind::InvalidData,
"The contents of the file are not valid UTF8",
)
}) })
} }
@@ -43,6 +46,6 @@ pub fn read_dir(path: impl AsRef<Path>) -> Result<Box<dyn Iterator<Item = Result
.collect(); .collect();
READ_DIR_CACHE.insert(path.clone(), entries); READ_DIR_CACHE.insert(path.clone(), entries);
Ok(read_dir(path).unwrap()) Ok(read_dir(path).unwrap())
}, }
} }
} }
+4 -1
View File
@@ -12,7 +12,10 @@ pub fn clear_directory(path: impl AsRef<Path>) -> Result<()> {
.with_context(|| format!("Failed to read directory: {}", path.as_ref().display()))? .with_context(|| format!("Failed to read directory: {}", path.as_ref().display()))?
{ {
let entry = entry.with_context(|| { let entry = entry.with_context(|| {
format!("Failed to read an entry in directory: {}", path.as_ref().display()) format!(
"Failed to read an entry in directory: {}",
path.as_ref().display()
)
})?; })?;
let entry_path = entry.path(); let entry_path = entry.path();
+9 -5
View File
@@ -37,13 +37,17 @@ where
)); ));
} }
match future().await.context("Polled future returned an error during polling loop")? { match future()
.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,
PollingWaitBehavior::ExponentialBackoff => PollingWaitBehavior::ExponentialBackoff => {
Duration::from_secs(2u64.pow(retries)) Duration::from_secs(2u64.pow(retries))
.min(EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION), .min(EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION)
}
}; };
let next_wait_duration = let next_wait_duration =
next_wait_duration.min(max_allowed_wait_duration - total_wait_duration); next_wait_duration.min(max_allowed_wait_duration - total_wait_duration);
@@ -51,10 +55,10 @@ where
retries += 1; retries += 1;
tokio::time::sleep(next_wait_duration).await; tokio::time::sleep(next_wait_duration).await;
}, }
ControlFlow::Break(output) => { ControlFlow::Break(output) => {
break Ok(output); break Ok(output);
}, }
} }
} }
} }
@@ -75,12 +75,13 @@ impl Iterator for FilesWithExtensionIterator {
for entry_path in iterator.flatten() { for entry_path in iterator.flatten() {
if entry_path.is_dir() { if entry_path.is_dir() {
self.directories_to_search.push(entry_path) self.directories_to_search.push(entry_path)
} else if entry_path.is_file() && } else if entry_path.is_file()
entry_path.extension().is_some_and(|ext| { && entry_path.extension().is_some_and(|ext| {
self.allowed_extensions self.allowed_extensions
.iter() .iter()
.any(|allowed| ext.eq_ignore_ascii_case(allowed.as_ref())) .any(|allowed| ext.eq_ignore_ascii_case(allowed.as_ref()))
}) { })
{
self.files_matching_allowed_extensions.push(entry_path) self.files_matching_allowed_extensions.push(entry_path)
} }
} }
+3 -1
View File
@@ -76,7 +76,9 @@ impl FromStr for ModePipeline {
// Don't go via Yul IR // Don't go via Yul IR
"E" => Ok(ModePipeline::ViaEVMAssembly), "E" => Ok(ModePipeline::ViaEVMAssembly),
// Anything else that we see isn't a mode at all // Anything else that we see isn't a mode at all
_ => Err(anyhow::anyhow!("Unsupported pipeline '{s}': expected 'Y' or 'E'")), _ => Err(anyhow::anyhow!(
"Unsupported pipeline '{s}': expected 'Y' or 'E'"
)),
} }
} }
} }
@@ -15,7 +15,10 @@ pub struct PrivateKeyAllocator {
impl PrivateKeyAllocator { impl PrivateKeyAllocator {
/// Creates a new instance of the private key allocator. /// Creates a new instance of the private key allocator.
pub fn new(highest_private_key_inclusive: U256) -> Self { pub fn new(highest_private_key_inclusive: U256) -> Self {
Self { next_private_key: U256::ONE, highest_private_key_inclusive } Self {
next_private_key: U256::ONE,
highest_private_key_inclusive,
}
} }
/// Allocates a new private key and errors out if the maximum private key has been reached. /// Allocates a new private key and errors out if the maximum private key has been reached.
+4 -1
View File
@@ -7,7 +7,10 @@ pub struct RoundRobinPool<T> {
impl<T> RoundRobinPool<T> { impl<T> RoundRobinPool<T> {
pub fn new(items: Vec<T>) -> Self { pub fn new(items: Vec<T>) -> Self {
Self { next_index: Default::default(), items } Self {
next_index: Default::default(),
items,
}
} }
pub fn round_robin(&self) -> &T { pub fn round_robin(&self) -> &T {
+20 -13
View File
@@ -60,7 +60,10 @@ impl Resolc {
Ok(COMPILERS_CACHE Ok(COMPILERS_CACHE
.entry(solc.clone()) .entry(solc.clone())
.or_insert_with(|| { .or_insert_with(|| {
Self(Arc::new(ResolcInner { solc, resolc_path: resolc_configuration.path.clone() })) Self(Arc::new(ResolcInner {
solc,
resolc_path: resolc_configuration.path.clone(),
}))
}) })
.clone()) .clone())
} }
@@ -138,7 +141,9 @@ impl SolidityCompiler for Resolc {
output_selection: Some(SolcStandardJsonInputSettingsSelection::new_required()), output_selection: Some(SolcStandardJsonInputSettingsSelection::new_required()),
via_ir: Some(true), via_ir: Some(true),
optimizer: SolcStandardJsonInputSettingsOptimizer::new( optimizer: SolcStandardJsonInputSettingsOptimizer::new(
optimization.unwrap_or(ModeOptimizerSetting::M0).optimizations_enabled(), optimization
.unwrap_or(ModeOptimizerSetting::M0)
.optimizations_enabled(),
None, None,
&Version::new(0, 0, 0), &Version::new(0, 0, 0),
false, false,
@@ -248,14 +253,16 @@ 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 =
{
let metadata = contract_information let metadata = contract_information
.metadata .metadata
.as_ref() .as_ref()
.context("No metadata found for the contract")?; .context("No metadata found for the contract")?;
let solc_metadata_str = match metadata { let solc_metadata_str = match metadata {
serde_json::Value::String(solc_metadata_str) => serde_json::Value::String(solc_metadata_str) => {
solc_metadata_str.as_str(), solc_metadata_str.as_str()
}
serde_json::Value::Object(metadata_object) => { serde_json::Value::Object(metadata_object) => {
let solc_metadata_value = metadata_object let solc_metadata_value = metadata_object
.get("solc_metadata") .get("solc_metadata")
@@ -263,13 +270,13 @@ impl SolidityCompiler for Resolc {
solc_metadata_value solc_metadata_value
.as_str() .as_str()
.context("The 'solc_metadata' field is not a string")? .context("The 'solc_metadata' field is not a string")?
}, }
serde_json::Value::Null | serde_json::Value::Null
serde_json::Value::Bool(_) | | serde_json::Value::Bool(_)
serde_json::Value::Number(_) | | serde_json::Value::Number(_)
serde_json::Value::Array(_) => { | serde_json::Value::Array(_) => {
anyhow::bail!("Unsupported type of metadata {metadata:?}") anyhow::bail!("Unsupported type of metadata {metadata:?}")
}, }
}; };
let solc_metadata = let solc_metadata =
serde_json::from_str::<serde_json::Value>(solc_metadata_str).context( serde_json::from_str::<serde_json::Value>(solc_metadata_str).context(
@@ -297,7 +304,7 @@ impl SolidityCompiler for Resolc {
optimize_setting: ModeOptimizerSetting, optimize_setting: ModeOptimizerSetting,
pipeline: ModePipeline, pipeline: ModePipeline,
) -> bool { ) -> bool {
pipeline == ModePipeline::ViaYulIR && pipeline == ModePipeline::ViaYulIR
SolidityCompiler::supports_mode(&self.0.solc, optimize_setting, pipeline) && SolidityCompiler::supports_mode(&self.0.solc, optimize_setting, pipeline)
} }
} }
+13 -5
View File
@@ -56,7 +56,9 @@ impl Solc {
// resolution for us. Therefore, even if the download didn't proceed, this function will // resolution for us. Therefore, even if the download didn't proceed, this function will
// resolve the version requirement into a canonical version of the compiler. It's then up // resolve the version requirement into a canonical version of the compiler. It's then up
// to us to either use the provided path or not. // to us to either use the provided path or not.
let version = version.into().unwrap_or_else(|| solc_configuration.version.clone().into()); let version = version
.into()
.unwrap_or_else(|| solc_configuration.version.clone().into());
let (version, path) = let (version, path) =
download_solc(working_directory_configuration.as_path(), version, false) download_solc(working_directory_configuration.as_path(), version, false)
.await .await
@@ -70,7 +72,10 @@ impl Solc {
solc_version = %version, solc_version = %version,
"Created a new solc compiler object" "Created a new solc compiler object"
); );
Self(Arc::new(SolcInner { solc_path: path, solc_version: version })) Self(Arc::new(SolcInner {
solc_path: path,
solc_version: version,
}))
}) })
.clone()) .clone())
} }
@@ -247,7 +252,10 @@ impl SolidityCompiler for Solc {
let map = compiler_output let map = compiler_output
.contracts .contracts
.entry(contract_path.canonicalize().with_context(|| { .entry(contract_path.canonicalize().with_context(|| {
format!("Failed to canonicalize contract path {}", contract_path.display()) 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() {
@@ -278,8 +286,8 @@ impl SolidityCompiler for Solc {
// solc 0.8.13 and above supports --via-ir, and less than that does not. Thus, we support // solc 0.8.13 and above supports --via-ir, and less than that does not. Thus, we support
// mode E (ie no Yul IR) in either case, but only support Y (via Yul IR) if the compiler // mode E (ie no Yul IR) in either case, but only support Y (via Yul IR) if the compiler
// is new enough. // is new enough.
pipeline == ModePipeline::ViaEVMAssembly || pipeline == ModePipeline::ViaEVMAssembly
(pipeline == ModePipeline::ViaYulIR && self.compiler_supports_yul()) || (pipeline == ModePipeline::ViaYulIR && self.compiler_supports_yul())
} }
} }
+20 -7
View File
@@ -154,7 +154,7 @@ impl AsRef<GenesisConfiguration> for Context {
Self::Benchmark(..) => { Self::Benchmark(..) => {
static GENESIS: LazyLock<GenesisConfiguration> = LazyLock::new(Default::default); static GENESIS: LazyLock<GenesisConfiguration> = LazyLock::new(Default::default);
&GENESIS &GENESIS
}, }
Self::ExportJsonSchema => unreachable!(), Self::ExportJsonSchema => unreachable!(),
} }
} }
@@ -626,7 +626,11 @@ pub struct KurtosisConfiguration {
/// ///
/// If this is not specified, then the tool assumes that it should use the kurtosis binary /// If this is not specified, then the tool assumes that it should use the kurtosis binary
/// that's provided in the user's $PATH. /// that's provided in the user's $PATH.
#[clap(id = "kurtosis.path", long = "kurtosis.path", default_value = "kurtosis")] #[clap(
id = "kurtosis.path",
long = "kurtosis.path",
default_value = "kurtosis"
)]
pub path: PathBuf, pub path: PathBuf,
} }
@@ -637,7 +641,11 @@ pub struct KitchensinkConfiguration {
/// ///
/// If this is not specified, then the tool assumes that it should use the kitchensink binary /// If this is not specified, then the tool assumes that it should use the kitchensink binary
/// that's provided in the user's $PATH. /// that's provided in the user's $PATH.
#[clap(id = "kitchensink.path", long = "kitchensink.path", default_value = "substrate-node")] #[clap(
id = "kitchensink.path",
long = "kitchensink.path",
default_value = "substrate-node"
)]
pub path: PathBuf, pub path: PathBuf,
/// The amount of time to wait upon startup before considering that the node timed out. /// The amount of time to wait upon startup before considering that the node timed out.
@@ -723,11 +731,11 @@ impl GenesisConfiguration {
Some(genesis_path) => { Some(genesis_path) => {
let genesis_content = read_to_string(genesis_path)?; let genesis_content = read_to_string(genesis_path)?;
serde_json::from_str(genesis_content.as_str())? serde_json::from_str(genesis_content.as_str())?
}, }
None => DEFAULT_GENESIS.clone(), None => DEFAULT_GENESIS.clone(),
}; };
Ok(self.genesis.get_or_init(|| genesis)) Ok(self.genesis.get_or_init(|| genesis))
}, }
} }
} }
} }
@@ -815,7 +823,10 @@ impl ConcurrencyConfiguration {
pub fn concurrency_limit(&self) -> Option<usize> { pub fn concurrency_limit(&self) -> Option<usize> {
match self.ignore_concurrency_limit { match self.ignore_concurrency_limit {
true => None, true => None,
false => Some(self.number_concurrent_tasks.unwrap_or(20 * self.number_of_nodes)), false => Some(
self.number_concurrent_tasks
.unwrap_or(20 * self.number_of_nodes),
),
} }
} }
} }
@@ -906,7 +917,9 @@ impl Serialize for WorkingDirectoryConfiguration {
} }
fn parse_duration(s: &str) -> anyhow::Result<Duration> { fn parse_duration(s: &str) -> anyhow::Result<Duration> {
u64::from_str(s).map(Duration::from_millis).map_err(Into::into) u64::from_str(s)
.map(Duration::from_millis)
.map_err(Into::into)
} }
/// The Solidity compatible node implementation. /// The Solidity compatible node implementation.
@@ -206,7 +206,9 @@ where
"Deployed library" "Deployed library"
); );
let library_address = receipt.contract_address.expect("Failed to deploy the library"); let library_address = receipt
.contract_address
.expect("Failed to deploy the library");
deployed_libraries.get_or_insert_default().insert( deployed_libraries.get_or_insert_default().insert(
library_instance.clone(), library_instance.clone(),
@@ -234,8 +236,10 @@ where
}) })
.context("Failed to compile the post-link contracts")?; .context("Failed to compile the post-link contracts")?;
self.execution_state = self.execution_state = ExecutionState::new(
ExecutionState::new(compiler_output.contracts, deployed_libraries.unwrap_or_default()); compiler_output.contracts,
deployed_libraries.unwrap_or_default(),
);
Ok(()) Ok(())
} }
@@ -321,7 +325,11 @@ where
) -> Result<HashMap<ContractInstance, TransactionReceipt>> { ) -> Result<HashMap<ContractInstance, TransactionReceipt>> {
let mut instances_we_must_deploy = IndexMap::<ContractInstance, bool>::new(); let mut instances_we_must_deploy = IndexMap::<ContractInstance, bool>::new();
for instance in step.find_all_contract_instances().into_iter() { for instance in step.find_all_contract_instances().into_iter() {
if !self.execution_state.deployed_contracts.contains_key(&instance) { if !self
.execution_state
.deployed_contracts
.contains_key(&instance)
{
instances_we_must_deploy.entry(instance).or_insert(false); instances_we_must_deploy.entry(instance).or_insert(false);
} }
} }
@@ -333,11 +341,15 @@ where
let mut receipts = HashMap::new(); let mut receipts = HashMap::new();
for (instance, deploy_with_constructor_arguments) in instances_we_must_deploy.into_iter() { for (instance, deploy_with_constructor_arguments) in instances_we_must_deploy.into_iter() {
let calldata = deploy_with_constructor_arguments.then_some(&step.calldata); let calldata = deploy_with_constructor_arguments.then_some(&step.calldata);
let value = deploy_with_constructor_arguments.then_some(step.value).flatten(); let value = deploy_with_constructor_arguments
.then_some(step.value)
.flatten();
let caller = { let caller = {
let context = self.default_resolution_context(); let context = self.default_resolution_context();
step.caller.resolve_address(self.resolver.as_ref(), context).await? step.caller
.resolve_address(self.resolver.as_ref(), context)
.await?
}; };
if let (_, _, Some(receipt)) = self if let (_, _, Some(receipt)) = self
.get_or_deploy_contract_instance(&instance, caller, calldata, value) .get_or_deploy_contract_instance(&instance, caller, calldata, value)
@@ -367,7 +379,7 @@ where
.as_transaction(self.resolver.as_ref(), self.default_resolution_context()) .as_transaction(self.resolver.as_ref(), self.default_resolution_context())
.await?; .await?;
self.execute_transaction(tx).await self.execute_transaction(tx).await
}, }
} }
} }
@@ -412,13 +424,18 @@ where
}; };
// Handling the return data variable assignments. // Handling the return data variable assignments.
for (variable_name, output_word) in assignments for (variable_name, output_word) in assignments.return_data.iter().zip(
.return_data tracing_result
.iter() .output
.zip(tracing_result.output.as_ref().unwrap_or_default().to_vec().chunks(32)) .as_ref()
{ .unwrap_or_default()
.to_vec()
.chunks(32),
) {
let value = U256::from_be_slice(output_word); let value = U256::from_be_slice(output_word);
self.execution_state.variables.insert(variable_name.clone(), value); self.execution_state
.variables
.insert(variable_name.clone(), value);
tracing::info!( tracing::info!(
variable_name, variable_name,
variable_value = hex::encode(value.to_be_bytes::<32>()), variable_value = hex::encode(value.to_be_bytes::<32>()),
@@ -486,7 +503,9 @@ where
// receipt and how this would impact the architecture and the possibility of us not waiting // receipt and how this would impact the architecture and the possibility of us not waiting
// for receipts in the future. // for receipts in the future.
self.watcher_tx self.watcher_tx
.send(WatcherEvent::RepetitionStartEvent { ignore_block_before: 0 }) .send(WatcherEvent::RepetitionStartEvent {
ignore_block_before: 0,
})
.context("Failed to send message on the watcher's tx")?; .context("Failed to send message on the watcher's tx")?;
let res = futures::future::try_join_all(tasks) let res = futures::future::try_join_all(tasks)
@@ -514,7 +533,9 @@ where
let account = private_key.address(); let account = private_key.address();
let variable = U256::from_be_slice(account.0.as_slice()); let variable = U256::from_be_slice(account.0.as_slice());
self.execution_state.variables.insert(variable_name.to_string(), variable); self.execution_state
.variables
.insert(variable_name.to_string(), variable);
Ok(1) Ok(1)
} }
@@ -539,8 +560,10 @@ where
calldata: Option<&Calldata>, calldata: Option<&Calldata>,
value: Option<EtherValue>, value: Option<EtherValue>,
) -> Result<(Address, JsonAbi, Option<TransactionReceipt>)> { ) -> Result<(Address, JsonAbi, Option<TransactionReceipt>)> {
if let Some((_, address, abi)) = if let Some((_, address, abi)) = self
self.execution_state.deployed_contracts.get(contract_instance) .execution_state
.deployed_contracts
.get(contract_instance)
{ {
info!( info!(
@@ -580,10 +603,19 @@ where
calldata: Option<&Calldata>, calldata: Option<&Calldata>,
value: Option<EtherValue>, value: Option<EtherValue>,
) -> Result<(Address, JsonAbi, TransactionReceipt)> { ) -> Result<(Address, JsonAbi, TransactionReceipt)> {
let Some(ContractPathAndIdent { contract_source_path, contract_ident }) = let Some(ContractPathAndIdent {
self.test_definition.metadata.contract_sources()?.remove(contract_instance) contract_source_path,
contract_ident,
}) = self
.test_definition
.metadata
.contract_sources()?
.remove(contract_instance)
else { else {
anyhow::bail!("Contract source not found for instance {:?}", contract_instance) anyhow::bail!(
"Contract source not found for instance {:?}",
contract_instance
)
}; };
let Some((code, abi)) = self let Some((code, abi)) = self
@@ -593,7 +625,10 @@ where
.and_then(|source_file_contracts| source_file_contracts.get(contract_ident.as_ref())) .and_then(|source_file_contracts| source_file_contracts.get(contract_ident.as_ref()))
.cloned() .cloned()
else { else {
anyhow::bail!("Failed to find information for contract {:?}", contract_instance) anyhow::bail!(
"Failed to find information for contract {:?}",
contract_instance
)
}; };
let mut code = match alloy::hex::decode(&code) { let mut code = match alloy::hex::decode(&code) {
@@ -606,7 +641,7 @@ where
"Failed to hex-decode byte code - This could possibly mean that the bytecode requires linking" "Failed to hex-decode byte code - This could possibly mean that the bytecode requires linking"
); );
anyhow::bail!("Failed to hex-decode the byte code {}", error) anyhow::bail!("Failed to hex-decode the byte code {}", error)
}, }
}; };
if let Some(calldata) = calldata { if let Some(calldata) = calldata {
@@ -630,7 +665,7 @@ where
Err(error) => { Err(error) => {
tracing::error!(?error, "Contract deployment transaction failed."); tracing::error!(?error, "Contract deployment transaction failed.");
return Err(error); return Err(error);
}, }
}; };
let Some(address) = receipt.contract_address else { let Some(address) = receipt.contract_address else {
@@ -645,9 +680,10 @@ where
.reporter .reporter
.report_contract_deployed_event(contract_instance.clone(), address)?; .report_contract_deployed_event(contract_instance.clone(), address)?;
self.execution_state self.execution_state.deployed_contracts.insert(
.deployed_contracts contract_instance.clone(),
.insert(contract_instance.clone(), (contract_ident, address, abi.clone())); (contract_ident, address, abi.clone()),
);
Ok((address, abi, receipt)) Ok((address, abi, receipt))
} }
@@ -660,7 +696,9 @@ where
match step_address { match step_address {
StepAddress::Address(address) => Ok(*address), StepAddress::Address(address) => Ok(*address),
StepAddress::ResolvableAddress(resolvable) => { StepAddress::ResolvableAddress(resolvable) => {
let Some(instance) = resolvable.strip_suffix(".address").map(ContractInstance::new) let Some(instance) = resolvable
.strip_suffix(".address")
.map(ContractInstance::new)
else { else {
bail!("Not an address variable"); bail!("Not an address variable");
}; };
@@ -673,7 +711,7 @@ where
) )
.await .await
.map(|v| v.0) .map(|v| v.0)
}, }
} }
} }
// endregion:Contract Deployment // endregion:Contract Deployment
@@ -719,7 +757,7 @@ where
Ok(receipt) => { Ok(receipt) => {
info!("Polling succeeded, receipt found"); info!("Polling succeeded, receipt found");
Ok(ControlFlow::Break(receipt)) Ok(ControlFlow::Break(receipt))
}, }
Err(_) => Ok(ControlFlow::Continue(())), Err(_) => Ok(ControlFlow::Continue(())),
} }
} }
@@ -96,8 +96,13 @@ pub async fn handle_differential_benchmarks(
// Creating the objects that will be shared between the various runs. The cached compiler is the // Creating the objects that will be shared between the various runs. The cached compiler is the
// only one at the current moment of time that's safe to share between runs. // only one at the current moment of time that's safe to share between runs.
let cached_compiler = CachedCompiler::new( let cached_compiler = CachedCompiler::new(
context.working_directory.as_path().join("compilation_cache"), context
context.compilation_configuration.invalidate_compilation_cache, .working_directory
.as_path()
.join("compilation_cache"),
context
.compilation_configuration
.invalidate_compilation_cache,
) )
.await .await
.map(Arc::new) .map(Arc::new)
@@ -156,7 +161,9 @@ pub async fn handle_differential_benchmarks(
watcher.run(), watcher.run(),
driver.execute_all().inspect(|_| { driver.execute_all().inspect(|_| {
info!("All transactions submitted - driver completed execution"); info!("All transactions submitted - driver completed execution");
watcher_tx.send(WatcherEvent::AllTransactionsSubmitted).unwrap() watcher_tx
.send(WatcherEvent::AllTransactionsSubmitted)
.unwrap()
}), }),
) )
.await .await
@@ -27,7 +27,11 @@ impl ExecutionState {
compiled_contracts: HashMap<PathBuf, HashMap<String, (String, JsonAbi)>>, compiled_contracts: HashMap<PathBuf, HashMap<String, (String, JsonAbi)>>,
deployed_contracts: HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>, deployed_contracts: HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>,
) -> Self { ) -> Self {
Self { compiled_contracts, deployed_contracts, variables: Default::default() } Self {
compiled_contracts,
deployed_contracts,
variables: Default::default(),
}
} }
pub fn empty() -> Self { pub fn empty() -> Self {
@@ -33,7 +33,14 @@ impl Watcher {
blocks_stream: Pin<Box<dyn Stream<Item = MinedBlockInformation>>>, blocks_stream: Pin<Box<dyn Stream<Item = MinedBlockInformation>>>,
) -> (Self, UnboundedSender<WatcherEvent>) { ) -> (Self, UnboundedSender<WatcherEvent>) {
let (tx, rx) = unbounded_channel::<WatcherEvent>(); let (tx, rx) = unbounded_channel::<WatcherEvent>();
(Self { platform_identifier, rx, blocks_stream }, tx) (
Self {
platform_identifier,
rx,
blocks_stream,
},
tx,
)
} }
#[instrument(level = "info", skip_all)] #[instrument(level = "info", skip_all)]
@@ -42,8 +49,9 @@ impl Watcher {
// the watcher of the last block number that it should ignore and what the block number is // the watcher of the last block number that it should ignore and what the block number is
// for the first important block that it should look for. // for the first important block that it should look for.
let ignore_block_before = loop { let ignore_block_before = loop {
let Some(WatcherEvent::RepetitionStartEvent { ignore_block_before }) = let Some(WatcherEvent::RepetitionStartEvent {
self.rx.recv().await ignore_block_before,
}) = self.rx.recv().await
else { else {
continue; continue;
}; };
@@ -72,16 +80,19 @@ impl Watcher {
// Subsequent repetition starts are ignored since certain workloads can // Subsequent repetition starts are ignored since certain workloads can
// contain nested repetitions and therefore there's no use in doing any // contain nested repetitions and therefore there's no use in doing any
// action if the repetitions are nested. // action if the repetitions are nested.
WatcherEvent::RepetitionStartEvent { .. } => {}, WatcherEvent::RepetitionStartEvent { .. } => {}
WatcherEvent::SubmittedTransaction { transaction_hash } => { WatcherEvent::SubmittedTransaction { transaction_hash } => {
watch_for_transaction_hashes.write().await.insert(transaction_hash); watch_for_transaction_hashes
}, .write()
.await
.insert(transaction_hash);
}
WatcherEvent::AllTransactionsSubmitted => { WatcherEvent::AllTransactionsSubmitted => {
*all_transactions_submitted.write().await = true; *all_transactions_submitted.write().await = true;
self.rx.close(); self.rx.close();
info!("Watcher's Events Watching Task Finished"); info!("Watcher's Events Watching Task Finished");
break; break;
}, }
} }
} }
} }
@@ -100,8 +111,8 @@ impl Watcher {
continue; continue;
} }
if *all_transactions_submitted.read().await && if *all_transactions_submitted.read().await
watch_for_transaction_hashes.read().await.is_empty() && watch_for_transaction_hashes.read().await.is_empty()
{ {
break; break;
} }
@@ -140,8 +151,15 @@ impl Watcher {
use std::io::Write; use std::io::Write;
let mut stderr = std::io::stderr().lock(); let mut stderr = std::io::stderr().lock();
writeln!(stderr, "Watcher information for {}", self.platform_identifier)?; writeln!(
writeln!(stderr, "block_number,block_timestamp,mined_gas,block_gas_limit,tx_count")?; stderr,
"Watcher information for {}",
self.platform_identifier
)?;
writeln!(
stderr,
"block_number,block_timestamp,mined_gas,block_gas_limit,tx_count"
)?;
for block in mined_blocks_information { for block in mined_blocks_information {
writeln!( writeln!(
stderr, stderr,
+105 -43
View File
@@ -112,7 +112,9 @@ impl<'a> Driver<'a, StepsIterator> {
pub async fn execute_all(mut self) -> Result<usize> { pub async fn execute_all(mut self) -> Result<usize> {
let platform_drivers = std::mem::take(&mut self.platform_drivers); let platform_drivers = std::mem::take(&mut self.platform_drivers);
let results = futures::future::try_join_all( let results = futures::future::try_join_all(
platform_drivers.into_values().map(|driver| driver.execute_all()), platform_drivers
.into_values()
.map(|driver| driver.execute_all()),
) )
.await .await
.context("Failed to execute all of the steps on the driver")?; .context("Failed to execute all of the steps on the driver")?;
@@ -250,8 +252,11 @@ where
TransactionRequest::default().from(deployer_address), TransactionRequest::default().from(deployer_address),
code, code,
); );
let receipt = let receipt = platform_information
platform_information.node.execute_transaction(tx).await.inspect_err(|err| { .node
.execute_transaction(tx)
.await
.inspect_err(|err| {
error!( error!(
?err, ?err,
%library_instance, %library_instance,
@@ -260,7 +265,9 @@ where
) )
})?; })?;
let library_address = receipt.contract_address.expect("Failed to deploy the library"); let library_address = receipt
.contract_address
.expect("Failed to deploy the library");
deployed_libraries.get_or_insert_default().insert( deployed_libraries.get_or_insert_default().insert(
library_instance.clone(), library_instance.clone(),
@@ -288,7 +295,10 @@ where
}) })
.context("Failed to compile the post-link contracts")?; .context("Failed to compile the post-link contracts")?;
Ok(ExecutionState::new(compiler_output.contracts, deployed_libraries.unwrap_or_default())) Ok(ExecutionState::new(
compiler_output.contracts,
deployed_libraries.unwrap_or_default(),
))
} }
// endregion:Constructors & Initialization // endregion:Constructors & Initialization
@@ -382,7 +392,11 @@ where
) -> Result<HashMap<ContractInstance, TransactionReceipt>> { ) -> Result<HashMap<ContractInstance, TransactionReceipt>> {
let mut instances_we_must_deploy = IndexMap::<ContractInstance, bool>::new(); let mut instances_we_must_deploy = IndexMap::<ContractInstance, bool>::new();
for instance in step.find_all_contract_instances().into_iter() { for instance in step.find_all_contract_instances().into_iter() {
if !self.execution_state.deployed_contracts.contains_key(&instance) { if !self
.execution_state
.deployed_contracts
.contains_key(&instance)
{
instances_we_must_deploy.entry(instance).or_insert(false); instances_we_must_deploy.entry(instance).or_insert(false);
} }
} }
@@ -394,13 +408,20 @@ where
let mut receipts = HashMap::new(); let mut receipts = HashMap::new();
for (instance, deploy_with_constructor_arguments) in instances_we_must_deploy.into_iter() { for (instance, deploy_with_constructor_arguments) in instances_we_must_deploy.into_iter() {
let calldata = deploy_with_constructor_arguments.then_some(&step.calldata); let calldata = deploy_with_constructor_arguments.then_some(&step.calldata);
let value = deploy_with_constructor_arguments.then_some(step.value).flatten(); let value = deploy_with_constructor_arguments
.then_some(step.value)
.flatten();
let caller = { let caller = {
let context = self.default_resolution_context(); let context = self.default_resolution_context();
let resolver = self.platform_information.node.resolver().await?; let resolver = self.platform_information.node.resolver().await?;
let resolved = step.caller.resolve_address(resolver.as_ref(), context).await?; let resolved = step
self.platform_information.node.resolve_signer_or_default(resolved) .caller
.resolve_address(resolver.as_ref(), context)
.await?;
self.platform_information
.node
.resolve_signer_or_default(resolved)
}; };
if let (_, _, Some(receipt)) = self if let (_, _, Some(receipt)) = self
.get_or_deploy_contract_instance(&instance, caller, calldata, value) .get_or_deploy_contract_instance(&instance, caller, calldata, value)
@@ -435,16 +456,20 @@ where
Ok(tx) => tx, Ok(tx) => tx,
Err(err) => { Err(err) => {
return Err(err); return Err(err);
}, }
}; };
// Resolve the signer to ensure we use an address that has keys // Resolve the signer to ensure we use an address that has keys
if let Some(from) = tx.from { if let Some(from) = tx.from {
tx.from = Some(self.platform_information.node.resolve_signer_or_default(from)); tx.from = Some(
self.platform_information
.node
.resolve_signer_or_default(from),
);
} }
self.platform_information.node.execute_transaction(tx).await self.platform_information.node.execute_transaction(tx).await
}, }
} }
} }
@@ -491,13 +516,18 @@ where
}; };
// Handling the return data variable assignments. // Handling the return data variable assignments.
for (variable_name, output_word) in assignments for (variable_name, output_word) in assignments.return_data.iter().zip(
.return_data tracing_result
.iter() .output
.zip(tracing_result.output.as_ref().unwrap_or_default().to_vec().chunks(32)) .as_ref()
{ .unwrap_or_default()
.to_vec()
.chunks(32),
) {
let value = U256::from_be_slice(output_word); let value = U256::from_be_slice(output_word);
self.execution_state.variables.insert(variable_name.clone(), value); self.execution_state
.variables
.insert(variable_name.clone(), value);
tracing::info!( tracing::info!(
variable_name, variable_name,
variable_value = hex::encode(value.to_be_bytes::<32>()), variable_value = hex::encode(value.to_be_bytes::<32>()),
@@ -517,12 +547,18 @@ where
) -> Result<()> { ) -> Result<()> {
// Resolving the `step.expected` into a series of expectations that we can then assert on. // Resolving the `step.expected` into a series of expectations that we can then assert on.
let mut expectations = match step { let mut expectations = match step {
FunctionCallStep { expected: Some(Expected::Calldata(calldata)), .. } => FunctionCallStep {
vec![ExpectedOutput::new().with_calldata(calldata.clone())], expected: Some(Expected::Calldata(calldata)),
FunctionCallStep { expected: Some(Expected::Expected(expected)), .. } => ..
vec![expected.clone()], } => vec![ExpectedOutput::new().with_calldata(calldata.clone())],
FunctionCallStep { expected: Some(Expected::ExpectedMany(expected)), .. } => FunctionCallStep {
expected.clone(), expected: Some(Expected::Expected(expected)),
..
} => vec![expected.clone()],
FunctionCallStep {
expected: Some(Expected::ExpectedMany(expected)),
..
} => expected.clone(),
FunctionCallStep { expected: None, .. } => vec![ExpectedOutput::new().with_success()], FunctionCallStep { expected: None, .. } => vec![ExpectedOutput::new().with_success()],
}; };
@@ -641,8 +677,11 @@ where
} }
// Handling the topics assertion. // Handling the topics assertion.
for (expected, actual) in for (expected, actual) in expected_event
expected_event.topics.as_slice().iter().zip(actual_event.topics()) .topics
.as_slice()
.iter()
.zip(actual_event.topics())
{ {
let expected = Calldata::new_compound([expected]); let expected = Calldata::new_compound([expected]);
if !expected if !expected
@@ -812,7 +851,9 @@ where
let account = private_key.address(); let account = private_key.address();
let variable = U256::from_be_slice(account.0.as_slice()); let variable = U256::from_be_slice(account.0.as_slice());
self.execution_state.variables.insert(variable_name.to_string(), variable); self.execution_state
.variables
.insert(variable_name.to_string(), variable);
Ok(1) Ok(1)
} }
@@ -835,8 +876,10 @@ where
calldata: Option<&Calldata>, calldata: Option<&Calldata>,
value: Option<EtherValue>, value: Option<EtherValue>,
) -> Result<(Address, JsonAbi, Option<TransactionReceipt>)> { ) -> Result<(Address, JsonAbi, Option<TransactionReceipt>)> {
if let Some((_, address, abi)) = if let Some((_, address, abi)) = self
self.execution_state.deployed_contracts.get(contract_instance) .execution_state
.deployed_contracts
.get(contract_instance)
{ {
info!( info!(
@@ -874,10 +917,19 @@ where
calldata: Option<&Calldata>, calldata: Option<&Calldata>,
value: Option<EtherValue>, value: Option<EtherValue>,
) -> Result<(Address, JsonAbi, TransactionReceipt)> { ) -> Result<(Address, JsonAbi, TransactionReceipt)> {
let Some(ContractPathAndIdent { contract_source_path, contract_ident }) = let Some(ContractPathAndIdent {
self.test_definition.metadata.contract_sources()?.remove(contract_instance) contract_source_path,
contract_ident,
}) = self
.test_definition
.metadata
.contract_sources()?
.remove(contract_instance)
else { else {
anyhow::bail!("Contract source not found for instance {:?}", contract_instance) anyhow::bail!(
"Contract source not found for instance {:?}",
contract_instance
)
}; };
let Some((code, abi)) = self let Some((code, abi)) = self
@@ -887,7 +939,10 @@ where
.and_then(|source_file_contracts| source_file_contracts.get(contract_ident.as_ref())) .and_then(|source_file_contracts| source_file_contracts.get(contract_ident.as_ref()))
.cloned() .cloned()
else { else {
anyhow::bail!("Failed to find information for contract {:?}", contract_instance) anyhow::bail!(
"Failed to find information for contract {:?}",
contract_instance
)
}; };
let mut code = match alloy::hex::decode(&code) { let mut code = match alloy::hex::decode(&code) {
@@ -900,18 +955,22 @@ where
"Failed to hex-decode byte code - This could possibly mean that the bytecode requires linking" "Failed to hex-decode byte code - This could possibly mean that the bytecode requires linking"
); );
anyhow::bail!("Failed to hex-decode the byte code {}", error) anyhow::bail!("Failed to hex-decode the byte code {}", error)
}, }
}; };
if let Some(calldata) = calldata { if let Some(calldata) = calldata {
let resolver = self.platform_information.node.resolver().await?; let resolver = self.platform_information.node.resolver().await?;
let calldata = let calldata = calldata
calldata.calldata(resolver.as_ref(), self.default_resolution_context()).await?; .calldata(resolver.as_ref(), self.default_resolution_context())
.await?;
code.extend(calldata); code.extend(calldata);
} }
let tx = { let tx = {
let deployer = self.platform_information.node.resolve_signer_or_default(deployer); let deployer = self
.platform_information
.node
.resolve_signer_or_default(deployer);
let tx = TransactionRequest::default().from(deployer); let tx = TransactionRequest::default().from(deployer);
let tx = match value { let tx = match value {
Some(ref value) => tx.value(value.into_inner()), Some(ref value) => tx.value(value.into_inner()),
@@ -925,7 +984,7 @@ where
Err(error) => { Err(error) => {
tracing::error!(?error, "Contract deployment transaction failed."); tracing::error!(?error, "Contract deployment transaction failed.");
return Err(error); return Err(error);
}, }
}; };
let Some(address) = receipt.contract_address else { let Some(address) = receipt.contract_address else {
@@ -940,9 +999,10 @@ where
.reporter .reporter
.report_contract_deployed_event(contract_instance.clone(), address)?; .report_contract_deployed_event(contract_instance.clone(), address)?;
self.execution_state self.execution_state.deployed_contracts.insert(
.deployed_contracts contract_instance.clone(),
.insert(contract_instance.clone(), (contract_ident, address, abi.clone())); (contract_ident, address, abi.clone()),
);
Ok((address, abi, receipt)) Ok((address, abi, receipt))
} }
@@ -955,7 +1015,9 @@ where
match step_address { match step_address {
StepAddress::Address(address) => Ok(*address), StepAddress::Address(address) => Ok(*address),
StepAddress::ResolvableAddress(resolvable) => { StepAddress::ResolvableAddress(resolvable) => {
let Some(instance) = resolvable.strip_suffix(".address").map(ContractInstance::new) let Some(instance) = resolvable
.strip_suffix(".address")
.map(ContractInstance::new)
else { else {
bail!("Not an address variable"); bail!("Not an address variable");
}; };
@@ -968,7 +1030,7 @@ where
) )
.await .await
.map(|v| v.0) .map(|v| v.0)
}, }
} }
} }
// endregion:Contract Deployment // endregion:Contract Deployment
@@ -85,8 +85,13 @@ pub async fn handle_differential_tests(
// Creating everything else required for the driver to run. // Creating everything else required for the driver to run.
let cached_compiler = CachedCompiler::new( let cached_compiler = CachedCompiler::new(
context.working_directory.as_path().join("compilation_cache"), context
context.compilation_configuration.invalidate_compilation_cache, .working_directory
.as_path()
.join("compilation_cache"),
context
.compilation_configuration
.invalidate_compilation_cache,
) )
.await .await
.map(Arc::new) .map(Arc::new)
@@ -141,7 +146,7 @@ pub async fn handle_differential_tests(
drop(permit); drop(permit);
running_task_list.write().await.remove(&test_id); running_task_list.write().await.remove(&test_id);
return; return;
}, }
}; };
info!("Created the driver for the test case"); info!("Created the driver for the test case");
@@ -156,7 +161,7 @@ pub async fn handle_differential_tests(
.report_test_failed_event(format!("{error:#}")) .report_test_failed_event(format!("{error:#}"))
.expect("Can't fail"); .expect("Can't fail");
error!("Test Case Failed"); error!("Test Case Failed");
}, }
}; };
info!("Finished the execution of the test case"); info!("Finished the execution of the test case");
drop(permit); drop(permit);
@@ -167,14 +172,20 @@ pub async fn handle_differential_tests(
)) ))
.inspect(|_| { .inspect(|_| {
info!("Finished executing all test cases"); info!("Finished executing all test cases");
reporter_clone.report_completion_event().expect("Can't fail") reporter_clone
.report_completion_event()
.expect("Can't fail")
}); });
let cli_reporting_task = start_cli_reporting_task(reporter); let cli_reporting_task = start_cli_reporting_task(reporter);
tokio::task::spawn(async move { tokio::task::spawn(async move {
loop { loop {
let remaining_tasks = running_task_list.read().await; let remaining_tasks = running_task_list.read().await;
info!(count = remaining_tasks.len(), ?remaining_tasks, "Remaining Tests"); info!(
count = remaining_tasks.len(),
?remaining_tasks,
"Remaining Tests"
);
tokio::time::sleep(Duration::from_secs(10)).await tokio::time::sleep(Duration::from_secs(10)).await
} }
}); });
@@ -223,7 +234,7 @@ async fn start_cli_reporting_task(reporter: Reporter) {
"{}{}Case Succeeded{} - Steps Executed: {}{}", "{}{}Case Succeeded{} - Steps Executed: {}{}",
GREEN, BOLD, BOLD_RESET, steps_executed, COLOR_RESET GREEN, BOLD, BOLD_RESET, steps_executed, COLOR_RESET
) )
}, }
TestCaseStatus::Failed { reason } => { TestCaseStatus::Failed { reason } => {
number_of_failures += 1; number_of_failures += 1;
writeln!( writeln!(
@@ -235,7 +246,7 @@ async fn start_cli_reporting_task(reporter: Reporter) {
reason.trim(), reason.trim(),
COLOR_RESET, COLOR_RESET,
) )
}, }
TestCaseStatus::Ignored { reason, .. } => writeln!( TestCaseStatus::Ignored { reason, .. } => writeln!(
buf, buf,
"{}{}Case Ignored{} - Reason: {}{}", "{}{}Case Ignored{} - Reason: {}{}",
@@ -27,6 +27,10 @@ impl ExecutionState {
compiled_contracts: HashMap<PathBuf, HashMap<String, (String, JsonAbi)>>, compiled_contracts: HashMap<PathBuf, HashMap<String, (String, JsonAbi)>>,
deployed_contracts: HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>, deployed_contracts: HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>,
) -> Self { ) -> Self {
Self { compiled_contracts, deployed_contracts, variables: Default::default() } Self {
compiled_contracts,
deployed_contracts,
variables: Default::default(),
}
} }
} }
+28 -17
View File
@@ -41,7 +41,10 @@ impl<'a> CachedCompiler<'a> {
.await .await
.context("Failed to invalidate compilation cache directory")?; .context("Failed to invalidate compilation cache directory")?;
} }
Ok(Self { artifacts_cache: cache, cache_key_lock: Default::default() }) Ok(Self {
artifacts_cache: cache,
cache_key_lock: Default::default(),
})
} }
/// Compiles or gets the compilation artifacts from the cache. /// Compiles or gets the compilation artifacts from the cache.
@@ -109,7 +112,7 @@ impl<'a> CachedCompiler<'a> {
.await .await
.context("Compilation callback for deployed libraries failed")? .context("Compilation callback for deployed libraries failed")?
.compiler_output .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.
None => { None => {
@@ -123,7 +126,7 @@ impl<'a> CachedCompiler<'a> {
Some(value) => { Some(value) => {
drop(read_guard); drop(read_guard);
value value
}, }
None => { None => {
drop(read_guard); drop(read_guard);
self.cache_key_lock self.cache_key_lock
@@ -132,7 +135,7 @@ impl<'a> CachedCompiler<'a> {
.entry(cache_key.clone()) .entry(cache_key.clone())
.or_default() .or_default()
.clone() .clone()
}, }
}; };
let _guard = mutex.lock().await; let _guard = mutex.lock().await;
@@ -160,7 +163,7 @@ impl<'a> CachedCompiler<'a> {
.expect("Can't happen"); .expect("Can't happen");
} }
cache_value.compiler_output cache_value.compiler_output
}, }
None => { None => {
let compiler_output = compilation_callback() let compiler_output = compilation_callback()
.await .await
@@ -169,16 +172,18 @@ impl<'a> CachedCompiler<'a> {
self.artifacts_cache self.artifacts_cache
.insert( .insert(
&cache_key, &cache_key,
&CacheValue { compiler_output: compiler_output.clone() }, &CacheValue {
compiler_output: compiler_output.clone(),
},
) )
.await .await
.context( .context(
"Failed to write the cached value of the compilation artifacts", "Failed to write the cached value of the compilation artifacts",
)?; )?;
compiler_output compiler_output
},
} }
}, }
}
}; };
Ok(compiled_contracts) Ok(compiled_contracts)
@@ -220,7 +225,9 @@ async fn compile_contracts(
.flat_map(|value| value.iter()) .flat_map(|value| value.iter())
.map(|(instance, (ident, address, abi))| (instance, ident, address, abi)) .map(|(instance, (ident, address, abi))| (instance, ident, address, abi))
.flat_map(|(_, ident, address, _)| { .flat_map(|(_, ident, address, _)| {
all_sources_in_dir.iter().map(move |path| (ident, address, path)) all_sources_in_dir
.iter()
.map(move |path| (ident, address, path))
}) })
.fold(compiler, |compiler, (ident, address, path)| { .fold(compiler, |compiler, (ident, address, path)| {
compiler.with_library(path, ident.as_str(), *address) compiler.with_library(path, ident.as_str(), *address)
@@ -241,7 +248,7 @@ async fn compile_contracts(
output.clone(), output.clone(),
) )
.expect("Can't happen"); .expect("Can't happen");
}, }
(Ok(output), false) => { (Ok(output), false) => {
reporter reporter
.report_pre_link_contracts_compilation_succeeded_event( .report_pre_link_contracts_compilation_succeeded_event(
@@ -252,7 +259,7 @@ async fn compile_contracts(
output.clone(), output.clone(),
) )
.expect("Can't happen"); .expect("Can't happen");
}, }
(Err(err), true) => { (Err(err), true) => {
reporter reporter
.report_post_link_contracts_compilation_failed_event( .report_post_link_contracts_compilation_failed_event(
@@ -262,7 +269,7 @@ async fn compile_contracts(
format!("{err:#}"), format!("{err:#}"),
) )
.expect("Can't happen"); .expect("Can't happen");
}, }
(Err(err), false) => { (Err(err), false) => {
reporter reporter
.report_pre_link_contracts_compilation_failed_event( .report_pre_link_contracts_compilation_failed_event(
@@ -272,7 +279,7 @@ async fn compile_contracts(
format!("{err:#}"), format!("{err:#}"),
) )
.expect("Can't happen"); .expect("Can't happen");
}, }
} }
output output
@@ -284,7 +291,9 @@ struct ArtifactsCache {
impl ArtifactsCache { impl ArtifactsCache {
pub fn new(path: impl AsRef<Path>) -> Self { pub fn new(path: impl AsRef<Path>) -> Self {
Self { path: path.as_ref().to_path_buf() } Self {
path: path.as_ref().to_path_buf(),
}
} }
#[instrument(level = "debug", skip_all, err)] #[instrument(level = "debug", skip_all, err)]
@@ -310,7 +319,9 @@ impl ArtifactsCache {
pub async fn get(&self, key: &CacheKey<'_>) -> Option<CacheValue> { pub async fn get(&self, key: &CacheKey<'_>) -> Option<CacheValue> {
let key = bson::to_vec(key).ok()?; let key = bson::to_vec(key).ok()?;
let value = cacache::read(self.path.as_path(), key.encode_hex()).await.ok()?; let value = cacache::read(self.path.as_path(), key.encode_hex())
.await
.ok()?;
let value = bson::from_slice::<CacheValue>(&value).ok()?; let value = bson::from_slice::<CacheValue>(&value).ok()?;
Some(value) Some(value)
} }
@@ -325,13 +336,13 @@ impl ArtifactsCache {
Some(value) => { Some(value) => {
debug!("Cache hit"); debug!("Cache hit");
Ok(value) Ok(value)
}, }
None => { None => {
debug!("Cache miss"); debug!("Cache miss");
let value = callback().await?; let value = callback().await?;
self.insert(key, &value).await?; self.insert(key, &value).await?;
Ok(value) Ok(value)
}, }
} }
} }
} }
+8 -3
View File
@@ -37,13 +37,18 @@ impl NodePool {
); );
} }
let pre_transactions_tasks = let pre_transactions_tasks = nodes
nodes.iter_mut().map(|node| node.pre_transactions()).collect::<Vec<_>>(); .iter_mut()
.map(|node| node.pre_transactions())
.collect::<Vec<_>>();
futures::future::try_join_all(pre_transactions_tasks) futures::future::try_join_all(pre_transactions_tasks)
.await .await
.context("Failed to run the pre-transactions task")?; .context("Failed to run the pre-transactions task")?;
Ok(Self { nodes, next: Default::default() }) Ok(Self {
nodes,
next: Default::default(),
})
} }
/// Get a handle to the next node. /// Get a handle to the next node.
+21 -8
View File
@@ -66,12 +66,15 @@ pub async fn create_test_definitions_stream<'a>(
// Inform the reporter of each one of the test cases that were discovered which we // Inform the reporter of each one of the test cases that were discovered which we
// expect to run. // expect to run.
.inspect(|(_, _, _, _, reporter)| { .inspect(|(_, _, _, _, reporter)| {
reporter.report_test_case_discovery_event().expect("Can't fail"); reporter
.report_test_case_discovery_event()
.expect("Can't fail");
}), }),
) )
// Creating the Test Definition objects from all of the various objects we have and creating // Creating the Test Definition objects from all of the various objects we have and creating
// their required dependencies (e.g., compiler). // their required dependencies (e.g., compiler).
.filter_map(move |(metadata_file, case_idx, case, mode, reporter)| async move { .filter_map(
move |(metadata_file, case_idx, case, mode, reporter)| async move {
let mut platforms = BTreeMap::new(); let mut platforms = BTreeMap::new();
for (platform, node_pool) in platforms_and_nodes.values() { for (platform, node_pool) in platforms_and_nodes.values() {
let node = node_pool.round_robbin(); let node = node_pool.round_robbin();
@@ -100,7 +103,12 @@ pub async fn create_test_definitions_stream<'a>(
platforms.insert( platforms.insert(
platform.platform_identifier(), platform.platform_identifier(),
TestPlatformInformation { platform: *platform, node, compiler, reporter }, TestPlatformInformation {
platform: *platform,
node,
compiler,
reporter,
},
); );
} }
@@ -122,7 +130,8 @@ pub async fn create_test_definitions_stream<'a>(
/* Reporter */ /* Reporter */
reporter, reporter,
}) })
}) },
)
// Filter out the test cases which are incompatible or that can't run in the current setup. // Filter out the test cases which are incompatible or that can't run in the current setup.
.filter_map(move |test| async move { .filter_map(move |test| async move {
match test.check_compatibility() { match test.check_compatibility() {
@@ -147,7 +156,7 @@ pub async fn create_test_definitions_stream<'a>(
) )
.expect("Can't fail"); .expect("Can't fail");
None None
}, }
} }
}) })
.inspect(|test| { .inspect(|test| {
@@ -221,8 +230,9 @@ impl<'a> TestDefinition<'a> {
for (_, platform_information) in self.platforms.iter() { for (_, platform_information) in self.platforms.iter() {
let is_allowed_for_platform = match self.metadata.targets.as_ref() { let is_allowed_for_platform = match self.metadata.targets.as_ref() {
None => true, None => true,
Some(required_vm_identifiers) => Some(required_vm_identifiers) => {
required_vm_identifiers.contains(&platform_information.platform.vm_identifier()), required_vm_identifiers.contains(&platform_information.platform.vm_identifier())
}
}; };
is_allowed &= is_allowed_for_platform; is_allowed &= is_allowed_for_platform;
error_map.insert( error_map.insert(
@@ -264,7 +274,10 @@ impl<'a> TestDefinition<'a> {
if is_allowed { if is_allowed {
Ok(()) Ok(())
} else { } else {
Err(("EVM version is incompatible for the platforms specified", error_map)) Err((
"EVM version is incompatible for the platforms specified",
error_map,
))
} }
} }
+71 -38
View File
@@ -37,7 +37,11 @@ pub trait Platform {
/// Returns a full identifier for the platform. /// Returns a full identifier for the platform.
fn full_identifier(&self) -> (NodeIdentifier, VmIdentifier, CompilerIdentifier) { fn full_identifier(&self) -> (NodeIdentifier, VmIdentifier, CompilerIdentifier) {
(self.node_identifier(), self.vm_identifier(), self.compiler_identifier()) (
self.node_identifier(),
self.vm_identifier(),
self.compiler_identifier(),
)
} }
/// Returns the identifier of the node used. /// Returns the identifier of the node used.
@@ -179,7 +183,9 @@ impl Platform for KitchensinkPolkavmResolcPlatform {
context: Context, context: Context,
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> { ) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> {
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context); let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
let kitchensink_path = AsRef::<KitchensinkConfiguration>::as_ref(&context).path.clone(); let kitchensink_path = AsRef::<KitchensinkConfiguration>::as_ref(&context)
.path
.clone();
let genesis = genesis_configuration.genesis()?.clone(); let genesis = genesis_configuration.genesis()?.clone();
Ok(thread::spawn(move || { Ok(thread::spawn(move || {
let node = SubstrateNode::new( let node = SubstrateNode::new(
@@ -229,7 +235,9 @@ impl Platform for KitchensinkRevmSolcPlatform {
context: Context, context: Context,
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> { ) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> {
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context); let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
let kitchensink_path = AsRef::<KitchensinkConfiguration>::as_ref(&context).path.clone(); let kitchensink_path = AsRef::<KitchensinkConfiguration>::as_ref(&context)
.path
.clone();
let genesis = genesis_configuration.genesis()?.clone(); let genesis = genesis_configuration.genesis()?.clone();
Ok(thread::spawn(move || { Ok(thread::spawn(move || {
let node = SubstrateNode::new( let node = SubstrateNode::new(
@@ -279,8 +287,9 @@ impl Platform for ReviveDevNodePolkavmResolcPlatform {
context: Context, context: Context,
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> { ) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> {
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context); let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
let revive_dev_node_path = let revive_dev_node_path = AsRef::<ReviveDevNodeConfiguration>::as_ref(&context)
AsRef::<ReviveDevNodeConfiguration>::as_ref(&context).path.clone(); .path
.clone();
let genesis = genesis_configuration.genesis()?.clone(); let genesis = genesis_configuration.genesis()?.clone();
Ok(thread::spawn(move || { Ok(thread::spawn(move || {
let node = SubstrateNode::new( let node = SubstrateNode::new(
@@ -330,8 +339,9 @@ impl Platform for ReviveDevNodeRevmSolcPlatform {
context: Context, context: Context,
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> { ) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> {
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context); let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
let revive_dev_node_path = let revive_dev_node_path = AsRef::<ReviveDevNodeConfiguration>::as_ref(&context)
AsRef::<ReviveDevNodeConfiguration>::as_ref(&context).path.clone(); .path
.clone();
let genesis = genesis_configuration.genesis()?.clone(); let genesis = genesis_configuration.genesis()?.clone();
Ok(thread::spawn(move || { Ok(thread::spawn(move || {
let node = SubstrateNode::new( let node = SubstrateNode::new(
@@ -381,8 +391,9 @@ impl Platform for ZombienetPolkavmResolcPlatform {
context: Context, context: Context,
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> { ) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> {
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context); let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
let polkadot_parachain_path = let polkadot_parachain_path = AsRef::<PolkadotParachainConfiguration>::as_ref(&context)
AsRef::<PolkadotParachainConfiguration>::as_ref(&context).path.clone(); .path
.clone();
let genesis = genesis_configuration.genesis()?.clone(); let genesis = genesis_configuration.genesis()?.clone();
Ok(thread::spawn(move || { Ok(thread::spawn(move || {
let node = ZombieNode::new(polkadot_parachain_path, context); let node = ZombieNode::new(polkadot_parachain_path, context);
@@ -428,8 +439,9 @@ impl Platform for ZombienetRevmSolcPlatform {
context: Context, context: Context,
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> { ) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> {
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context); let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
let polkadot_parachain_path = let polkadot_parachain_path = AsRef::<PolkadotParachainConfiguration>::as_ref(&context)
AsRef::<PolkadotParachainConfiguration>::as_ref(&context).path.clone(); .path
.clone();
let genesis = genesis_configuration.genesis()?.clone(); let genesis = genesis_configuration.genesis()?.clone();
Ok(thread::spawn(move || { Ok(thread::spawn(move || {
let node = ZombieNode::new(polkadot_parachain_path, context); let node = ZombieNode::new(polkadot_parachain_path, context);
@@ -454,18 +466,24 @@ impl From<PlatformIdentifier> for Box<dyn Platform> {
fn from(value: PlatformIdentifier) -> Self { fn from(value: PlatformIdentifier) -> Self {
match value { match value {
PlatformIdentifier::GethEvmSolc => Box::new(GethEvmSolcPlatform) as Box<_>, PlatformIdentifier::GethEvmSolc => Box::new(GethEvmSolcPlatform) as Box<_>,
PlatformIdentifier::LighthouseGethEvmSolc => PlatformIdentifier::LighthouseGethEvmSolc => {
Box::new(LighthouseGethEvmSolcPlatform) as Box<_>, Box::new(LighthouseGethEvmSolcPlatform) as Box<_>
PlatformIdentifier::KitchensinkPolkavmResolc => }
Box::new(KitchensinkPolkavmResolcPlatform) as Box<_>, PlatformIdentifier::KitchensinkPolkavmResolc => {
PlatformIdentifier::KitchensinkRevmSolc => Box::new(KitchensinkPolkavmResolcPlatform) as Box<_>
Box::new(KitchensinkRevmSolcPlatform) as Box<_>, }
PlatformIdentifier::ReviveDevNodePolkavmResolc => PlatformIdentifier::KitchensinkRevmSolc => {
Box::new(ReviveDevNodePolkavmResolcPlatform) as Box<_>, Box::new(KitchensinkRevmSolcPlatform) as Box<_>
PlatformIdentifier::ReviveDevNodeRevmSolc => }
Box::new(ReviveDevNodeRevmSolcPlatform) as Box<_>, PlatformIdentifier::ReviveDevNodePolkavmResolc => {
PlatformIdentifier::ZombienetPolkavmResolc => Box::new(ReviveDevNodePolkavmResolcPlatform) as Box<_>
Box::new(ZombienetPolkavmResolcPlatform) as Box<_>, }
PlatformIdentifier::ReviveDevNodeRevmSolc => {
Box::new(ReviveDevNodeRevmSolcPlatform) as Box<_>
}
PlatformIdentifier::ZombienetPolkavmResolc => {
Box::new(ZombienetPolkavmResolcPlatform) as Box<_>
}
PlatformIdentifier::ZombienetRevmSolc => Box::new(ZombienetRevmSolcPlatform) as Box<_>, PlatformIdentifier::ZombienetRevmSolc => Box::new(ZombienetRevmSolcPlatform) as Box<_>,
} }
} }
@@ -475,18 +493,24 @@ impl From<PlatformIdentifier> for &dyn Platform {
fn from(value: PlatformIdentifier) -> Self { fn from(value: PlatformIdentifier) -> Self {
match value { match value {
PlatformIdentifier::GethEvmSolc => &GethEvmSolcPlatform as &dyn Platform, PlatformIdentifier::GethEvmSolc => &GethEvmSolcPlatform as &dyn Platform,
PlatformIdentifier::LighthouseGethEvmSolc => PlatformIdentifier::LighthouseGethEvmSolc => {
&LighthouseGethEvmSolcPlatform as &dyn Platform, &LighthouseGethEvmSolcPlatform as &dyn Platform
PlatformIdentifier::KitchensinkPolkavmResolc => }
&KitchensinkPolkavmResolcPlatform as &dyn Platform, PlatformIdentifier::KitchensinkPolkavmResolc => {
PlatformIdentifier::KitchensinkRevmSolc => &KitchensinkPolkavmResolcPlatform as &dyn Platform
&KitchensinkRevmSolcPlatform as &dyn Platform, }
PlatformIdentifier::ReviveDevNodePolkavmResolc => PlatformIdentifier::KitchensinkRevmSolc => {
&ReviveDevNodePolkavmResolcPlatform as &dyn Platform, &KitchensinkRevmSolcPlatform as &dyn Platform
PlatformIdentifier::ReviveDevNodeRevmSolc => }
&ReviveDevNodeRevmSolcPlatform as &dyn Platform, PlatformIdentifier::ReviveDevNodePolkavmResolc => {
PlatformIdentifier::ZombienetPolkavmResolc => &ReviveDevNodePolkavmResolcPlatform as &dyn Platform
&ZombienetPolkavmResolcPlatform as &dyn Platform, }
PlatformIdentifier::ReviveDevNodeRevmSolc => {
&ReviveDevNodeRevmSolcPlatform as &dyn Platform
}
PlatformIdentifier::ZombienetPolkavmResolc => {
&ZombienetPolkavmResolcPlatform as &dyn Platform
}
PlatformIdentifier::ZombienetRevmSolc => &ZombienetRevmSolcPlatform as &dyn Platform, PlatformIdentifier::ZombienetRevmSolc => &ZombienetRevmSolcPlatform as &dyn Platform,
} }
} }
@@ -496,8 +520,17 @@ fn spawn_node<T: Node + EthereumNode + Send + Sync>(
mut node: T, mut node: T,
genesis: Genesis, genesis: Genesis,
) -> anyhow::Result<T> { ) -> anyhow::Result<T> {
info!(id = node.id(), connection_string = node.connection_string(), "Spawning node"); info!(
node.spawn(genesis).context("Failed to spawn node process")?; id = node.id(),
info!(id = node.id(), connection_string = node.connection_string(), "Spawned node"); connection_string = node.connection_string(),
"Spawning node"
);
node.spawn(genesis)
.context("Failed to spawn node process")?;
info!(
id = node.id(),
connection_string = node.connection_string(),
"Spawned node"
);
Ok(node) Ok(node)
} }
+1 -1
View File
@@ -76,6 +76,6 @@ fn main() -> anyhow::Result<()> {
let schema = schema_for!(Metadata); let schema = schema_for!(Metadata);
println!("{}", serde_json::to_string_pretty(&schema).unwrap()); println!("{}", serde_json::to_string_pretty(&schema).unwrap());
Ok(()) Ok(())
}, }
} }
} }
+8 -2
View File
@@ -54,7 +54,11 @@ pub struct Case {
impl Case { impl Case {
pub fn steps_iterator(&self) -> impl Iterator<Item = Step> { pub fn steps_iterator(&self) -> impl Iterator<Item = Step> {
let steps_len = self.steps.len(); let steps_len = self.steps.len();
self.steps.clone().into_iter().enumerate().map(move |(idx, mut step)| { self.steps
.clone()
.into_iter()
.enumerate()
.map(move |(idx, mut step)| {
let Step::FunctionCall(ref mut input) = step else { let Step::FunctionCall(ref mut input) = step else {
return step; return step;
}; };
@@ -80,7 +84,9 @@ impl Case {
&self, &self,
default_repeat_count: usize, default_repeat_count: usize,
) -> Box<dyn Iterator<Item = Step> + '_> { ) -> 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 { if contains_repeat {
Box::new(self.steps_iterator()) as Box<_> Box::new(self.steps_iterator()) as Box<_>
} else { } else {
+17 -9
View File
@@ -86,7 +86,11 @@ impl Corpus {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
tests.sort_by(|a, b| a.metadata_file_path.cmp(&b.metadata_file_path)); 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); 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 tests
} }
@@ -98,19 +102,23 @@ impl Corpus {
pub fn paths_iter(&self) -> impl Iterator<Item = &Path> { pub fn paths_iter(&self) -> impl Iterator<Item = &Path> {
match self { match self {
Corpus::SinglePath { path, .. } => Corpus::SinglePath { path, .. } => {
Box::new(std::iter::once(path.as_path())) as Box<dyn Iterator<Item = _>>, 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::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> { pub fn paths_iter_mut(&mut self) -> impl Iterator<Item = &mut PathBuf> {
match self { match self {
Corpus::SinglePath { path, .. } => Corpus::SinglePath { path, .. } => {
Box::new(std::iter::once(path)) as Box<dyn Iterator<Item = _>>, 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::MultiplePaths { paths, .. } => {
Box::new(paths.iter_mut()) as Box<dyn Iterator<Item = _>>
}
} }
} }
+65 -19
View File
@@ -44,7 +44,9 @@ impl MetadataFile {
if self.corpus_file_path.is_file() { if self.corpus_file_path.is_file() {
&self.corpus_file_path &self.corpus_file_path
} else { } else {
self.metadata_file_path.strip_prefix(&self.corpus_file_path).unwrap() self.metadata_file_path
.strip_prefix(&self.corpus_file_path)
.unwrap()
} }
} }
} }
@@ -157,10 +159,19 @@ impl Metadata {
return Ok(sources); return Ok(sources);
}; };
for (alias, ContractPathAndIdent { contract_source_path, contract_ident }) in contracts { for (
alias,
ContractPathAndIdent {
contract_source_path,
contract_ident,
},
) in contracts
{
let alias = alias.clone(); let alias = alias.clone();
let absolute_path = let absolute_path = directory
directory.join(contract_source_path).canonicalize().map_err(|error| { .join(contract_source_path)
.canonicalize()
.map_err(|error| {
anyhow::anyhow!( anyhow::anyhow!(
"Failed to canonicalize contract source path '{}': {error}", "Failed to canonicalize contract source path '{}': {error}",
directory.join(contract_source_path).display() directory.join(contract_source_path).display()
@@ -170,7 +181,10 @@ impl Metadata {
sources.insert( sources.insert(
alias, alias,
ContractPathAndIdent { contract_source_path: absolute_path, contract_ident }, ContractPathAndIdent {
contract_source_path: absolute_path,
contract_ident,
},
); );
} }
@@ -208,11 +222,11 @@ impl Metadata {
Ok(mut metadata) => { Ok(mut metadata) => {
metadata.file_path = Some(path.to_path_buf()); metadata.file_path = Some(path.to_path_buf());
Some(metadata) Some(metadata)
}, }
Err(err) => { Err(err) => {
error!(path = %path.display(), %err, "Deserialization of metadata failed"); error!(path = %path.display(), %err, "Deserialization of metadata failed");
None None
}, }
} }
} }
@@ -245,11 +259,11 @@ impl Metadata {
.into(), .into(),
); );
Some(metadata) Some(metadata)
}, }
Err(err) => { Err(err) => {
error!(path = %path.display(), %err, "Failed to deserialize metadata"); error!(path = %path.display(), %err, "Failed to deserialize metadata");
None None
}, }
} }
} }
@@ -323,7 +337,12 @@ pub struct ContractPathAndIdent {
impl Display for ContractPathAndIdent { impl Display for ContractPathAndIdent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 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()
)
} }
} }
@@ -343,7 +362,7 @@ impl FromStr for ContractPathAndIdent {
Some(ref mut path) => { Some(ref mut path) => {
path.push(':'); path.push(':');
path.push_str(next_item); path.push_str(next_item);
}, }
None => path = Some(next_item.to_owned()), None => path = Some(next_item.to_owned()),
} }
} else { } else {
@@ -363,7 +382,7 @@ impl FromStr for ContractPathAndIdent {
contract_source_path: PathBuf::from(path), contract_source_path: PathBuf::from(path),
contract_ident: ContractIdent::new(identifier), contract_ident: ContractIdent::new(identifier),
}) })
}, }
(None, None) => anyhow::bail!("Failed to find the path and identifier"), (None, None) => anyhow::bail!("Failed to find the path and identifier"),
} }
} }
@@ -401,23 +420,43 @@ pub struct EvmVersionRequirement {
impl EvmVersionRequirement { impl EvmVersionRequirement {
pub fn new_greater_than_or_equals(version: EVMVersion) -> Self { pub fn new_greater_than_or_equals(version: EVMVersion) -> Self {
Self { ordering: Ordering::Greater, or_equal: true, evm_version: version } Self {
ordering: Ordering::Greater,
or_equal: true,
evm_version: version,
}
} }
pub fn new_greater_than(version: EVMVersion) -> Self { pub fn new_greater_than(version: EVMVersion) -> Self {
Self { ordering: Ordering::Greater, or_equal: false, evm_version: version } Self {
ordering: Ordering::Greater,
or_equal: false,
evm_version: version,
}
} }
pub fn new_equals(version: EVMVersion) -> Self { pub fn new_equals(version: EVMVersion) -> Self {
Self { ordering: Ordering::Equal, or_equal: false, evm_version: version } Self {
ordering: Ordering::Equal,
or_equal: false,
evm_version: version,
}
} }
pub fn new_less_than(version: EVMVersion) -> Self { pub fn new_less_than(version: EVMVersion) -> Self {
Self { ordering: Ordering::Less, or_equal: false, evm_version: version } Self {
ordering: Ordering::Less,
or_equal: false,
evm_version: version,
}
} }
pub fn new_less_than_or_equals(version: EVMVersion) -> Self { pub fn new_less_than_or_equals(version: EVMVersion) -> Self {
Self { ordering: Ordering::Less, or_equal: true, evm_version: version } Self {
ordering: Ordering::Less,
or_equal: true,
evm_version: version,
}
} }
pub fn matches(&self, other: &EVMVersion) -> bool { pub fn matches(&self, other: &EVMVersion) -> bool {
@@ -428,7 +467,11 @@ impl EvmVersionRequirement {
impl Display for EvmVersionRequirement { impl Display for EvmVersionRequirement {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { ordering, or_equal, evm_version } = self; let Self {
ordering,
or_equal,
evm_version,
} = self;
match ordering { match ordering {
Ordering::Less => write!(f, "<")?, Ordering::Less => write!(f, "<")?,
Ordering::Equal => write!(f, "=")?, Ordering::Equal => write!(f, "=")?,
@@ -555,7 +598,10 @@ mod test {
// Assert // Assert
let identifier = identifier.expect("Failed to parse"); 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()); assert_eq!(identifier.contract_ident, "ERC20".to_owned().into());
// Act // Act
+20 -6
View File
@@ -77,7 +77,12 @@ impl FromStr for ParsedMode {
None => None, None => None,
}; };
Ok(ParsedMode { pipeline, optimize_flag, optimize_setting, version }) Ok(ParsedMode {
pipeline,
optimize_flag,
optimize_setting,
version,
})
} }
} }
@@ -133,9 +138,13 @@ impl ParsedMode {
|p| EitherIter::B(std::iter::once(*p)), |p| EitherIter::B(std::iter::once(*p)),
); );
let optimize_flag_setting = self let optimize_flag_setting = self.optimize_flag.map(|flag| {
.optimize_flag if flag {
.map(|flag| if flag { ModeOptimizerSetting::M3 } else { ModeOptimizerSetting::M0 }); ModeOptimizerSetting::M3
} else {
ModeOptimizerSetting::M0
}
});
let optimize_flag_iter = match optimize_flag_setting { let optimize_flag_iter = match optimize_flag_setting {
Some(setting) => EitherIter::A(std::iter::once(setting)), Some(setting) => EitherIter::A(std::iter::once(setting)),
@@ -148,7 +157,9 @@ impl ParsedMode {
); );
pipeline_iter.flat_map(move |pipeline| { pipeline_iter.flat_map(move |pipeline| {
optimize_settings_iter.clone().map(move |optimize_setting| Mode { optimize_settings_iter
.clone()
.map(move |optimize_setting| Mode {
pipeline, pipeline,
optimize_setting, optimize_setting,
version: self.version.clone(), version: self.version.clone(),
@@ -224,7 +235,10 @@ mod tests {
("Y+", vec!["Y M3"]), ("Y+", vec!["Y M3"]),
("Y-", vec!["Y M0"]), ("Y-", vec!["Y M0"]),
("Y <=0.8", vec!["Y M0 <=0.8", "Y M3 <=0.8"]), ("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 { for (actual, expected) in strings {
+106 -32
View File
@@ -78,7 +78,12 @@ impl StepPath {
impl Display for StepPath { impl Display for StepPath {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 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)
} }
} }
@@ -451,7 +456,9 @@ impl StepAddress {
impl FunctionCallStep { impl FunctionCallStep {
pub const fn default_caller_address() -> Address { pub const fn default_caller_address() -> Address {
Address(FixedBytes(alloy::hex!("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"))) Address(FixedBytes(alloy::hex!(
"0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"
)))
} }
pub const fn default_caller() -> StepAddress { pub const fn default_caller() -> StepAddress {
@@ -476,7 +483,7 @@ impl FunctionCallStep {
.context("Failed to produce calldata for deployer/fallback method")?; .context("Failed to produce calldata for deployer/fallback method")?;
Ok(calldata.into()) Ok(calldata.into())
}, }
Method::FunctionName(ref function_name) => { Method::FunctionName(ref function_name) => {
let Some(abi) = context.deployed_contract_abi(&self.instance) else { let Some(abi) = context.deployed_contract_abi(&self.instance) else {
anyhow::bail!("ABI for instance '{}' not found", self.instance.as_ref()); anyhow::bail!("ABI for instance '{}' not found", self.instance.as_ref());
@@ -527,7 +534,7 @@ impl FunctionCallStep {
.context("Failed to append encoded argument to calldata buffer")?; .context("Failed to append encoded argument to calldata buffer")?;
Ok(calldata.into()) Ok(calldata.into())
}, }
} }
} }
@@ -542,9 +549,11 @@ impl FunctionCallStep {
.await .await
.context("Failed to encode input bytes for transaction request")?; .context("Failed to encode input bytes for transaction request")?;
let caller = self.caller.resolve_address(resolver, context).await?; let caller = self.caller.resolve_address(resolver, context).await?;
let transaction_request = TransactionRequest::default() let transaction_request = TransactionRequest::default().from(caller).value(
.from(caller) self.value
.value(self.value.map(|value| value.into_inner()).unwrap_or_default()); .map(|value| value.into_inner())
.unwrap_or_default(),
);
match self.method { match self.method {
Method::Deployer => Ok(transaction_request.with_deploy_code(input_data)), Method::Deployer => Ok(transaction_request.with_deploy_code(input_data)),
_ => Ok(transaction_request _ => Ok(transaction_request
@@ -626,7 +635,8 @@ impl Calldata {
context: ResolutionContext<'_>, context: ResolutionContext<'_>,
) -> anyhow::Result<Vec<u8>> { ) -> anyhow::Result<Vec<u8>> {
let mut buffer = Vec::<u8>::with_capacity(self.size_requirement()); 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) Ok(buffer)
} }
@@ -639,7 +649,7 @@ impl Calldata {
match self { match self {
Calldata::Single(bytes) => { Calldata::Single(bytes) => {
buffer.extend_from_slice(bytes); buffer.extend_from_slice(bytes);
}, }
Calldata::Compound(items) => { Calldata::Compound(items) => {
let resolved = stream::iter(items.iter().enumerate()) let resolved = stream::iter(items.iter().enumerate())
.map(|(arg_idx, arg)| async move { .map(|(arg_idx, arg)| async move {
@@ -654,7 +664,7 @@ impl Calldata {
.context("Failed to resolve one or more calldata arguments")?; .context("Failed to resolve one or more calldata arguments")?;
buffer.extend(resolved.into_iter().flatten()); buffer.extend(resolved.into_iter().flatten());
}, }
}; };
Ok(()) Ok(())
} }
@@ -703,7 +713,7 @@ impl Calldata {
.all(|v| async move { v.is_ok_and(|v| v) }) .all(|v| async move { v.is_ok_and(|v| v) })
.map(Ok) .map(Ok)
.await .await
}, }
} }
} }
} }
@@ -717,7 +727,10 @@ impl CalldataItem {
) -> anyhow::Result<U256> { ) -> anyhow::Result<U256> {
let mut stack = Vec::<CalldataToken<U256>>::new(); 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 token = token.await?;
let new_token = match token { let new_token = match token {
CalldataToken::Item(_) => token, CalldataToken::Item(_) => token,
@@ -739,15 +752,17 @@ impl CalldataItem {
Operation::BitwiseAnd => Some(left_operand & right_operand), Operation::BitwiseAnd => Some(left_operand & right_operand),
Operation::BitwiseOr => Some(left_operand | right_operand), Operation::BitwiseOr => Some(left_operand | right_operand),
Operation::BitwiseXor => Some(left_operand ^ right_operand), Operation::BitwiseXor => Some(left_operand ^ right_operand),
Operation::ShiftLeft => Operation::ShiftLeft => {
Some(left_operand << usize::try_from(right_operand)?), Some(left_operand << usize::try_from(right_operand)?)
Operation::ShiftRight => }
Some(left_operand >> usize::try_from(right_operand)?), Operation::ShiftRight => {
Some(left_operand >> usize::try_from(right_operand)?)
}
} }
.context("Invalid calldata arithmetic operation - Invalid operation")?; .context("Invalid calldata arithmetic operation - Invalid operation")?;
CalldataToken::Item(result) CalldataToken::Item(result)
}, }
}; };
stack.push(new_token) stack.push(new_token)
} }
@@ -756,7 +771,9 @@ impl CalldataItem {
// Empty stack means that we got an empty compound calldata which we resolve to zero. // Empty stack means that we got an empty compound calldata which we resolve to zero.
[] => Ok(U256::ZERO), [] => Ok(U256::ZERO),
[CalldataToken::Item(item)] => Ok(*item), [CalldataToken::Item(item)] => Ok(*item),
_ => Err(anyhow::anyhow!("Invalid calldata arithmetic operation - Invalid stack")), _ => Err(anyhow::anyhow!(
"Invalid calldata arithmetic operation - Invalid stack"
)),
} }
} }
@@ -900,13 +917,16 @@ impl<T: AsRef<str>> CalldataToken<T> {
.await .await
.map(U256::from) .map(U256::from)
} else if let Some(variable_name) = item.strip_prefix(Self::VARIABLE_PREFIX) { } 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 { } else {
U256::from_str_radix(item, 10) U256::from_str_radix(item, 10)
.map_err(|error| anyhow::anyhow!("Invalid decimal literal: {}", error)) .map_err(|error| anyhow::anyhow!("Invalid decimal literal: {}", error))
}; };
value.map(CalldataToken::Item) value.map(CalldataToken::Item)
}, }
Self::Operation(operation) => Ok(CalldataToken::Operation(operation)), Self::Operation(operation) => Ok(CalldataToken::Operation(operation)),
} }
} }
@@ -1030,7 +1050,13 @@ mod tests {
"#; "#;
let parsed_abi: JsonAbi = serde_json::from_str(raw_metadata).unwrap(); 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 { let input = FunctionCallStep {
instance: ContractInstance::new("Contract"), instance: ContractInstance::new("Contract"),
@@ -1068,7 +1094,13 @@ mod tests {
]"#; ]"#;
let parsed_abi: JsonAbi = serde_json::from_str(raw_abi).unwrap(); 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 { let input: FunctionCallStep = FunctionCallStep {
instance: "Contract".to_owned().into(), instance: "Contract".to_owned().into(),
@@ -1090,7 +1122,10 @@ mod tests {
type T = (alloy::primitives::Address,); type T = (alloy::primitives::Address,);
let decoded: T = T::abi_decode(&encoded.0[4..]).unwrap(); let decoded: T = T::abi_decode(&encoded.0[4..]).unwrap();
assert_eq!(decoded.0, address!("0x1000000000000000000000000000000000000001")); assert_eq!(
decoded.0,
address!("0x1000000000000000000000000000000000000001")
);
} }
#[tokio::test] #[tokio::test]
@@ -1106,7 +1141,13 @@ mod tests {
]"#; ]"#;
let parsed_abi: JsonAbi = serde_json::from_str(raw_abi).unwrap(); 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 { let input: FunctionCallStep = FunctionCallStep {
instance: ContractInstance::new("Contract"), instance: ContractInstance::new("Contract"),
@@ -1128,7 +1169,10 @@ mod tests {
type T = (alloy::primitives::Address,); type T = (alloy::primitives::Address,);
let decoded: T = T::abi_decode(&encoded.0[4..]).unwrap(); 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( async fn resolve_calldata_item(
@@ -1165,7 +1209,12 @@ mod tests {
let resolved = resolved.expect("Failed to resolve argument"); let resolved = resolved.expect("Failed to resolve argument");
assert_eq!( assert_eq!(
resolved, resolved,
U256::from(MockResolver.block_gas_limit(Default::default()).await.unwrap()) U256::from(
MockResolver
.block_gas_limit(Default::default())
.await
.unwrap()
)
) )
} }
@@ -1182,7 +1231,11 @@ mod tests {
assert_eq!( assert_eq!(
resolved, resolved,
U256::from_be_slice( U256::from_be_slice(
MockResolver.block_coinbase(Default::default()).await.unwrap().as_ref() MockResolver
.block_coinbase(Default::default())
.await
.unwrap()
.as_ref()
) )
) )
} }
@@ -1197,7 +1250,13 @@ mod tests {
// Assert // Assert
let resolved = resolved.expect("Failed to resolve argument"); 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] #[tokio::test]
@@ -1212,7 +1271,11 @@ mod tests {
let resolved = resolved.expect("Failed to resolve argument"); let resolved = resolved.expect("Failed to resolve argument");
assert_eq!( assert_eq!(
resolved, resolved,
MockResolver.block_base_fee(Default::default()).await.map(U256::from).unwrap() MockResolver
.block_base_fee(Default::default())
.await
.map(U256::from)
.unwrap()
) )
} }
@@ -1242,7 +1305,10 @@ mod tests {
// Assert // Assert
let resolved = resolved.expect("Failed to resolve argument"); 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] #[tokio::test]
@@ -1257,7 +1323,12 @@ mod tests {
let resolved = resolved.expect("Failed to resolve argument"); let resolved = resolved.expect("Failed to resolve argument");
assert_eq!( assert_eq!(
resolved, resolved,
U256::from(MockResolver.block_timestamp(Default::default()).await.unwrap()) U256::from(
MockResolver
.block_timestamp(Default::default())
.await
.unwrap()
)
) )
} }
@@ -1335,7 +1406,10 @@ mod tests {
// Assert // Assert
let resolved = resolved.expect("Failed to resolve argument"); 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] #[tokio::test]
+7 -6
View File
@@ -135,11 +135,11 @@ impl<'a> ResolutionContext<'a> {
match self.block_number { match self.block_number {
Some(block_number) => match number { Some(block_number) => match number {
BlockNumberOrTag::Latest => BlockNumberOrTag::Number(*block_number), BlockNumberOrTag::Latest => BlockNumberOrTag::Number(*block_number),
n @ (BlockNumberOrTag::Finalized | n @ (BlockNumberOrTag::Finalized
BlockNumberOrTag::Safe | | BlockNumberOrTag::Safe
BlockNumberOrTag::Earliest | | BlockNumberOrTag::Earliest
BlockNumberOrTag::Pending | | BlockNumberOrTag::Pending
BlockNumberOrTag::Number(_)) => n, | BlockNumberOrTag::Number(_)) => n,
}, },
None => number, None => number,
} }
@@ -162,7 +162,8 @@ impl<'a> ResolutionContext<'a> {
} }
pub fn variable(&self, name: impl AsRef<str>) -> Option<&U256> { 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> { pub fn tip_block_number(&self) -> Option<&'a BlockNumber> {
+55 -26
View File
@@ -131,17 +131,20 @@ async fn run(args: MlTestRunnerArgs) -> anyhow::Result<()> {
Ok(mf) => { Ok(mf) => {
info!("Loaded metadata with {} case(s)", mf.cases.len()); info!("Loaded metadata with {} case(s)", mf.cases.len());
mf mf
}, }
Err(e) => { Err(e) => {
println!("test {} ... {RED}FAILED{COLOUR_RESET}", file_display); println!("test {} ... {RED}FAILED{COLOUR_RESET}", file_display);
println!(" Error loading metadata: {}", e); println!(" Error loading metadata: {}", e);
failed_files += 1; failed_files += 1;
failures.push((file_display.clone(), format!("Error loading metadata: {}", e))); failures.push((
file_display.clone(),
format!("Error loading metadata: {}", e),
));
if args.bail { if args.bail {
break; break;
} }
continue; continue;
}, }
}; };
info!("Executing test file: {}", file_display); info!("Executing test file: {}", file_display);
@@ -155,7 +158,7 @@ async fn run(args: MlTestRunnerArgs) -> anyhow::Result<()> {
let mut cache = cached_passed.lock().await; let mut cache = cached_passed.lock().await;
cache.insert(file_display); cache.insert(file_display);
} }
}, }
Err(e) => { Err(e) => {
println!("test {} ... {RED}FAILED{COLOUR_RESET}", file_display); println!("test {} ... {RED}FAILED{COLOUR_RESET}", file_display);
failed_files += 1; failed_files += 1;
@@ -165,7 +168,7 @@ async fn run(args: MlTestRunnerArgs) -> anyhow::Result<()> {
info!("Bailing after first failure"); info!("Bailing after first failure");
break; break;
} }
}, }
} }
} }
@@ -223,7 +226,7 @@ fn discover_test_files(path: &Path) -> anyhow::Result<Vec<PathBuf>> {
"sol" => { "sol" => {
// Single .sol file // Single .sol file
files.push(path.to_path_buf()); files.push(path.to_path_buf());
}, }
"json" => { "json" => {
// Corpus file - enumerate its tests // Corpus file - enumerate its tests
let corpus = Corpus::try_from_path(path)?; let corpus = Corpus::try_from_path(path)?;
@@ -231,8 +234,11 @@ fn discover_test_files(path: &Path) -> anyhow::Result<Vec<PathBuf>> {
for metadata in metadata_files { for metadata in metadata_files {
files.push(metadata.metadata_file_path); files.push(metadata.metadata_file_path);
} }
}, }
_ => anyhow::bail!("Unsupported file extension: {}. Expected .sol or .json", extension), _ => anyhow::bail!(
"Unsupported file extension: {}. Expected .sol or .json",
extension
),
} }
} else if path.is_dir() { } else if path.is_dir() {
// Walk directory recursively for .sol files // Walk directory recursively for .sol files
@@ -278,13 +284,15 @@ async fn execute_test_file(
PlatformIdentifier::LighthouseGethEvmSolc => &revive_dt_core::LighthouseGethEvmSolcPlatform, PlatformIdentifier::LighthouseGethEvmSolc => &revive_dt_core::LighthouseGethEvmSolcPlatform,
PlatformIdentifier::KitchensinkPolkavmResolc => { PlatformIdentifier::KitchensinkPolkavmResolc => {
&revive_dt_core::KitchensinkPolkavmResolcPlatform &revive_dt_core::KitchensinkPolkavmResolcPlatform
}, }
PlatformIdentifier::KitchensinkRevmSolc => &revive_dt_core::KitchensinkRevmSolcPlatform, PlatformIdentifier::KitchensinkRevmSolc => &revive_dt_core::KitchensinkRevmSolcPlatform,
PlatformIdentifier::ReviveDevNodePolkavmResolc => { PlatformIdentifier::ReviveDevNodePolkavmResolc => {
&revive_dt_core::ReviveDevNodePolkavmResolcPlatform &revive_dt_core::ReviveDevNodePolkavmResolcPlatform
}, }
PlatformIdentifier::ReviveDevNodeRevmSolc => &revive_dt_core::ReviveDevNodeRevmSolcPlatform, PlatformIdentifier::ReviveDevNodeRevmSolc => &revive_dt_core::ReviveDevNodeRevmSolcPlatform,
PlatformIdentifier::ZombienetPolkavmResolc => &revive_dt_core::ZombienetPolkavmResolcPlatform, PlatformIdentifier::ZombienetPolkavmResolc => {
&revive_dt_core::ZombienetPolkavmResolcPlatform
}
PlatformIdentifier::ZombienetRevmSolc => &revive_dt_core::ZombienetRevmSolcPlatform, PlatformIdentifier::ZombienetRevmSolc => &revive_dt_core::ZombienetRevmSolcPlatform,
}; };
@@ -296,8 +304,9 @@ async fn execute_test_file(
let node: &'static dyn revive_dt_node_interaction::EthereumNode = if args.start_platform { let node: &'static dyn revive_dt_node_interaction::EthereumNode = if args.start_platform {
info!("Starting blockchain node..."); info!("Starting blockchain node...");
let node_handle = let node_handle = platform
platform.new_node(context.clone()).context("Failed to spawn node thread")?; .new_node(context.clone())
.context("Failed to spawn node thread")?;
info!("Waiting for node to start..."); info!("Waiting for node to start...");
let node = node_handle let node = node_handle
@@ -305,24 +314,32 @@ async fn execute_test_file(
.map_err(|e| anyhow::anyhow!("Node thread panicked: {:?}", e))? .map_err(|e| anyhow::anyhow!("Node thread panicked: {:?}", e))?
.context("Failed to start node")?; .context("Failed to start node")?;
info!("Node started with ID: {}, connection: {}", node.id(), node.connection_string()); info!(
"Node started with ID: {}, connection: {}",
node.id(),
node.connection_string()
);
let node = Box::leak(node); let node = Box::leak(node);
info!("Running pre-transactions..."); info!("Running pre-transactions...");
node.pre_transactions().await.context("Failed to run pre-transactions")?; node.pre_transactions()
.await
.context("Failed to run pre-transactions")?;
info!("Pre-transactions completed"); info!("Pre-transactions completed");
node node
} else { } else {
info!("Using existing node"); info!("Using existing node");
let existing_node: Box<dyn revive_dt_node_interaction::EthereumNode> = match args.platform { let existing_node: Box<dyn revive_dt_node_interaction::EthereumNode> = match args.platform {
PlatformIdentifier::GethEvmSolc | PlatformIdentifier::LighthouseGethEvmSolc => Box::new( PlatformIdentifier::GethEvmSolc | PlatformIdentifier::LighthouseGethEvmSolc => {
Box::new(
revive_dt_node::node_implementations::geth::GethNode::new_existing( revive_dt_node::node_implementations::geth::GethNode::new_existing(
&args.private_key, &args.private_key,
args.rpc_port, args.rpc_port,
) )
.await?, .await?,
), )
}
PlatformIdentifier::KitchensinkPolkavmResolc PlatformIdentifier::KitchensinkPolkavmResolc
| PlatformIdentifier::KitchensinkRevmSolc | PlatformIdentifier::KitchensinkRevmSolc
| PlatformIdentifier::ReviveDevNodePolkavmResolc | PlatformIdentifier::ReviveDevNodePolkavmResolc
@@ -345,15 +362,19 @@ async fn execute_test_file(
.map(Arc::new) .map(Arc::new)
.context("Failed to create cached compiler")?; .context("Failed to create cached compiler")?;
let private_key_allocator = let private_key_allocator = Arc::new(Mutex::new(PrivateKeyAllocator::new(
Arc::new(Mutex::new(PrivateKeyAllocator::new(alloy::primitives::U256::from(100)))); alloy::primitives::U256::from(100),
)));
let (reporter, report_task) = let (reporter, report_task) =
revive_dt_report::ReportAggregator::new(context.clone()).into_task(); revive_dt_report::ReportAggregator::new(context.clone()).into_task();
tokio::spawn(report_task); tokio::spawn(report_task);
info!("Building test definitions for {} case(s)", metadata_file.cases.len()); info!(
"Building test definitions for {} case(s)",
metadata_file.cases.len()
);
let mut test_definitions = Vec::new(); let mut test_definitions = Vec::new();
for (case_idx, case) in metadata_file.cases.iter().enumerate() { for (case_idx, case) in metadata_file.cases.iter().enumerate() {
info!("Building test definition for case {}", case_idx); info!("Building test definition for case {}", case_idx);
@@ -400,17 +421,20 @@ async fn execute_test_file(
test_definition.case.steps.len(), test_definition.case.steps.len(),
test_definition.case_idx test_definition.case_idx
); );
let steps_executed = driver let steps_executed = driver.execute_all().await.context(format!(
.execute_all() "Failed to execute case {}",
.await test_definition.case_idx
.context(format!("Failed to execute case {}", test_definition.case_idx))?; ))?;
info!( info!(
"✓ Case {} completed successfully, executed {} step(s)", "✓ Case {} completed successfully, executed {} step(s)",
test_definition.case_idx, steps_executed test_definition.case_idx, steps_executed
); );
} }
info!("─────────────────────────────────────────────────────────────────"); info!("─────────────────────────────────────────────────────────────────");
info!("All {} test case(s) executed successfully", test_definitions.len()); info!(
"All {} test case(s) executed successfully",
test_definitions.len()
);
Ok(()) Ok(())
} }
@@ -453,7 +477,12 @@ async fn build_test_definition<'a>(
let mut platforms = BTreeMap::new(); let mut platforms = BTreeMap::new();
platforms.insert( platforms.insert(
platform.platform_identifier(), platform.platform_identifier(),
TestPlatformInformation { platform, node, compiler, reporter: execution_reporter }, TestPlatformInformation {
platform,
node,
compiler,
reporter: execution_reporter,
},
); );
let test_definition = TestDefinition { let test_definition = TestDefinition {
+32 -13
View File
@@ -33,7 +33,10 @@ impl Process {
let log_file_prefix = log_file_prefix.into(); let log_file_prefix = log_file_prefix.into();
let (stdout_file_name, stderr_file_name) = match log_file_prefix { let (stdout_file_name, stderr_file_name) = match log_file_prefix {
Some(prefix) => (format!("{prefix}_stdout.log"), format!("{prefix}_stderr.log")), Some(prefix) => (
format!("{prefix}_stdout.log"),
format!("{prefix}_stderr.log"),
),
None => ("stdout.log".to_string(), "stderr.log".to_string()), None => ("stdout.log".to_string(), "stderr.log".to_string()),
}; };
@@ -54,19 +57,23 @@ impl Process {
.context("Failed to open the stderr logs file")?; .context("Failed to open the stderr logs file")?;
let mut command = { let mut command = {
let stdout_logs_file = let stdout_logs_file = stdout_logs_file
stdout_logs_file.try_clone().context("Failed to clone the stdout logs file")?; .try_clone()
let stderr_logs_file = .context("Failed to clone the stdout logs file")?;
stderr_logs_file.try_clone().context("Failed to clone the stderr logs file")?; let stderr_logs_file = stderr_logs_file
.try_clone()
.context("Failed to clone the stderr logs file")?;
let mut command = Command::new(binary_path.as_ref()); let mut command = Command::new(binary_path.as_ref());
command_building_callback(&mut command, stdout_logs_file, stderr_logs_file); command_building_callback(&mut command, stdout_logs_file, stderr_logs_file);
command command
}; };
let mut child = command.spawn().context("Failed to spawn the built command")?; let mut child = command
.spawn()
.context("Failed to spawn the built command")?;
match process_readiness_wait_behavior { match process_readiness_wait_behavior {
ProcessReadinessWaitBehavior::NoStartupWait => {}, ProcessReadinessWaitBehavior::NoStartupWait => {}
ProcessReadinessWaitBehavior::WaitDuration(duration) => std::thread::sleep(duration), ProcessReadinessWaitBehavior::WaitDuration(duration) => std::thread::sleep(duration),
ProcessReadinessWaitBehavior::TimeBoundedWaitFunction { ProcessReadinessWaitBehavior::TimeBoundedWaitFunction {
max_wait_duration, max_wait_duration,
@@ -119,23 +126,35 @@ impl Process {
) )
} }
} }
}, }
ProcessReadinessWaitBehavior::WaitForCommandToExit => { ProcessReadinessWaitBehavior::WaitForCommandToExit => {
if !child.wait().context("Failed waiting for process to finish")?.success() { if !child
.wait()
.context("Failed waiting for process to finish")?
.success()
{
anyhow::bail!("Failed to spawn command"); anyhow::bail!("Failed to spawn command");
} }
}, }
} }
Ok(Self { child, stdout_logs_file, stderr_logs_file }) Ok(Self {
child,
stdout_logs_file,
stderr_logs_file,
})
} }
} }
impl Drop for Process { impl Drop for Process {
fn drop(&mut self) { fn drop(&mut self) {
self.child.kill().expect("Failed to kill the process"); self.child.kill().expect("Failed to kill the process");
self.stdout_logs_file.flush().expect("Failed to flush the stdout logs file"); self.stdout_logs_file
self.stderr_logs_file.flush().expect("Failed to flush the stderr logs file"); .flush()
.expect("Failed to flush the stdout logs file");
self.stderr_logs_file
.flush()
.expect("Failed to flush the stderr logs file");
} }
} }
+68 -23
View File
@@ -108,7 +108,9 @@ impl GethNode {
let wallet_configuration = AsRef::<WalletConfiguration>::as_ref(&context); let wallet_configuration = AsRef::<WalletConfiguration>::as_ref(&context);
let geth_configuration = AsRef::<GethConfiguration>::as_ref(&context); let geth_configuration = AsRef::<GethConfiguration>::as_ref(&context);
let geth_directory = working_directory_configuration.as_path().join(Self::BASE_DIRECTORY); let geth_directory = working_directory_configuration
.as_path()
.join(Self::BASE_DIRECTORY);
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst); let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
let base_directory = geth_directory.join(id.to_string()); let base_directory = geth_directory.join(id.to_string());
@@ -137,7 +139,10 @@ impl GethNode {
signers::local::PrivateKeySigner, signers::local::PrivateKeySigner,
}; };
let key_str = private_key.trim().strip_prefix("0x").unwrap_or(private_key.trim()); let key_str = private_key
.trim()
.strip_prefix("0x")
.unwrap_or(private_key.trim());
let key_bytes = alloy::hex::decode(key_str) let key_bytes = alloy::hex::decode(key_str)
.map_err(|e| anyhow::anyhow!("Failed to decode private key hex: {}", e))?; .map_err(|e| anyhow::anyhow!("Failed to decode private key hex: {}", e))?;
@@ -331,14 +336,15 @@ impl GethNode {
ProcessReadinessWaitBehavior::TimeBoundedWaitFunction { ProcessReadinessWaitBehavior::TimeBoundedWaitFunction {
max_wait_duration: self.start_timeout, max_wait_duration: self.start_timeout,
check_function: Box::new(|_, stderr_line| match stderr_line { check_function: Box::new(|_, stderr_line| match stderr_line {
Some(line) => Some(line) => {
if line.contains(Self::ERROR_MARKER) { if line.contains(Self::ERROR_MARKER) {
anyhow::bail!("Failed to start geth {line}"); anyhow::bail!("Failed to start geth {line}");
} else if line.contains(Self::READY_MARKER) { } else if line.contains(Self::READY_MARKER) {
Ok(true) Ok(true)
} else { } else {
Ok(false) Ok(false)
}, }
}
None => Ok(false), None => Ok(false),
}), }),
}, },
@@ -351,7 +357,7 @@ impl GethNode {
self.shutdown() self.shutdown()
.context("Failed to gracefully shutdown after geth start error")?; .context("Failed to gracefully shutdown after geth start error")?;
return Err(err); return Err(err);
}, }
} }
Ok(self) Ok(self)
@@ -491,12 +497,15 @@ impl EthereumNode for GethNode {
true => Ok(ControlFlow::Continue(())), true => Ok(ControlFlow::Continue(())),
false => Err(error.into()), false => Err(error.into()),
} }
}, }
} }
} }
}, },
) )
.instrument(tracing::info_span!("Awaiting transaction receipt", ?transaction_hash)) .instrument(tracing::info_span!(
"Awaiting transaction receipt",
?transaction_hash
))
.await .await
}) })
} }
@@ -508,8 +517,10 @@ impl EthereumNode for GethNode {
trace_options: GethDebugTracingOptions, trace_options: GethDebugTracingOptions,
) -> Pin<Box<dyn Future<Output = anyhow::Result<GethTrace>> + '_>> { ) -> Pin<Box<dyn Future<Output = anyhow::Result<GethTrace>> + '_>> {
Box::pin(async move { Box::pin(async move {
let provider = let provider = self
self.provider().await.context("Failed to create provider for tracing")?; .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)),
@@ -517,7 +528,10 @@ impl EthereumNode for GethNode {
let provider = provider.clone(); let provider = provider.clone();
let trace_options = trace_options.clone(); let trace_options = trace_options.clone();
async move { async move {
match provider.debug_trace_transaction(tx_hash, trace_options).await { match provider
.debug_trace_transaction(tx_hash, trace_options)
.await
{
Ok(trace) => Ok(ControlFlow::Break(trace)), Ok(trace) => Ok(ControlFlow::Break(trace)),
Err(error) => { Err(error) => {
let error_string = error.to_string(); let error_string = error.to_string();
@@ -525,7 +539,7 @@ impl EthereumNode for GethNode {
true => Ok(ControlFlow::Continue(())), true => Ok(ControlFlow::Continue(())),
false => Err(error.into()), false => Err(error.into()),
} }
}, }
} }
} }
}, },
@@ -740,7 +754,10 @@ impl ResolverApi for GethNodeResolver {
.context("Failed to get the geth block")? .context("Failed to get the geth block")?
.context("Failed to get the Geth block, perhaps there are no blocks?") .context("Failed to get the Geth block, perhaps there are no blocks?")
.and_then(|block| { .and_then(|block| {
block.header.base_fee_per_gas.context("Failed to get the base fee per gas") block
.header
.base_fee_per_gas
.context("Failed to get the base fee per gas")
}) })
}) })
} }
@@ -857,7 +874,11 @@ mod tests {
// Arrange // Arrange
let (context, node) = shared_state(); let (context, node) = shared_state();
let account_address = context.wallet_configuration.wallet().default_signer().address(); let account_address = context
.wallet_configuration
.wallet()
.default_signer()
.address();
let transaction = TransactionRequest::default() let transaction = TransactionRequest::default()
.to(account_address) .to(account_address)
.value(U256::from(100_000_000_000_000u128)); .value(U256::from(100_000_000_000_000u128));
@@ -880,7 +901,10 @@ mod tests {
// Assert // Assert
let version = version.expect("Failed to get the version"); let version = version.expect("Failed to get the version");
assert!(version.starts_with("geth version"), "expected version string, got: '{version}'"); assert!(
version.starts_with("geth version"),
"expected version string, got: '{version}'"
);
} }
#[tokio::test] #[tokio::test]
@@ -904,8 +928,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let gas_limit = let gas_limit = node
node.resolver().await.unwrap().block_gas_limit(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_gas_limit(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = gas_limit.expect("Failed to get the gas limit"); let _ = gas_limit.expect("Failed to get the gas limit");
@@ -918,8 +946,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let coinbase = let coinbase = node
node.resolver().await.unwrap().block_coinbase(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_coinbase(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = coinbase.expect("Failed to get the coinbase"); let _ = coinbase.expect("Failed to get the coinbase");
@@ -932,8 +964,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let block_difficulty = let block_difficulty = node
node.resolver().await.unwrap().block_difficulty(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_difficulty(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_difficulty.expect("Failed to get the block difficulty"); let _ = block_difficulty.expect("Failed to get the block difficulty");
@@ -946,7 +982,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let block_hash = node.resolver().await.unwrap().block_hash(BlockNumberOrTag::Latest).await; let block_hash = node
.resolver()
.await
.unwrap()
.block_hash(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_hash.expect("Failed to get the block hash"); let _ = block_hash.expect("Failed to get the block hash");
@@ -959,8 +1000,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let block_timestamp = let block_timestamp = node
node.resolver().await.unwrap().block_timestamp(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_timestamp(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_timestamp.expect("Failed to get the block timestamp"); let _ = block_timestamp.expect("Failed to get the block timestamp");
@@ -132,7 +132,9 @@ impl LighthouseGethNode {
let wallet_configuration = AsRef::<WalletConfiguration>::as_ref(&context); let wallet_configuration = AsRef::<WalletConfiguration>::as_ref(&context);
let kurtosis_configuration = AsRef::<KurtosisConfiguration>::as_ref(&context); let kurtosis_configuration = AsRef::<KurtosisConfiguration>::as_ref(&context);
let geth_directory = working_directory_configuration.as_path().join(Self::BASE_DIRECTORY); let geth_directory = working_directory_configuration
.as_path()
.join(Self::BASE_DIRECTORY);
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst); let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
let base_directory = geth_directory.join(id.to_string()); let base_directory = geth_directory.join(id.to_string());
@@ -145,7 +147,10 @@ impl LighthouseGethNode {
http_connection_string: String::default(), http_connection_string: String::default(),
enclave_name: format!( enclave_name: format!(
"enclave-{}-{}", "enclave-{}-{}",
SystemTime::now().duration_since(UNIX_EPOCH).expect("Must not fail").as_nanos(), SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Must not fail")
.as_nanos(),
id id
), ),
@@ -521,12 +526,15 @@ impl LighthouseGethNode {
true => Ok(ControlFlow::Continue(())), true => Ok(ControlFlow::Continue(())),
false => Err(error.into()), false => Err(error.into()),
} }
}, }
} }
} }
}, },
) )
.instrument(tracing::info_span!("Awaiting transaction receipt", ?transaction_hash)) .instrument(tracing::info_span!(
"Awaiting transaction receipt",
?transaction_hash
))
.await .await
}) })
} }
@@ -615,7 +623,9 @@ impl EthereumNode for LighthouseGethNode {
) -> Pin<Box<dyn Future<Output = anyhow::Result<GethTrace>> + '_>> { ) -> Pin<Box<dyn Future<Output = anyhow::Result<GethTrace>> + '_>> {
Box::pin(async move { Box::pin(async move {
let provider = Arc::new( let provider = Arc::new(
self.http_provider().await.context("Failed to create provider for tracing")?, self.http_provider()
.await
.context("Failed to create provider for tracing")?,
); );
poll( poll(
Self::TRACE_POLLING_DURATION, Self::TRACE_POLLING_DURATION,
@@ -624,7 +634,10 @@ impl EthereumNode for LighthouseGethNode {
let provider = provider.clone(); let provider = provider.clone();
let trace_options = trace_options.clone(); let trace_options = trace_options.clone();
async move { async move {
match provider.debug_trace_transaction(tx_hash, trace_options).await { match provider
.debug_trace_transaction(tx_hash, trace_options)
.await
{
Ok(trace) => Ok(ControlFlow::Break(trace)), Ok(trace) => Ok(ControlFlow::Break(trace)),
Err(error) => { Err(error) => {
let error_string = error.to_string(); let error_string = error.to_string();
@@ -632,7 +645,7 @@ impl EthereumNode for LighthouseGethNode {
true => Ok(ControlFlow::Continue(())), true => Ok(ControlFlow::Continue(())),
false => Err(error.into()), false => Err(error.into()),
} }
}, }
} }
} }
}, },
@@ -846,7 +859,10 @@ impl<F: TxFiller<Ethereum>, P: Provider<Ethereum>> ResolverApi
.context("Failed to get the geth block")? .context("Failed to get the geth block")?
.context("Failed to get the Geth block, perhaps there are no blocks?") .context("Failed to get the Geth block, perhaps there are no blocks?")
.and_then(|block| { .and_then(|block| {
block.header.base_fee_per_gas.context("Failed to get the base fee per gas") block
.header
.base_fee_per_gas
.context("Failed to get the base fee per gas")
}) })
}) })
} }
@@ -900,7 +916,11 @@ impl Node for LighthouseGethNode {
.spawn() .spawn()
.expect("Failed to spawn the enclave kill command"); .expect("Failed to spawn the enclave kill command");
if !child.wait().expect("Failed to wait for the enclave kill command").success() { if !child
.wait()
.expect("Failed to wait for the enclave kill command")
.success()
{
let stdout = { let stdout = {
let mut stdout = String::default(); let mut stdout = String::default();
child child
@@ -1126,7 +1146,11 @@ mod tests {
let (context, node) = new_node(); let (context, node) = new_node();
node.fund_all_accounts().await.expect("Failed"); node.fund_all_accounts().await.expect("Failed");
let account_address = context.wallet_configuration.wallet().default_signer().address(); let account_address = context
.wallet_configuration
.wallet()
.default_signer()
.address();
let transaction = TransactionRequest::default() let transaction = TransactionRequest::default()
.to(account_address) .to(account_address)
.value(U256::from(100_000_000_000_000u128)); .value(U256::from(100_000_000_000_000u128));
@@ -1149,7 +1173,10 @@ mod tests {
// Assert // Assert
let version = version.expect("Failed to get the version"); let version = version.expect("Failed to get the version");
assert!(version.starts_with("CLI Version"), "expected version string, got: '{version}'"); assert!(
version.starts_with("CLI Version"),
"expected version string, got: '{version}'"
);
} }
#[tokio::test] #[tokio::test]
@@ -1173,8 +1200,12 @@ mod tests {
let (_context, node) = new_node(); let (_context, node) = new_node();
// Act // Act
let gas_limit = let gas_limit = node
node.resolver().await.unwrap().block_gas_limit(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_gas_limit(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = gas_limit.expect("Failed to get the gas limit"); let _ = gas_limit.expect("Failed to get the gas limit");
@@ -1187,8 +1218,12 @@ mod tests {
let (_context, node) = new_node(); let (_context, node) = new_node();
// Act // Act
let coinbase = let coinbase = node
node.resolver().await.unwrap().block_coinbase(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_coinbase(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = coinbase.expect("Failed to get the coinbase"); let _ = coinbase.expect("Failed to get the coinbase");
@@ -1201,8 +1236,12 @@ mod tests {
let (_context, node) = new_node(); let (_context, node) = new_node();
// Act // Act
let block_difficulty = let block_difficulty = node
node.resolver().await.unwrap().block_difficulty(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_difficulty(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_difficulty.expect("Failed to get the block difficulty"); let _ = block_difficulty.expect("Failed to get the block difficulty");
@@ -1215,7 +1254,12 @@ mod tests {
let (_context, node) = new_node(); let (_context, node) = new_node();
// Act // Act
let block_hash = node.resolver().await.unwrap().block_hash(BlockNumberOrTag::Latest).await; let block_hash = node
.resolver()
.await
.unwrap()
.block_hash(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_hash.expect("Failed to get the block hash"); let _ = block_hash.expect("Failed to get the block hash");
@@ -1228,8 +1272,12 @@ mod tests {
let (_context, node) = new_node(); let (_context, node) = new_node();
// Act // Act
let block_timestamp = let block_timestamp = node
node.resolver().await.unwrap().block_timestamp(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_timestamp(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_timestamp.expect("Failed to get the block timestamp"); let _ = block_timestamp.expect("Failed to get the block timestamp");
@@ -109,7 +109,9 @@ impl SubstrateNode {
) -> Self { ) -> Self {
let working_directory_path = let working_directory_path =
AsRef::<WorkingDirectoryConfiguration>::as_ref(&context).as_path(); AsRef::<WorkingDirectoryConfiguration>::as_ref(&context).as_path();
let eth_rpc_path = AsRef::<EthRpcConfiguration>::as_ref(&context).path.as_path(); let eth_rpc_path = AsRef::<EthRpcConfiguration>::as_ref(&context)
.path
.as_path();
let wallet = AsRef::<WalletConfiguration>::as_ref(&context).wallet(); let wallet = AsRef::<WalletConfiguration>::as_ref(&context).wallet();
let substrate_directory = working_directory_path.join(Self::BASE_DIRECTORY); let substrate_directory = working_directory_path.join(Self::BASE_DIRECTORY);
@@ -141,7 +143,10 @@ impl SubstrateNode {
signers::local::PrivateKeySigner, signers::local::PrivateKeySigner,
}; };
let key_str = private_key.trim().strip_prefix("0x").unwrap_or(private_key.trim()); let key_str = private_key
.trim()
.strip_prefix("0x")
.unwrap_or(private_key.trim());
let key_bytes = alloy::hex::decode(key_str) let key_bytes = alloy::hex::decode(key_str)
.map_err(|e| anyhow::anyhow!("Failed to decode private key hex: {}", e))?; .map_err(|e| anyhow::anyhow!("Failed to decode private key hex: {}", e))?;
@@ -315,7 +320,7 @@ impl SubstrateNode {
self.shutdown() self.shutdown()
.context("Failed to gracefully shutdown after substrate start error")?; .context("Failed to gracefully shutdown after substrate start error")?;
return Err(err); return Err(err);
}, }
} }
let eth_proxy_process = Process::new( let eth_proxy_process = Process::new(
@@ -350,7 +355,7 @@ impl SubstrateNode {
self.shutdown() self.shutdown()
.context("Failed to gracefully shutdown after eth proxy start error")?; .context("Failed to gracefully shutdown after eth proxy start error")?;
return Err(err); return Err(err);
}, }
} }
Ok(()) Ok(())
@@ -360,7 +365,10 @@ impl SubstrateNode {
&self, &self,
genesis: &Genesis, genesis: &Genesis,
) -> anyhow::Result<Vec<(String, u128)>> { ) -> anyhow::Result<Vec<(String, u128)>> {
genesis.alloc.iter().try_fold(Vec::new(), |mut vec, (address, acc)| { genesis
.alloc
.iter()
.try_fold(Vec::new(), |mut vec, (address, acc)| {
let substrate_address = Self::eth_to_substrate_address(address); let substrate_address = Self::eth_to_substrate_address(address);
let balance = acc.balance.try_into()?; let balance = acc.balance.try_into()?;
vec.push((substrate_address, balance)); vec.push((substrate_address, balance));
@@ -460,7 +468,10 @@ impl EthereumNode for SubstrateNode {
transaction: TransactionRequest, transaction: TransactionRequest,
) -> Pin<Box<dyn Future<Output = anyhow::Result<TransactionReceipt>> + '_>> { ) -> Pin<Box<dyn Future<Output = anyhow::Result<TransactionReceipt>> + '_>> {
Box::pin(async move { Box::pin(async move {
let provider = self.provider().await.context("Failed to create the provider")?; let provider = self
.provider()
.await
.context("Failed to create the provider")?;
execute_transaction(provider, transaction).await execute_transaction(provider, transaction).await
}) })
} }
@@ -682,7 +693,10 @@ impl ResolverApi for SubstrateNodeResolver {
.context("Failed to get the substrate block")? .context("Failed to get the substrate block")?
.context("Failed to get the substrate block, perhaps the chain has no blocks?") .context("Failed to get the substrate block, perhaps the chain has no blocks?")
.and_then(|block| { .and_then(|block| {
block.header.base_fee_per_gas.context("Failed to get the base fee per gas") block
.header
.base_fee_per_gas
.context("Failed to get the base fee per gas")
}) })
}) })
} }
@@ -961,27 +975,33 @@ impl TransactionBuilder<ReviveNetwork> for <Ethereum as Network>::TransactionReq
); );
match result { match result {
Ok(unsigned_tx) => Ok(unsigned_tx), Ok(unsigned_tx) => Ok(unsigned_tx),
Err(UnbuiltTransactionError { request, error }) => Err(UnbuiltTransactionError { request, error }) => {
Err(UnbuiltTransactionError::<ReviveNetwork> { Err(UnbuiltTransactionError::<ReviveNetwork> {
request, request,
error: match error { error: match error {
TransactionBuilderError::InvalidTransactionRequest(tx_type, items) => TransactionBuilderError::InvalidTransactionRequest(tx_type, items) => {
TransactionBuilderError::InvalidTransactionRequest(tx_type, items), TransactionBuilderError::InvalidTransactionRequest(tx_type, items)
TransactionBuilderError::UnsupportedSignatureType => }
TransactionBuilderError::UnsupportedSignatureType, TransactionBuilderError::UnsupportedSignatureType => {
TransactionBuilderError::Signer(error) => TransactionBuilderError::UnsupportedSignatureType
TransactionBuilderError::Signer(error), }
TransactionBuilderError::Custom(error) => TransactionBuilderError::Signer(error) => {
TransactionBuilderError::Custom(error), TransactionBuilderError::Signer(error)
}
TransactionBuilderError::Custom(error) => {
TransactionBuilderError::Custom(error)
}
}, },
}), })
}
} }
} }
async fn build<W: alloy::network::NetworkWallet<ReviveNetwork>>( async fn build<W: alloy::network::NetworkWallet<ReviveNetwork>>(
self, self,
wallet: &W, wallet: &W,
) -> Result<<ReviveNetwork as Network>::TxEnvelope, TransactionBuilderError<ReviveNetwork>> { ) -> Result<<ReviveNetwork as Network>::TxEnvelope, TransactionBuilderError<ReviveNetwork>>
{
Ok(wallet.sign_request(self).await?) Ok(wallet.sign_request(self).await?)
} }
} }
@@ -1241,7 +1261,11 @@ mod tests {
let provider = node.provider().await.expect("Failed to create provider"); let provider = node.provider().await.expect("Failed to create provider");
let account_address = context.wallet_configuration.wallet().default_signer().address(); let account_address = context
.wallet_configuration
.wallet()
.default_signer()
.address();
let transaction = TransactionRequest::default() let transaction = TransactionRequest::default()
.to(account_address) .to(account_address)
.value(U256::from(100_000_000_000_000u128)); .value(U256::from(100_000_000_000_000u128));
@@ -1286,8 +1310,9 @@ mod tests {
.expect("init failed"); .expect("init failed");
// Check that the patched chainspec file was generated // Check that the patched chainspec file was generated
let final_chainspec_path = let final_chainspec_path = dummy_node
dummy_node.base_directory.join(SubstrateNode::CHAIN_SPEC_JSON_FILE); .base_directory
.join(SubstrateNode::CHAIN_SPEC_JSON_FILE);
assert!(final_chainspec_path.exists(), "Chainspec file should exist"); assert!(final_chainspec_path.exists(), "Chainspec file should exist");
let contents = fs::read_to_string(&final_chainspec_path).expect("Failed to read chainspec"); let contents = fs::read_to_string(&final_chainspec_path).expect("Failed to read chainspec");
@@ -1393,7 +1418,10 @@ mod tests {
for (eth_addr, expected_ss58) in cases { for (eth_addr, expected_ss58) in cases {
let result = SubstrateNode::eth_to_substrate_address(&eth_addr.parse().unwrap()); let result = SubstrateNode::eth_to_substrate_address(&eth_addr.parse().unwrap());
assert_eq!(result, expected_ss58, "Mismatch for Ethereum address {eth_addr}"); assert_eq!(
result, expected_ss58,
"Mismatch for Ethereum address {eth_addr}"
);
} }
} }
@@ -1444,8 +1472,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let gas_limit = let gas_limit = node
node.resolver().await.unwrap().block_gas_limit(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_gas_limit(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = gas_limit.expect("Failed to get the gas limit"); let _ = gas_limit.expect("Failed to get the gas limit");
@@ -1458,8 +1490,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let coinbase = let coinbase = node
node.resolver().await.unwrap().block_coinbase(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_coinbase(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = coinbase.expect("Failed to get the coinbase"); let _ = coinbase.expect("Failed to get the coinbase");
@@ -1472,8 +1508,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let block_difficulty = let block_difficulty = node
node.resolver().await.unwrap().block_difficulty(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_difficulty(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_difficulty.expect("Failed to get the block difficulty"); let _ = block_difficulty.expect("Failed to get the block difficulty");
@@ -1486,7 +1526,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let block_hash = node.resolver().await.unwrap().block_hash(BlockNumberOrTag::Latest).await; let block_hash = node
.resolver()
.await
.unwrap()
.block_hash(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_hash.expect("Failed to get the block hash"); let _ = block_hash.expect("Failed to get the block hash");
@@ -1499,8 +1544,12 @@ mod tests {
let node = shared_node(); let node = shared_node();
// Act // Act
let block_timestamp = let block_timestamp = node
node.resolver().await.unwrap().block_timestamp(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_timestamp(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_timestamp.expect("Failed to get the block timestamp"); let _ = block_timestamp.expect("Failed to get the block timestamp");
@@ -122,10 +122,14 @@ impl ZombieNode {
+ AsRef<EthRpcConfiguration> + AsRef<EthRpcConfiguration>
+ AsRef<WalletConfiguration>, + AsRef<WalletConfiguration>,
) -> Self { ) -> Self {
let eth_proxy_binary = AsRef::<EthRpcConfiguration>::as_ref(&context).path.to_owned(); let eth_proxy_binary = AsRef::<EthRpcConfiguration>::as_ref(&context)
.path
.to_owned();
let working_directory_path = AsRef::<WorkingDirectoryConfiguration>::as_ref(&context); let working_directory_path = AsRef::<WorkingDirectoryConfiguration>::as_ref(&context);
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst); let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
let base_directory = working_directory_path.join(Self::BASE_DIRECTORY).join(id.to_string()); let base_directory = working_directory_path
.join(Self::BASE_DIRECTORY)
.join(id.to_string());
let base_directory = base_directory.canonicalize().unwrap_or(base_directory); let base_directory = base_directory.canonicalize().unwrap_or(base_directory);
let logs_directory = base_directory.join(Self::LOGS_DIRECTORY); let logs_directory = base_directory.join(Self::LOGS_DIRECTORY);
let wallet = AsRef::<WalletConfiguration>::as_ref(&context).wallet(); let wallet = AsRef::<WalletConfiguration>::as_ref(&context).wallet();
@@ -193,8 +197,10 @@ impl ZombieNode {
} }
fn spawn_process(&mut self) -> anyhow::Result<()> { fn spawn_process(&mut self) -> anyhow::Result<()> {
let network_config = let network_config = self
self.network_config.clone().context("Node not initialized, call init() first")?; .network_config
.clone()
.context("Node not initialized, call init() first")?;
let rt = tokio::runtime::Runtime::new().unwrap(); let rt = tokio::runtime::Runtime::new().unwrap();
let network = rt.block_on(async { let network = rt.block_on(async {
@@ -242,7 +248,7 @@ impl ZombieNode {
self.shutdown() self.shutdown()
.context("Failed to gracefully shutdown after eth proxy start error")?; .context("Failed to gracefully shutdown after eth proxy start error")?;
return Err(err); return Err(err);
}, }
} }
tracing::debug!("eth-rpc is up"); tracing::debug!("eth-rpc is up");
@@ -266,7 +272,10 @@ impl ZombieNode {
let output = cmd.output().context("Failed to export the chain-spec")?; let output = cmd.output().context("Failed to export the chain-spec")?;
if !output.status.success() { if !output.status.success() {
anyhow::bail!("Build chain-spec failed: {}", String::from_utf8_lossy(&output.stderr)); anyhow::bail!(
"Build chain-spec failed: {}",
String::from_utf8_lossy(&output.stderr)
);
} }
let content = String::from_utf8(output.stdout) let content = String::from_utf8(output.stdout)
@@ -327,7 +336,10 @@ impl ZombieNode {
&self, &self,
genesis: &Genesis, genesis: &Genesis,
) -> anyhow::Result<Vec<(String, u128)>> { ) -> anyhow::Result<Vec<(String, u128)>> {
genesis.alloc.iter().try_fold(Vec::new(), |mut vec, (address, acc)| { genesis
.alloc
.iter()
.try_fold(Vec::new(), |mut vec, (address, acc)| {
let polkadot_address = Self::eth_to_polkadot_address(address); let polkadot_address = Self::eth_to_polkadot_address(address);
let balance = acc.balance.try_into()?; let balance = acc.balance.try_into()?;
vec.push((polkadot_address, balance)); vec.push((polkadot_address, balance));
@@ -663,7 +675,10 @@ impl<F: TxFiller<ReviveNetwork>, P: Provider<ReviveNetwork>> ResolverApi
.context("Failed to get the zombie block")? .context("Failed to get the zombie block")?
.context("Failed to get the zombie block, perhaps the chain has no blocks?") .context("Failed to get the zombie block, perhaps the chain has no blocks?")
.and_then(|block| { .and_then(|block| {
block.header.base_fee_per_gas.context("Failed to get the base fee per gas") block
.header
.base_fee_per_gas
.context("Failed to get the base fee per gas")
}) })
}) })
} }
@@ -775,8 +790,10 @@ mod tests {
pub async fn new_node() -> (TestExecutionContext, ZombieNode) { pub async fn new_node() -> (TestExecutionContext, ZombieNode) {
let context = test_config(); let context = test_config();
let mut node = let mut node = ZombieNode::new(
ZombieNode::new(context.polkadot_parachain_configuration.path.clone(), &context); context.polkadot_parachain_configuration.path.clone(),
&context,
);
let genesis = context.genesis_configuration.genesis().unwrap().clone(); let genesis = context.genesis_configuration.genesis().unwrap().clone();
node.init(genesis).unwrap(); node.init(genesis).unwrap();
@@ -841,11 +858,14 @@ mod tests {
"#; "#;
let context = test_config(); let context = test_config();
let mut node = let mut node = ZombieNode::new(
ZombieNode::new(context.polkadot_parachain_configuration.path.clone(), &context); context.polkadot_parachain_configuration.path.clone(),
&context,
);
// Call `init()` // Call `init()`
node.init(serde_json::from_str(genesis_content).unwrap()).expect("init failed"); node.init(serde_json::from_str(genesis_content).unwrap())
.expect("init failed");
// Check that the patched chainspec file was generated // Check that the patched chainspec file was generated
let final_chainspec_path = node.base_directory.join(ZombieNode::CHAIN_SPEC_JSON_FILE); let final_chainspec_path = node.base_directory.join(ZombieNode::CHAIN_SPEC_JSON_FILE);
@@ -886,7 +906,10 @@ mod tests {
"#; "#;
let context = test_config(); let context = test_config();
let node = ZombieNode::new(context.polkadot_parachain_configuration.path.clone(), &context); let node = ZombieNode::new(
context.polkadot_parachain_configuration.path.clone(),
&context,
);
let result = node let result = node
.extract_balance_from_genesis_file(&serde_json::from_str(genesis_json).unwrap()) .extract_balance_from_genesis_file(&serde_json::from_str(genesis_json).unwrap())
@@ -948,7 +971,10 @@ mod tests {
for (eth_addr, expected_ss58) in cases { for (eth_addr, expected_ss58) in cases {
let result = ZombieNode::eth_to_polkadot_address(&eth_addr.parse().unwrap()); let result = ZombieNode::eth_to_polkadot_address(&eth_addr.parse().unwrap());
assert_eq!(result, expected_ss58, "Mismatch for Ethereum address {eth_addr}"); assert_eq!(
result, expected_ss58,
"Mismatch for Ethereum address {eth_addr}"
);
} }
} }
@@ -956,7 +982,10 @@ mod tests {
fn eth_rpc_version_works() { fn eth_rpc_version_works() {
// Arrange // Arrange
let context = test_config(); let context = test_config();
let node = ZombieNode::new(context.polkadot_parachain_configuration.path.clone(), &context); let node = ZombieNode::new(
context.polkadot_parachain_configuration.path.clone(),
&context,
);
// Act // Act
let version = node.eth_rpc_version().unwrap(); let version = node.eth_rpc_version().unwrap();
@@ -972,7 +1001,10 @@ mod tests {
fn version_works() { fn version_works() {
// Arrange // Arrange
let context = test_config(); let context = test_config();
let node = ZombieNode::new(context.polkadot_parachain_configuration.path.clone(), &context); let node = ZombieNode::new(
context.polkadot_parachain_configuration.path.clone(),
&context,
);
// Act // Act
let version = node.version().unwrap(); let version = node.version().unwrap();
@@ -1010,8 +1042,12 @@ mod tests {
let node = shared_node().await; let node = shared_node().await;
// Act // Act
let gas_limit = let gas_limit = node
node.resolver().await.unwrap().block_gas_limit(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_gas_limit(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = gas_limit.expect("Failed to get the gas limit"); let _ = gas_limit.expect("Failed to get the gas limit");
@@ -1024,8 +1060,12 @@ mod tests {
let node = shared_node().await; let node = shared_node().await;
// Act // Act
let coinbase = let coinbase = node
node.resolver().await.unwrap().block_coinbase(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_coinbase(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = coinbase.expect("Failed to get the coinbase"); let _ = coinbase.expect("Failed to get the coinbase");
@@ -1038,8 +1078,12 @@ mod tests {
let node = shared_node().await; let node = shared_node().await;
// Act // Act
let block_difficulty = let block_difficulty = node
node.resolver().await.unwrap().block_difficulty(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_difficulty(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_difficulty.expect("Failed to get the block difficulty"); let _ = block_difficulty.expect("Failed to get the block difficulty");
@@ -1052,7 +1096,12 @@ mod tests {
let node = shared_node().await; let node = shared_node().await;
// Act // Act
let block_hash = node.resolver().await.unwrap().block_hash(BlockNumberOrTag::Latest).await; let block_hash = node
.resolver()
.await
.unwrap()
.block_hash(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_hash.expect("Failed to get the block hash"); let _ = block_hash.expect("Failed to get the block hash");
@@ -1065,8 +1114,12 @@ mod tests {
let node = shared_node().await; let node = shared_node().await;
// Act // Act
let block_timestamp = let block_timestamp = node
node.resolver().await.unwrap().block_timestamp(BlockNumberOrTag::Latest).await; .resolver()
.await
.unwrap()
.block_timestamp(BlockNumberOrTag::Latest)
.await;
// Assert // Assert
let _ = block_timestamp.expect("Failed to get the block timestamp"); let _ = block_timestamp.expect("Failed to get the block timestamp");
@@ -11,7 +11,9 @@ pub struct ConcurrencyLimiterLayer {
impl ConcurrencyLimiterLayer { impl ConcurrencyLimiterLayer {
pub fn new(permit_count: usize) -> Self { pub fn new(permit_count: usize) -> Self {
Self { semaphore: Arc::new(Semaphore::new(permit_count)) } Self {
semaphore: Arc::new(Semaphore::new(permit_count)),
}
} }
} }
@@ -19,7 +21,10 @@ impl<S> Layer<S> for ConcurrencyLimiterLayer {
type Service = ConcurrencyLimiterService<S>; type Service = ConcurrencyLimiterService<S>;
fn layer(&self, inner: S) -> Self::Service { fn layer(&self, inner: S) -> Self::Service {
ConcurrencyLimiterService { service: inner, semaphore: self.semaphore.clone() } ConcurrencyLimiterService {
service: inner,
semaphore: self.semaphore.clone(),
}
} }
} }
@@ -50,7 +55,10 @@ where
let future = self.service.call(req); let future = self.service.call(req);
Box::pin(async move { Box::pin(async move {
let _permit = semaphore.acquire().await.expect("Semaphore has been closed"); let _permit = semaphore
.acquire()
.await
.expect("Semaphore has been closed");
tracing::debug!( tracing::debug!(
available_permits = semaphore.available_permits(), available_permits = semaphore.available_permits(),
"Acquired Semaphore Permit" "Acquired Semaphore Permit"
@@ -21,7 +21,12 @@ impl FallbackGasFiller {
default_max_fee_per_gas: u128, default_max_fee_per_gas: u128,
default_priority_fee: u128, default_priority_fee: u128,
) -> Self { ) -> Self {
Self { inner: GasFiller, default_gas_limit, default_max_fee_per_gas, default_priority_fee } Self {
inner: GasFiller,
default_gas_limit,
default_max_fee_per_gas,
default_priority_fee,
}
} }
} }
+14 -9
View File
@@ -80,8 +80,10 @@ where
NonceFiller: TxFiller<N>, NonceFiller: TxFiller<N>,
WalletFiller<W>: TxFiller<N>, WalletFiller<W>: TxFiller<N>,
{ {
let sendable_transaction = let sendable_transaction = provider
provider.fill(transaction).await.context("Failed to fill transaction")?; .fill(transaction)
.await
.context("Failed to fill transaction")?;
let transaction_envelope = sendable_transaction let transaction_envelope = sendable_transaction
.try_into_envelope() .try_into_envelope()
@@ -98,17 +100,19 @@ where
} else { } else {
return Err(error).context(format!("Failed to submit transaction {tx_hash}")); return Err(error).context(format!("Failed to submit transaction {tx_hash}"));
} }
}, }
}; };
debug!(%tx_hash, "Submitted Transaction"); debug!(%tx_hash, "Submitted Transaction");
pending_transaction.set_timeout(Some(Duration::from_secs(120))); pending_transaction.set_timeout(Some(Duration::from_secs(120)));
let tx_hash = pending_transaction let tx_hash = pending_transaction.watch().await.context(format!(
.watch() "Transaction inclusion watching timeout for {tx_hash}"
.await ))?;
.context(format!("Transaction inclusion watching timeout for {tx_hash}"))?;
poll(Duration::from_secs(60), PollingWaitBehavior::Constant(Duration::from_secs(3)), || { poll(
Duration::from_secs(60),
PollingWaitBehavior::Constant(Duration::from_secs(3)),
|| {
let provider = provider.clone(); let provider = provider.clone();
async move { async move {
@@ -117,7 +121,8 @@ where
_ => Ok(ControlFlow::Continue(())), _ => Ok(ControlFlow::Continue(())),
} }
} }
}) },
)
.await .await
.context(format!("Polling for receipt failed for {tx_hash}")) .context(format!("Polling for receipt failed for {tx_hash}"))
} }
+87 -37
View File
@@ -66,45 +66,50 @@ impl ReportAggregator {
match event { match event {
RunnerEvent::SubscribeToEvents(event) => { RunnerEvent::SubscribeToEvents(event) => {
self.handle_subscribe_to_events_event(*event); self.handle_subscribe_to_events_event(*event);
}, }
RunnerEvent::CorpusFileDiscovery(event) => RunnerEvent::CorpusFileDiscovery(event) => {
self.handle_corpus_file_discovered_event(*event), self.handle_corpus_file_discovered_event(*event)
}
RunnerEvent::MetadataFileDiscovery(event) => { RunnerEvent::MetadataFileDiscovery(event) => {
self.handle_metadata_file_discovery_event(*event); self.handle_metadata_file_discovery_event(*event);
}, }
RunnerEvent::TestCaseDiscovery(event) => { RunnerEvent::TestCaseDiscovery(event) => {
self.handle_test_case_discovery(*event); self.handle_test_case_discovery(*event);
}, }
RunnerEvent::TestSucceeded(event) => { RunnerEvent::TestSucceeded(event) => {
self.handle_test_succeeded_event(*event); self.handle_test_succeeded_event(*event);
}, }
RunnerEvent::TestFailed(event) => { RunnerEvent::TestFailed(event) => {
self.handle_test_failed_event(*event); self.handle_test_failed_event(*event);
}, }
RunnerEvent::TestIgnored(event) => { RunnerEvent::TestIgnored(event) => {
self.handle_test_ignored_event(*event); self.handle_test_ignored_event(*event);
}, }
RunnerEvent::NodeAssigned(event) => { RunnerEvent::NodeAssigned(event) => {
self.handle_node_assigned_event(*event); self.handle_node_assigned_event(*event);
}, }
RunnerEvent::PreLinkContractsCompilationSucceeded(event) => RunnerEvent::PreLinkContractsCompilationSucceeded(event) => {
self.handle_pre_link_contracts_compilation_succeeded_event(*event), self.handle_pre_link_contracts_compilation_succeeded_event(*event)
RunnerEvent::PostLinkContractsCompilationSucceeded(event) => }
self.handle_post_link_contracts_compilation_succeeded_event(*event), RunnerEvent::PostLinkContractsCompilationSucceeded(event) => {
RunnerEvent::PreLinkContractsCompilationFailed(event) => self.handle_post_link_contracts_compilation_succeeded_event(*event)
self.handle_pre_link_contracts_compilation_failed_event(*event), }
RunnerEvent::PostLinkContractsCompilationFailed(event) => RunnerEvent::PreLinkContractsCompilationFailed(event) => {
self.handle_post_link_contracts_compilation_failed_event(*event), self.handle_pre_link_contracts_compilation_failed_event(*event)
}
RunnerEvent::PostLinkContractsCompilationFailed(event) => {
self.handle_post_link_contracts_compilation_failed_event(*event)
}
RunnerEvent::LibrariesDeployed(event) => { RunnerEvent::LibrariesDeployed(event) => {
self.handle_libraries_deployed_event(*event); self.handle_libraries_deployed_event(*event);
}, }
RunnerEvent::ContractDeployed(event) => { RunnerEvent::ContractDeployed(event) => {
self.handle_contract_deployed_event(*event); self.handle_contract_deployed_event(*event);
}, }
RunnerEvent::Completion(event) => { RunnerEvent::Completion(event) => {
self.handle_completion(*event); self.handle_completion(*event);
break; break;
}, }
} }
} }
debug!("Report aggregation completed"); debug!("Report aggregation completed");
@@ -118,8 +123,12 @@ impl ReportAggregator {
file_name.push_str(".json"); file_name.push_str(".json");
file_name file_name
}; };
let file_path = let file_path = self
self.report.context.working_directory_configuration().as_path().join(file_name); .report
.context
.working_directory_configuration()
.as_path()
.join(file_name);
let file = OpenOptions::new() let file = OpenOptions::new()
.create(true) .create(true)
.write(true) .write(true)
@@ -127,7 +136,10 @@ impl ReportAggregator {
.read(false) .read(false)
.open(&file_path) .open(&file_path)
.with_context(|| { .with_context(|| {
format!("Failed to open report file for writing: {}", file_path.display()) format!(
"Failed to open report file for writing: {}",
file_path.display()
)
})?; })?;
serde_json::to_writer_pretty(&file, &self.report).with_context(|| { serde_json::to_writer_pretty(&file, &self.report).with_context(|| {
format!("Failed to serialize report JSON to {}", file_path.display()) format!("Failed to serialize report JSON to {}", file_path.display())
@@ -168,8 +180,9 @@ impl ReportAggregator {
// Add information on the fact that the case was ignored to the report. // Add information on the fact that the case was ignored to the report.
let test_case_report = self.test_case_report(&event.test_specifier); let test_case_report = self.test_case_report(&event.test_specifier);
test_case_report.status = test_case_report.status = Some(TestCaseStatus::Succeeded {
Some(TestCaseStatus::Succeeded { steps_executed: event.steps_executed }); steps_executed: event.steps_executed,
});
self.handle_post_test_case_status_update(&event.test_specifier); self.handle_post_test_case_status_update(&event.test_specifier);
} }
@@ -184,7 +197,9 @@ impl ReportAggregator {
// Add information on the fact that the case was ignored to the report. // Add information on the fact that the case was ignored to the report.
let test_case_report = self.test_case_report(&event.test_specifier); let test_case_report = self.test_case_report(&event.test_specifier);
test_case_report.status = Some(TestCaseStatus::Failed { reason: event.reason }); test_case_report.status = Some(TestCaseStatus::Failed {
reason: event.reason,
});
self.handle_post_test_case_status_update(&event.test_specifier); self.handle_post_test_case_status_update(&event.test_specifier);
} }
@@ -226,7 +241,10 @@ impl ReportAggregator {
.or_default() .or_default()
.iter() .iter()
.map(|(case_idx, case_report)| { .map(|(case_idx, case_report)| {
(*case_idx, case_report.status.clone().expect("Can't be uninitialized")) (
*case_idx,
case_report.status.clone().expect("Can't be uninitialized"),
)
}) })
.collect::<BTreeMap<_, _>>(); .collect::<BTreeMap<_, _>>();
let event = ReporterEvent::MetadataFileSolcModeCombinationExecutionCompleted { let event = ReporterEvent::MetadataFileSolcModeCombinationExecutionCompleted {
@@ -258,13 +276,29 @@ impl ReportAggregator {
&mut self, &mut self,
event: PreLinkContractsCompilationSucceededEvent, event: PreLinkContractsCompilationSucceededEvent,
) { ) {
let include_input = self.report.context.report_configuration().include_compiler_input; let include_input = self
let include_output = self.report.context.report_configuration().include_compiler_output; .report
.context
.report_configuration()
.include_compiler_input;
let include_output = self
.report
.context
.report_configuration()
.include_compiler_output;
let execution_information = self.execution_information(&event.execution_specifier); let execution_information = self.execution_information(&event.execution_specifier);
let compiler_input = if include_input { event.compiler_input } else { None }; let compiler_input = if include_input {
let compiler_output = if include_output { Some(event.compiler_output) } else { None }; event.compiler_input
} else {
None
};
let compiler_output = if include_output {
Some(event.compiler_output)
} else {
None
};
execution_information.pre_link_compilation_status = Some(CompilationStatus::Success { execution_information.pre_link_compilation_status = Some(CompilationStatus::Success {
is_cached: event.is_cached, is_cached: event.is_cached,
@@ -279,13 +313,29 @@ impl ReportAggregator {
&mut self, &mut self,
event: PostLinkContractsCompilationSucceededEvent, event: PostLinkContractsCompilationSucceededEvent,
) { ) {
let include_input = self.report.context.report_configuration().include_compiler_input; let include_input = self
let include_output = self.report.context.report_configuration().include_compiler_output; .report
.context
.report_configuration()
.include_compiler_input;
let include_output = self
.report
.context
.report_configuration()
.include_compiler_output;
let execution_information = self.execution_information(&event.execution_specifier); let execution_information = self.execution_information(&event.execution_specifier);
let compiler_input = if include_input { event.compiler_input } else { None }; let compiler_input = if include_input {
let compiler_output = if include_output { Some(event.compiler_output) } else { None }; event.compiler_input
} else {
None
};
let compiler_output = if include_output {
Some(event.compiler_output)
} else {
None
};
execution_information.post_link_compilation_status = Some(CompilationStatus::Success { execution_information.post_link_compilation_status = Some(CompilationStatus::Success {
is_cached: event.is_cached, is_cached: event.is_cached,
@@ -325,8 +375,8 @@ impl ReportAggregator {
} }
fn handle_libraries_deployed_event(&mut self, event: LibrariesDeployedEvent) { fn handle_libraries_deployed_event(&mut self, event: LibrariesDeployedEvent) {
self.execution_information(&event.execution_specifier).deployed_libraries = self.execution_information(&event.execution_specifier)
Some(event.libraries); .deployed_libraries = Some(event.libraries);
} }
fn handle_contract_deployed_event(&mut self, event: ContractDeployedEvent) { fn handle_contract_deployed_event(&mut self, event: ContractDeployedEvent) {
+24 -5
View File
@@ -34,11 +34,19 @@ pub(crate) async fn get_or_download(
} }
create_dir_all(&target_directory).with_context(|| { create_dir_all(&target_directory).with_context(|| {
format!("Failed to create solc cache directory: {}", target_directory.display()) format!(
"Failed to create solc cache directory: {}",
target_directory.display()
)
})?; })?;
download_to_file(&target_file, downloader) download_to_file(&target_file, downloader)
.await .await
.with_context(|| format!("Failed to write downloaded solc to {}", target_file.display()))?; .with_context(|| {
format!(
"Failed to write downloaded solc to {}",
target_file.display()
)
})?;
cache.insert(target_file.clone()); cache.insert(target_file.clone());
Ok((downloader.version.clone(), target_file)) Ok((downloader.version.clone(), target_file))
@@ -62,7 +70,12 @@ async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::R
} }
let mut file = BufWriter::new(file); let mut file = BufWriter::new(file);
file.write_all(&downloader.download().await.context("Failed to download solc binary bytes")?) file.write_all(
&downloader
.download()
.await
.context("Failed to download solc binary bytes")?,
)
.with_context(|| format!("Failed to write solc binary to {}", path.display()))?; .with_context(|| format!("Failed to write solc binary to {}", path.display()))?;
file.flush() file.flush()
.with_context(|| format!("Failed to flush file {}", path.display()))?; .with_context(|| format!("Failed to flush file {}", path.display()))?;
@@ -78,11 +91,17 @@ async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::R
.stdout(std::process::Stdio::null()) .stdout(std::process::Stdio::null())
.spawn() .spawn()
.with_context(|| { .with_context(|| {
format!("Failed to spawn xattr to remove quarantine attribute on {}", path.display()) format!(
"Failed to spawn xattr to remove quarantine attribute on {}",
path.display()
)
})? })?
.wait() .wait()
.with_context(|| { .with_context(|| {
format!("Failed waiting for xattr operation to complete on {}", path.display()) format!(
"Failed waiting for xattr operation to complete on {}",
path.display()
)
})?; })?;
Ok(()) Ok(())
+52 -11
View File
@@ -67,7 +67,11 @@ impl SolcDownloader {
) -> anyhow::Result<Self> { ) -> anyhow::Result<Self> {
let version_or_requirement = version.into(); let version_or_requirement = version.into();
match version_or_requirement { match version_or_requirement {
VersionOrRequirement::Version(version) => Ok(Self { version, target, list }), VersionOrRequirement::Version(version) => Ok(Self {
version,
target,
list,
}),
VersionOrRequirement::Requirement(requirement) => { VersionOrRequirement::Requirement(requirement) => {
let Some(version) = List::download(list) let Some(version) = List::download(list)
.await .await
@@ -80,8 +84,12 @@ impl SolcDownloader {
else { else {
anyhow::bail!("Failed to find a version that satisfies {requirement:?}"); anyhow::bail!("Failed to find a version that satisfies {requirement:?}");
}; };
Ok(Self { version, target, list }) Ok(Self {
}, version,
target,
list,
})
}
} }
} }
@@ -122,7 +130,11 @@ impl SolcDownloader {
})?; })?;
let path = build.path.clone(); let path = build.path.clone();
let expected_digest = build.sha256.strip_prefix("0x").unwrap_or(&build.sha256).to_string(); let expected_digest = build
.sha256
.strip_prefix("0x")
.unwrap_or(&build.sha256)
.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)
@@ -147,25 +159,54 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn try_get_windows() { async fn try_get_windows() {
let version = List::download(List::WINDOWS_URL).await.unwrap().latest_release; let version = List::download(List::WINDOWS_URL)
SolcDownloader::windows(version).await.unwrap().download().await.unwrap(); .await
.unwrap()
.latest_release;
SolcDownloader::windows(version)
.await
.unwrap()
.download()
.await
.unwrap();
} }
#[tokio::test] #[tokio::test]
async fn try_get_macosx() { async fn try_get_macosx() {
let version = List::download(List::MACOSX_URL).await.unwrap().latest_release; let version = List::download(List::MACOSX_URL)
SolcDownloader::macosx(version).await.unwrap().download().await.unwrap(); .await
.unwrap()
.latest_release;
SolcDownloader::macosx(version)
.await
.unwrap()
.download()
.await
.unwrap();
} }
#[tokio::test] #[tokio::test]
async fn try_get_linux() { async fn try_get_linux() {
let version = List::download(List::LINUX_URL).await.unwrap().latest_release; let version = List::download(List::LINUX_URL)
SolcDownloader::linux(version).await.unwrap().download().await.unwrap(); .await
.unwrap()
.latest_release;
SolcDownloader::linux(version)
.await
.unwrap()
.download()
.await
.unwrap();
} }
#[tokio::test] #[tokio::test]
async fn try_get_wasm() { async fn try_get_wasm() {
let version = List::download(List::WASM_URL).await.unwrap().latest_release; let version = List::download(List::WASM_URL).await.unwrap().latest_release;
SolcDownloader::wasm(version).await.unwrap().download().await.unwrap(); SolcDownloader::wasm(version)
.await
.unwrap()
.download()
.await
.unwrap();
} }
} }