From 5c957e5ac1cd4094d678b67f93e145f8c7fc6bc3 Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Tue, 22 Jul 2025 09:07:01 +0300 Subject: [PATCH 1/5] Add a way to skip tests if they don't match the target --- crates/core/src/driver/mod.rs | 56 ++++++++++++++++++---------------- crates/core/src/lib.rs | 4 +-- crates/format/src/case.rs | 10 +++++- crates/format/src/input.rs | 2 +- crates/format/src/metadata.rs | 1 + crates/node/src/geth.rs | 8 +++++ crates/node/src/kitchensink.rs | 8 +++++ crates/node/src/lib.rs | 4 +++ 8 files changed, 63 insertions(+), 30 deletions(-) diff --git a/crates/core/src/driver/mod.rs b/crates/core/src/driver/mod.rs index 0f76c9b..d8a2f01 100644 --- a/crates/core/src/driver/mod.rs +++ b/crates/core/src/driver/mod.rs @@ -26,6 +26,7 @@ use revive_dt_format::case::CaseIdx; use revive_dt_format::input::{Calldata, Expected, ExpectedOutput, Method}; use revive_dt_format::metadata::{ContractInstance, ContractPathAndIdentifier}; use revive_dt_format::{input::Input, metadata::Metadata, mode::SolcMode}; +use revive_dt_node::Node; use revive_dt_node_interaction::EthereumNode; use revive_dt_report::reporter::{CompilationTask, Report, Span}; use revive_solc_json_interface::SolcStandardJsonOutput; @@ -435,16 +436,15 @@ where // Additionally, what happens if the compiler filter doesn't match? Do we consider that the // transaction should succeed? Do we just ignore the expectation? + let error_span = + tracing::error_span!("Exception failed", ?tracing_result, ?execution_receipt,); + let _guard = error_span.enter(); + // Handling the receipt state assertion. let expected = !expectation.exception; let actual = execution_receipt.status(); if actual != expected { - tracing::error!( - ?execution_receipt, - expected, - actual, - "Transaction status assertion failed", - ); + tracing::error!(expected, actual, "Transaction status assertion failed",); anyhow::bail!( "Transaction status assertion failed - Expected {expected} but got {actual}", ); @@ -457,7 +457,11 @@ where .map(Bytes::from)?; let actual = tracing_result.output.clone().unwrap_or_default(); if !expected.starts_with(&actual) { - tracing::error!(?execution_receipt, %expected, %actual, "Calldata assertion failed"); + tracing::error!( + %expected, + %actual, + "Calldata assertion failed" + ); anyhow::bail!("Calldata assertion failed - Expected {expected} but got {actual}",); } } @@ -468,12 +472,7 @@ where let expected = expected_events.len(); let actual = execution_receipt.logs().len(); if actual != expected { - tracing::error!( - ?execution_receipt, - expected, - actual, - "Event count assertion failed", - ); + tracing::error!(expected, actual, "Event count assertion failed",); anyhow::bail!( "Event count assertion failed - Expected {expected} but got {actual}", ); @@ -489,7 +488,6 @@ where let actual = actual_event.address(); if actual != expected { tracing::error!( - ?execution_receipt, %expected, %actual, "Event emitter assertion failed", @@ -511,12 +509,7 @@ where .calldata(self.deployed_contracts.entry(case_idx).or_default(), node)?; let actual = actual_topic.to_vec(); if actual != expected { - tracing::error!( - ?execution_receipt, - ?expected, - ?actual, - "Event topics assertion failed", - ); + tracing::error!(?expected, ?actual, "Event topics assertion failed",); anyhow::bail!( "Event topics assertion failed - Expected {expected:?} but got {actual:?}", ); @@ -530,12 +523,7 @@ where .map(Bytes::from)?; let actual = &actual_event.data().data; if !expected.starts_with(actual) { - tracing::error!( - ?execution_receipt, - ?expected, - ?actual, - "Event value assertion failed", - ); + tracing::error!(?expected, ?actual, "Event value assertion failed",); anyhow::bail!( "Event value assertion failed - Expected {expected:?} but got {actual:?}", ); @@ -649,6 +637,22 @@ where let tracing_span = tracing::info_span!("Handling metadata file"); let _guard = tracing_span.enter(); + // We only execute this input if it's valid for the leader and the follower. Otherwise, we + // skip it with a warning. + if !self + .leader_node + .matches_target(self.metadata.targets.as_deref()) + || !self + .follower_node + .matches_target(self.metadata.targets.as_deref()) + { + tracing::warn!( + targets = ?self.metadata.targets, + "Either the leader or follower node do not support the targets of the file" + ); + return execution_result; + } + for mode in self.metadata.solc_modes() { let tracing_span = tracing::info_span!("With solc mode", solc_mode = ?mode); let _guard = tracing_span.enter(); diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index e9bcdd1..f7df15c 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -5,7 +5,7 @@ use revive_dt_compiler::{SolidityCompiler, revive_resolc, solc}; use revive_dt_config::TestingPlatform; -use revive_dt_node::{geth, kitchensink::KitchensinkNode}; +use revive_dt_node::{Node, geth, kitchensink::KitchensinkNode}; use revive_dt_node_interaction::EthereumNode; pub mod common; @@ -15,7 +15,7 @@ pub mod driver; /// /// For this we need a blockchain node implementation and a compiler. pub trait Platform { - type Blockchain: EthereumNode; + type Blockchain: EthereumNode + Node; type Compiler: SolidityCompiler; /// Returns the matching [TestingPlatform] of the [revive_dt_config::Arguments]. diff --git a/crates/format/src/case.rs b/crates/format/src/case.rs index 4a5802b..998c1d8 100644 --- a/crates/format/src/case.rs +++ b/crates/format/src/case.rs @@ -26,7 +26,15 @@ impl Case { .enumerate() .map(move |(idx, mut input)| { if idx + 1 == inputs_len { - input.expected = self.expected.clone(); + if input.expected.is_none() { + input.expected = self.expected.clone(); + } + + // TODO: What does it mean for us to have an `expected` field on the case itself + // but the final input also has an expected field that doesn't match the one on + // the case? What are we supposed to do with that final expected field on the + // case? + input } else { input diff --git a/crates/format/src/input.rs b/crates/format/src/input.rs index e682243..e3d06e5 100644 --- a/crates/format/src/input.rs +++ b/crates/format/src/input.rs @@ -324,7 +324,7 @@ impl Input { chain_state_provider: &impl EthereumNode, ) -> anyhow::Result { let input_data = self.encoded_input(deployed_contracts, chain_state_provider)?; - let transaction_request = TransactionRequest::default(); + let transaction_request = TransactionRequest::default().from(self.caller); match self.method { Method::Deployer => Ok(transaction_request.with_deploy_code(input_data)), _ => Ok(transaction_request diff --git a/crates/format/src/metadata.rs b/crates/format/src/metadata.rs index c62c174..12b2316 100644 --- a/crates/format/src/metadata.rs +++ b/crates/format/src/metadata.rs @@ -48,6 +48,7 @@ impl Deref for MetadataFile { #[derive(Debug, Default, Deserialize, Clone, Eq, PartialEq)] pub struct Metadata { + pub targets: Option>, pub cases: Vec, pub contracts: Option>, // TODO: Convert into wrapper types for clarity. diff --git a/crates/node/src/geth.rs b/crates/node/src/geth.rs index 2d82e29..24c26ff 100644 --- a/crates/node/src/geth.rs +++ b/crates/node/src/geth.rs @@ -510,6 +510,14 @@ impl Node for Instance { .stdout; Ok(String::from_utf8_lossy(&output).into()) } + + #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] + fn matches_target(&self, targets: Option<&[String]>) -> bool { + match targets { + None => true, + Some(targets) => targets.iter().any(|str| str.as_str() == "evm"), + } + } } impl Drop for Instance { diff --git a/crates/node/src/kitchensink.rs b/crates/node/src/kitchensink.rs index 9a2fd86..6977036 100644 --- a/crates/node/src/kitchensink.rs +++ b/crates/node/src/kitchensink.rs @@ -584,6 +584,14 @@ impl Node for KitchensinkNode { .stdout; Ok(String::from_utf8_lossy(&output).into()) } + + #[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))] + fn matches_target(&self, targets: Option<&[String]>) -> bool { + match targets { + None => true, + Some(targets) => targets.iter().any(|str| str.as_str() == "pvm"), + } + } } impl Drop for KitchensinkNode { diff --git a/crates/node/src/lib.rs b/crates/node/src/lib.rs index 380f621..4b43474 100644 --- a/crates/node/src/lib.rs +++ b/crates/node/src/lib.rs @@ -35,4 +35,8 @@ pub trait Node: EthereumNode { /// Returns the node version. fn version(&self) -> anyhow::Result; + + /// Given a list of targets from the metadata file, this function determines if the metadata + /// file can be ran on this node or not. + fn matches_target(&self, targets: Option<&[String]>) -> bool; } From e7ebe4fa2f8f7649d48917b65fc1d097d3506fb4 Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Tue, 22 Jul 2025 09:24:09 +0300 Subject: [PATCH 2/5] Handle values from the metadata files --- crates/core/src/driver/mod.rs | 6 +++++ crates/format/src/input.rs | 48 ++++++++++++++++++++++++++++++---- crates/node/src/geth.rs | 3 ++- crates/node/src/kitchensink.rs | 2 +- genesis.json | 2 +- 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/crates/core/src/driver/mod.rs b/crates/core/src/driver/mod.rs index d8a2f01..544307f 100644 --- a/crates/core/src/driver/mod.rs +++ b/crates/core/src/driver/mod.rs @@ -251,6 +251,12 @@ where let tx = { let tx = TransactionRequest::default().from(input.caller); + let tx = match input.value { + Some(ref value) if deploy_with_constructor_arguments => { + tx.value(value.into_inner()) + } + _ => tx, + }; TransactionBuilder::::with_deploy_code(tx, code) }; diff --git a/crates/format/src/input.rs b/crates/format/src/input.rs index e3d06e5..fdf7a54 100644 --- a/crates/format/src/input.rs +++ b/crates/format/src/input.rs @@ -7,13 +7,16 @@ use alloy::{ primitives::{Address, Bytes, U256}, rpc::types::TransactionRequest, }; -use alloy_primitives::FixedBytes; +use alloy_primitives::{FixedBytes, utils::parse_units}; use semver::VersionReq; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use revive_dt_node_interaction::EthereumNode; -use crate::metadata::{AddressReplacementMap, ContractInstance}; +use crate::{ + define_wrapper_type, + metadata::{AddressReplacementMap, ContractInstance}, +}; #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] pub struct Input { @@ -26,7 +29,7 @@ pub struct Input { #[serde(default)] pub calldata: Calldata, pub expected: Option, - pub value: Option, + pub value: Option, pub storage: Option>, } @@ -82,6 +85,37 @@ pub enum Method { FunctionName(String), } +define_wrapper_type!( + #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] + EtherValue(U256); +); + +impl Serialize for EtherValue { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + format!("{} wei", self.0).serialize(serializer) + } +} + +impl<'de> Deserialize<'de> for EtherValue { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let string = String::deserialize(deserializer)?; + let mut splitted = string.split(' '); + let (Some(value), Some(unit)) = (splitted.next(), splitted.next()) else { + return Err(serde::de::Error::custom("Failed to parse the value")); + }; + let parsed = parse_units(value, unit.replace("eth", "ether")) + .map_err(|_| serde::de::Error::custom("Failed to parse units"))? + .into(); + Ok(Self(parsed)) + } +} + impl ExpectedOutput { pub fn new() -> Self { Default::default() @@ -324,7 +358,11 @@ impl Input { chain_state_provider: &impl EthereumNode, ) -> anyhow::Result { let input_data = self.encoded_input(deployed_contracts, chain_state_provider)?; - let transaction_request = TransactionRequest::default().from(self.caller); + let transaction_request = TransactionRequest::default().from(self.caller).value( + self.value + .map(|value| value.into_inner()) + .unwrap_or_default(), + ); match self.method { Method::Deployer => Ok(transaction_request.with_deploy_code(input_data)), _ => Ok(transaction_request diff --git a/crates/node/src/geth.rs b/crates/node/src/geth.rs index 24c26ff..8a1dd38 100644 --- a/crates/node/src/geth.rs +++ b/crates/node/src/geth.rs @@ -85,7 +85,8 @@ impl Instance { >::signer_addresses(&self.wallet) { genesis.alloc.entry(signer_address).or_insert( - GenesisAccount::default().with_balance(1000000000000000000u128.try_into().unwrap()), + GenesisAccount::default() + .with_balance(10000000000000000000000u128.try_into().unwrap()), ); } let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE); diff --git a/crates/node/src/kitchensink.rs b/crates/node/src/kitchensink.rs index 6977036..91dec27 100644 --- a/crates/node/src/kitchensink.rs +++ b/crates/node/src/kitchensink.rs @@ -131,7 +131,7 @@ impl KitchensinkNode { { genesis.alloc.entry(signer_address).or_insert( GenesisAccount::default() - .with_balance(1000000000000000000u128.try_into().unwrap()), + .with_balance(10000000000000000000000u128.try_into().unwrap()), ); } self.extract_balance_from_genesis_file(&genesis)? diff --git a/genesis.json b/genesis.json index ae85d1f..9993430 100644 --- a/genesis.json +++ b/genesis.json @@ -35,7 +35,7 @@ "timestamp": "0x00", "alloc": { "90F8bf6A479f320ead074411a4B0e7944Ea8c9C1": { - "balance": "1000000000000000000" + "balance": "10000000000000000000000" } } } \ No newline at end of file From 0392b6b629dc14194b1b54b6a8fd8987468b0df8 Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Tue, 22 Jul 2025 14:34:22 +0300 Subject: [PATCH 3/5] Remove address replacement --- crates/config/src/lib.rs | 6 ++ crates/core/src/main.rs | 86 +++----------------- crates/format/src/input.rs | 99 +---------------------- crates/format/src/metadata.rs | 140 +-------------------------------- crates/node/src/geth.rs | 28 +++---- crates/node/src/kitchensink.rs | 35 +++++---- crates/node/src/lib.rs | 6 +- crates/node/src/pool.rs | 23 +----- 8 files changed, 55 insertions(+), 368 deletions(-) diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 7f1c92e..9cc51df 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -73,6 +73,12 @@ pub struct Arguments { )] pub account: String, + /// This argument controls which private keys the nodes should have access to and be added to + /// its wallet signers. With a value of N, private keys (0, N] will be added to the signer set + /// of the node. + #[arg(short, long = "account", default_value_t = 30)] + pub private_keys_to_add: usize, + /// The differential testing leader node implementation. #[arg(short, long = "leader", default_value = "geth")] pub leader: TestingPlatform, diff --git a/crates/core/src/main.rs b/crates/core/src/main.rs index e64ea64..c8403af 100644 --- a/crates/core/src/main.rs +++ b/crates/core/src/main.rs @@ -1,13 +1,5 @@ -use std::{ - collections::{HashMap, HashSet}, - sync::LazyLock, -}; +use std::{collections::HashMap, sync::LazyLock}; -use alloy::{ - network::TxSigner, - primitives::FixedBytes, - signers::{Signature, local::PrivateKeySigner}, -}; use clap::Parser; use rayon::{ThreadPoolBuilder, prelude::*}; @@ -16,11 +8,7 @@ use revive_dt_core::{ Geth, Kitchensink, Platform, driver::{Driver, State}, }; -use revive_dt_format::{ - corpus::Corpus, - input::default_caller, - metadata::{AddressReplacementMap, MetadataFile}, -}; +use revive_dt_format::{corpus::Corpus, metadata::MetadataFile}; use revive_dt_node::pool::NodePool; use revive_dt_report::reporter::{Report, Span}; use temp_dir::TempDir; @@ -32,48 +20,12 @@ static TEMP_DIR: LazyLock = LazyLock::new(|| TempDir::new().unwrap()); fn main() -> anyhow::Result<()> { let args = init_cli()?; - let mut corpora = collect_corpora(&args)?; - let mut replacement_private_keys = HashSet::>::new(); - for case in corpora - .values_mut() - .flat_map(|metadata| metadata.iter_mut()) - .flat_map(|metadata| metadata.content.cases.iter_mut()) - { - let mut replacement_map = AddressReplacementMap::new(); - for address in case.inputs.iter().filter_map(|input| { - if input.caller != default_caller() { - Some(input.caller) - } else { - None - } - }) { - replacement_map.add(address); - } - case.handle_address_replacement(&mut replacement_map)?; - replacement_private_keys.extend( - replacement_map - .into_inner() - .into_values() - .map(|(sk, _)| sk) - .map(|sk| sk.to_bytes()), - ); - } - - for (corpus, tests) in corpora { + for (corpus, tests) in collect_corpora(&args)? { let span = Span::new(corpus, args.clone())?; match &args.compile_only { Some(platform) => compile_corpus(&args, &tests, platform, span), - None => execute_corpus( - &args, - &tests, - replacement_private_keys - .clone() - .into_iter() - .map(|bytes| PrivateKeySigner::from_bytes(&bytes).expect("Can't fail")) - .collect::>(), - span, - )?, + None => execute_corpus(&args, &tests, span)?, } Report::save()?; @@ -131,24 +83,15 @@ fn collect_corpora(args: &Arguments) -> anyhow::Result( - args: &Arguments, - tests: &[MetadataFile], - additional_signers: impl IntoIterator + Send + Sync + 'static> - + Clone - + Send - + Sync - + 'static, - span: Span, -) -> anyhow::Result<()> +fn run_driver(args: &Arguments, tests: &[MetadataFile], span: Span) -> anyhow::Result<()> where L: Platform, F: Platform, L::Blockchain: revive_dt_node::Node + Send + Sync + 'static, F::Blockchain: revive_dt_node::Node + Send + Sync + 'static, { - let leader_nodes = NodePool::::new(args, additional_signers.clone())?; - let follower_nodes = NodePool::::new(args, additional_signers)?; + let leader_nodes = NodePool::::new(args)?; + let follower_nodes = NodePool::::new(args)?; tests.par_iter().for_each( |MetadataFile { @@ -198,22 +141,13 @@ where Ok(()) } -fn execute_corpus( - args: &Arguments, - tests: &[MetadataFile], - additional_signers: impl IntoIterator + Send + Sync + 'static> - + Clone - + Send - + Sync - + 'static, - span: Span, -) -> anyhow::Result<()> { +fn execute_corpus(args: &Arguments, tests: &[MetadataFile], span: Span) -> anyhow::Result<()> { match (&args.leader, &args.follower) { (TestingPlatform::Geth, TestingPlatform::Kitchensink) => { - run_driver::(args, tests, additional_signers, span)? + run_driver::(args, tests, span)? } (TestingPlatform::Geth, TestingPlatform::Geth) => { - run_driver::(args, tests, additional_signers, span)? + run_driver::(args, tests, span)? } _ => unimplemented!(), } diff --git a/crates/format/src/input.rs b/crates/format/src/input.rs index fdf7a54..ad59177 100644 --- a/crates/format/src/input.rs +++ b/crates/format/src/input.rs @@ -13,10 +13,7 @@ use serde::{Deserialize, Serialize}; use revive_dt_node_interaction::EthereumNode; -use crate::{ - define_wrapper_type, - metadata::{AddressReplacementMap, ContractInstance}, -}; +use crate::{define_wrapper_type, metadata::ContractInstance}; #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] pub struct Input { @@ -135,41 +132,6 @@ impl ExpectedOutput { self.return_data = Some(calldata); self } - - pub fn handle_address_replacement( - &mut self, - old_to_new_mapping: &AddressReplacementMap, - ) -> anyhow::Result<()> { - if let Some(ref mut calldata) = self.return_data { - calldata.handle_address_replacement(old_to_new_mapping)?; - } - if let Some(ref mut events) = self.events { - for event in events.iter_mut() { - event.handle_address_replacement(old_to_new_mapping)?; - } - } - Ok(()) - } -} - -impl Event { - pub fn handle_address_replacement( - &mut self, - old_to_new_mapping: &AddressReplacementMap, - ) -> anyhow::Result<()> { - if let Some(ref mut address) = self.address { - if let Some(new_address) = old_to_new_mapping.resolve(address.to_string().as_str()) { - *address = new_address - } - }; - for topic in self.topics.iter_mut() { - if let Some(new_address) = old_to_new_mapping.resolve(topic.to_string().as_str()) { - *topic = new_address.to_string(); - } - } - self.values.handle_address_replacement(old_to_new_mapping)?; - Ok(()) - } } impl Default for Calldata { @@ -189,23 +151,6 @@ impl Calldata { } } - pub fn handle_address_replacement( - &mut self, - old_to_new_mapping: &AddressReplacementMap, - ) -> anyhow::Result<()> { - match self { - Calldata::Single(_) => {} - Calldata::Compound(items) => { - for item in items.iter_mut() { - if let Some(resolved) = old_to_new_mapping.resolve(item) { - *item = resolved.to_string() - } - } - } - } - Ok(()) - } - pub fn calldata( &self, deployed_contracts: &HashMap, @@ -251,27 +196,7 @@ impl Calldata { } } -impl Expected { - pub fn handle_address_replacement( - &mut self, - old_to_new_mapping: &AddressReplacementMap, - ) -> anyhow::Result<()> { - match self { - Expected::Calldata(calldata) => { - calldata.handle_address_replacement(old_to_new_mapping)?; - } - Expected::Expected(expected_output) => { - expected_output.handle_address_replacement(old_to_new_mapping)?; - } - Expected::ExpectedMany(expected_outputs) => { - for expected_output in expected_outputs.iter_mut() { - expected_output.handle_address_replacement(old_to_new_mapping)?; - } - } - } - Ok(()) - } -} +impl Expected {} impl Input { fn instance_to_address( @@ -379,26 +304,6 @@ impl Input { vec } - - pub fn handle_address_replacement( - &mut self, - old_to_new_mapping: &mut AddressReplacementMap, - ) -> anyhow::Result<()> { - if self.caller != default_caller() { - self.caller = old_to_new_mapping.add(self.caller); - } - self.calldata - .handle_address_replacement(old_to_new_mapping)?; - if let Some(ref mut expected) = self.expected { - expected.handle_address_replacement(old_to_new_mapping)?; - } - if let Some(ref mut storage) = self.storage { - for calldata in storage.values_mut() { - calldata.handle_address_replacement(old_to_new_mapping)?; - } - } - Ok(()) - } } fn default_instance() -> ContractInstance { diff --git a/crates/format/src/metadata.rs b/crates/format/src/metadata.rs index 12b2316..c1cef62 100644 --- a/crates/format/src/metadata.rs +++ b/crates/format/src/metadata.rs @@ -1,5 +1,5 @@ use std::{ - collections::{BTreeMap, HashMap}, + collections::BTreeMap, fmt::Display, fs::{File, read_to_string}, ops::Deref, @@ -7,15 +7,11 @@ use std::{ str::FromStr, }; -use alloy::signers::local::PrivateKeySigner; -use alloy_primitives::Address; -use revive_dt_node_interaction::EthereumNode; use serde::{Deserialize, Serialize}; use crate::{ case::Case, define_wrapper_type, - input::resolve_argument, mode::{Mode, SolcMode}, }; @@ -215,17 +211,6 @@ impl Metadata { } } } - - pub fn handle_address_replacement( - &mut self, - old_to_new_mapping: &mut AddressReplacementMap, - ) -> anyhow::Result<()> { - for case in self.cases.iter_mut() { - case.handle_address_replacement(old_to_new_mapping)?; - } - tracing::debug!(metadata = ?self, "Performed replacement on metadata"); - Ok(()) - } } define_wrapper_type!( @@ -324,129 +309,6 @@ impl From for String { } } -#[derive(Clone, Debug, Default)] -pub struct AddressReplacementMap(HashMap); - -impl AddressReplacementMap { - pub fn new() -> Self { - Self(Default::default()) - } - - pub fn into_inner(self) -> HashMap { - self.0 - } - - pub fn contains_key(&self, address: &Address) -> bool { - self.0.contains_key(address) - } - - pub fn add(&mut self, address: Address) -> Address { - self.0 - .entry(address) - .or_insert_with(|| { - let private_key = Self::new_random_private_key_signer(); - let account = private_key.address(); - tracing::debug!( - old_address = %address, - new_address = %account, - "Added a new address replacement" - ); - (private_key, account) - }) - .1 - } - - pub fn resolve(&self, value: &str) -> Option
{ - // We attempt to resolve the given string without any additional context of the deployed - // contracts or the node API as we do not need them. If the resolution fails then we know - // that this isn't an address and we skip it. - let Ok(resolved) = resolve_argument(value, &Default::default(), &UnimplementedEthereumNode) - else { - return None; - }; - let resolved_bytes = resolved.to_be_bytes_trimmed_vec(); - let Ok(address) = Address::try_from(resolved_bytes.as_slice()) else { - return None; - }; - self.0.get(&address).map(|(_, address)| *address) - } - - fn new_random_private_key_signer() -> PrivateKeySigner { - // TODO: Use a seedable RNG to allow for deterministic allocation of the private keys so - // that we get reproducible runs. - PrivateKeySigner::random() - } -} - -impl AsRef> for AddressReplacementMap { - fn as_ref(&self) -> &HashMap { - &self.0 - } -} - -struct UnimplementedEthereumNode; - -impl EthereumNode for UnimplementedEthereumNode { - fn execute_transaction( - &self, - _: alloy::rpc::types::TransactionRequest, - ) -> anyhow::Result { - anyhow::bail!("Unimplemented") - } - - fn chain_id(&self) -> anyhow::Result { - anyhow::bail!("Unimplemented") - } - - fn block_gas_limit(&self, _: alloy::eips::BlockNumberOrTag) -> anyhow::Result { - anyhow::bail!("Unimplemented") - } - - fn block_coinbase(&self, _: alloy::eips::BlockNumberOrTag) -> anyhow::Result
{ - anyhow::bail!("Unimplemented") - } - - fn block_difficulty( - &self, - _: alloy::eips::BlockNumberOrTag, - ) -> anyhow::Result { - anyhow::bail!("Unimplemented") - } - - fn block_hash( - &self, - _: alloy::eips::BlockNumberOrTag, - ) -> anyhow::Result { - anyhow::bail!("Unimplemented") - } - - fn block_timestamp( - &self, - _: alloy::eips::BlockNumberOrTag, - ) -> anyhow::Result { - anyhow::bail!("Unimplemented") - } - - fn last_block_number(&self) -> anyhow::Result { - anyhow::bail!("Unimplemented") - } - - fn trace_transaction( - &self, - _: &alloy::rpc::types::TransactionReceipt, - _: alloy::rpc::types::trace::geth::GethDebugTracingOptions, - ) -> anyhow::Result { - anyhow::bail!("Unimplemented") - } - - fn state_diff( - &self, - _: &alloy::rpc::types::TransactionReceipt, - ) -> anyhow::Result { - anyhow::bail!("Unimplemented") - } -} - #[cfg(test)] mod test { use super::*; diff --git a/crates/node/src/geth.rs b/crates/node/src/geth.rs index 8a1dd38..794650c 100644 --- a/crates/node/src/geth.rs +++ b/crates/node/src/geth.rs @@ -12,8 +12,8 @@ use std::{ use alloy::{ eips::BlockNumberOrTag, genesis::{Genesis, GenesisAccount}, - network::{Ethereum, EthereumWallet, NetworkWallet, TxSigner}, - primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, U256}, + network::{Ethereum, EthereumWallet, NetworkWallet}, + primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, FixedBytes, U256}, providers::{ Provider, ProviderBuilder, ext::DebugApi, @@ -23,7 +23,7 @@ use alloy::{ TransactionReceipt, TransactionRequest, trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame}, }, - signers::Signature, + signers::local::PrivateKeySigner, }; use revive_dt_config::Arguments; use revive_dt_node_interaction::{BlockingExecutor, EthereumNode}; @@ -435,16 +435,17 @@ impl EthereumNode for Instance { } impl Node for Instance { - fn new( - config: &Arguments, - additional_signers: impl IntoIterator + Send + Sync + 'static>, - ) -> Self { + fn new(config: &Arguments) -> Self { let geth_directory = config.directory().join(Self::BASE_DIRECTORY); let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst); let base_directory = geth_directory.join(id.to_string()); let mut wallet = config.wallet(); - for signer in additional_signers { + for signer in (1..=config.private_keys_to_add) + .map(|id| U256::from(id)) + .map(|id| id.to_be_bytes::<32>()) + .map(|id| PrivateKeySigner::from_bytes(&FixedBytes(id)).unwrap()) + { wallet.register_signer(signer); } @@ -532,7 +533,6 @@ impl Drop for Instance { mod tests { use revive_dt_config::Arguments; - use alloy::signers::local::PrivateKeySigner; use temp_dir::TempDir; use crate::{GENESIS_JSON, Node}; @@ -549,7 +549,7 @@ mod tests { fn new_node() -> (Instance, TempDir) { let (args, temp_dir) = test_config(); - let mut node = Instance::new(&args, Vec::::with_capacity(0)); + let mut node = Instance::new(&args); node.init(GENESIS_JSON.to_owned()) .expect("Failed to initialize the node") .spawn_process() @@ -559,23 +559,21 @@ mod tests { #[test] fn init_works() { - Instance::new(&test_config().0, Vec::::with_capacity(0)) + Instance::new(&test_config().0) .init(GENESIS_JSON.to_string()) .unwrap(); } #[test] fn spawn_works() { - Instance::new(&test_config().0, Vec::::with_capacity(0)) + Instance::new(&test_config().0) .spawn(GENESIS_JSON.to_string()) .unwrap(); } #[test] fn version_works() { - let version = Instance::new(&test_config().0, Vec::::with_capacity(0)) - .version() - .unwrap(); + let version = Instance::new(&test_config().0).version().unwrap(); assert!( version.starts_with("geth version"), "expected version string, got: '{version}'" diff --git a/crates/node/src/kitchensink.rs b/crates/node/src/kitchensink.rs index 91dec27..3820f08 100644 --- a/crates/node/src/kitchensink.rs +++ b/crates/node/src/kitchensink.rs @@ -13,9 +13,11 @@ use alloy::{ genesis::{Genesis, GenesisAccount}, network::{ Ethereum, EthereumWallet, Network, NetworkWallet, TransactionBuilder, - TransactionBuilderError, TxSigner, UnbuiltTransactionError, + TransactionBuilderError, UnbuiltTransactionError, + }, + primitives::{ + Address, B64, B256, BlockHash, BlockNumber, BlockTimestamp, Bloom, Bytes, FixedBytes, U256, }, - primitives::{Address, B64, B256, BlockHash, BlockNumber, BlockTimestamp, Bloom, Bytes, U256}, providers::{ Provider, ProviderBuilder, ext::DebugApi, @@ -26,7 +28,7 @@ use alloy::{ eth::{Block, Header, Transaction}, trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame}, }, - signers::Signature, + signers::local::PrivateKeySigner, }; use serde::{Deserialize, Serialize}; use serde_json::{Value as JsonValue, json}; @@ -504,17 +506,18 @@ impl EthereumNode for KitchensinkNode { } impl Node for KitchensinkNode { - fn new( - config: &Arguments, - additional_signers: impl IntoIterator + Send + Sync + 'static>, - ) -> Self { + fn new(config: &Arguments) -> Self { let kitchensink_directory = config.directory().join(Self::BASE_DIRECTORY); let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst); let base_directory = kitchensink_directory.join(id.to_string()); let logs_directory = base_directory.join(Self::LOGS_DIRECTORY); let mut wallet = config.wallet(); - for signer in additional_signers { + for signer in (1..=config.private_keys_to_add) + .map(|id| U256::from(id)) + .map(|id| id.to_be_bytes::<32>()) + .map(|id| PrivateKeySigner::from_bytes(&FixedBytes(id)).unwrap()) + { wallet.register_signer(signer); } @@ -1030,7 +1033,7 @@ impl BlockHeader for KitchenSinkHeader { #[cfg(test)] mod tests { - use alloy::{rpc::types::TransactionRequest, signers::local::PrivateKeySigner}; + use alloy::rpc::types::TransactionRequest; use revive_dt_config::Arguments; use std::path::PathBuf; use std::sync::{LazyLock, Mutex}; @@ -1073,7 +1076,7 @@ mod tests { let _guard = NODE_START_MUTEX.lock().unwrap(); let (args, temp_dir) = test_config(); - let mut node = KitchensinkNode::new(&args, Vec::::with_capacity(0)); + let mut node = KitchensinkNode::new(&args); node.init(GENESIS_JSON) .expect("Failed to initialize the node") .spawn_process() @@ -1128,8 +1131,7 @@ mod tests { } "#; - let mut dummy_node = - KitchensinkNode::new(&test_config().0, Vec::::with_capacity(0)); + let mut dummy_node = KitchensinkNode::new(&test_config().0); // Call `init()` dummy_node.init(genesis_content).expect("init failed"); @@ -1173,8 +1175,7 @@ mod tests { } "#; - let node = - KitchensinkNode::new(&test_config().0, Vec::::with_capacity(0)); + let node = KitchensinkNode::new(&test_config().0); let result = node .extract_balance_from_genesis_file(&serde_json::from_str(genesis_json).unwrap()) @@ -1247,7 +1248,7 @@ mod tests { fn spawn_works() { let (config, _temp_dir) = test_config(); - let mut node = KitchensinkNode::new(&config, Vec::::with_capacity(0)); + let mut node = KitchensinkNode::new(&config); node.spawn(GENESIS_JSON.to_string()).unwrap(); } @@ -1255,7 +1256,7 @@ mod tests { fn version_works() { let (config, _temp_dir) = test_config(); - let node = KitchensinkNode::new(&config, Vec::::with_capacity(0)); + let node = KitchensinkNode::new(&config); let version = node.version().unwrap(); assert!( @@ -1268,7 +1269,7 @@ mod tests { fn eth_rpc_version_works() { let (config, _temp_dir) = test_config(); - let node = KitchensinkNode::new(&config, Vec::::with_capacity(0)); + let node = KitchensinkNode::new(&config); let version = node.eth_rpc_version().unwrap(); assert!( diff --git a/crates/node/src/lib.rs b/crates/node/src/lib.rs index 4b43474..8084150 100644 --- a/crates/node/src/lib.rs +++ b/crates/node/src/lib.rs @@ -1,6 +1,5 @@ //! This crate implements the testing nodes. -use alloy::{network::TxSigner, signers::Signature}; use revive_dt_config::Arguments; use revive_dt_node_interaction::EthereumNode; @@ -15,10 +14,7 @@ pub const GENESIS_JSON: &str = include_str!("../../../genesis.json"); /// An abstract interface for testing nodes. pub trait Node: EthereumNode { /// Create a new uninitialized instance. - fn new( - config: &Arguments, - additional_signers: impl IntoIterator + Send + Sync + 'static>, - ) -> Self; + fn new(config: &Arguments) -> Self; /// Spawns a node configured according to the genesis json. /// diff --git a/crates/node/src/pool.rs b/crates/node/src/pool.rs index 363dc29..10d4d59 100644 --- a/crates/node/src/pool.rs +++ b/crates/node/src/pool.rs @@ -6,7 +6,6 @@ use std::{ thread, }; -use alloy::{network::TxSigner, signers::Signature}; use anyhow::Context; use revive_dt_config::Arguments; @@ -24,14 +23,7 @@ where T: Node + Send + 'static, { /// Create a new Pool. This will start as many nodes as there are workers in `config`. - pub fn new( - config: &Arguments, - additional_signers: impl IntoIterator + Send + Sync + 'static> - + Clone - + Send - + Sync - + 'static, - ) -> anyhow::Result { + pub fn new(config: &Arguments) -> anyhow::Result { let nodes = config.workers; let genesis = read_to_string(&config.genesis_file).context(format!( "can not read genesis file: {}", @@ -42,10 +34,7 @@ where for _ in 0..nodes { let config = config.clone(); let genesis = genesis.clone(); - let additional_signers = additional_signers.clone(); - handles.push(thread::spawn(move || { - spawn_node::(&config, additional_signers, genesis) - })); + handles.push(thread::spawn(move || spawn_node::(&config, genesis))); } let mut nodes = Vec::with_capacity(nodes); @@ -71,12 +60,8 @@ where } } -fn spawn_node( - args: &Arguments, - additional_signers: impl IntoIterator + Send + Sync + 'static>, - genesis: String, -) -> anyhow::Result { - let mut node = T::new(args, additional_signers); +fn spawn_node(args: &Arguments, genesis: String) -> anyhow::Result { + let mut node = T::new(args); tracing::info!("starting node: {}", node.connection_string()); node.spawn(genesis)?; Ok(node) From c81279fc8f1b69efd579dcb9461081b37cf83cdf Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Tue, 22 Jul 2025 14:37:02 +0300 Subject: [PATCH 4/5] Correct the arguments --- crates/config/src/lib.rs | 2 +- crates/format/src/case.rs | 14 -------------- crates/format/src/input.rs | 2 +- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 9cc51df..61211ad 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -76,7 +76,7 @@ pub struct Arguments { /// This argument controls which private keys the nodes should have access to and be added to /// its wallet signers. With a value of N, private keys (0, N] will be added to the signer set /// of the node. - #[arg(short, long = "account", default_value_t = 30)] + #[arg(short, long = "private-keys-count", default_value_t = 30)] pub private_keys_to_add: usize, /// The differential testing leader node implementation. diff --git a/crates/format/src/case.rs b/crates/format/src/case.rs index 998c1d8..29e4ef5 100644 --- a/crates/format/src/case.rs +++ b/crates/format/src/case.rs @@ -3,7 +3,6 @@ use serde::Deserialize; use crate::{ define_wrapper_type, input::{Expected, Input}, - metadata::AddressReplacementMap, mode::Mode, }; @@ -41,19 +40,6 @@ impl Case { } }) } - - pub fn handle_address_replacement( - &mut self, - old_to_new_mapping: &mut AddressReplacementMap, - ) -> anyhow::Result<()> { - for input in self.inputs.iter_mut() { - input.handle_address_replacement(old_to_new_mapping)?; - } - if let Some(ref mut expected) = self.expected { - expected.handle_address_replacement(old_to_new_mapping)?; - } - Ok(()) - } } define_wrapper_type!( diff --git a/crates/format/src/input.rs b/crates/format/src/input.rs index ad59177..0420f63 100644 --- a/crates/format/src/input.rs +++ b/crates/format/src/input.rs @@ -324,7 +324,7 @@ pub const fn default_caller() -> Address { /// This piece of code is taken from the matter-labs-tester repository which is licensed under MIT /// or Apache. The original source code can be found here: /// https://github.com/matter-labs/era-compiler-tester/blob/0ed598a27f6eceee7008deab3ff2311075a2ec69/compiler_tester/src/test/case/input/value.rs#L43-L146 -pub fn resolve_argument( +fn resolve_argument( value: &str, deployed_contracts: &HashMap, chain_state_provider: &impl EthereumNode, From 51191013c114925ce5db5b3c9f6ae81da4900275 Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Tue, 22 Jul 2025 15:13:38 +0300 Subject: [PATCH 5/5] Remove empty impl --- crates/format/src/input.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/format/src/input.rs b/crates/format/src/input.rs index 0420f63..59156e5 100644 --- a/crates/format/src/input.rs +++ b/crates/format/src/input.rs @@ -196,8 +196,6 @@ impl Calldata { } } -impl Expected {} - impl Input { fn instance_to_address( &self,