Compare commits

...

24 Commits

Author SHA1 Message Date
Omar Abdulla edbbbab934 Fix tests 2025-07-23 18:48:59 +03:00
Omar 757cbaf61e Merge pull request #57 from paritytech/feature/caller-replacement
Implement caller replacement
2025-07-23 18:46:18 +03:00
Omar Abdulla 2c7e95bb4f Merge remote-tracking branch 'origin/feature/handle-exceptions' into feature/caller-replacement 2025-07-23 18:45:59 +03:00
Omar Abdulla 2b6ee18e40 Better handling for length in equivalency checks 2025-07-23 18:43:39 +03:00
Omar Abdulla ca1ce3e5b4 Fix calldata construction of single calldata 2025-07-23 18:43:39 +03:00
Omar Abdulla 3d28179dde Add support for wildcards in exceptions 2025-07-23 18:43:39 +03:00
Omar Abdulla 6303f3b917 Fix size_requirement underflow 2025-07-23 18:42:10 +03:00
Omar Abdulla e434c163c7 Make initial balance a constant 2025-07-23 18:42:09 +03:00
Omar Abdulla 404d2f7452 Better handling for length in equivalency checks 2025-07-23 14:53:19 +03:00
Omar 750d9fff27 Merge pull request #59 from paritytech/feature/check-target
Honor the target in the metadata files
2025-07-23 12:35:14 +03:00
Omar Abdulla 94afdbecc7 Fix calldata construction of single calldata 2025-07-23 10:13:31 +03:00
Omar Abdulla ce1b4862b4 Add support for wildcards in exceptions 2025-07-23 10:05:07 +03:00
Omar Abdulla 799f07f04f Fix size_requirement underflow 2025-07-23 09:54:58 +03:00
Omar Abdulla 2a1f81fb6d Merge remote-tracking branch 'origin/feature/caller-replacement' into feature/check-target 2025-07-23 08:28:07 +03:00
Omar Abdulla 51191013c1 Remove empty impl 2025-07-23 08:26:22 +03:00
Omar Abdulla c81279fc8f Correct the arguments 2025-07-23 08:26:22 +03:00
Omar Abdulla 0392b6b629 Remove address replacement 2025-07-23 08:26:22 +03:00
Omar Abdulla ac94c972de Remove empty impl 2025-07-22 15:18:14 +03:00
Omar 5cc814b0e0 Merge pull request #58 from paritytech/feature/lighter-trace
Switch to callframe tracer
2025-07-22 15:05:17 +03:00
Omar Abdulla 0722791a28 Correct the arguments 2025-07-22 14:37:02 +03:00
Omar Abdulla 52042dfff5 Remove address replacement 2025-07-22 14:34:22 +03:00
Omar e3c717f4d9 Merge pull request #60 from paritytech/feature/handle-values
Handle values
2025-07-22 13:57:05 +03:00
Omar Abdulla e7ebe4fa2f Handle values from the metadata files 2025-07-22 09:24:09 +03:00
Omar Abdulla 5c957e5ac1 Add a way to skip tests if they don't match the target 2025-07-22 09:07:01 +03:00
13 changed files with 226 additions and 427 deletions
+6
View File
@@ -73,6 +73,12 @@ pub struct Arguments {
)] )]
pub account: String, 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(long = "private-keys-count", default_value_t = 30)]
pub private_keys_to_add: usize,
/// The differential testing leader node implementation. /// The differential testing leader node implementation.
#[arg(short, long = "leader", default_value = "geth")] #[arg(short, long = "leader", default_value = "geth")]
pub leader: TestingPlatform, pub leader: TestingPlatform,
+47 -31
View File
@@ -5,7 +5,6 @@ use std::marker::PhantomData;
use alloy::json_abi::JsonAbi; use alloy::json_abi::JsonAbi;
use alloy::network::{Ethereum, TransactionBuilder}; use alloy::network::{Ethereum, TransactionBuilder};
use alloy::primitives::Bytes;
use alloy::rpc::types::TransactionReceipt; use alloy::rpc::types::TransactionReceipt;
use alloy::rpc::types::trace::geth::{ use alloy::rpc::types::trace::geth::{
CallFrame, GethDebugBuiltInTracerType, GethDebugTracerType, GethDebugTracingOptions, GethTrace, CallFrame, GethDebugBuiltInTracerType, GethDebugTracerType, GethDebugTracingOptions, GethTrace,
@@ -26,6 +25,7 @@ use revive_dt_format::case::CaseIdx;
use revive_dt_format::input::{Calldata, Expected, ExpectedOutput, Method}; use revive_dt_format::input::{Calldata, Expected, ExpectedOutput, Method};
use revive_dt_format::metadata::{ContractInstance, ContractPathAndIdentifier}; use revive_dt_format::metadata::{ContractInstance, ContractPathAndIdentifier};
use revive_dt_format::{input::Input, metadata::Metadata, mode::SolcMode}; use revive_dt_format::{input::Input, metadata::Metadata, mode::SolcMode};
use revive_dt_node::Node;
use revive_dt_node_interaction::EthereumNode; use revive_dt_node_interaction::EthereumNode;
use revive_dt_report::reporter::{CompilationTask, Report, Span}; use revive_dt_report::reporter::{CompilationTask, Report, Span};
use revive_solc_json_interface::SolcStandardJsonOutput; use revive_solc_json_interface::SolcStandardJsonOutput;
@@ -250,6 +250,12 @@ where
let tx = { let tx = {
let tx = TransactionRequest::default().from(input.caller); 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::<Ethereum>::with_deploy_code(tx, code) TransactionBuilder::<Ethereum>::with_deploy_code(tx, code)
}; };
@@ -435,16 +441,14 @@ where
// Additionally, what happens if the compiler filter doesn't match? Do we consider that the // Additionally, what happens if the compiler filter doesn't match? Do we consider that the
// transaction should succeed? Do we just ignore the expectation? // transaction should succeed? Do we just ignore the expectation?
let deployed_contracts = self.deployed_contracts.entry(case_idx).or_default();
let chain_state_provider = node;
// Handling the receipt state assertion. // Handling the receipt state assertion.
let expected = !expectation.exception; let expected = !expectation.exception;
let actual = execution_receipt.status(); let actual = execution_receipt.status();
if actual != expected { if actual != expected {
tracing::error!( tracing::error!(expected, actual, "Transaction status assertion failed",);
?execution_receipt,
expected,
actual,
"Transaction status assertion failed",
);
anyhow::bail!( anyhow::bail!(
"Transaction status assertion failed - Expected {expected} but got {actual}", "Transaction status assertion failed - Expected {expected} but got {actual}",
); );
@@ -452,13 +456,16 @@ where
// Handling the calldata assertion // Handling the calldata assertion
if let Some(ref expected_calldata) = expectation.return_data { if let Some(ref expected_calldata) = expectation.return_data {
let expected = expected_calldata let expected = expected_calldata;
.calldata(self.deployed_contracts.entry(case_idx).or_default(), node) let actual = &tracing_result.output.as_ref().unwrap_or_default();
.map(Bytes::from)?; if !expected.is_equivalent(actual, deployed_contracts, chain_state_provider)? {
let actual = tracing_result.output.clone().unwrap_or_default(); tracing::error!(
if !expected.starts_with(&actual) { ?execution_receipt,
tracing::error!(?execution_receipt, %expected, %actual, "Calldata assertion failed"); ?expected,
anyhow::bail!("Calldata assertion failed - Expected {expected} but got {actual}",); %actual,
"Calldata assertion failed"
);
anyhow::bail!("Calldata assertion failed - Expected {expected:?} but got {actual}",);
} }
} }
@@ -468,12 +475,7 @@ where
let expected = expected_events.len(); let expected = expected_events.len();
let actual = execution_receipt.logs().len(); let actual = execution_receipt.logs().len();
if actual != expected { if actual != expected {
tracing::error!( tracing::error!(expected, actual, "Event count assertion failed",);
?execution_receipt,
expected,
actual,
"Event count assertion failed",
);
anyhow::bail!( anyhow::bail!(
"Event count assertion failed - Expected {expected} but got {actual}", "Event count assertion failed - Expected {expected} but got {actual}",
); );
@@ -489,7 +491,6 @@ where
let actual = actual_event.address(); let actual = actual_event.address();
if actual != expected { if actual != expected {
tracing::error!( tracing::error!(
?execution_receipt,
%expected, %expected,
%actual, %actual,
"Event emitter assertion failed", "Event emitter assertion failed",
@@ -501,16 +502,18 @@ where
} }
// Handling the topics assertion. // Handling the topics assertion.
for (expected_topic, actual_topic) in expected_event for (expected, actual) in expected_event
.topics .topics
.as_slice() .as_slice()
.iter() .iter()
.zip(actual_event.topics()) .zip(actual_event.topics())
{ {
let expected = Calldata::Compound(vec![expected_topic.clone()]) let expected = Calldata::Compound(vec![expected.clone()]);
.calldata(self.deployed_contracts.entry(case_idx).or_default(), node)?; if !expected.is_equivalent(
let actual = actual_topic.to_vec(); &actual.0,
if actual != expected { deployed_contracts,
chain_state_provider,
)? {
tracing::error!( tracing::error!(
?execution_receipt, ?execution_receipt,
?expected, ?expected,
@@ -524,12 +527,9 @@ where
} }
// Handling the values assertion. // Handling the values assertion.
let expected = &expected_event let expected = &expected_event.values;
.values
.calldata(self.deployed_contracts.entry(case_idx).or_default(), node)
.map(Bytes::from)?;
let actual = &actual_event.data().data; let actual = &actual_event.data().data;
if !expected.starts_with(actual) { if !expected.is_equivalent(&actual.0, deployed_contracts, chain_state_provider)? {
tracing::error!( tracing::error!(
?execution_receipt, ?execution_receipt,
?expected, ?expected,
@@ -649,6 +649,22 @@ where
let tracing_span = tracing::info_span!("Handling metadata file"); let tracing_span = tracing::info_span!("Handling metadata file");
let _guard = tracing_span.enter(); 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() { for mode in self.metadata.solc_modes() {
let tracing_span = tracing::info_span!("With solc mode", solc_mode = ?mode); let tracing_span = tracing::info_span!("With solc mode", solc_mode = ?mode);
let _guard = tracing_span.enter(); let _guard = tracing_span.enter();
+2 -2
View File
@@ -5,7 +5,7 @@
use revive_dt_compiler::{SolidityCompiler, revive_resolc, solc}; use revive_dt_compiler::{SolidityCompiler, revive_resolc, solc};
use revive_dt_config::TestingPlatform; 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; use revive_dt_node_interaction::EthereumNode;
pub mod common; pub mod common;
@@ -15,7 +15,7 @@ pub mod driver;
/// ///
/// For this we need a blockchain node implementation and a compiler. /// For this we need a blockchain node implementation and a compiler.
pub trait Platform { pub trait Platform {
type Blockchain: EthereumNode; type Blockchain: EthereumNode + Node;
type Compiler: SolidityCompiler; type Compiler: SolidityCompiler;
/// Returns the matching [TestingPlatform] of the [revive_dt_config::Arguments]. /// Returns the matching [TestingPlatform] of the [revive_dt_config::Arguments].
+10 -76
View File
@@ -1,13 +1,5 @@
use std::{ use std::{collections::HashMap, sync::LazyLock};
collections::{HashMap, HashSet},
sync::LazyLock,
};
use alloy::{
network::TxSigner,
primitives::FixedBytes,
signers::{Signature, local::PrivateKeySigner},
};
use clap::Parser; use clap::Parser;
use rayon::{ThreadPoolBuilder, prelude::*}; use rayon::{ThreadPoolBuilder, prelude::*};
@@ -16,11 +8,7 @@ use revive_dt_core::{
Geth, Kitchensink, Platform, Geth, Kitchensink, Platform,
driver::{Driver, State}, driver::{Driver, State},
}; };
use revive_dt_format::{ use revive_dt_format::{corpus::Corpus, metadata::MetadataFile};
corpus::Corpus,
input::default_caller,
metadata::{AddressReplacementMap, MetadataFile},
};
use revive_dt_node::pool::NodePool; use revive_dt_node::pool::NodePool;
use revive_dt_report::reporter::{Report, Span}; use revive_dt_report::reporter::{Report, Span};
use temp_dir::TempDir; use temp_dir::TempDir;
@@ -32,48 +20,12 @@ static TEMP_DIR: LazyLock<TempDir> = LazyLock::new(|| TempDir::new().unwrap());
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
let args = init_cli()?; let args = init_cli()?;
let mut corpora = collect_corpora(&args)?; for (corpus, tests) in collect_corpora(&args)? {
let mut replacement_private_keys = HashSet::<FixedBytes<32>>::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 {
let span = Span::new(corpus, args.clone())?; let span = Span::new(corpus, args.clone())?;
match &args.compile_only { match &args.compile_only {
Some(platform) => compile_corpus(&args, &tests, platform, span), Some(platform) => compile_corpus(&args, &tests, platform, span),
None => execute_corpus( None => execute_corpus(&args, &tests, span)?,
&args,
&tests,
replacement_private_keys
.clone()
.into_iter()
.map(|bytes| PrivateKeySigner::from_bytes(&bytes).expect("Can't fail"))
.collect::<Vec<_>>(),
span,
)?,
} }
Report::save()?; Report::save()?;
@@ -131,24 +83,15 @@ fn collect_corpora(args: &Arguments) -> anyhow::Result<HashMap<Corpus, Vec<Metad
Ok(corpora) Ok(corpora)
} }
fn run_driver<L, F>( fn run_driver<L, F>(args: &Arguments, tests: &[MetadataFile], span: Span) -> anyhow::Result<()>
args: &Arguments,
tests: &[MetadataFile],
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>
+ Clone
+ Send
+ Sync
+ 'static,
span: Span,
) -> anyhow::Result<()>
where where
L: Platform, L: Platform,
F: Platform, F: Platform,
L::Blockchain: revive_dt_node::Node + Send + Sync + 'static, L::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
F::Blockchain: revive_dt_node::Node + Send + Sync + 'static, F::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
{ {
let leader_nodes = NodePool::<L::Blockchain>::new(args, additional_signers.clone())?; let leader_nodes = NodePool::<L::Blockchain>::new(args)?;
let follower_nodes = NodePool::<F::Blockchain>::new(args, additional_signers)?; let follower_nodes = NodePool::<F::Blockchain>::new(args)?;
tests.par_iter().for_each( tests.par_iter().for_each(
|MetadataFile { |MetadataFile {
@@ -198,22 +141,13 @@ where
Ok(()) Ok(())
} }
fn execute_corpus( fn execute_corpus(args: &Arguments, tests: &[MetadataFile], span: Span) -> anyhow::Result<()> {
args: &Arguments,
tests: &[MetadataFile],
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>
+ Clone
+ Send
+ Sync
+ 'static,
span: Span,
) -> anyhow::Result<()> {
match (&args.leader, &args.follower) { match (&args.leader, &args.follower) {
(TestingPlatform::Geth, TestingPlatform::Kitchensink) => { (TestingPlatform::Geth, TestingPlatform::Kitchensink) => {
run_driver::<Geth, Kitchensink>(args, tests, additional_signers, span)? run_driver::<Geth, Kitchensink>(args, tests, span)?
} }
(TestingPlatform::Geth, TestingPlatform::Geth) => { (TestingPlatform::Geth, TestingPlatform::Geth) => {
run_driver::<Geth, Geth>(args, tests, additional_signers, span)? run_driver::<Geth, Geth>(args, tests, span)?
} }
_ => unimplemented!(), _ => unimplemented!(),
} }
+8 -14
View File
@@ -3,7 +3,6 @@ use serde::Deserialize;
use crate::{ use crate::{
define_wrapper_type, define_wrapper_type,
input::{Expected, Input}, input::{Expected, Input},
metadata::AddressReplacementMap,
mode::Mode, mode::Mode,
}; };
@@ -26,26 +25,21 @@ impl Case {
.enumerate() .enumerate()
.map(move |(idx, mut input)| { .map(move |(idx, mut input)| {
if idx + 1 == inputs_len { if idx + 1 == inputs_len {
if input.expected.is_none() {
input.expected = self.expected.clone(); 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 input
} else { } else {
input input
} }
}) })
} }
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!( define_wrapper_type!(
+76 -97
View File
@@ -7,13 +7,13 @@ use alloy::{
primitives::{Address, Bytes, U256}, primitives::{Address, Bytes, U256},
rpc::types::TransactionRequest, rpc::types::TransactionRequest,
}; };
use alloy_primitives::FixedBytes; use alloy_primitives::{FixedBytes, utils::parse_units};
use semver::VersionReq; use semver::VersionReq;
use serde::Deserialize; use serde::{Deserialize, Serialize};
use revive_dt_node_interaction::EthereumNode; use revive_dt_node_interaction::EthereumNode;
use crate::metadata::{AddressReplacementMap, ContractInstance}; use crate::{define_wrapper_type, metadata::ContractInstance};
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
pub struct Input { pub struct Input {
@@ -26,7 +26,7 @@ pub struct Input {
#[serde(default)] #[serde(default)]
pub calldata: Calldata, pub calldata: Calldata,
pub expected: Option<Expected>, pub expected: Option<Expected>,
pub value: Option<String>, pub value: Option<EtherValue>,
pub storage: Option<HashMap<String, Calldata>>, pub storage: Option<HashMap<String, Calldata>>,
} }
@@ -57,7 +57,7 @@ pub struct Event {
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)] #[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(untagged)] #[serde(untagged)]
pub enum Calldata { pub enum Calldata {
Single(String), Single(Bytes),
Compound(Vec<String>), Compound(Vec<String>),
} }
@@ -82,6 +82,37 @@ pub enum Method {
FunctionName(String), FunctionName(String),
} }
define_wrapper_type!(
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
EtherValue(U256);
);
impl Serialize for EtherValue {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
format!("{} wei", self.0).serialize(serializer)
}
}
impl<'de> Deserialize<'de> for EtherValue {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
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 { impl ExpectedOutput {
pub fn new() -> Self { pub fn new() -> Self {
Default::default() Default::default()
@@ -101,41 +132,6 @@ impl ExpectedOutput {
self.return_data = Some(calldata); self.return_data = Some(calldata);
self 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 { impl Default for Calldata {
@@ -155,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( pub fn calldata(
&self, &self,
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>, deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
@@ -189,8 +168,8 @@ impl Calldata {
chain_state_provider: &impl EthereumNode, chain_state_provider: &impl EthereumNode,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match self { match self {
Calldata::Single(string) => { Calldata::Single(bytes) => {
alloy::hex::decode_to_slice(string, buffer)?; buffer.extend_from_slice(bytes);
} }
Calldata::Compound(items) => { Calldata::Compound(items) => {
for (arg_idx, arg) in items.iter().enumerate() { for (arg_idx, arg) in items.iter().enumerate() {
@@ -211,31 +190,47 @@ impl Calldata {
pub fn size_requirement(&self) -> usize { pub fn size_requirement(&self) -> usize {
match self { match self {
Calldata::Single(single) => (single.len() - 2) / 2, Calldata::Single(single) => single.len(),
Calldata::Compound(items) => items.len() * 32, Calldata::Compound(items) => items.len() * 32,
} }
} }
}
impl Expected { /// Checks if this [`Calldata`] is equivalent to the passed calldata bytes.
pub fn handle_address_replacement( pub fn is_equivalent(
&mut self, &self,
old_to_new_mapping: &AddressReplacementMap, other: &[u8],
) -> anyhow::Result<()> { deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
chain_state_provider: &impl EthereumNode,
) -> anyhow::Result<bool> {
match self { match self {
Expected::Calldata(calldata) => { Calldata::Single(calldata) => Ok(calldata == other),
calldata.handle_address_replacement(old_to_new_mapping)?; Calldata::Compound(items) => {
// Chunking the "other" calldata into 32 byte chunks since each
// one of the items in the compound calldata represents 32 bytes
for (this, other) in items.iter().zip(other.chunks(32)) {
// The matterlabs format supports wildcards and therefore we
// also need to support them.
if this == "*" {
continue;
} }
Expected::Expected(expected_output) => {
expected_output.handle_address_replacement(old_to_new_mapping)?; let other = if other.len() < 32 {
} let mut vec = other.to_vec();
Expected::ExpectedMany(expected_outputs) => { vec.resize(32, 0);
for expected_output in expected_outputs.iter_mut() { std::borrow::Cow::Owned(vec)
expected_output.handle_address_replacement(old_to_new_mapping)?; } else {
std::borrow::Cow::Borrowed(other)
};
let this = resolve_argument(this, deployed_contracts, chain_state_provider)?;
let other = U256::from_be_slice(&other);
if this != other {
return Ok(false);
} }
} }
Ok(true)
}
} }
Ok(())
} }
} }
@@ -324,7 +319,11 @@ impl Input {
chain_state_provider: &impl EthereumNode, chain_state_provider: &impl EthereumNode,
) -> anyhow::Result<TransactionRequest> { ) -> anyhow::Result<TransactionRequest> {
let input_data = self.encoded_input(deployed_contracts, chain_state_provider)?; let input_data = self.encoded_input(deployed_contracts, chain_state_provider)?;
let transaction_request = TransactionRequest::default(); let transaction_request = TransactionRequest::default().from(self.caller).value(
self.value
.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
@@ -341,26 +340,6 @@ impl Input {
vec 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 { fn default_instance() -> ContractInstance {
@@ -381,7 +360,7 @@ pub const fn default_caller() -> Address {
/// This piece of code is taken from the matter-labs-tester repository which is licensed under MIT /// 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: /// 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 /// 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, value: &str,
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>, deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
chain_state_provider: &impl EthereumNode, chain_state_provider: &impl EthereumNode,
+2 -139
View File
@@ -1,5 +1,5 @@
use std::{ use std::{
collections::{BTreeMap, HashMap}, collections::BTreeMap,
fmt::Display, fmt::Display,
fs::{File, read_to_string}, fs::{File, read_to_string},
ops::Deref, ops::Deref,
@@ -7,15 +7,11 @@ use std::{
str::FromStr, str::FromStr,
}; };
use alloy::signers::local::PrivateKeySigner;
use alloy_primitives::Address;
use revive_dt_node_interaction::EthereumNode;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{ use crate::{
case::Case, case::Case,
define_wrapper_type, define_wrapper_type,
input::resolve_argument,
mode::{Mode, SolcMode}, mode::{Mode, SolcMode},
}; };
@@ -48,6 +44,7 @@ impl Deref for MetadataFile {
#[derive(Debug, Default, Deserialize, Clone, Eq, PartialEq)] #[derive(Debug, Default, Deserialize, Clone, Eq, PartialEq)]
pub struct Metadata { pub struct Metadata {
pub targets: Option<Vec<String>>,
pub cases: Vec<Case>, pub cases: Vec<Case>,
pub contracts: Option<BTreeMap<ContractInstance, ContractPathAndIdentifier>>, pub contracts: Option<BTreeMap<ContractInstance, ContractPathAndIdentifier>>,
// TODO: Convert into wrapper types for clarity. // TODO: Convert into wrapper types for clarity.
@@ -214,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!( define_wrapper_type!(
@@ -323,129 +309,6 @@ impl From<ContractPathAndIdentifier> for String {
} }
} }
#[derive(Clone, Debug, Default)]
pub struct AddressReplacementMap(HashMap<Address, (PrivateKeySigner, Address)>);
impl AddressReplacementMap {
pub fn new() -> Self {
Self(Default::default())
}
pub fn into_inner(self) -> HashMap<Address, (PrivateKeySigner, Address)> {
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<Address> {
// 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<HashMap<Address, (PrivateKeySigner, Address)>> for AddressReplacementMap {
fn as_ref(&self) -> &HashMap<Address, (PrivateKeySigner, Address)> {
&self.0
}
}
struct UnimplementedEthereumNode;
impl EthereumNode for UnimplementedEthereumNode {
fn execute_transaction(
&self,
_: alloy::rpc::types::TransactionRequest,
) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> {
anyhow::bail!("Unimplemented")
}
fn chain_id(&self) -> anyhow::Result<alloy_primitives::ChainId> {
anyhow::bail!("Unimplemented")
}
fn block_gas_limit(&self, _: alloy::eips::BlockNumberOrTag) -> anyhow::Result<u128> {
anyhow::bail!("Unimplemented")
}
fn block_coinbase(&self, _: alloy::eips::BlockNumberOrTag) -> anyhow::Result<Address> {
anyhow::bail!("Unimplemented")
}
fn block_difficulty(
&self,
_: alloy::eips::BlockNumberOrTag,
) -> anyhow::Result<alloy_primitives::U256> {
anyhow::bail!("Unimplemented")
}
fn block_hash(
&self,
_: alloy::eips::BlockNumberOrTag,
) -> anyhow::Result<alloy_primitives::BlockHash> {
anyhow::bail!("Unimplemented")
}
fn block_timestamp(
&self,
_: alloy::eips::BlockNumberOrTag,
) -> anyhow::Result<alloy_primitives::BlockTimestamp> {
anyhow::bail!("Unimplemented")
}
fn last_block_number(&self) -> anyhow::Result<alloy_primitives::BlockNumber> {
anyhow::bail!("Unimplemented")
}
fn trace_transaction(
&self,
_: &alloy::rpc::types::TransactionReceipt,
_: alloy::rpc::types::trace::geth::GethDebugTracingOptions,
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
anyhow::bail!("Unimplemented")
}
fn state_diff(
&self,
_: &alloy::rpc::types::TransactionReceipt,
) -> anyhow::Result<alloy::rpc::types::trace::geth::DiffMode> {
anyhow::bail!("Unimplemented")
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
+5
View File
@@ -0,0 +1,5 @@
/// This constant defines how much Wei accounts are pre-seeded with in genesis.
///
/// We use [`u128::MAX`] here which means that accounts will be given 2^128 - 1 WEI which is
/// (2^128 - 1) / 10^18 ETH.
pub const INITIAL_BALANCE: u128 = u128::MAX;
+26 -19
View File
@@ -12,8 +12,8 @@ use std::{
use alloy::{ use alloy::{
eips::BlockNumberOrTag, eips::BlockNumberOrTag,
genesis::{Genesis, GenesisAccount}, genesis::{Genesis, GenesisAccount},
network::{Ethereum, EthereumWallet, NetworkWallet, TxSigner}, network::{Ethereum, EthereumWallet, NetworkWallet},
primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, U256}, primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, FixedBytes, U256},
providers::{ providers::{
Provider, ProviderBuilder, Provider, ProviderBuilder,
ext::DebugApi, ext::DebugApi,
@@ -23,13 +23,13 @@ use alloy::{
TransactionReceipt, TransactionRequest, TransactionReceipt, TransactionRequest,
trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame}, trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame},
}, },
signers::Signature, signers::local::PrivateKeySigner,
}; };
use revive_dt_config::Arguments; use revive_dt_config::Arguments;
use revive_dt_node_interaction::{BlockingExecutor, EthereumNode}; use revive_dt_node_interaction::{BlockingExecutor, EthereumNode};
use tracing::Level; use tracing::Level;
use crate::{Node, common::FallbackGasFiller}; use crate::{Node, common::FallbackGasFiller, constants::INITIAL_BALANCE};
static NODE_COUNT: AtomicU32 = AtomicU32::new(0); static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
@@ -84,9 +84,10 @@ impl Instance {
for signer_address in for signer_address in
<EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet) <EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet)
{ {
genesis.alloc.entry(signer_address).or_insert( genesis
GenesisAccount::default().with_balance(1000000000000000000u128.try_into().unwrap()), .alloc
); .entry(signer_address)
.or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE)));
} }
let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE); let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE);
serde_json::to_writer(File::create(&genesis_path)?, &genesis)?; serde_json::to_writer(File::create(&genesis_path)?, &genesis)?;
@@ -434,16 +435,17 @@ impl EthereumNode for Instance {
} }
impl Node for Instance { impl Node for Instance {
fn new( fn new(config: &Arguments) -> Self {
config: &Arguments,
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>,
) -> Self {
let geth_directory = config.directory().join(Self::BASE_DIRECTORY); let geth_directory = config.directory().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());
let mut wallet = config.wallet(); 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); wallet.register_signer(signer);
} }
@@ -510,6 +512,14 @@ impl Node for Instance {
.stdout; .stdout;
Ok(String::from_utf8_lossy(&output).into()) 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 { impl Drop for Instance {
@@ -523,7 +533,6 @@ impl Drop for Instance {
mod tests { mod tests {
use revive_dt_config::Arguments; use revive_dt_config::Arguments;
use alloy::signers::local::PrivateKeySigner;
use temp_dir::TempDir; use temp_dir::TempDir;
use crate::{GENESIS_JSON, Node}; use crate::{GENESIS_JSON, Node};
@@ -540,7 +549,7 @@ mod tests {
fn new_node() -> (Instance, TempDir) { fn new_node() -> (Instance, TempDir) {
let (args, temp_dir) = test_config(); let (args, temp_dir) = test_config();
let mut node = Instance::new(&args, Vec::<PrivateKeySigner>::with_capacity(0)); let mut node = Instance::new(&args);
node.init(GENESIS_JSON.to_owned()) node.init(GENESIS_JSON.to_owned())
.expect("Failed to initialize the node") .expect("Failed to initialize the node")
.spawn_process() .spawn_process()
@@ -550,23 +559,21 @@ mod tests {
#[test] #[test]
fn init_works() { fn init_works() {
Instance::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0)) Instance::new(&test_config().0)
.init(GENESIS_JSON.to_string()) .init(GENESIS_JSON.to_string())
.unwrap(); .unwrap();
} }
#[test] #[test]
fn spawn_works() { fn spawn_works() {
Instance::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0)) Instance::new(&test_config().0)
.spawn(GENESIS_JSON.to_string()) .spawn(GENESIS_JSON.to_string())
.unwrap(); .unwrap();
} }
#[test] #[test]
fn version_works() { fn version_works() {
let version = Instance::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0)) let version = Instance::new(&test_config().0).version().unwrap();
.version()
.unwrap();
assert!( assert!(
version.starts_with("geth version"), version.starts_with("geth version"),
"expected version string, got: '{version}'" "expected version string, got: '{version}'"
+31 -22
View File
@@ -13,9 +13,11 @@ use alloy::{
genesis::{Genesis, GenesisAccount}, genesis::{Genesis, GenesisAccount},
network::{ network::{
Ethereum, EthereumWallet, Network, NetworkWallet, TransactionBuilder, 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::{ providers::{
Provider, ProviderBuilder, Provider, ProviderBuilder,
ext::DebugApi, ext::DebugApi,
@@ -26,7 +28,7 @@ use alloy::{
eth::{Block, Header, Transaction}, eth::{Block, Header, Transaction},
trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame}, trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame},
}, },
signers::Signature, signers::local::PrivateKeySigner,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{Value as JsonValue, json}; use serde_json::{Value as JsonValue, json};
@@ -37,7 +39,7 @@ use tracing::Level;
use revive_dt_config::Arguments; use revive_dt_config::Arguments;
use revive_dt_node_interaction::{BlockingExecutor, EthereumNode}; use revive_dt_node_interaction::{BlockingExecutor, EthereumNode};
use crate::{Node, common::FallbackGasFiller}; use crate::{Node, common::FallbackGasFiller, constants::INITIAL_BALANCE};
static NODE_COUNT: AtomicU32 = AtomicU32::new(0); static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
@@ -129,10 +131,10 @@ impl KitchensinkNode {
for signer_address in for signer_address in
<EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet) <EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet)
{ {
genesis.alloc.entry(signer_address).or_insert( genesis
GenesisAccount::default() .alloc
.with_balance(1000000000000000000u128.try_into().unwrap()), .entry(signer_address)
); .or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE)));
} }
self.extract_balance_from_genesis_file(&genesis)? self.extract_balance_from_genesis_file(&genesis)?
}; };
@@ -504,17 +506,18 @@ impl EthereumNode for KitchensinkNode {
} }
impl Node for KitchensinkNode { impl Node for KitchensinkNode {
fn new( fn new(config: &Arguments) -> Self {
config: &Arguments,
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>,
) -> Self {
let kitchensink_directory = config.directory().join(Self::BASE_DIRECTORY); let kitchensink_directory = config.directory().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 = kitchensink_directory.join(id.to_string()); let base_directory = kitchensink_directory.join(id.to_string());
let logs_directory = base_directory.join(Self::LOGS_DIRECTORY); let logs_directory = base_directory.join(Self::LOGS_DIRECTORY);
let mut wallet = config.wallet(); 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); wallet.register_signer(signer);
} }
@@ -584,6 +587,14 @@ impl Node for KitchensinkNode {
.stdout; .stdout;
Ok(String::from_utf8_lossy(&output).into()) 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 { impl Drop for KitchensinkNode {
@@ -1022,7 +1033,7 @@ impl BlockHeader for KitchenSinkHeader {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use alloy::{rpc::types::TransactionRequest, signers::local::PrivateKeySigner}; use alloy::rpc::types::TransactionRequest;
use revive_dt_config::Arguments; use revive_dt_config::Arguments;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::{LazyLock, Mutex}; use std::sync::{LazyLock, Mutex};
@@ -1065,7 +1076,7 @@ mod tests {
let _guard = NODE_START_MUTEX.lock().unwrap(); let _guard = NODE_START_MUTEX.lock().unwrap();
let (args, temp_dir) = test_config(); let (args, temp_dir) = test_config();
let mut node = KitchensinkNode::new(&args, Vec::<PrivateKeySigner>::with_capacity(0)); let mut node = KitchensinkNode::new(&args);
node.init(GENESIS_JSON) node.init(GENESIS_JSON)
.expect("Failed to initialize the node") .expect("Failed to initialize the node")
.spawn_process() .spawn_process()
@@ -1120,8 +1131,7 @@ mod tests {
} }
"#; "#;
let mut dummy_node = let mut dummy_node = KitchensinkNode::new(&test_config().0);
KitchensinkNode::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0));
// Call `init()` // Call `init()`
dummy_node.init(genesis_content).expect("init failed"); dummy_node.init(genesis_content).expect("init failed");
@@ -1165,8 +1175,7 @@ mod tests {
} }
"#; "#;
let node = let node = KitchensinkNode::new(&test_config().0);
KitchensinkNode::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0));
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())
@@ -1239,7 +1248,7 @@ mod tests {
fn spawn_works() { fn spawn_works() {
let (config, _temp_dir) = test_config(); let (config, _temp_dir) = test_config();
let mut node = KitchensinkNode::new(&config, Vec::<PrivateKeySigner>::with_capacity(0)); let mut node = KitchensinkNode::new(&config);
node.spawn(GENESIS_JSON.to_string()).unwrap(); node.spawn(GENESIS_JSON.to_string()).unwrap();
} }
@@ -1247,7 +1256,7 @@ mod tests {
fn version_works() { fn version_works() {
let (config, _temp_dir) = test_config(); let (config, _temp_dir) = test_config();
let node = KitchensinkNode::new(&config, Vec::<PrivateKeySigner>::with_capacity(0)); let node = KitchensinkNode::new(&config);
let version = node.version().unwrap(); let version = node.version().unwrap();
assert!( assert!(
@@ -1260,7 +1269,7 @@ mod tests {
fn eth_rpc_version_works() { fn eth_rpc_version_works() {
let (config, _temp_dir) = test_config(); let (config, _temp_dir) = test_config();
let node = KitchensinkNode::new(&config, Vec::<PrivateKeySigner>::with_capacity(0)); let node = KitchensinkNode::new(&config);
let version = node.eth_rpc_version().unwrap(); let version = node.eth_rpc_version().unwrap();
assert!( assert!(
+6 -5
View File
@@ -1,10 +1,10 @@
//! This crate implements the testing nodes. //! This crate implements the testing nodes.
use alloy::{network::TxSigner, signers::Signature};
use revive_dt_config::Arguments; use revive_dt_config::Arguments;
use revive_dt_node_interaction::EthereumNode; use revive_dt_node_interaction::EthereumNode;
pub mod common; pub mod common;
pub mod constants;
pub mod geth; pub mod geth;
pub mod kitchensink; pub mod kitchensink;
pub mod pool; pub mod pool;
@@ -15,10 +15,7 @@ pub const GENESIS_JSON: &str = include_str!("../../../genesis.json");
/// An abstract interface for testing nodes. /// An abstract interface for testing nodes.
pub trait Node: EthereumNode { pub trait Node: EthereumNode {
/// Create a new uninitialized instance. /// Create a new uninitialized instance.
fn new( fn new(config: &Arguments) -> Self;
config: &Arguments,
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>,
) -> Self;
/// Spawns a node configured according to the genesis json. /// Spawns a node configured according to the genesis json.
/// ///
@@ -35,4 +32,8 @@ pub trait Node: EthereumNode {
/// Returns the node version. /// Returns the node version.
fn version(&self) -> anyhow::Result<String>; fn version(&self) -> anyhow::Result<String>;
/// 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;
} }
+4 -19
View File
@@ -6,7 +6,6 @@ use std::{
thread, thread,
}; };
use alloy::{network::TxSigner, signers::Signature};
use anyhow::Context; use anyhow::Context;
use revive_dt_config::Arguments; use revive_dt_config::Arguments;
@@ -24,14 +23,7 @@ where
T: Node + Send + 'static, T: Node + Send + 'static,
{ {
/// Create a new Pool. This will start as many nodes as there are workers in `config`. /// Create a new Pool. This will start as many nodes as there are workers in `config`.
pub fn new( pub fn new(config: &Arguments) -> anyhow::Result<Self> {
config: &Arguments,
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>
+ Clone
+ Send
+ Sync
+ 'static,
) -> anyhow::Result<Self> {
let nodes = config.workers; let nodes = config.workers;
let genesis = read_to_string(&config.genesis_file).context(format!( let genesis = read_to_string(&config.genesis_file).context(format!(
"can not read genesis file: {}", "can not read genesis file: {}",
@@ -42,10 +34,7 @@ where
for _ in 0..nodes { for _ in 0..nodes {
let config = config.clone(); let config = config.clone();
let genesis = genesis.clone(); let genesis = genesis.clone();
let additional_signers = additional_signers.clone(); handles.push(thread::spawn(move || spawn_node::<T>(&config, genesis)));
handles.push(thread::spawn(move || {
spawn_node::<T>(&config, additional_signers, genesis)
}));
} }
let mut nodes = Vec::with_capacity(nodes); let mut nodes = Vec::with_capacity(nodes);
@@ -71,12 +60,8 @@ where
} }
} }
fn spawn_node<T: Node + Send>( fn spawn_node<T: Node + Send>(args: &Arguments, genesis: String) -> anyhow::Result<T> {
args: &Arguments, let mut node = T::new(args);
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>,
genesis: String,
) -> anyhow::Result<T> {
let mut node = T::new(args, additional_signers);
tracing::info!("starting node: {}", node.connection_string()); tracing::info!("starting node: {}", node.connection_string());
node.spawn(genesis)?; node.spawn(genesis)?;
Ok(node) Ok(node)
+1 -1
View File
@@ -35,7 +35,7 @@
"timestamp": "0x00", "timestamp": "0x00",
"alloc": { "alloc": {
"90F8bf6A479f320ead074411a4B0e7944Ea8c9C1": { "90F8bf6A479f320ead074411a4B0e7944Ea8c9C1": {
"balance": "1000000000000000000" "balance": "10000000000000000000000"
} }
} }
} }