Remove address replacement

This commit is contained in:
Omar Abdulla
2025-07-22 14:34:22 +03:00
parent 6a9acea748
commit 52042dfff5
8 changed files with 55 additions and 365 deletions
+13 -15
View File
@@ -12,8 +12,8 @@ use std::{
use alloy::{
eips::BlockNumberOrTag,
genesis::{Genesis, GenesisAccount},
network::{Ethereum, EthereumWallet, NetworkWallet, TxSigner},
primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, U256},
network::{Ethereum, EthereumWallet, NetworkWallet},
primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, FixedBytes, U256},
providers::{
Provider, ProviderBuilder,
ext::DebugApi,
@@ -23,7 +23,7 @@ use alloy::{
TransactionReceipt, TransactionRequest,
trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame},
},
signers::Signature,
signers::local::PrivateKeySigner,
};
use revive_dt_config::Arguments;
use revive_dt_node_interaction::{BlockingExecutor, EthereumNode};
@@ -434,16 +434,17 @@ impl EthereumNode for Instance {
}
impl Node for Instance {
fn new(
config: &Arguments,
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>,
) -> Self {
fn new(config: &Arguments) -> Self {
let geth_directory = config.directory().join(Self::BASE_DIRECTORY);
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
let base_directory = geth_directory.join(id.to_string());
let mut wallet = config.wallet();
for signer in additional_signers {
for signer in (1..=config.private_keys_to_add)
.map(|id| U256::from(id))
.map(|id| id.to_be_bytes::<32>())
.map(|id| PrivateKeySigner::from_bytes(&FixedBytes(id)).unwrap())
{
wallet.register_signer(signer);
}
@@ -523,7 +524,6 @@ impl Drop for Instance {
mod tests {
use revive_dt_config::Arguments;
use alloy::signers::local::PrivateKeySigner;
use temp_dir::TempDir;
use crate::{GENESIS_JSON, Node};
@@ -540,7 +540,7 @@ mod tests {
fn new_node() -> (Instance, TempDir) {
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())
.expect("Failed to initialize the node")
.spawn_process()
@@ -550,23 +550,21 @@ mod tests {
#[test]
fn init_works() {
Instance::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0))
Instance::new(&test_config().0)
.init(GENESIS_JSON.to_string())
.unwrap();
}
#[test]
fn spawn_works() {
Instance::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0))
Instance::new(&test_config().0)
.spawn(GENESIS_JSON.to_string())
.unwrap();
}
#[test]
fn version_works() {
let version = Instance::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0))
.version()
.unwrap();
let version = Instance::new(&test_config().0).version().unwrap();
assert!(
version.starts_with("geth version"),
"expected version string, got: '{version}'"
+18 -17
View File
@@ -13,9 +13,11 @@ use alloy::{
genesis::{Genesis, GenesisAccount},
network::{
Ethereum, EthereumWallet, Network, NetworkWallet, TransactionBuilder,
TransactionBuilderError, TxSigner, UnbuiltTransactionError,
TransactionBuilderError, UnbuiltTransactionError,
},
primitives::{
Address, B64, B256, BlockHash, BlockNumber, BlockTimestamp, Bloom, Bytes, FixedBytes, U256,
},
primitives::{Address, B64, B256, BlockHash, BlockNumber, BlockTimestamp, Bloom, Bytes, U256},
providers::{
Provider, ProviderBuilder,
ext::DebugApi,
@@ -26,7 +28,7 @@ use alloy::{
eth::{Block, Header, Transaction},
trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame},
},
signers::Signature,
signers::local::PrivateKeySigner,
};
use serde::{Deserialize, Serialize};
use serde_json::{Value as JsonValue, json};
@@ -504,17 +506,18 @@ impl EthereumNode for KitchensinkNode {
}
impl Node for KitchensinkNode {
fn new(
config: &Arguments,
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>,
) -> Self {
fn new(config: &Arguments) -> Self {
let kitchensink_directory = config.directory().join(Self::BASE_DIRECTORY);
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
let base_directory = kitchensink_directory.join(id.to_string());
let logs_directory = base_directory.join(Self::LOGS_DIRECTORY);
let mut wallet = config.wallet();
for signer in additional_signers {
for signer in (1..=config.private_keys_to_add)
.map(|id| U256::from(id))
.map(|id| id.to_be_bytes::<32>())
.map(|id| PrivateKeySigner::from_bytes(&FixedBytes(id)).unwrap())
{
wallet.register_signer(signer);
}
@@ -1022,7 +1025,7 @@ impl BlockHeader for KitchenSinkHeader {
#[cfg(test)]
mod tests {
use alloy::{rpc::types::TransactionRequest, signers::local::PrivateKeySigner};
use alloy::rpc::types::TransactionRequest;
use revive_dt_config::Arguments;
use std::path::PathBuf;
use std::sync::{LazyLock, Mutex};
@@ -1065,7 +1068,7 @@ mod tests {
let _guard = NODE_START_MUTEX.lock().unwrap();
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)
.expect("Failed to initialize the node")
.spawn_process()
@@ -1120,8 +1123,7 @@ mod tests {
}
"#;
let mut dummy_node =
KitchensinkNode::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0));
let mut dummy_node = KitchensinkNode::new(&test_config().0);
// Call `init()`
dummy_node.init(genesis_content).expect("init failed");
@@ -1165,8 +1167,7 @@ mod tests {
}
"#;
let node =
KitchensinkNode::new(&test_config().0, Vec::<PrivateKeySigner>::with_capacity(0));
let node = KitchensinkNode::new(&test_config().0);
let result = node
.extract_balance_from_genesis_file(&serde_json::from_str(genesis_json).unwrap())
@@ -1239,7 +1240,7 @@ mod tests {
fn spawn_works() {
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();
}
@@ -1247,7 +1248,7 @@ mod tests {
fn version_works() {
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();
assert!(
@@ -1260,7 +1261,7 @@ mod tests {
fn eth_rpc_version_works() {
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();
assert!(
+1 -5
View File
@@ -1,6 +1,5 @@
//! This crate implements the testing nodes.
use alloy::{network::TxSigner, signers::Signature};
use revive_dt_config::Arguments;
use revive_dt_node_interaction::EthereumNode;
@@ -15,10 +14,7 @@ pub const GENESIS_JSON: &str = include_str!("../../../genesis.json");
/// An abstract interface for testing nodes.
pub trait Node: EthereumNode {
/// Create a new uninitialized instance.
fn new(
config: &Arguments,
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>,
) -> Self;
fn new(config: &Arguments) -> Self;
/// Spawns a node configured according to the genesis json.
///
+4 -19
View File
@@ -6,7 +6,6 @@ use std::{
thread,
};
use alloy::{network::TxSigner, signers::Signature};
use anyhow::Context;
use revive_dt_config::Arguments;
@@ -24,14 +23,7 @@ where
T: Node + Send + 'static,
{
/// Create a new Pool. This will start as many nodes as there are workers in `config`.
pub fn new(
config: &Arguments,
additional_signers: impl IntoIterator<Item: TxSigner<Signature> + Send + Sync + 'static>
+ Clone
+ Send
+ Sync
+ 'static,
) -> anyhow::Result<Self> {
pub fn new(config: &Arguments) -> anyhow::Result<Self> {
let nodes = config.workers;
let genesis = read_to_string(&config.genesis_file).context(format!(
"can not read genesis file: {}",
@@ -42,10 +34,7 @@ where
for _ in 0..nodes {
let config = config.clone();
let genesis = genesis.clone();
let additional_signers = additional_signers.clone();
handles.push(thread::spawn(move || {
spawn_node::<T>(&config, additional_signers, genesis)
}));
handles.push(thread::spawn(move || spawn_node::<T>(&config, genesis)));
}
let mut nodes = Vec::with_capacity(nodes);
@@ -71,12 +60,8 @@ where
}
}
fn spawn_node<T: Node + Send>(
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);
fn spawn_node<T: Node + Send>(args: &Arguments, genesis: String) -> anyhow::Result<T> {
let mut node = T::new(args);
tracing::info!("starting node: {}", node.connection_string());
node.spawn(genesis)?;
Ok(node)