Use the solc version required in tests rather than one on PATH

This commit is contained in:
James Wilson
2025-08-21 12:23:54 +01:00
parent 85033cfead
commit 491a9a32b2
11 changed files with 263 additions and 307 deletions
+7 -12
View File
@@ -9,9 +9,10 @@ use std::{
use futures::FutureExt;
use revive_dt_common::iterators::FilesWithExtensionIterator;
use revive_dt_compiler::{Compiler, CompilerOutput, Mode, SolidityCompiler};
use revive_dt_compiler::{Compiler, CompilerOutput, Mode};
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::{Error, Result};
@@ -57,14 +58,7 @@ impl CachedCompiler {
Lazy::new(Default::default);
let compiler_version_or_requirement = mode.compiler_version_to_use(config.solc.clone());
let compiler_path = <P::Compiler as SolidityCompiler>::get_compiler_executable(
config,
compiler_version_or_requirement,
)
.await?;
let compiler_version = <P::Compiler as SolidityCompiler>::new(compiler_path.clone())
.version()
.await?;
let compiler_version = solc_version(compiler_version_or_requirement, config.wasm).await?;
let cache_key = CacheKey {
platform_key: P::config_id().to_string(),
@@ -77,8 +71,8 @@ impl CachedCompiler {
async move {
compile_contracts::<P>(
metadata.directory()?,
compiler_path,
metadata.files_to_compile()?,
config,
mode,
deployed_libraries,
)
@@ -138,8 +132,8 @@ impl CachedCompiler {
async fn compile_contracts<P: Platform>(
metadata_directory: impl AsRef<Path>,
compiler_path: impl AsRef<Path>,
mut files_to_compile: impl Iterator<Item = PathBuf>,
config: &Arguments,
mode: &Mode,
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
) -> Result<CompilerOutput> {
@@ -149,6 +143,7 @@ async fn compile_contracts<P: Platform>(
.collect::<Vec<_>>();
Compiler::<P::Compiler>::new()
.with_solc_version_req(mode.version.clone())
.with_allow_path(metadata_directory)
// Handling the modes
.with_optimization(mode.optimize_setting)
@@ -172,7 +167,7 @@ async fn compile_contracts<P: Platform>(
compiler.with_library(path, ident.as_str(), *address)
})
})
.try_build(compiler_path)
.try_build(config)
.await
}
+12 -38
View File
@@ -14,8 +14,8 @@ use alloy::{
};
use anyhow::Context;
use clap::Parser;
use futures::StreamExt;
use futures::stream;
use futures::{Stream, StreamExt};
use indexmap::IndexMap;
use revive_dt_node_interaction::EthereumNode;
use temp_dir::TempDir;
@@ -163,7 +163,7 @@ where
{
let (report_tx, report_rx) = mpsc::unbounded_channel::<(Test<'_>, CaseResult)>();
let tests = prepare_tests::<L, F>(args, metadata_files);
let tests = prepare_tests::<L, F>(metadata_files);
let driver_task = start_driver_task::<L, F>(args, tests, span, report_tx).await?;
let status_reporter_task = start_reporter_task(report_rx);
@@ -172,17 +172,14 @@ where
Ok(())
}
fn prepare_tests<'a, L, F>(
args: &Arguments,
metadata_files: &'a [MetadataFile],
) -> impl Stream<Item = Test<'a>>
fn prepare_tests<'a, L, F>(metadata_files: &'a [MetadataFile]) -> impl Iterator<Item = Test<'a>>
where
L: Platform,
F: Platform,
L::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
F::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
{
let filtered_tests = metadata_files
metadata_files
.iter()
.flat_map(|metadata_file| {
metadata_file
@@ -289,19 +286,12 @@ where
} else {
true
}
});
stream::iter(filtered_tests)
// Filter based on the compiler compatibility
.filter_map(move |test| async move {
let leader_support = does_compiler_support_mode::<L>(args, &test.mode)
.await
.ok()
.unwrap_or(false);
let follower_support = does_compiler_support_mode::<F>(args, &test.mode)
.await
.ok()
.unwrap_or(false);
})
.filter_map(move |test| {
let leader_support =
L::Compiler::supports_mode(test.mode.optimize_setting, test.mode.pipeline);
let follower_support =
F::Compiler::supports_mode(test.mode.optimize_setting, test.mode.pipeline);
let is_allowed = leader_support && follower_support;
if !is_allowed {
@@ -317,25 +307,9 @@ where
})
}
async fn does_compiler_support_mode<P: Platform>(
args: &Arguments,
mode: &Mode,
) -> anyhow::Result<bool> {
let compiler_version_or_requirement = mode.compiler_version_to_use(args.solc.clone());
let compiler_path =
P::Compiler::get_compiler_executable(args, compiler_version_or_requirement).await?;
let compiler_version = P::Compiler::new(compiler_path.clone()).version().await?;
Ok(P::Compiler::supports_mode(
&compiler_version,
mode.optimize_setting,
mode.pipeline,
))
}
async fn start_driver_task<'a, L, F>(
args: &Arguments,
tests: impl Stream<Item = Test<'a>>,
tests: impl Iterator<Item = Test<'a>>,
span: Span,
report_tx: mpsc::UnboundedSender<(Test<'a>, CaseResult)>,
) -> anyhow::Result<impl Future<Output = ()>>
@@ -356,7 +330,7 @@ where
.await?,
);
Ok(tests.for_each_concurrent(
Ok(stream::iter(tests).for_each_concurrent(
// We want to limit the concurrent tasks here because:
//
// 1. We don't want to overwhelm the nodes with too many requests, leading to responses timing out.