mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-28 23:38:00 +00:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e7ebe4fa2f | |||
| 5c957e5ac1 | |||
| a0248b58f3 | |||
| 6a9acea748 | |||
| c31c7d94f9 | |||
| dcc43d4ea6 | |||
| cb13c3c2cd | |||
| 7cda3416f0 | |||
| d7bc4f1fab | |||
| b6db597a57 | |||
| d7136d9a3d | |||
| e5a3f0aee9 | |||
| 3cdf57f7c3 | |||
| dab8ffe520 | |||
| c913a8222f | |||
| c8cef4834f | |||
| ca59a1f6a9 | |||
| adc0c44cde | |||
| 811e17136b | |||
| ba32bad6b3 | |||
| bb754cba4f | |||
| c858bbe66d | |||
| 906878f06a | |||
| 9a71369e8a | |||
| 84ab873b46 | |||
| 2ef6f7ba63 | |||
| 38e6140a7c | |||
| ca6c5529e2 | |||
| 038a2db53c |
@@ -73,12 +73,6 @@ 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,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ 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,
|
||||||
@@ -441,8 +442,9 @@ 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 error_span =
|
||||||
let chain_state_provider = node;
|
tracing::error_span!("Exception failed", ?tracing_result, ?execution_receipt,);
|
||||||
|
let _guard = error_span.enter();
|
||||||
|
|
||||||
// Handling the receipt state assertion.
|
// Handling the receipt state assertion.
|
||||||
let expected = !expectation.exception;
|
let expected = !expectation.exception;
|
||||||
@@ -456,16 +458,17 @@ 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
|
||||||
let actual = &tracing_result.output.as_ref().unwrap_or_default();
|
.calldata(self.deployed_contracts.entry(case_idx).or_default(), node)
|
||||||
if !expected.is_equivalent(actual, deployed_contracts, chain_state_provider)? {
|
.map(Bytes::from)?;
|
||||||
|
let actual = tracing_result.output.clone().unwrap_or_default();
|
||||||
|
if !expected.starts_with(&actual) {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
?execution_receipt,
|
%expected,
|
||||||
?expected,
|
|
||||||
%actual,
|
%actual,
|
||||||
"Calldata assertion failed"
|
"Calldata assertion failed"
|
||||||
);
|
);
|
||||||
anyhow::bail!("Calldata assertion failed - Expected {expected:?} but got {actual}",);
|
anyhow::bail!("Calldata assertion failed - Expected {expected} but got {actual}",);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,24 +505,17 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handling the topics assertion.
|
// Handling the topics assertion.
|
||||||
for (expected, actual) in expected_event
|
for (expected_topic, actual_topic) 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.clone()]);
|
let expected = Calldata::Compound(vec![expected_topic.clone()])
|
||||||
if !expected.is_equivalent(
|
.calldata(self.deployed_contracts.entry(case_idx).or_default(), node)?;
|
||||||
&actual.0,
|
let actual = actual_topic.to_vec();
|
||||||
deployed_contracts,
|
if actual != expected {
|
||||||
chain_state_provider,
|
tracing::error!(?expected, ?actual, "Event topics assertion failed",);
|
||||||
)? {
|
|
||||||
tracing::error!(
|
|
||||||
?execution_receipt,
|
|
||||||
?expected,
|
|
||||||
?actual,
|
|
||||||
"Event topics assertion failed",
|
|
||||||
);
|
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Event topics assertion failed - Expected {expected:?} but got {actual:?}",
|
"Event topics assertion failed - Expected {expected:?} but got {actual:?}",
|
||||||
);
|
);
|
||||||
@@ -527,15 +523,13 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handling the values assertion.
|
// Handling the values assertion.
|
||||||
let expected = &expected_event.values;
|
let expected = &expected_event
|
||||||
|
.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.is_equivalent(&actual.0, deployed_contracts, chain_state_provider)? {
|
if !expected.starts_with(actual) {
|
||||||
tracing::error!(
|
tracing::error!(?expected, ?actual, "Event value assertion failed",);
|
||||||
?execution_receipt,
|
|
||||||
?expected,
|
|
||||||
?actual,
|
|
||||||
"Event value assertion failed",
|
|
||||||
);
|
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Event value assertion failed - Expected {expected:?} but got {actual:?}",
|
"Event value assertion failed - Expected {expected:?} but got {actual:?}",
|
||||||
);
|
);
|
||||||
|
|||||||
+76
-10
@@ -1,5 +1,13 @@
|
|||||||
use std::{collections::HashMap, sync::LazyLock};
|
use std::{
|
||||||
|
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::*};
|
||||||
|
|
||||||
@@ -8,7 +16,11 @@ use revive_dt_core::{
|
|||||||
Geth, Kitchensink, Platform,
|
Geth, Kitchensink, Platform,
|
||||||
driver::{Driver, State},
|
driver::{Driver, State},
|
||||||
};
|
};
|
||||||
use revive_dt_format::{corpus::Corpus, metadata::MetadataFile};
|
use revive_dt_format::{
|
||||||
|
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;
|
||||||
@@ -20,12 +32,48 @@ 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()?;
|
||||||
|
|
||||||
for (corpus, tests) in collect_corpora(&args)? {
|
let mut corpora = 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(&args, &tests, span)?,
|
None => execute_corpus(
|
||||||
|
&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()?;
|
||||||
@@ -83,15 +131,24 @@ fn collect_corpora(args: &Arguments) -> anyhow::Result<HashMap<Corpus, Vec<Metad
|
|||||||
Ok(corpora)
|
Ok(corpora)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_driver<L, F>(args: &Arguments, tests: &[MetadataFile], span: Span) -> anyhow::Result<()>
|
fn run_driver<L, F>(
|
||||||
|
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)?;
|
let leader_nodes = NodePool::<L::Blockchain>::new(args, additional_signers.clone())?;
|
||||||
let follower_nodes = NodePool::<F::Blockchain>::new(args)?;
|
let follower_nodes = NodePool::<F::Blockchain>::new(args, additional_signers)?;
|
||||||
|
|
||||||
tests.par_iter().for_each(
|
tests.par_iter().for_each(
|
||||||
|MetadataFile {
|
|MetadataFile {
|
||||||
@@ -141,13 +198,22 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_corpus(args: &Arguments, tests: &[MetadataFile], span: Span) -> anyhow::Result<()> {
|
fn execute_corpus(
|
||||||
|
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, span)?
|
run_driver::<Geth, Kitchensink>(args, tests, additional_signers, span)?
|
||||||
}
|
}
|
||||||
(TestingPlatform::Geth, TestingPlatform::Geth) => {
|
(TestingPlatform::Geth, TestingPlatform::Geth) => {
|
||||||
run_driver::<Geth, Geth>(args, tests, span)?
|
run_driver::<Geth, Geth>(args, tests, additional_signers, span)?
|
||||||
}
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -40,6 +41,19 @@ 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!(
|
define_wrapper_type!(
|
||||||
|
|||||||
+97
-38
@@ -13,7 +13,10 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use revive_dt_node_interaction::EthereumNode;
|
use revive_dt_node_interaction::EthereumNode;
|
||||||
|
|
||||||
use crate::{define_wrapper_type, metadata::ContractInstance};
|
use crate::{
|
||||||
|
define_wrapper_type,
|
||||||
|
metadata::{AddressReplacementMap, ContractInstance},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
|
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
|
||||||
pub struct Input {
|
pub struct Input {
|
||||||
@@ -57,7 +60,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(Bytes),
|
Single(String),
|
||||||
Compound(Vec<String>),
|
Compound(Vec<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +135,41 @@ 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 {
|
||||||
@@ -151,6 +189,23 @@ 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)>,
|
||||||
@@ -168,8 +223,8 @@ impl Calldata {
|
|||||||
chain_state_provider: &impl EthereumNode,
|
chain_state_provider: &impl EthereumNode,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Calldata::Single(bytes) => {
|
Calldata::Single(string) => {
|
||||||
buffer.extend_from_slice(bytes);
|
alloy::hex::decode_to_slice(string, buffer)?;
|
||||||
}
|
}
|
||||||
Calldata::Compound(items) => {
|
Calldata::Compound(items) => {
|
||||||
for (arg_idx, arg) in items.iter().enumerate() {
|
for (arg_idx, arg) in items.iter().enumerate() {
|
||||||
@@ -190,47 +245,31 @@ impl Calldata {
|
|||||||
|
|
||||||
pub fn size_requirement(&self) -> usize {
|
pub fn size_requirement(&self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
Calldata::Single(single) => single.len(),
|
Calldata::Single(single) => (single.len() - 2) / 2,
|
||||||
Calldata::Compound(items) => items.len() * 32,
|
Calldata::Compound(items) => items.len() * 32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks if this [`Calldata`] is equivalent to the passed calldata bytes.
|
impl Expected {
|
||||||
pub fn is_equivalent(
|
pub fn handle_address_replacement(
|
||||||
&self,
|
&mut self,
|
||||||
other: &[u8],
|
old_to_new_mapping: &AddressReplacementMap,
|
||||||
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
) -> anyhow::Result<()> {
|
||||||
chain_state_provider: &impl EthereumNode,
|
|
||||||
) -> anyhow::Result<bool> {
|
|
||||||
match self {
|
match self {
|
||||||
Calldata::Single(calldata) => Ok(calldata == other),
|
Expected::Calldata(calldata) => {
|
||||||
Calldata::Compound(items) => {
|
calldata.handle_address_replacement(old_to_new_mapping)?;
|
||||||
// Chunking the "other" calldata into 32 byte chunks since each
|
}
|
||||||
// one of the items in the compound calldata represents 32 bytes
|
Expected::Expected(expected_output) => {
|
||||||
for (this, other) in items.iter().zip(other.chunks(32)) {
|
expected_output.handle_address_replacement(old_to_new_mapping)?;
|
||||||
// The matterlabs format supports wildcards and therefore we
|
}
|
||||||
// also need to support them.
|
Expected::ExpectedMany(expected_outputs) => {
|
||||||
if this == "*" {
|
for expected_output in expected_outputs.iter_mut() {
|
||||||
continue;
|
expected_output.handle_address_replacement(old_to_new_mapping)?;
|
||||||
}
|
|
||||||
|
|
||||||
let other = if other.len() < 32 {
|
|
||||||
let mut vec = other.to_vec();
|
|
||||||
vec.resize(32, 0);
|
|
||||||
std::borrow::Cow::Owned(vec)
|
|
||||||
} 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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,6 +379,26 @@ 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 {
|
||||||
@@ -360,7 +419,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
|
||||||
fn resolve_argument(
|
pub 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,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::BTreeMap,
|
collections::{BTreeMap, HashMap},
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
fs::{File, read_to_string},
|
fs::{File, read_to_string},
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
@@ -7,11 +7,15 @@ 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},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,6 +215,17 @@ 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!(
|
||||||
@@ -309,6 +324,129 @@ 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::*;
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
/// This constant defines how much Wei accounts are pre-seeded with in genesis.
|
|
||||||
///
|
|
||||||
/// Note: After changing this number, check that the tests for kitchensink work as we encountered
|
|
||||||
/// some issues with different values of the initial balance on Kitchensink.
|
|
||||||
pub const INITIAL_BALANCE: u128 = 10u128.pow(37);
|
|
||||||
+20
-20
@@ -12,8 +12,8 @@ use std::{
|
|||||||
use alloy::{
|
use alloy::{
|
||||||
eips::BlockNumberOrTag,
|
eips::BlockNumberOrTag,
|
||||||
genesis::{Genesis, GenesisAccount},
|
genesis::{Genesis, GenesisAccount},
|
||||||
network::{Ethereum, EthereumWallet, NetworkWallet},
|
network::{Ethereum, EthereumWallet, NetworkWallet, TxSigner},
|
||||||
primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, FixedBytes, U256},
|
primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, 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::local::PrivateKeySigner,
|
signers::Signature,
|
||||||
};
|
};
|
||||||
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, constants::INITIAL_BALANCE};
|
use crate::{Node, common::FallbackGasFiller};
|
||||||
|
|
||||||
static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
|
static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
|
||||||
|
|
||||||
@@ -84,12 +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)
|
||||||
{
|
{
|
||||||
// Note, the use of the entry API here means that we only modify the entries for any
|
genesis.alloc.entry(signer_address).or_insert(
|
||||||
// account that is not in the `alloc` field of the genesis state.
|
GenesisAccount::default()
|
||||||
genesis
|
.with_balance(10000000000000000000000u128.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)?;
|
||||||
@@ -437,17 +435,16 @@ impl EthereumNode for Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Node for Instance {
|
impl Node for Instance {
|
||||||
fn new(config: &Arguments) -> Self {
|
fn new(
|
||||||
|
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 (1..=config.private_keys_to_add)
|
for signer in additional_signers {
|
||||||
.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,6 +532,7 @@ 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};
|
||||||
@@ -551,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);
|
let mut node = Instance::new(&args, Vec::<PrivateKeySigner>::with_capacity(0));
|
||||||
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()
|
||||||
@@ -561,21 +559,23 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn init_works() {
|
fn init_works() {
|
||||||
Instance::new(&test_config().0)
|
Instance::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(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)
|
Instance::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(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).version().unwrap();
|
let version = Instance::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0))
|
||||||
|
.version()
|
||||||
|
.unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
version.starts_with("geth version"),
|
version.starts_with("geth version"),
|
||||||
"expected version string, got: '{version}'"
|
"expected version string, got: '{version}'"
|
||||||
|
|||||||
@@ -13,11 +13,9 @@ use alloy::{
|
|||||||
genesis::{Genesis, GenesisAccount},
|
genesis::{Genesis, GenesisAccount},
|
||||||
network::{
|
network::{
|
||||||
Ethereum, EthereumWallet, Network, NetworkWallet, TransactionBuilder,
|
Ethereum, EthereumWallet, Network, NetworkWallet, TransactionBuilder,
|
||||||
TransactionBuilderError, UnbuiltTransactionError,
|
TransactionBuilderError, TxSigner, 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,
|
||||||
@@ -28,7 +26,7 @@ use alloy::{
|
|||||||
eth::{Block, Header, Transaction},
|
eth::{Block, Header, Transaction},
|
||||||
trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame},
|
trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame},
|
||||||
},
|
},
|
||||||
signers::local::PrivateKeySigner,
|
signers::Signature,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{Value as JsonValue, json};
|
use serde_json::{Value as JsonValue, json};
|
||||||
@@ -39,7 +37,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, constants::INITIAL_BALANCE};
|
use crate::{Node, common::FallbackGasFiller};
|
||||||
|
|
||||||
static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
|
static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
|
||||||
|
|
||||||
@@ -131,12 +129,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)
|
||||||
{
|
{
|
||||||
// Note, the use of the entry API here means that we only modify the entries for any
|
genesis.alloc.entry(signer_address).or_insert(
|
||||||
// account that is not in the `alloc` field of the genesis state.
|
GenesisAccount::default()
|
||||||
genesis
|
.with_balance(10000000000000000000000u128.try_into().unwrap()),
|
||||||
.alloc
|
);
|
||||||
.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)?
|
||||||
};
|
};
|
||||||
@@ -508,18 +504,17 @@ impl EthereumNode for KitchensinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Node for KitchensinkNode {
|
impl Node for KitchensinkNode {
|
||||||
fn new(config: &Arguments) -> Self {
|
fn new(
|
||||||
|
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 (1..=config.private_keys_to_add)
|
for signer in additional_signers {
|
||||||
.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1035,7 +1030,7 @@ impl BlockHeader for KitchenSinkHeader {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use alloy::rpc::types::TransactionRequest;
|
use alloy::{rpc::types::TransactionRequest, signers::local::PrivateKeySigner};
|
||||||
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};
|
||||||
@@ -1078,7 +1073,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);
|
let mut node = KitchensinkNode::new(&args, Vec::<PrivateKeySigner>::with_capacity(0));
|
||||||
node.init(GENESIS_JSON)
|
node.init(GENESIS_JSON)
|
||||||
.expect("Failed to initialize the node")
|
.expect("Failed to initialize the node")
|
||||||
.spawn_process()
|
.spawn_process()
|
||||||
@@ -1133,7 +1128,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let mut dummy_node = KitchensinkNode::new(&test_config().0);
|
let mut dummy_node =
|
||||||
|
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");
|
||||||
@@ -1177,7 +1173,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let node = KitchensinkNode::new(&test_config().0);
|
let node =
|
||||||
|
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())
|
||||||
@@ -1250,7 +1247,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);
|
let mut node = KitchensinkNode::new(&config, Vec::<PrivateKeySigner>::with_capacity(0));
|
||||||
node.spawn(GENESIS_JSON.to_string()).unwrap();
|
node.spawn(GENESIS_JSON.to_string()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1258,7 +1255,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);
|
let node = KitchensinkNode::new(&config, Vec::<PrivateKeySigner>::with_capacity(0));
|
||||||
let version = node.version().unwrap();
|
let version = node.version().unwrap();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
@@ -1271,7 +1268,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);
|
let node = KitchensinkNode::new(&config, Vec::<PrivateKeySigner>::with_capacity(0));
|
||||||
let version = node.eth_rpc_version().unwrap();
|
let version = node.eth_rpc_version().unwrap();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
@@ -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,7 +15,10 @@ 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(config: &Arguments) -> Self;
|
fn new(
|
||||||
|
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.
|
||||||
///
|
///
|
||||||
|
|||||||
+19
-4
@@ -6,6 +6,7 @@ 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;
|
||||||
|
|
||||||
@@ -23,7 +24,14 @@ 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(config: &Arguments) -> anyhow::Result<Self> {
|
pub fn new(
|
||||||
|
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: {}",
|
||||||
@@ -34,7 +42,10 @@ 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();
|
||||||
handles.push(thread::spawn(move || spawn_node::<T>(&config, genesis)));
|
let additional_signers = additional_signers.clone();
|
||||||
|
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);
|
||||||
@@ -60,8 +71,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_node<T: Node + Send>(args: &Arguments, genesis: String) -> anyhow::Result<T> {
|
fn spawn_node<T: Node + Send>(
|
||||||
let mut node = T::new(args);
|
args: &Arguments,
|
||||||
|
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)
|
||||||
|
|||||||
+5
-1
@@ -33,5 +33,9 @@
|
|||||||
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"timestamp": "0x00",
|
"timestamp": "0x00",
|
||||||
"alloc": {}
|
"alloc": {
|
||||||
|
"90F8bf6A479f320ead074411a4B0e7944Ea8c9C1": {
|
||||||
|
"balance": "10000000000000000000000"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user