mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-12 20:31:10 +00:00
building for EVM works with complex cases
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -1 +1,68 @@
|
||||
//! The compiler driver builds the test case contracts for selected compilers.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use revive_dt_compiler::{Compiler, solc::Solc};
|
||||
use revive_dt_format::{
|
||||
metadata::Metadata,
|
||||
mode::{Mode, SolcMode},
|
||||
};
|
||||
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(
|
||||
metadata: &Metadata,
|
||||
) -> anyhow::Result<HashMap<SolcSettings, SolcStandardJsonOutput>> {
|
||||
let Some(metadata_path) = &metadata.path else {
|
||||
anyhow::bail!("missing directory in metadata");
|
||||
};
|
||||
let Some(directory) = metadata_path.parent() else {
|
||||
anyhow::bail!("metadata path has no parent: {}", metadata_path.display());
|
||||
};
|
||||
let Some(contracts) = &metadata.contracts else {
|
||||
anyhow::bail!("missing contracts in metadata: {}", metadata_path.display());
|
||||
};
|
||||
let modes = metadata
|
||||
.modes
|
||||
.to_owned()
|
||||
.unwrap_or_else(|| vec![Mode::Solidity(Default::default())]);
|
||||
|
||||
let sources = super::contract_sources_from_metadata(directory, contracts)?;
|
||||
|
||||
let mut result = HashMap::new();
|
||||
for mode in modes {
|
||||
let mut compiler = Compiler::<Solc>::new().base_path(directory.display().to_string());
|
||||
for (_, file) in &sources {
|
||||
compiler = compiler.with_source(file)?;
|
||||
}
|
||||
|
||||
match mode {
|
||||
Mode::Unknown(mode) => log::debug!("compiler: ignoring unknown mode '{mode}'"),
|
||||
Mode::Solidity(SolcMode {
|
||||
solc_version: _,
|
||||
solc_optimize,
|
||||
llvm_optimizer_settings: _,
|
||||
}) => {
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,28 @@
|
||||
//! The test driver handles the compilation and execution of the test cases.
|
||||
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
pub mod compiler;
|
||||
pub mod input;
|
||||
|
||||
pub(crate) fn contract_sources_from_metadata(
|
||||
directory: &Path,
|
||||
contracts: &BTreeMap<String, String>,
|
||||
) -> anyhow::Result<BTreeMap<String, PathBuf>> {
|
||||
let mut sources = BTreeMap::new();
|
||||
for (name, contract) in contracts {
|
||||
// TODO: broken if a colon is in the dir name..
|
||||
let Some(solidity_file_name) = contract.split(':').next() else {
|
||||
anyhow::bail!("metadata contains invalid contract: {contract}");
|
||||
};
|
||||
|
||||
let mut file = directory.to_path_buf();
|
||||
file.push(solidity_file_name);
|
||||
sources.insert(name.clone(), file);
|
||||
}
|
||||
|
||||
Ok(sources)
|
||||
}
|
||||
|
||||
+15
-2
@@ -2,7 +2,8 @@ use std::collections::BTreeSet;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use revive_dt_core::arguments::Arguments;
|
||||
use rayon::prelude::*;
|
||||
use revive_dt_core::{arguments::Arguments, driver::compiler::build_evm};
|
||||
use revive_dt_format::corpus::Corpus;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
@@ -16,8 +17,20 @@ fn main() -> anyhow::Result<()> {
|
||||
log::info!("found corpus: {corpus:?}");
|
||||
|
||||
let tests = corpus.enumerate_tests();
|
||||
log::info!("found {} tests", tests.len());
|
||||
|
||||
log::debug!("{tests:?}");
|
||||
tests
|
||||
.par_iter()
|
||||
.for_each(|metadata| match build_evm(&metadata) {
|
||||
Ok(_) => log::info!(
|
||||
"metadata {} compilation success",
|
||||
metadata.path.as_ref().unwrap().display()
|
||||
),
|
||||
Err(error) => log::warn!(
|
||||
"metadata {} compilation failure: {error:?}",
|
||||
metadata.path.as_ref().unwrap().display()
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user