mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-13 00:01:08 +00:00
Pass solc version into compiler rather than returning from compilation. Allows for better reporting
This commit is contained in:
@@ -9,10 +9,9 @@ use std::{
|
||||
|
||||
use futures::FutureExt;
|
||||
use revive_dt_common::iterators::FilesWithExtensionIterator;
|
||||
use revive_dt_compiler::{Compiler, CompilerInput, CompilerOutput, Mode, SolcCompilerInformation};
|
||||
use revive_dt_compiler::{Compiler, CompilerInput, CompilerOutput, Mode, SolcCompiler};
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_dt_format::metadata::{ContractIdent, ContractInstance, Metadata};
|
||||
use revive_dt_solc_binaries::solc_version;
|
||||
|
||||
use alloy::{hex::ToHexExt, json_abi::JsonAbi, primitives::Address};
|
||||
use anyhow::{Context as _, Error, Result};
|
||||
@@ -54,26 +53,20 @@ impl CachedCompiler {
|
||||
&self,
|
||||
metadata: &Metadata,
|
||||
metadata_file_path: impl AsRef<Path>,
|
||||
solc: SolcCompiler,
|
||||
mode: &Mode,
|
||||
config: &Arguments,
|
||||
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
|
||||
compilation_success_report_callback: impl Fn(bool, Option<CompilerInput>, CompilerOutput)
|
||||
+ Clone,
|
||||
compilation_failure_report_callback: impl Fn(
|
||||
Option<SolcCompilerInformation>,
|
||||
Option<CompilerInput>,
|
||||
String,
|
||||
),
|
||||
compilation_failure_report_callback: impl Fn(Option<CompilerInput>, String),
|
||||
) -> Result<CompilerOutput> {
|
||||
static CACHE_KEY_LOCK: Lazy<RwLock<HashMap<CacheKey, Arc<Mutex<()>>>>> =
|
||||
Lazy::new(Default::default);
|
||||
|
||||
let solc_version_or_requirement = mode.compiler_version_to_use(config.solc.clone());
|
||||
let solc_version = solc_version(solc_version_or_requirement, false).await?;
|
||||
|
||||
let cache_key = CacheKey {
|
||||
platform_key: P::config_id().to_string(),
|
||||
compiler_version: solc_version.clone(),
|
||||
compiler_version: solc.version.clone(),
|
||||
metadata_file_path: metadata_file_path.as_ref().to_path_buf(),
|
||||
solc_mode: mode.clone(),
|
||||
};
|
||||
@@ -91,6 +84,7 @@ impl CachedCompiler {
|
||||
.files_to_compile()
|
||||
.context("Failed to enumerate files to compile from metadata")?,
|
||||
config,
|
||||
solc,
|
||||
mode,
|
||||
deployed_libraries,
|
||||
compilation_success_report_callback,
|
||||
@@ -170,14 +164,11 @@ async fn compile_contracts<P: Platform>(
|
||||
metadata_directory: impl AsRef<Path>,
|
||||
mut files_to_compile: impl Iterator<Item = PathBuf>,
|
||||
config: &Arguments,
|
||||
solc: SolcCompiler,
|
||||
mode: &Mode,
|
||||
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
|
||||
compilation_success_report_callback: impl Fn(bool, Option<CompilerInput>, CompilerOutput),
|
||||
compilation_failure_report_callback: impl Fn(
|
||||
Option<SolcCompilerInformation>,
|
||||
Option<CompilerInput>,
|
||||
String,
|
||||
),
|
||||
compilation_failure_report_callback: impl Fn(Option<CompilerInput>, String),
|
||||
) -> Result<CompilerOutput> {
|
||||
let all_sources_in_dir = FilesWithExtensionIterator::new(metadata_directory.as_ref())
|
||||
.with_allowed_extension("sol")
|
||||
@@ -185,7 +176,7 @@ async fn compile_contracts<P: Platform>(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let compiler = Compiler::<P::Compiler>::new()
|
||||
.with_solc_version_req(mode.version.clone())
|
||||
.with_solc(solc)
|
||||
.with_allow_path(metadata_directory)
|
||||
// Handling the modes
|
||||
.with_optimization(mode.optimize_setting)
|
||||
@@ -194,7 +185,7 @@ async fn compile_contracts<P: Platform>(
|
||||
.try_then(|compiler| {
|
||||
files_to_compile.try_fold(compiler, |compiler, path| compiler.with_source(path))
|
||||
})
|
||||
.inspect_err(|err| compilation_failure_report_callback(None, None, format!("{err:#}")))?
|
||||
.inspect_err(|err| compilation_failure_report_callback(None, format!("{err:#}")))?
|
||||
// Adding the deployed libraries to the compiler.
|
||||
.then(|compiler| {
|
||||
deployed_libraries
|
||||
@@ -216,11 +207,7 @@ async fn compile_contracts<P: Platform>(
|
||||
.try_build(config)
|
||||
.await
|
||||
.inspect_err(|err| {
|
||||
compilation_failure_report_callback(
|
||||
None,
|
||||
Some(compiler_input.clone()),
|
||||
format!("{err:#}"),
|
||||
)
|
||||
compilation_failure_report_callback(Some(compiler_input.clone()), format!("{err:#}"))
|
||||
})
|
||||
.context("Failed to configure compiler with sources and options")?;
|
||||
|
||||
|
||||
+53
-17
@@ -604,6 +604,14 @@ where
|
||||
L::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
F::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
{
|
||||
let solc = revive_dt_compiler::solc_compiler(
|
||||
config.directory(),
|
||||
&config.solc,
|
||||
test.mode.version.as_ref(),
|
||||
test.mode.pipeline,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let leader_reporter = test
|
||||
.reporter
|
||||
.execution_specific_reporter(leader_node.id(), NodeDesignation::Leader);
|
||||
@@ -614,16 +622,15 @@ where
|
||||
let (
|
||||
CompilerOutput {
|
||||
contracts: leader_pre_link_contracts,
|
||||
..
|
||||
},
|
||||
CompilerOutput {
|
||||
contracts: follower_pre_link_contracts,
|
||||
..
|
||||
},
|
||||
) = try_join!(
|
||||
cached_compiler.compile_contracts::<L>(
|
||||
test.metadata,
|
||||
test.metadata_file_path,
|
||||
solc.clone(),
|
||||
&test.mode,
|
||||
config,
|
||||
None,
|
||||
@@ -631,15 +638,16 @@ where
|
||||
leader_reporter
|
||||
.report_pre_link_contracts_compilation_succeeded_event(
|
||||
is_cached,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
},
|
||||
|solc_info, compiler_input, failure_reason| {
|
||||
|compiler_input, failure_reason| {
|
||||
leader_reporter
|
||||
.report_pre_link_contracts_compilation_failed_event(
|
||||
solc_info,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
failure_reason,
|
||||
)
|
||||
@@ -649,6 +657,7 @@ where
|
||||
cached_compiler.compile_contracts::<F>(
|
||||
test.metadata,
|
||||
test.metadata_file_path,
|
||||
solc.clone(),
|
||||
&test.mode,
|
||||
config,
|
||||
None,
|
||||
@@ -656,15 +665,16 @@ where
|
||||
follower_reporter
|
||||
.report_pre_link_contracts_compilation_succeeded_event(
|
||||
is_cached,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
},
|
||||
|solc_info, compiler_input, failure_reason| {
|
||||
|compiler_input, failure_reason| {
|
||||
follower_reporter
|
||||
.report_pre_link_contracts_compilation_failed_event(
|
||||
solc_info,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
failure_reason,
|
||||
)
|
||||
@@ -802,17 +812,16 @@ where
|
||||
|
||||
let (
|
||||
CompilerOutput {
|
||||
solc: leader_solc_info,
|
||||
contracts: leader_post_link_contracts,
|
||||
},
|
||||
CompilerOutput {
|
||||
solc: follower_solc_info,
|
||||
contracts: follower_post_link_contracts,
|
||||
},
|
||||
) = try_join!(
|
||||
cached_compiler.compile_contracts::<L>(
|
||||
test.metadata,
|
||||
test.metadata_file_path,
|
||||
solc.clone(),
|
||||
&test.mode,
|
||||
config,
|
||||
leader_deployed_libraries.as_ref(),
|
||||
@@ -820,15 +829,16 @@ where
|
||||
leader_reporter
|
||||
.report_post_link_contracts_compilation_succeeded_event(
|
||||
is_cached,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
},
|
||||
|solc_info, compiler_input, failure_reason| {
|
||||
|compiler_input, failure_reason| {
|
||||
leader_reporter
|
||||
.report_post_link_contracts_compilation_failed_event(
|
||||
solc_info,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
failure_reason,
|
||||
)
|
||||
@@ -838,6 +848,7 @@ where
|
||||
cached_compiler.compile_contracts::<F>(
|
||||
test.metadata,
|
||||
test.metadata_file_path,
|
||||
solc.clone(),
|
||||
&test.mode,
|
||||
config,
|
||||
follower_deployed_libraries.as_ref(),
|
||||
@@ -845,15 +856,16 @@ where
|
||||
follower_reporter
|
||||
.report_post_link_contracts_compilation_succeeded_event(
|
||||
is_cached,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
},
|
||||
|solc_info, compiler_input, failure_reason| {
|
||||
|compiler_input, failure_reason| {
|
||||
follower_reporter
|
||||
.report_post_link_contracts_compilation_failed_event(
|
||||
solc_info,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
failure_reason,
|
||||
)
|
||||
@@ -864,13 +876,13 @@ where
|
||||
.context("Failed to compile post-link contracts for leader/follower in parallel")?;
|
||||
|
||||
let leader_state = CaseState::<L>::new(
|
||||
leader_solc_info.version,
|
||||
solc.version.clone(),
|
||||
leader_post_link_contracts,
|
||||
leader_deployed_libraries.unwrap_or_default(),
|
||||
leader_reporter,
|
||||
);
|
||||
let follower_state = CaseState::<F>::new(
|
||||
follower_solc_info.version,
|
||||
solc.version.clone(),
|
||||
follower_post_link_contracts,
|
||||
follower_deployed_libraries.unwrap_or_default(),
|
||||
follower_reporter,
|
||||
@@ -913,7 +925,7 @@ async fn compile_corpus(
|
||||
config: &Arguments,
|
||||
tests: &[MetadataFile],
|
||||
platform: &TestingPlatform,
|
||||
_: Reporter,
|
||||
reporter: Reporter,
|
||||
report_aggregator_task: impl Future<Output = anyhow::Result<()>>,
|
||||
) {
|
||||
let tests = tests.iter().flat_map(|metadata| {
|
||||
@@ -932,19 +944,42 @@ async fn compile_corpus(
|
||||
let compilation_task =
|
||||
futures::stream::iter(tests).for_each_concurrent(None, |(metadata, mode)| {
|
||||
let cached_compiler = cached_compiler.clone();
|
||||
let reporter = reporter.clone();
|
||||
|
||||
async move {
|
||||
let solc = revive_dt_compiler::solc_compiler(
|
||||
config.directory(),
|
||||
&config.solc,
|
||||
mode.version.as_ref(),
|
||||
mode.pipeline,
|
||||
)
|
||||
.await;
|
||||
|
||||
let solc = match solc {
|
||||
Ok(solc) => solc,
|
||||
Err(err) => {
|
||||
let test_specifier = TestSpecifier {
|
||||
solc_mode: mode,
|
||||
metadata_file_path: metadata.metadata_file_path.clone(),
|
||||
case_idx: 0.into(),
|
||||
};
|
||||
let _ = reporter.report_test_failed_event(test_specifier, err.to_string());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match platform {
|
||||
TestingPlatform::Geth => {
|
||||
let _ = cached_compiler
|
||||
.compile_contracts::<Geth>(
|
||||
metadata,
|
||||
metadata.metadata_file_path.as_path(),
|
||||
solc,
|
||||
&mode,
|
||||
config,
|
||||
None,
|
||||
|_, _, _| {},
|
||||
|_, _, _| {},
|
||||
|_, _| {},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -953,11 +988,12 @@ async fn compile_corpus(
|
||||
.compile_contracts::<Kitchensink>(
|
||||
metadata,
|
||||
metadata.metadata_file_path.as_path(),
|
||||
solc,
|
||||
&mode,
|
||||
config,
|
||||
None,
|
||||
|_, _, _| {},
|
||||
|_, _, _| {},
|
||||
|_, _| {},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user