the test driver

Signed-off-by: xermicus <bigcyrill@hotmail.com>
This commit is contained in:
xermicus
2025-03-24 15:48:26 +01:00
parent 9bba37b7a9
commit ad4901550d
12 changed files with 217 additions and 74 deletions
+6 -19
View File
@@ -2,7 +2,7 @@
use std::collections::HashMap;
use revive_dt_compiler::{Compiler, solc::Solc};
use revive_dt_compiler::{Compiler, CompilerInput, SolidityCompiler};
use revive_dt_format::{
metadata::Metadata,
mode::{Mode, SolcMode},
@@ -10,15 +10,9 @@ use revive_dt_format::{
use revive_solc_json_interface::SolcStandardJsonOutput;
use semver::Version;
#[derive(Hash, Eq, PartialEq)]
pub struct SolcSettings {
pub optimizer: bool,
pub solc_version: Version,
}
pub fn build_evm(
pub fn build<T: SolidityCompiler>(
metadata: &Metadata,
) -> anyhow::Result<HashMap<SolcSettings, SolcStandardJsonOutput>> {
) -> anyhow::Result<HashMap<CompilerInput<T::Options>, SolcStandardJsonOutput>> {
let sources = metadata.contract_sources()?;
let base_path = metadata.directory()?.display().to_string();
let modes = metadata
@@ -28,7 +22,7 @@ pub fn build_evm(
let mut result = HashMap::new();
for mode in modes {
let mut compiler = Compiler::<Solc>::new().base_path(base_path.clone());
let mut compiler = Compiler::<T>::new().base_path(base_path.clone());
for (file, _contract) in sources.values() {
compiler = compiler.with_source(file)?;
}
@@ -41,15 +35,8 @@ pub fn build_evm(
}) => {
let optimizer = solc_optimize.unwrap_or(true);
let version = Version::new(0, 8, 29);
let out = compiler.solc_optimizer(optimizer).try_build(&version)?;
result.insert(
SolcSettings {
optimizer: true,
solc_version: version,
},
out,
);
let output = compiler.solc_optimizer(optimizer).try_build(&version)?;
result.insert(output.input, output.output);
}
Mode::Unknown(mode) => log::debug!("compiler: ignoring unknown mode '{mode}'"),
}
+56
View File
@@ -1,4 +1,60 @@
//! The test driver handles the compilation and execution of the test cases.
use alloy::primitives::map::HashMap;
use compiler::build;
use revive_dt_compiler::{CompilerInput, SolidityCompiler};
use revive_dt_config::Arguments;
use revive_dt_format::metadata::Metadata;
use revive_dt_node::Node;
use revive_solc_json_interface::SolcStandardJsonOutput;
use crate::Platform;
pub mod compiler;
pub mod input;
type Contracts<T> = HashMap<
CompilerInput<<<T as Platform>::Compiler as SolidityCompiler>::Options>,
SolcStandardJsonOutput,
>;
pub struct Driver<'a, Leader: Platform, Follower: Platform> {
metadata: &'a Metadata,
config: &'a Arguments,
leader_contracts: Contracts<Leader>,
leader_node: <Leader as Platform>::Blockchain,
follower_contracts: Contracts<Follower>,
follower_node: <Follower as Platform>::Blockchain,
}
impl<'a, L, F> Driver<'a, L, F>
where
L: Platform + Default,
F: Platform + Default,
{
pub fn new(metadata: &'a Metadata, config: &'a Arguments) -> Driver<'a, L, F> {
Self {
metadata,
config,
leader_node: <<L as Platform>::Blockchain as Node>::new(config),
leader_contracts: Default::default(),
follower_node: <<F as Platform>::Blockchain as Node>::new(config),
follower_contracts: Default::default(),
}
}
pub fn execute(&mut self) -> anyhow::Result<()> {
self.leader_contracts = build::<L::Compiler>(self.metadata)?;
self.follower_contracts = build::<F::Compiler>(self.metadata)?;
if self.config.compile_only {
return Ok(());
}
todo!()
}
}
+27 -2
View File
@@ -2,7 +2,32 @@
//!
//! This crate defines the testing configuration and
//! provides a helper utilty to execute tests.
//!
//!
use revive_dt_compiler::{SolidityCompiler, solc};
use revive_dt_node::{Node, geth};
pub mod driver;
/// One platform can be tested differentially against another.
///
/// For this we need a blockchain node implementation and a compiler.
pub trait Platform {
type Blockchain: Node;
type Compiler: SolidityCompiler;
}
#[derive(Default)]
pub struct Geth;
impl Platform for Geth {
type Blockchain = geth::Instance;
type Compiler = solc::Solc;
}
#[derive(Default)]
pub struct Kitchensink;
impl Platform for Kitchensink {
type Blockchain = geth::Instance;
type Compiler = solc::Solc;
}
+12 -6
View File
@@ -4,7 +4,7 @@ use clap::Parser;
use rayon::prelude::*;
use revive_dt_config::*;
use revive_dt_core::driver::compiler::build_evm;
use revive_dt_core::{Geth, Kitchensink, driver::Driver};
use revive_dt_format::corpus::Corpus;
use temp_dir::TempDir;
@@ -27,22 +27,28 @@ fn main() -> anyhow::Result<()> {
log::info!("found {} tests", tests.len());
tests.par_iter().for_each(|metadata| {
let _ = match build_evm(metadata) {
let mut driver = match (&args.leader, &args.follower) {
(TestingPlatform::Geth, TestingPlatform::Kitchensink) => {
Driver::<Geth, Kitchensink>::new(metadata, &args)
}
_ => unimplemented!(),
};
match driver.execute() {
Ok(build) => {
log::info!(
"metadata {} compilation success",
"metadata {} success",
metadata.file_path.as_ref().unwrap().display()
);
build
}
Err(error) => {
log::warn!(
"metadata {} compilation failure: {error:?}",
"metadata {} failure: {error:?}",
metadata.file_path.as_ref().unwrap().display()
);
return;
}
};
}
});
}