Compare commits

..

2 Commits

Author SHA1 Message Date
activecoder10 8287146003 Improve tracing part 2025-06-10 09:50:45 +03:00
activecoder10 b8cd5d6031 Extended execute_input method 2025-06-09 19:10:23 +03:00
4 changed files with 22 additions and 101 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ clippy:
machete: machete:
cargo install cargo-machete cargo install cargo-machete
cargo machete crates cargo machete
test: format clippy machete test: format clippy machete
cargo test --workspace -- --nocapture cargo test --workspace -- --nocapture
+2 -59
View File
@@ -1,12 +1,8 @@
//! The test driver handles the compilation and execution of the test cases. //! The test driver handles the compilation and execution of the test cases.
use alloy::{ use alloy::{
network::TransactionBuilder, primitives::{Address, map::HashMap},
primitives::{Address, bytes::Bytes, map::HashMap}, rpc::types::trace::geth::{AccountState, DiffMode, GethTrace},
rpc::types::{
TransactionRequest,
trace::geth::{AccountState, DiffMode, GethTrace},
},
}; };
use revive_dt_compiler::{Compiler, CompilerInput, SolidityCompiler}; use revive_dt_compiler::{Compiler, CompilerInput, SolidityCompiler};
use revive_dt_config::Arguments; use revive_dt_config::Arguments;
@@ -113,56 +109,6 @@ where
Ok((trace, diff)) Ok((trace, diff))
} }
pub fn deploy_contracts(&mut self, input: &Input, node: &T::Blockchain) -> anyhow::Result<()> {
for output in self.contracts.values() {
let Some(contract_map) = &output.contracts else {
log::debug!("No contracts in output — skipping deployment for this input.");
continue;
};
for contracts in contract_map.values() {
for (contract_name, contract) in contracts {
if contract_name != &input.instance {
continue;
}
let bytecode = contract
.evm
.as_ref()
.and_then(|evm| evm.bytecode.as_ref())
.map(|b| b.object.clone());
let Some(code) = bytecode else {
anyhow::bail!("no bytecode for contract `{}`", contract_name);
};
let tx = TransactionRequest::default()
.with_from(input.caller)
.with_to(Address::ZERO)
.with_input(Bytes::from(code.clone()))
.with_gas_price(20_000_000_000)
.with_gas_limit(20_000_000_000)
.with_chain_id(self.config.network_id)
.with_nonce(0);
let receipt = node.execute_transaction(tx)?;
let Some(address) = receipt.contract_address else {
anyhow::bail!(
"contract `{}` deployment did not return an address",
contract_name
);
};
self.deployed_contracts
.insert(contract_name.clone(), address);
log::info!("deployed contract `{}` at {:?}", contract_name, address);
}
}
}
Ok(())
}
} }
pub struct Driver<'a, Leader: Platform, Follower: Platform> { pub struct Driver<'a, Leader: Platform, Follower: Platform> {
@@ -227,9 +173,6 @@ where
for case in &self.metadata.cases { for case in &self.metadata.cases {
for input in &case.inputs { for input in &case.inputs {
leader_state.deploy_contracts(input, self.leader_node)?;
follower_state.deploy_contracts(input, self.follower_node)?;
let (_, leader_diff) = leader_state.execute_input(input, self.leader_node)?; let (_, leader_diff) = leader_state.execute_input(input, self.leader_node)?;
let (_, follower_diff) = let (_, follower_diff) =
follower_state.execute_input(input, self.follower_node)?; follower_state.execute_input(input, self.follower_node)?;
+11 -27
View File
@@ -5,7 +5,7 @@ use rayon::{ThreadPoolBuilder, prelude::*};
use revive_dt_config::*; use revive_dt_config::*;
use revive_dt_core::{ use revive_dt_core::{
Geth, Kitchensink, Platform, Geth, Kitchensink,
driver::{Driver, State}, driver::{Driver, State},
}; };
use revive_dt_format::{corpus::Corpus, metadata::Metadata}; use revive_dt_format::{corpus::Corpus, metadata::Metadata};
@@ -74,30 +74,28 @@ fn collect_corpora(args: &Arguments) -> anyhow::Result<HashMap<Corpus, Vec<Metad
Ok(corpora) Ok(corpora)
} }
fn run_driver<L, F>(args: &Arguments, tests: &[Metadata], span: Span) -> anyhow::Result<()> fn execute_corpus(args: &Arguments, tests: &[Metadata], span: Span) -> anyhow::Result<()> {
where let leader_nodes = NodePool::new(args)?;
L: Platform, let follower_nodes = NodePool::new(args)?;
F: Platform,
L::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 follower_nodes = NodePool::<F::Blockchain>::new(args)?;
tests.par_iter().for_each(|metadata| { tests.par_iter().for_each(|metadata| {
let mut driver = Driver::<L, F>::new( let mut driver = match (&args.leader, &args.follower) {
(TestingPlatform::Geth, TestingPlatform::Kitchensink) => Driver::<Geth, Geth>::new(
metadata, metadata,
args, args,
leader_nodes.round_robbin(), leader_nodes.round_robbin(),
follower_nodes.round_robbin(), follower_nodes.round_robbin(),
); ),
_ => unimplemented!(),
};
match driver.execute(span) { match driver.execute(span) {
Ok(_) => { Ok(build) => {
log::info!( log::info!(
"metadata {} success", "metadata {} success",
metadata.directory().as_ref().unwrap().display() metadata.directory().as_ref().unwrap().display()
); );
build
} }
Err(error) => { Err(error) => {
log::warn!( log::warn!(
@@ -111,20 +109,6 @@ where
Ok(()) Ok(())
} }
fn execute_corpus(args: &Arguments, tests: &[Metadata], span: Span) -> anyhow::Result<()> {
match (&args.leader, &args.follower) {
(TestingPlatform::Geth, TestingPlatform::Kitchensink) => {
run_driver::<Geth, Kitchensink>(args, tests, span)?
}
(TestingPlatform::Geth, TestingPlatform::Geth) => {
run_driver::<Geth, Geth>(args, tests, span)?
}
_ => unimplemented!(),
}
Ok(())
}
fn compile_corpus(config: &Arguments, tests: &[Metadata], platform: &TestingPlatform, span: Span) { fn compile_corpus(config: &Arguments, tests: &[Metadata], platform: &TestingPlatform, span: Span) {
tests.par_iter().for_each(|metadata| { tests.par_iter().for_each(|metadata| {
for mode in &metadata.solc_modes() { for mode in &metadata.solc_modes() {
+4 -10
View File
@@ -132,7 +132,7 @@ impl Metadata {
} }
fn try_from_solidity(path: &Path) -> Option<Self> { fn try_from_solidity(path: &Path) -> Option<Self> {
let spec = read_to_string(path) let buf = read_to_string(path)
.inspect_err(|error| { .inspect_err(|error| {
log::error!( log::error!(
"opening JSON test metadata file '{}' error: {error}", "opening JSON test metadata file '{}' error: {error}",
@@ -147,24 +147,18 @@ impl Metadata {
buf buf
}); });
if spec.is_empty() { if buf.is_empty() {
return None; return None;
} }
match serde_json::from_str::<Self>(&spec) { match serde_json::from_str::<Self>(&buf) {
Ok(mut metadata) => { Ok(mut metadata) => {
metadata.file_path = Some(path.to_path_buf()); metadata.file_path = Some(path.to_path_buf());
let name = path
.file_name()
.expect("this should be the path to a Solidity file")
.to_str()
.expect("the file name should be valid UTF-8k");
metadata.contracts = Some([(String::from("Test"), format!("{name}:Test"))].into());
Some(metadata) Some(metadata)
} }
Err(error) => { Err(error) => {
log::error!( log::error!(
"parsing Solidity test metadata file '{}' error: '{error}' from data: {spec}", "parsing Solidity test metadata file '{}' error: {error}",
path.display() path.display()
); );
None None