mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-22 19:37:57 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b6e0701ec9 | |||
| f99b3dbc3c | |||
| 0e79594bb2 | |||
| 5c75228496 | |||
| 8229675ba8 | |||
| dd94b12b34 | |||
| 4af9f6695d | |||
| 4d8adb553c | |||
| bdd2eab194 | |||
| eb754bc9e8 | |||
| 0e5e57e703 | |||
| 491a9a32b2 |
Generated
+5
-10
@@ -4492,6 +4492,7 @@ dependencies = [
|
||||
"semver 1.0.26",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
@@ -4504,7 +4505,7 @@ dependencies = [
|
||||
"clap",
|
||||
"semver 1.0.26",
|
||||
"serde",
|
||||
"temp-dir",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4518,6 +4519,7 @@ dependencies = [
|
||||
"clap",
|
||||
"futures",
|
||||
"indexmap 2.10.0",
|
||||
"once_cell",
|
||||
"revive-dt-common",
|
||||
"revive-dt-compiler",
|
||||
"revive-dt-config",
|
||||
@@ -4528,7 +4530,7 @@ dependencies = [
|
||||
"semver 1.0.26",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"temp-dir",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
@@ -4569,7 +4571,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"sp-core",
|
||||
"sp-runtime",
|
||||
"temp-dir",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
@@ -4594,7 +4596,6 @@ dependencies = [
|
||||
"revive-dt-compiler",
|
||||
"revive-dt-config",
|
||||
"revive-dt-format",
|
||||
"semver 1.0.26",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
@@ -5816,12 +5817,6 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||
|
||||
[[package]]
|
||||
name = "temp-dir"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83176759e9416cf81ee66cb6508dbfe9c96f20b8b56265a39917551c23c70964"
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.20.0"
|
||||
|
||||
@@ -48,7 +48,6 @@ serde_with = { version = "3.14.0" }
|
||||
sha2 = { version = "0.10.9" }
|
||||
sp-core = "36.1.0"
|
||||
sp-runtime = "41.1.0"
|
||||
temp-dir = { version = "0.1.16" }
|
||||
tempfile = "3.3"
|
||||
thiserror = "2"
|
||||
tokio = { version = "1.47.0", default-features = false, features = [
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/// An iterator that could be either of two iterators.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum EitherIter<A, B> {
|
||||
A(A),
|
||||
B(B),
|
||||
}
|
||||
|
||||
impl<A, B, T> Iterator for EitherIter<A, B>
|
||||
where
|
||||
A: Iterator<Item = T>,
|
||||
B: Iterator<Item = T>,
|
||||
{
|
||||
type Item = T;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self {
|
||||
EitherIter::A(iter) => iter.next(),
|
||||
EitherIter::B(iter) => iter.next(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
mod either_iter;
|
||||
mod files_with_extension_iterator;
|
||||
|
||||
pub use either_iter::*;
|
||||
pub use files_with_extension_iterator::*;
|
||||
|
||||
@@ -3,7 +3,6 @@ use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
/// This represents a mode that a given test should be run with, if possible.
|
||||
///
|
||||
@@ -35,19 +34,14 @@ impl Display for Mode {
|
||||
|
||||
impl Mode {
|
||||
/// Return all of the available mode combinations.
|
||||
pub fn all() -> impl Iterator<Item = &'static Mode> {
|
||||
static ALL_MODES: LazyLock<Vec<Mode>> = LazyLock::new(|| {
|
||||
ModePipeline::test_cases()
|
||||
.flat_map(|pipeline| {
|
||||
ModeOptimizerSetting::test_cases().map(move |optimize_setting| Mode {
|
||||
pipeline,
|
||||
optimize_setting,
|
||||
version: None,
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
ALL_MODES.iter()
|
||||
pub fn all() -> impl Iterator<Item = Mode> {
|
||||
ModePipeline::test_cases().flat_map(|pipeline| {
|
||||
ModeOptimizerSetting::test_cases().map(move |optimize_setting| Mode {
|
||||
pipeline,
|
||||
optimize_setting,
|
||||
version: None,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Resolves the [`Mode`]'s solidity version requirement into a [`VersionOrRequirement`] if
|
||||
|
||||
@@ -6,6 +6,42 @@ pub enum VersionOrRequirement {
|
||||
Requirement(VersionReq),
|
||||
}
|
||||
|
||||
impl VersionOrRequirement {
|
||||
/// A helper function to convert a [`semver::Version`] into a [`semver::VersionReq`].
|
||||
pub fn version_to_requirement(version: &Version) -> VersionReq {
|
||||
// Ignoring "build" metadata in the version, we can turn
|
||||
// it into a requirement which is an exact match for the
|
||||
// given version and nothing else:
|
||||
VersionReq {
|
||||
comparators: vec![semver::Comparator {
|
||||
op: semver::Op::Exact,
|
||||
major: version.major,
|
||||
minor: Some(version.minor),
|
||||
patch: Some(version.patch),
|
||||
pre: version.pre.clone(),
|
||||
}],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::Serialize for VersionOrRequirement {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
match self {
|
||||
VersionOrRequirement::Version(v) => serializer.serialize_str(&v.to_string()),
|
||||
VersionOrRequirement::Requirement(r) => serializer.serialize_str(&r.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for VersionOrRequirement {
|
||||
fn default() -> Self {
|
||||
VersionOrRequirement::Requirement(VersionReq::STAR)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Version> for VersionOrRequirement {
|
||||
fn from(value: Version) -> Self {
|
||||
Self::Version(value)
|
||||
@@ -18,24 +54,45 @@ impl From<VersionReq> for VersionOrRequirement {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VersionOrRequirement> for VersionReq {
|
||||
fn from(value: VersionOrRequirement) -> Self {
|
||||
match value {
|
||||
VersionOrRequirement::Version(version) => {
|
||||
VersionOrRequirement::version_to_requirement(&version)
|
||||
}
|
||||
VersionOrRequirement::Requirement(version_req) => version_req,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<VersionOrRequirement> for Version {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: VersionOrRequirement) -> Result<Self, Self::Error> {
|
||||
let VersionOrRequirement::Version(version) = value else {
|
||||
anyhow::bail!("Version or requirement was not a version");
|
||||
};
|
||||
Ok(version)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<VersionOrRequirement> for VersionReq {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: VersionOrRequirement) -> Result<Self, Self::Error> {
|
||||
let VersionOrRequirement::Requirement(requirement) = value else {
|
||||
anyhow::bail!("Version or requirement was not a requirement");
|
||||
};
|
||||
Ok(requirement)
|
||||
match value {
|
||||
VersionOrRequirement::Version(version) => Ok(version),
|
||||
VersionOrRequirement::Requirement(mut version_req) => {
|
||||
if version_req.comparators.len() != 1 {
|
||||
anyhow::bail!(
|
||||
"The version requirement in VersionOrRequirement is not a single exact version"
|
||||
);
|
||||
}
|
||||
|
||||
let c = version_req.comparators.pop().unwrap();
|
||||
let (semver::Op::Exact, Some(minor), Some(patch)) = (c.op, c.minor, c.patch) else {
|
||||
anyhow::bail!(
|
||||
"The version requirement in VersionOrRequirement is not an exact version"
|
||||
);
|
||||
};
|
||||
|
||||
Ok(Version {
|
||||
major: c.major,
|
||||
minor,
|
||||
patch,
|
||||
pre: c.pre,
|
||||
build: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,5 +26,8 @@ serde_json = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
+52
-35
@@ -3,6 +3,8 @@
|
||||
//! - Polkadot revive resolc compiler
|
||||
//! - Polkadot revive Wasm compiler
|
||||
|
||||
mod utils;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
hash::Hash,
|
||||
@@ -11,56 +13,48 @@ use std::{
|
||||
|
||||
use alloy::json_abi::JsonAbi;
|
||||
use alloy_primitives::Address;
|
||||
use anyhow::{Context, Result};
|
||||
use semver::Version;
|
||||
use anyhow::Context;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use revive_common::EVMVersion;
|
||||
use revive_dt_common::cached_fs::read_to_string;
|
||||
use revive_dt_common::types::VersionOrRequirement;
|
||||
use revive_dt_config::Arguments;
|
||||
|
||||
// Re-export this as it's a part of the compiler interface.
|
||||
pub use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline};
|
||||
|
||||
// Expose functionality for instantiating a SolcCompiler.
|
||||
pub use utils::{SolcCompiler, solc_compiler};
|
||||
|
||||
pub mod revive_js;
|
||||
pub mod revive_resolc;
|
||||
pub mod solc;
|
||||
|
||||
/// A common interface for all supported Solidity compilers.
|
||||
pub trait SolidityCompiler: Sized {
|
||||
/// Instantiates a new compiler object.
|
||||
///
|
||||
/// Based on the given [`Arguments`] and [`VersionOrRequirement`] this function instantiates a
|
||||
/// new compiler object. Certain implementations of this trait might choose to cache cache the
|
||||
/// compiler objects and return the same ones over and over again.
|
||||
fn new(
|
||||
config: &Arguments,
|
||||
version: impl Into<Option<VersionOrRequirement>>,
|
||||
) -> impl Future<Output = Result<Self>>;
|
||||
|
||||
/// Returns the version of the compiler.
|
||||
fn version(&self) -> &Version;
|
||||
|
||||
/// Returns the path of the compiler executable.
|
||||
fn path(&self) -> &Path;
|
||||
pub trait SolidityCompiler {
|
||||
/// Extra options specific to the compiler.
|
||||
type Options: Default + PartialEq + Eq + Hash;
|
||||
|
||||
/// The low-level compiler interface.
|
||||
fn build(&self, input: CompilerInput) -> impl Future<Output = Result<CompilerOutput>>;
|
||||
|
||||
/// Does the compiler support the provided mode and version settings.
|
||||
fn supports_mode(
|
||||
fn build(
|
||||
&self,
|
||||
optimizer_setting: ModeOptimizerSetting,
|
||||
pipeline: ModePipeline,
|
||||
) -> bool;
|
||||
input: CompilerInput,
|
||||
additional_options: Self::Options,
|
||||
) -> impl Future<Output = anyhow::Result<CompilerOutput>>;
|
||||
|
||||
/// Instantiate a new compiler.
|
||||
fn new(config: &Arguments) -> Self;
|
||||
|
||||
/// Does the compiler support the provided mode and version settings?
|
||||
fn supports_mode(optimize_setting: ModeOptimizerSetting, pipeline: ModePipeline) -> bool;
|
||||
}
|
||||
|
||||
/// The generic compilation input configuration.
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct CompilerInput {
|
||||
pub pipeline: Option<ModePipeline>,
|
||||
pub optimization: Option<ModeOptimizerSetting>,
|
||||
pub solc: Option<SolcCompiler>,
|
||||
pub evm_version: Option<EVMVersion>,
|
||||
pub allow_paths: Vec<PathBuf>,
|
||||
pub base_path: Option<PathBuf>,
|
||||
@@ -78,17 +72,27 @@ pub struct CompilerOutput {
|
||||
}
|
||||
|
||||
/// A generic builder style interface for configuring the supported compiler options.
|
||||
#[derive(Default)]
|
||||
pub struct Compiler {
|
||||
pub struct Compiler<T: SolidityCompiler> {
|
||||
input: CompilerInput,
|
||||
additional_options: T::Options,
|
||||
}
|
||||
|
||||
impl Compiler {
|
||||
impl Default for Compiler<solc::Solc> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Compiler<T>
|
||||
where
|
||||
T: SolidityCompiler,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
input: CompilerInput {
|
||||
pipeline: Default::default(),
|
||||
optimization: Default::default(),
|
||||
solc: Default::default(),
|
||||
evm_version: Default::default(),
|
||||
allow_paths: Default::default(),
|
||||
base_path: Default::default(),
|
||||
@@ -96,9 +100,15 @@ impl Compiler {
|
||||
libraries: Default::default(),
|
||||
revert_string_handling: Default::default(),
|
||||
},
|
||||
additional_options: T::Options::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_solc(mut self, value: impl Into<Option<SolcCompiler>>) -> Self {
|
||||
self.input.solc = value.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_optimization(mut self, value: impl Into<Option<ModeOptimizerSetting>>) -> Self {
|
||||
self.input.optimization = value.into();
|
||||
self
|
||||
@@ -124,7 +134,7 @@ impl Compiler {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_source(mut self, path: impl AsRef<Path>) -> Result<Self> {
|
||||
pub fn with_source(mut self, path: impl AsRef<Path>) -> anyhow::Result<Self> {
|
||||
self.input.sources.insert(
|
||||
path.as_ref().to_path_buf(),
|
||||
read_to_string(path.as_ref()).context("Failed to read the contract source")?,
|
||||
@@ -154,6 +164,11 @@ impl Compiler {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_additional_options(mut self, options: impl Into<T::Options>) -> Self {
|
||||
self.additional_options = options.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn then(self, callback: impl FnOnce(Self) -> Self) -> Self {
|
||||
callback(self)
|
||||
}
|
||||
@@ -162,12 +177,14 @@ impl Compiler {
|
||||
callback(self)
|
||||
}
|
||||
|
||||
pub async fn try_build(self, compiler: &impl SolidityCompiler) -> Result<CompilerOutput> {
|
||||
compiler.build(self.input).await
|
||||
pub async fn try_build(self, config: &Arguments) -> anyhow::Result<CompilerOutput> {
|
||||
T::new(config)
|
||||
.build(self.input, self.additional_options)
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn input(&self) -> &CompilerInput {
|
||||
&self.input
|
||||
pub fn input(&self) -> CompilerInput {
|
||||
self.input.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
//! Implements the [SolidityCompiler] trait with `resolc` for
|
||||
//! compiling contracts to PolkaVM (PVM) bytecode.
|
||||
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
process::Stdio,
|
||||
sync::{Arc, LazyLock},
|
||||
};
|
||||
use std::{path::PathBuf, process::Stdio};
|
||||
|
||||
use dashmap::DashMap;
|
||||
use revive_dt_common::types::VersionOrRequirement;
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_solc_json_interface::{
|
||||
SolcStandardJsonInput, SolcStandardJsonInputLanguage, SolcStandardJsonInputSettings,
|
||||
@@ -16,61 +10,22 @@ use revive_solc_json_interface::{
|
||||
SolcStandardJsonOutput,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
CompilerInput, CompilerOutput, ModeOptimizerSetting, ModePipeline, SolidityCompiler, solc::Solc,
|
||||
};
|
||||
use crate::{CompilerInput, CompilerOutput, ModeOptimizerSetting, ModePipeline, SolidityCompiler};
|
||||
|
||||
use alloy::json_abi::JsonAbi;
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::Context;
|
||||
use semver::Version;
|
||||
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
||||
|
||||
/// A wrapper around the `resolc` binary, emitting PVM-compatible bytecode.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Resolc(Arc<ResolcInner>);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
struct ResolcInner {
|
||||
/// The internal solc compiler that the resolc compiler uses as a compiler frontend.
|
||||
solc: Solc,
|
||||
#[derive(Debug)]
|
||||
pub struct Resolc {
|
||||
/// Path to the `resolc` executable
|
||||
resolc_path: PathBuf,
|
||||
}
|
||||
|
||||
impl SolidityCompiler for Resolc {
|
||||
async fn new(
|
||||
config: &Arguments,
|
||||
version: impl Into<Option<VersionOrRequirement>>,
|
||||
) -> Result<Self> {
|
||||
/// This is a cache of all of the resolc compiler objects. Since we do not currently support
|
||||
/// multiple resolc compiler versions, so our cache is just keyed by the solc compiler and
|
||||
/// its version to the resolc compiler.
|
||||
static COMPILERS_CACHE: LazyLock<DashMap<Solc, Resolc>> = LazyLock::new(Default::default);
|
||||
|
||||
let solc = Solc::new(config, version)
|
||||
.await
|
||||
.context("Failed to create the solc compiler frontend for resolc")?;
|
||||
|
||||
Ok(COMPILERS_CACHE
|
||||
.entry(solc.clone())
|
||||
.or_insert_with(|| {
|
||||
Self(Arc::new(ResolcInner {
|
||||
solc,
|
||||
resolc_path: config.resolc.clone(),
|
||||
}))
|
||||
})
|
||||
.clone())
|
||||
}
|
||||
|
||||
fn version(&self) -> &Version {
|
||||
// We currently return the solc compiler version since we do not support multiple resolc
|
||||
// compiler versions.
|
||||
self.0.solc.version()
|
||||
}
|
||||
|
||||
fn path(&self) -> &std::path::Path {
|
||||
&self.0.resolc_path
|
||||
}
|
||||
type Options = Vec<String>;
|
||||
|
||||
#[tracing::instrument(level = "debug", ret)]
|
||||
async fn build(
|
||||
@@ -78,6 +33,7 @@ impl SolidityCompiler for Resolc {
|
||||
CompilerInput {
|
||||
pipeline,
|
||||
optimization,
|
||||
solc,
|
||||
evm_version,
|
||||
allow_paths,
|
||||
base_path,
|
||||
@@ -87,13 +43,15 @@ impl SolidityCompiler for Resolc {
|
||||
// resolc. So, we need to go back to this later once it's supported.
|
||||
revert_string_handling: _,
|
||||
}: CompilerInput,
|
||||
) -> Result<CompilerOutput> {
|
||||
additional_options: Self::Options,
|
||||
) -> anyhow::Result<CompilerOutput> {
|
||||
if !matches!(pipeline, None | Some(ModePipeline::ViaYulIR)) {
|
||||
anyhow::bail!(
|
||||
"Resolc only supports the Y (via Yul IR) pipeline, but the provided pipeline is {pipeline:?}"
|
||||
);
|
||||
}
|
||||
|
||||
let solc = solc.ok_or_else(|| anyhow::anyhow!("solc compiler not provided to resolc."))?;
|
||||
let input = SolcStandardJsonInput {
|
||||
language: SolcStandardJsonInputLanguage::Solidity,
|
||||
sources: sources
|
||||
@@ -134,11 +92,13 @@ impl SolidityCompiler for Resolc {
|
||||
},
|
||||
};
|
||||
|
||||
let mut command = AsyncCommand::new(self.path());
|
||||
let mut command = AsyncCommand::new(&self.resolc_path);
|
||||
command
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.arg("--solc")
|
||||
.arg(&solc.path)
|
||||
.arg("--standard-json");
|
||||
|
||||
if let Some(ref base_path) = base_path {
|
||||
@@ -155,7 +115,7 @@ impl SolidityCompiler for Resolc {
|
||||
}
|
||||
let mut child = command
|
||||
.spawn()
|
||||
.with_context(|| format!("Failed to spawn resolc at {}", self.path().display()))?;
|
||||
.with_context(|| format!("Failed to spawn resolc at {}", self.resolc_path.display()))?;
|
||||
|
||||
let stdin_pipe = child.stdin.as_mut().expect("stdin must be piped");
|
||||
let serialized_input = serde_json::to_vec(&input)
|
||||
@@ -272,11 +232,15 @@ impl SolidityCompiler for Resolc {
|
||||
Ok(compiler_output)
|
||||
}
|
||||
|
||||
fn supports_mode(
|
||||
&self,
|
||||
optimize_setting: ModeOptimizerSetting,
|
||||
pipeline: ModePipeline,
|
||||
) -> bool {
|
||||
pipeline == ModePipeline::ViaYulIR && self.0.solc.supports_mode(optimize_setting, pipeline)
|
||||
fn new(config: &Arguments) -> Self {
|
||||
Resolc {
|
||||
resolc_path: config.resolc.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn supports_mode(_optimize_setting: ModeOptimizerSetting, pipeline: ModePipeline) -> bool {
|
||||
// We only support the Y (IE compile via Yul IR) mode here. We must always compile
|
||||
// via Yul IR as resolc needs this to translate to LLVM IR and then RISCV.
|
||||
pipeline == ModePipeline::ViaYulIR
|
||||
}
|
||||
}
|
||||
|
||||
+23
-78
@@ -1,20 +1,9 @@
|
||||
//! Implements the [SolidityCompiler] trait with solc for
|
||||
//! compiling contracts to EVM bytecode.
|
||||
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
process::Stdio,
|
||||
sync::{Arc, LazyLock},
|
||||
};
|
||||
|
||||
use dashmap::DashMap;
|
||||
use revive_dt_common::types::VersionOrRequirement;
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_dt_solc_binaries::download_solc;
|
||||
|
||||
use super::utils;
|
||||
use crate::{CompilerInput, CompilerOutput, ModeOptimizerSetting, ModePipeline, SolidityCompiler};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::Context;
|
||||
use foundry_compilers_artifacts::{
|
||||
output_selection::{
|
||||
BytecodeOutputSelection, ContractOutputSelection, EvmOutputSelection, OutputSelection,
|
||||
@@ -22,57 +11,15 @@ use foundry_compilers_artifacts::{
|
||||
solc::CompilerOutput as SolcOutput,
|
||||
solc::*,
|
||||
};
|
||||
use semver::Version;
|
||||
use revive_dt_config::Arguments;
|
||||
use std::process::Stdio;
|
||||
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Solc(Arc<SolcInner>);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
struct SolcInner {
|
||||
/// The path of the solidity compiler executable that this object uses.
|
||||
solc_path: PathBuf,
|
||||
/// The version of the solidity compiler executable that this object uses.
|
||||
solc_version: Version,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct Solc {}
|
||||
|
||||
impl SolidityCompiler for Solc {
|
||||
async fn new(
|
||||
config: &Arguments,
|
||||
version: impl Into<Option<VersionOrRequirement>>,
|
||||
) -> Result<Self> {
|
||||
// This is a cache for the compiler objects so that whenever the same compiler version is
|
||||
// requested the same object is returned. We do this as we do not want to keep cloning the
|
||||
// compiler around.
|
||||
static COMPILERS_CACHE: LazyLock<DashMap<Version, Solc>> = LazyLock::new(Default::default);
|
||||
|
||||
// We attempt to download the solc binary. Note the following: this call does the version
|
||||
// resolution for us. Therefore, even if the download didn't proceed, this function will
|
||||
// resolve the version requirement into a canonical version of the compiler. It's then up
|
||||
// to us to either use the provided path or not.
|
||||
let version = version.into().unwrap_or_else(|| config.solc.clone().into());
|
||||
let (version, path) = download_solc(config.directory(), version, false)
|
||||
.await
|
||||
.context("Failed to download/get path to solc binary")?;
|
||||
|
||||
Ok(COMPILERS_CACHE
|
||||
.entry(version.clone())
|
||||
.or_insert_with(|| {
|
||||
Self(Arc::new(SolcInner {
|
||||
solc_path: path,
|
||||
solc_version: version,
|
||||
}))
|
||||
})
|
||||
.clone())
|
||||
}
|
||||
|
||||
fn version(&self) -> &Version {
|
||||
&self.0.solc_version
|
||||
}
|
||||
|
||||
fn path(&self) -> &std::path::Path {
|
||||
&self.0.solc_path
|
||||
}
|
||||
type Options = ();
|
||||
|
||||
#[tracing::instrument(level = "debug", ret)]
|
||||
async fn build(
|
||||
@@ -80,6 +27,7 @@ impl SolidityCompiler for Solc {
|
||||
CompilerInput {
|
||||
pipeline,
|
||||
optimization,
|
||||
solc,
|
||||
evm_version,
|
||||
allow_paths,
|
||||
base_path,
|
||||
@@ -87,12 +35,17 @@ impl SolidityCompiler for Solc {
|
||||
libraries,
|
||||
revert_string_handling,
|
||||
}: CompilerInput,
|
||||
) -> Result<CompilerOutput> {
|
||||
_: Self::Options,
|
||||
) -> anyhow::Result<CompilerOutput> {
|
||||
let solc = solc.ok_or_else(|| anyhow::anyhow!("solc compiler not provided to resolc."))?;
|
||||
let compiler_supports_via_ir =
|
||||
utils::solc_versions_supporting_yul_ir().matches(&solc.version);
|
||||
|
||||
// Be careful to entirely omit the viaIR field if the compiler does not support it,
|
||||
// as it will error if you provide fields it does not know about. Because
|
||||
// `supports_mode` is called prior to instantiating a compiler, we should never
|
||||
// ask for something which is invalid.
|
||||
let via_ir = match (pipeline, self.compiler_supports_yul()) {
|
||||
let via_ir = match (pipeline, compiler_supports_via_ir) {
|
||||
(pipeline, true) => pipeline.map(|p| p.via_yul_ir()),
|
||||
(_pipeline, false) => None,
|
||||
};
|
||||
@@ -152,7 +105,7 @@ impl SolidityCompiler for Solc {
|
||||
},
|
||||
};
|
||||
|
||||
let mut command = AsyncCommand::new(self.path());
|
||||
let mut command = AsyncCommand::new(&solc.path);
|
||||
command
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
@@ -173,7 +126,7 @@ impl SolidityCompiler for Solc {
|
||||
}
|
||||
let mut child = command
|
||||
.spawn()
|
||||
.with_context(|| format!("Failed to spawn solc at {}", self.path().display()))?;
|
||||
.with_context(|| format!("Failed to spawn solc at {}", solc.path.display()))?;
|
||||
|
||||
let stdin = child.stdin.as_mut().expect("should be piped");
|
||||
let serialized_input = serde_json::to_vec(&input)
|
||||
@@ -253,21 +206,13 @@ impl SolidityCompiler for Solc {
|
||||
Ok(compiler_output)
|
||||
}
|
||||
|
||||
fn supports_mode(
|
||||
&self,
|
||||
_optimize_setting: ModeOptimizerSetting,
|
||||
pipeline: ModePipeline,
|
||||
) -> bool {
|
||||
fn new(_config: &Arguments) -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
fn supports_mode(_optimize_setting: ModeOptimizerSetting, pipeline: ModePipeline) -> bool {
|
||||
// solc 0.8.13 and above supports --via-ir, and less than that does not. Thus, we support mode E
|
||||
// (ie no Yul IR) in either case, but only support Y (via Yul IR) if the compiler is new enough.
|
||||
pipeline == ModePipeline::ViaEVMAssembly
|
||||
|| (pipeline == ModePipeline::ViaYulIR && self.compiler_supports_yul())
|
||||
}
|
||||
}
|
||||
|
||||
impl Solc {
|
||||
fn compiler_supports_yul(&self) -> bool {
|
||||
const SOLC_VERSION_SUPPORTING_VIA_YUL_IR: Version = Version::new(0, 8, 13);
|
||||
self.version() >= &SOLC_VERSION_SUPPORTING_VIA_YUL_IR
|
||||
pipeline == ModePipeline::ViaEVMAssembly || pipeline == ModePipeline::ViaYulIR
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use dashmap::DashMap;
|
||||
use revive_dt_common::types::{ModePipeline, VersionOrRequirement};
|
||||
use semver::{Version, VersionReq};
|
||||
|
||||
/// Return the path and version of a suitable `solc` compiler given the requirements provided.
|
||||
///
|
||||
/// This caches any compiler binaries/paths that are downloaded as a result of calling this.
|
||||
pub async fn solc_compiler(
|
||||
cache_directory: &Path,
|
||||
fallback_version: &Version,
|
||||
required_version: Option<&VersionReq>,
|
||||
pipeline: ModePipeline,
|
||||
) -> anyhow::Result<SolcCompiler> {
|
||||
// Require Yul compatible solc, or any if we don't care about compiling via Yul.
|
||||
let mut version_req = if pipeline == ModePipeline::ViaYulIR {
|
||||
solc_versions_supporting_yul_ir()
|
||||
} else {
|
||||
VersionReq::STAR
|
||||
};
|
||||
|
||||
// Take into account the version requirements passed in, too.
|
||||
if let Some(other_version_req) = required_version {
|
||||
version_req
|
||||
.comparators
|
||||
.extend(other_version_req.comparators.iter().cloned());
|
||||
}
|
||||
|
||||
// If no requirements yet then fall back to the fallback version.
|
||||
let version_req = if version_req == VersionReq::STAR {
|
||||
VersionOrRequirement::version_to_requirement(fallback_version)
|
||||
} else {
|
||||
version_req
|
||||
};
|
||||
|
||||
// Download (or pull from cache) a suitable solc compiler given this.
|
||||
let solc_path =
|
||||
revive_dt_solc_binaries::download_solc(cache_directory, version_req, false).await?;
|
||||
let solc_version = solc_version(&solc_path).await?;
|
||||
|
||||
Ok(SolcCompiler {
|
||||
version: solc_version,
|
||||
path: solc_path,
|
||||
})
|
||||
}
|
||||
|
||||
/// A `solc` compiler, returned from [`solc_compiler`].
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SolcCompiler {
|
||||
/// Version of the compiler.
|
||||
pub version: Version,
|
||||
/// Path to the compiler executable.
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
/// Fetch the solc version given a path to the executable
|
||||
async fn solc_version(solc_path: &Path) -> anyhow::Result<semver::Version> {
|
||||
/// This is a cache of the path of the compiler to the version number of the compiler. We
|
||||
/// choose to cache the version in this way rather than through a field on the struct since
|
||||
/// compiler objects are being created all the time from the path and the compiler object is
|
||||
/// not reused over time.
|
||||
static VERSION_CACHE: LazyLock<DashMap<PathBuf, Version>> = LazyLock::new(Default::default);
|
||||
|
||||
match VERSION_CACHE.entry(solc_path.to_path_buf()) {
|
||||
dashmap::Entry::Occupied(occupied_entry) => Ok(occupied_entry.get().clone()),
|
||||
dashmap::Entry::Vacant(vacant_entry) => {
|
||||
// The following is the parsing code for the version from the solc version strings
|
||||
// which look like the following:
|
||||
// ```
|
||||
// solc, the solidity compiler commandline interface
|
||||
// Version: 0.8.30+commit.73712a01.Darwin.appleclang
|
||||
// ```
|
||||
let child = Command::new(solc_path)
|
||||
.arg("--version")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?;
|
||||
let output = child.wait_with_output()?;
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
let version_line = output
|
||||
.split("Version: ")
|
||||
.nth(1)
|
||||
.context("Version parsing failed")?;
|
||||
let version_string = version_line
|
||||
.split("+")
|
||||
.next()
|
||||
.context("Version parsing failed")?;
|
||||
|
||||
let version = Version::parse(version_string)?;
|
||||
|
||||
vacant_entry.insert(version.clone());
|
||||
|
||||
Ok(version)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This returns the solc versions which support Yul IR.
|
||||
pub fn solc_versions_supporting_yul_ir() -> VersionReq {
|
||||
use semver::{Comparator, Op, Prerelease, VersionReq};
|
||||
VersionReq {
|
||||
comparators: vec![Comparator {
|
||||
op: Op::GreaterEq,
|
||||
major: 0,
|
||||
minor: Some(8),
|
||||
patch: Some(13),
|
||||
pre: Prerelease::EMPTY,
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn compiler_version_can_be_obtained() {
|
||||
// Arrange
|
||||
let temp_dir = tempfile::tempdir().expect("can create tempdir");
|
||||
let solc_path =
|
||||
revive_dt_solc_binaries::download_solc(temp_dir.path(), Version::new(0, 7, 6), false)
|
||||
.await
|
||||
.expect("can download solc");
|
||||
|
||||
// Act
|
||||
let version = solc_version(&solc_path).await;
|
||||
|
||||
// Assert
|
||||
assert_eq!(
|
||||
version.expect("Failed to get version"),
|
||||
Version::new(0, 7, 6)
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn compiler_version_can_be_obtained1() {
|
||||
// Arrange
|
||||
let temp_dir = tempfile::tempdir().expect("can create tempdir");
|
||||
let solc_path =
|
||||
revive_dt_solc_binaries::download_solc(temp_dir.path(), Version::new(0, 4, 21), false)
|
||||
.await
|
||||
.expect("can download solc");
|
||||
|
||||
// Act
|
||||
let version = solc_version(&solc_path).await;
|
||||
|
||||
// Assert
|
||||
assert_eq!(
|
||||
version.expect("Failed to get version"),
|
||||
Version::new(0, 4, 21)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,20 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use revive_dt_common::types::VersionOrRequirement;
|
||||
use revive_dt_compiler::{Compiler, SolidityCompiler, revive_resolc::Resolc, solc::Solc};
|
||||
use revive_dt_compiler::{Compiler, revive_resolc::Resolc, solc::Solc};
|
||||
use revive_dt_config::Arguments;
|
||||
use semver::Version;
|
||||
|
||||
#[tokio::test]
|
||||
async fn contracts_can_be_compiled_with_solc() {
|
||||
// Arrange
|
||||
let args = Arguments::default();
|
||||
let solc = Solc::new(&args, VersionOrRequirement::Version(Version::new(0, 8, 30)))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Act
|
||||
let output = Compiler::new()
|
||||
let output = Compiler::<Solc>::new()
|
||||
.with_source("./tests/assets/array_one_element/callable.sol")
|
||||
.unwrap()
|
||||
.with_source("./tests/assets/array_one_element/main.sol")
|
||||
.unwrap()
|
||||
.try_build(&solc)
|
||||
.try_build(&args)
|
||||
.await;
|
||||
|
||||
// Assert
|
||||
@@ -50,17 +45,14 @@ async fn contracts_can_be_compiled_with_solc() {
|
||||
async fn contracts_can_be_compiled_with_resolc() {
|
||||
// Arrange
|
||||
let args = Arguments::default();
|
||||
let resolc = Resolc::new(&args, VersionOrRequirement::Version(Version::new(0, 8, 30)))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Act
|
||||
let output = Compiler::new()
|
||||
let output = Compiler::<Resolc>::new()
|
||||
.with_source("./tests/assets/array_one_element/callable.sol")
|
||||
.unwrap()
|
||||
.with_source("./tests/assets/array_one_element/main.sol")
|
||||
.unwrap()
|
||||
.try_build(&resolc)
|
||||
.try_build(&args)
|
||||
.await;
|
||||
|
||||
// Assert
|
||||
|
||||
@@ -12,7 +12,7 @@ rust-version.workspace = true
|
||||
alloy = { workspace = true }
|
||||
clap = { workspace = true }
|
||||
semver = { workspace = true }
|
||||
temp-dir = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -10,7 +10,7 @@ use alloy::{network::EthereumWallet, signers::local::PrivateKeySigner};
|
||||
use clap::{Parser, ValueEnum};
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use temp_dir::TempDir;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[derive(Debug, Parser, Clone, Serialize, Deserialize)]
|
||||
#[command(name = "retester")]
|
||||
@@ -84,6 +84,10 @@ pub struct Arguments {
|
||||
#[arg(short, long = "follower", default_value = "kitchensink")]
|
||||
pub follower: TestingPlatform,
|
||||
|
||||
/// Only compile against this testing platform (doesn't execute the tests).
|
||||
#[arg(long = "compile-only")]
|
||||
pub compile_only: Option<TestingPlatform>,
|
||||
|
||||
/// Determines the amount of nodes that will be spawned for each chain.
|
||||
#[arg(long, default_value = "1")]
|
||||
pub number_of_nodes: usize,
|
||||
|
||||
@@ -28,6 +28,7 @@ cacache = { workspace = true }
|
||||
clap = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
indexmap = { workspace = true }
|
||||
once_cell = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-appender = { workspace = true }
|
||||
@@ -35,7 +36,7 @@ tracing-subscriber = { workspace = true }
|
||||
semver = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
temp-dir = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
//! be reused between runs.
|
||||
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashMap,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
@@ -10,13 +9,13 @@ use std::{
|
||||
|
||||
use futures::FutureExt;
|
||||
use revive_dt_common::iterators::FilesWithExtensionIterator;
|
||||
use revive_dt_compiler::{Compiler, CompilerOutput, Mode, SolidityCompiler};
|
||||
use revive_dt_config::TestingPlatform;
|
||||
use revive_dt_compiler::{Compiler, CompilerInput, CompilerOutput, Mode, SolcCompiler};
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_dt_format::metadata::{ContractIdent, ContractInstance, Metadata};
|
||||
|
||||
use alloy::{hex::ToHexExt, json_abi::JsonAbi, primitives::Address};
|
||||
use anyhow::{Context as _, Error, Result};
|
||||
use revive_dt_report::ExecutionSpecificReporter;
|
||||
use once_cell::sync::Lazy;
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::{Mutex, RwLock};
|
||||
@@ -24,17 +23,9 @@ use tracing::{Instrument, debug, debug_span, instrument};
|
||||
|
||||
use crate::Platform;
|
||||
|
||||
pub struct CachedCompiler<'a> {
|
||||
/// The cache that stores the compiled contracts.
|
||||
artifacts_cache: ArtifactsCache,
|
||||
pub struct CachedCompiler(ArtifactsCache);
|
||||
|
||||
/// This is a mechanism that the cached compiler uses so that if multiple compilation requests
|
||||
/// come in for the same contract we never compile all of them and only compile it once and all
|
||||
/// other tasks that request this same compilation concurrently get the cached version.
|
||||
cache_key_lock: RwLock<HashMap<CacheKey<'a>, Arc<Mutex<()>>>>,
|
||||
}
|
||||
|
||||
impl<'a> CachedCompiler<'a> {
|
||||
impl CachedCompiler {
|
||||
pub async fn new(path: impl AsRef<Path>, invalidate_cache: bool) -> Result<Self> {
|
||||
let mut cache = ArtifactsCache::new(path);
|
||||
if invalidate_cache {
|
||||
@@ -43,10 +34,7 @@ impl<'a> CachedCompiler<'a> {
|
||||
.await
|
||||
.context("Failed to invalidate compilation cache directory")?;
|
||||
}
|
||||
Ok(Self {
|
||||
artifacts_cache: cache,
|
||||
cache_key_lock: Default::default(),
|
||||
})
|
||||
Ok(Self(cache))
|
||||
}
|
||||
|
||||
/// Compiles or gets the compilation artifacts from the cache.
|
||||
@@ -55,7 +43,7 @@ impl<'a> CachedCompiler<'a> {
|
||||
level = "debug",
|
||||
skip_all,
|
||||
fields(
|
||||
metadata_file_path = %metadata_file_path.display(),
|
||||
metadata_file_path = %metadata_file_path.as_ref().display(),
|
||||
%mode,
|
||||
platform = P::config_id().to_string()
|
||||
),
|
||||
@@ -63,21 +51,30 @@ impl<'a> CachedCompiler<'a> {
|
||||
)]
|
||||
pub async fn compile_contracts<P: Platform>(
|
||||
&self,
|
||||
metadata: &'a Metadata,
|
||||
metadata_file_path: &'a Path,
|
||||
mode: Cow<'a, Mode>,
|
||||
metadata: &Metadata,
|
||||
metadata_file_path: impl AsRef<Path>,
|
||||
solc: SolcCompiler,
|
||||
mode: &Mode,
|
||||
config: &Arguments,
|
||||
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
|
||||
compiler: &P::Compiler,
|
||||
reporter: &ExecutionSpecificReporter,
|
||||
compilation_success_report_callback: impl Fn(bool, Option<CompilerInput>, CompilerOutput)
|
||||
+ Clone,
|
||||
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 cache_key = CacheKey {
|
||||
platform_key: P::config_id(),
|
||||
compiler_version: compiler.version().clone(),
|
||||
metadata_file_path,
|
||||
platform_key: P::config_id().to_string(),
|
||||
compiler_version: solc.version.clone(),
|
||||
metadata_file_path: metadata_file_path.as_ref().to_path_buf(),
|
||||
solc_mode: mode.clone(),
|
||||
};
|
||||
|
||||
let compilation_callback = || {
|
||||
// let compiler_path = compiler_path.clone();
|
||||
// let compiler_version = compiler_version.clone();
|
||||
let compilation_success_report_callback = compilation_success_report_callback.clone();
|
||||
async move {
|
||||
compile_contracts::<P>(
|
||||
metadata
|
||||
@@ -86,10 +83,12 @@ impl<'a> CachedCompiler<'a> {
|
||||
metadata
|
||||
.files_to_compile()
|
||||
.context("Failed to enumerate files to compile from metadata")?,
|
||||
&mode,
|
||||
config,
|
||||
solc,
|
||||
mode,
|
||||
deployed_libraries,
|
||||
compiler,
|
||||
reporter,
|
||||
compilation_success_report_callback,
|
||||
compilation_failure_report_callback,
|
||||
)
|
||||
.map(|compilation_result| compilation_result.map(CacheValue::new))
|
||||
.await
|
||||
@@ -122,15 +121,12 @@ impl<'a> CachedCompiler<'a> {
|
||||
// Lock this specific cache key such that we do not get inconsistent state. We want
|
||||
// that when multiple cases come in asking for the compilation artifacts then they
|
||||
// don't all trigger a compilation if there's a cache miss. Hence, the lock here.
|
||||
let read_guard = self.cache_key_lock.read().await;
|
||||
let read_guard = CACHE_KEY_LOCK.read().await;
|
||||
let mutex = match read_guard.get(&cache_key).cloned() {
|
||||
Some(value) => {
|
||||
drop(read_guard);
|
||||
value
|
||||
}
|
||||
Some(value) => value,
|
||||
None => {
|
||||
drop(read_guard);
|
||||
self.cache_key_lock
|
||||
CACHE_KEY_LOCK
|
||||
.write()
|
||||
.await
|
||||
.entry(cache_key.clone())
|
||||
@@ -140,29 +136,13 @@ impl<'a> CachedCompiler<'a> {
|
||||
};
|
||||
let _guard = mutex.lock().await;
|
||||
|
||||
match self.artifacts_cache.get(&cache_key).await {
|
||||
match self.0.get(&cache_key).await {
|
||||
Some(cache_value) => {
|
||||
if deployed_libraries.is_some() {
|
||||
reporter
|
||||
.report_post_link_contracts_compilation_succeeded_event(
|
||||
compiler.version().clone(),
|
||||
compiler.path(),
|
||||
true,
|
||||
None,
|
||||
cache_value.compiler_output.clone(),
|
||||
)
|
||||
.expect("Can't happen");
|
||||
} else {
|
||||
reporter
|
||||
.report_pre_link_contracts_compilation_succeeded_event(
|
||||
compiler.version().clone(),
|
||||
compiler.path(),
|
||||
true,
|
||||
None,
|
||||
cache_value.compiler_output.clone(),
|
||||
)
|
||||
.expect("Can't happen");
|
||||
}
|
||||
compilation_success_report_callback(
|
||||
true,
|
||||
None,
|
||||
cache_value.compiler_output.clone(),
|
||||
);
|
||||
cache_value.compiler_output
|
||||
}
|
||||
None => {
|
||||
@@ -179,20 +159,24 @@ impl<'a> CachedCompiler<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
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)>>,
|
||||
compiler: &P::Compiler,
|
||||
reporter: &ExecutionSpecificReporter,
|
||||
compilation_success_report_callback: impl Fn(bool, Option<CompilerInput>, CompilerOutput),
|
||||
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")
|
||||
.with_use_cached_fs(true)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let compilation = Compiler::new()
|
||||
let compiler = Compiler::<P::Compiler>::new()
|
||||
.with_solc(solc)
|
||||
.with_allow_path(metadata_directory)
|
||||
// Handling the modes
|
||||
.with_optimization(mode.optimize_setting)
|
||||
@@ -200,7 +184,8 @@ async fn compile_contracts<P: Platform>(
|
||||
// Adding the contract sources to the compiler.
|
||||
.try_then(|compiler| {
|
||||
files_to_compile.try_fold(compiler, |compiler, path| compiler.with_source(path))
|
||||
})?
|
||||
})
|
||||
.inspect_err(|err| compilation_failure_report_callback(None, format!("{err:#}")))?
|
||||
// Adding the deployed libraries to the compiler.
|
||||
.then(|compiler| {
|
||||
deployed_libraries
|
||||
@@ -217,55 +202,17 @@ async fn compile_contracts<P: Platform>(
|
||||
})
|
||||
});
|
||||
|
||||
let input = compilation.input().clone();
|
||||
let output = compilation.try_build(compiler).await;
|
||||
let compiler_input = compiler.input();
|
||||
let compiler_output = compiler
|
||||
.try_build(config)
|
||||
.await
|
||||
.inspect_err(|err| {
|
||||
compilation_failure_report_callback(Some(compiler_input.clone()), format!("{err:#}"))
|
||||
})
|
||||
.context("Failed to configure compiler with sources and options")?;
|
||||
|
||||
match (output.as_ref(), deployed_libraries.is_some()) {
|
||||
(Ok(output), true) => {
|
||||
reporter
|
||||
.report_post_link_contracts_compilation_succeeded_event(
|
||||
compiler.version().clone(),
|
||||
compiler.path(),
|
||||
false,
|
||||
input,
|
||||
output.clone(),
|
||||
)
|
||||
.expect("Can't happen");
|
||||
}
|
||||
(Ok(output), false) => {
|
||||
reporter
|
||||
.report_pre_link_contracts_compilation_succeeded_event(
|
||||
compiler.version().clone(),
|
||||
compiler.path(),
|
||||
false,
|
||||
input,
|
||||
output.clone(),
|
||||
)
|
||||
.expect("Can't happen");
|
||||
}
|
||||
(Err(err), true) => {
|
||||
reporter
|
||||
.report_post_link_contracts_compilation_failed_event(
|
||||
compiler.version().clone(),
|
||||
compiler.path().to_path_buf(),
|
||||
input,
|
||||
format!("{err:#}"),
|
||||
)
|
||||
.expect("Can't happen");
|
||||
}
|
||||
(Err(err), false) => {
|
||||
reporter
|
||||
.report_pre_link_contracts_compilation_failed_event(
|
||||
compiler.version().clone(),
|
||||
compiler.path().to_path_buf(),
|
||||
input,
|
||||
format!("{err:#}"),
|
||||
)
|
||||
.expect("Can't happen");
|
||||
}
|
||||
}
|
||||
|
||||
output
|
||||
compilation_success_report_callback(false, Some(compiler_input), compiler_output.clone());
|
||||
Ok(compiler_output)
|
||||
}
|
||||
|
||||
struct ArtifactsCache {
|
||||
@@ -289,7 +236,7 @@ impl ArtifactsCache {
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip_all, err)]
|
||||
pub async fn insert(&self, key: &CacheKey<'_>, value: &CacheValue) -> Result<()> {
|
||||
pub async fn insert(&self, key: &CacheKey, value: &CacheValue) -> Result<()> {
|
||||
let key = bson::to_vec(key).context("Failed to serialize cache key (bson)")?;
|
||||
let value = bson::to_vec(value).context("Failed to serialize cache value (bson)")?;
|
||||
cacache::write(self.path.as_path(), key.encode_hex(), value)
|
||||
@@ -300,7 +247,7 @@ impl ArtifactsCache {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get(&self, key: &CacheKey<'_>) -> Option<CacheValue> {
|
||||
pub async fn get(&self, key: &CacheKey) -> Option<CacheValue> {
|
||||
let key = bson::to_vec(key).ok()?;
|
||||
let value = cacache::read(self.path.as_path(), key.encode_hex())
|
||||
.await
|
||||
@@ -312,7 +259,7 @@ impl ArtifactsCache {
|
||||
#[instrument(level = "debug", skip_all, err)]
|
||||
pub async fn get_or_insert_with(
|
||||
&self,
|
||||
key: &CacheKey<'_>,
|
||||
key: &CacheKey,
|
||||
callback: impl AsyncFnOnce() -> Result<CacheValue>,
|
||||
) -> Result<CacheValue> {
|
||||
match self.get(key).await {
|
||||
@@ -330,20 +277,20 @@ impl ArtifactsCache {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
|
||||
struct CacheKey<'a> {
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
struct CacheKey {
|
||||
/// The platform name that this artifact was compiled for. For example, this could be EVM or
|
||||
/// PVM.
|
||||
platform_key: &'a TestingPlatform,
|
||||
platform_key: String,
|
||||
|
||||
/// The version of the compiler that was used to compile the artifacts.
|
||||
compiler_version: Version,
|
||||
|
||||
/// The path of the metadata file that the compilation artifacts are for.
|
||||
metadata_file_path: &'a Path,
|
||||
metadata_file_path: PathBuf,
|
||||
|
||||
/// The mode that the compilation artifacts where compiled with.
|
||||
solc_mode: Cow<'a, Mode>,
|
||||
solc_mode: Mode,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
||||
@@ -19,7 +19,7 @@ pub trait Platform {
|
||||
type Compiler: SolidityCompiler;
|
||||
|
||||
/// Returns the matching [TestingPlatform] of the [revive_dt_config::Arguments].
|
||||
fn config_id() -> &'static TestingPlatform;
|
||||
fn config_id() -> TestingPlatform;
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -29,8 +29,8 @@ impl Platform for Geth {
|
||||
type Blockchain = geth::GethNode;
|
||||
type Compiler = solc::Solc;
|
||||
|
||||
fn config_id() -> &'static TestingPlatform {
|
||||
&TestingPlatform::Geth
|
||||
fn config_id() -> TestingPlatform {
|
||||
TestingPlatform::Geth
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ impl Platform for Kitchensink {
|
||||
type Blockchain = KitchensinkNode;
|
||||
type Compiler = revive_resolc::Resolc;
|
||||
|
||||
fn config_id() -> &'static TestingPlatform {
|
||||
&TestingPlatform::Kitchensink
|
||||
fn config_id() -> TestingPlatform {
|
||||
TestingPlatform::Kitchensink
|
||||
}
|
||||
}
|
||||
|
||||
+429
-273
@@ -1,7 +1,6 @@
|
||||
mod cached_compiler;
|
||||
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{BTreeMap, HashMap},
|
||||
io::{BufWriter, Write, stderr},
|
||||
path::Path,
|
||||
@@ -15,22 +14,21 @@ use alloy::{
|
||||
};
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
use futures::StreamExt;
|
||||
use futures::stream;
|
||||
use futures::{Stream, StreamExt};
|
||||
use indexmap::{IndexMap, indexmap};
|
||||
use indexmap::IndexMap;
|
||||
use revive_dt_node_interaction::EthereumNode;
|
||||
use revive_dt_report::{
|
||||
NodeDesignation, ReportAggregator, Reporter, ReporterEvent, TestCaseStatus,
|
||||
TestSpecificReporter, TestSpecifier,
|
||||
};
|
||||
use serde_json::{Value, json};
|
||||
use temp_dir::TempDir;
|
||||
use tokio::try_join;
|
||||
use tracing::{debug, error, info, info_span, instrument};
|
||||
use tempfile::TempDir;
|
||||
use tokio::{join, try_join};
|
||||
use tracing::{debug, info, info_span, instrument};
|
||||
use tracing_appender::non_blocking::WorkerGuard;
|
||||
use tracing_subscriber::{EnvFilter, FmtSubscriber};
|
||||
|
||||
use revive_dt_common::{iterators::EitherIter, types::Mode};
|
||||
use revive_dt_common::types::Mode;
|
||||
use revive_dt_compiler::{CompilerOutput, SolidityCompiler};
|
||||
use revive_dt_config::*;
|
||||
use revive_dt_core::{
|
||||
@@ -50,6 +48,17 @@ use crate::cached_compiler::CachedCompiler;
|
||||
|
||||
static TEMP_DIR: LazyLock<TempDir> = LazyLock::new(|| TempDir::new().unwrap());
|
||||
|
||||
/// this represents a single "test"; a mode, path and collection of cases.
|
||||
#[derive(Clone, Debug)]
|
||||
struct Test<'a> {
|
||||
metadata: &'a MetadataFile,
|
||||
metadata_file_path: &'a Path,
|
||||
mode: Mode,
|
||||
case_idx: CaseIdx,
|
||||
case: &'a Case,
|
||||
reporter: TestSpecificReporter,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let (args, _guard) = init_cli().context("Failed to initialize CLI and tracing subscriber")?;
|
||||
info!(
|
||||
@@ -84,9 +93,14 @@ fn main() -> anyhow::Result<()> {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
execute_corpus(&args, &tests, reporter, report_aggregator_task)
|
||||
.await
|
||||
.context("Failed to execute corpus")?;
|
||||
match &args.compile_only {
|
||||
Some(platform) => {
|
||||
compile_corpus(&args, &tests, platform, reporter, report_aggregator_task).await
|
||||
}
|
||||
None => execute_corpus(&args, &tests, reporter, report_aggregator_task)
|
||||
.await
|
||||
.context("Failed to execute corpus")?,
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
|
||||
@@ -171,20 +185,8 @@ where
|
||||
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).context("Failed to initialize leader node pool")?;
|
||||
let follower_nodes =
|
||||
NodePool::<F::Blockchain>::new(args).context("Failed to initialize follower node pool")?;
|
||||
|
||||
let tests_stream = tests_stream(
|
||||
args,
|
||||
metadata_files.iter(),
|
||||
&leader_nodes,
|
||||
&follower_nodes,
|
||||
reporter.clone(),
|
||||
)
|
||||
.await;
|
||||
let driver_task = start_driver_task::<L, F>(args, tests_stream)
|
||||
let tests = prepare_tests::<L, F>(metadata_files, reporter.clone());
|
||||
let driver_task = start_driver_task::<L, F>(args, tests)
|
||||
.await
|
||||
.context("Failed to start driver task")?;
|
||||
let cli_reporting_task = start_cli_reporting_task(reporter);
|
||||
@@ -195,21 +197,18 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn tests_stream<'a, L, F>(
|
||||
args: &Arguments,
|
||||
metadata_files: impl IntoIterator<Item = &'a MetadataFile> + Clone,
|
||||
leader_node_pool: &'a NodePool<L::Blockchain>,
|
||||
follower_node_pool: &'a NodePool<F::Blockchain>,
|
||||
fn prepare_tests<'a, L, F>(
|
||||
metadata_files: &'a [MetadataFile],
|
||||
reporter: Reporter,
|
||||
) -> impl Stream<Item = Test<'a, L, F>>
|
||||
) -> 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 tests = metadata_files
|
||||
.into_iter()
|
||||
metadata_files
|
||||
.iter()
|
||||
.flat_map(|metadata_file| {
|
||||
metadata_file
|
||||
.cases
|
||||
@@ -219,120 +218,217 @@ where
|
||||
})
|
||||
// Flatten over the modes, prefer the case modes over the metadata file modes.
|
||||
.flat_map(|(metadata_file, case_idx, case)| {
|
||||
let reporter = reporter.clone();
|
||||
|
||||
let modes = case.modes.as_ref().or(metadata_file.modes.as_ref());
|
||||
let modes = match modes {
|
||||
Some(modes) => EitherIter::A(
|
||||
ParsedMode::many_to_modes(modes.iter()).map(Cow::<'static, _>::Owned),
|
||||
),
|
||||
None => EitherIter::B(Mode::all().map(Cow::<'static, _>::Borrowed)),
|
||||
};
|
||||
|
||||
modes.into_iter().map(move |mode| {
|
||||
(
|
||||
metadata_file,
|
||||
case_idx,
|
||||
case,
|
||||
mode.clone(),
|
||||
reporter.test_specific_reporter(Arc::new(TestSpecifier {
|
||||
solc_mode: mode.as_ref().clone(),
|
||||
metadata_file_path: metadata_file.metadata_file_path.clone(),
|
||||
case_idx: CaseIdx::new(case_idx),
|
||||
})),
|
||||
)
|
||||
})
|
||||
case.modes
|
||||
.as_ref()
|
||||
.or(metadata_file.modes.as_ref())
|
||||
.map(|modes| ParsedMode::many_to_modes(modes.iter()).collect::<Vec<_>>())
|
||||
.unwrap_or(Mode::all().collect())
|
||||
.into_iter()
|
||||
.map(move |mode| (metadata_file, case_idx, case, mode))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
.map(move |(metadata_file, case_idx, case, mode)| Test {
|
||||
metadata: metadata_file,
|
||||
metadata_file_path: metadata_file.metadata_file_path.as_path(),
|
||||
mode: mode.clone(),
|
||||
case_idx: CaseIdx::new(case_idx),
|
||||
case,
|
||||
reporter: reporter.test_specific_reporter(Arc::new(TestSpecifier {
|
||||
solc_mode: mode.clone(),
|
||||
metadata_file_path: metadata_file.metadata_file_path.clone(),
|
||||
case_idx: CaseIdx::new(case_idx),
|
||||
})),
|
||||
})
|
||||
.inspect(|test| {
|
||||
test.reporter
|
||||
.report_test_case_discovery_event()
|
||||
.expect("Can't fail")
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
// Filter the test out if the leader and follower do not support the target.
|
||||
.filter(|test| {
|
||||
let leader_support =
|
||||
<L::Blockchain as Node>::matches_target(test.metadata.targets.as_deref());
|
||||
let follower_support =
|
||||
<F::Blockchain as Node>::matches_target(test.metadata.targets.as_deref());
|
||||
let is_allowed = leader_support && follower_support;
|
||||
|
||||
// Note: before we do any kind of filtering or process the iterator in any way, we need to
|
||||
// inform the report aggregator of all of the cases that were found as it keeps a state of the
|
||||
// test cases for its internal use.
|
||||
for (_, _, _, _, reporter) in tests.iter() {
|
||||
reporter
|
||||
.report_test_case_discovery_event()
|
||||
.expect("Can't fail")
|
||||
}
|
||||
if !is_allowed {
|
||||
debug!(
|
||||
file_path = %test.metadata.relative_path().display(),
|
||||
leader_support,
|
||||
follower_support,
|
||||
"Target is not supported, throwing metadata file out"
|
||||
);
|
||||
test
|
||||
.reporter
|
||||
.report_test_ignored_event(
|
||||
"Either the leader or the follower do not support the target desired by the test",
|
||||
IndexMap::from_iter([
|
||||
(
|
||||
"test_desired_targets".to_string(),
|
||||
serde_json::to_value(test.metadata.targets.as_ref())
|
||||
.expect("Can't fail")
|
||||
),
|
||||
(
|
||||
"leader_support".to_string(),
|
||||
serde_json::to_value(leader_support)
|
||||
.expect("Can't fail")
|
||||
),
|
||||
(
|
||||
"follower_support".to_string(),
|
||||
serde_json::to_value(follower_support)
|
||||
.expect("Can't fail")
|
||||
)
|
||||
])
|
||||
)
|
||||
.expect("Can't fail");
|
||||
}
|
||||
|
||||
stream::iter(tests.into_iter())
|
||||
.filter_map(
|
||||
move |(metadata_file, case_idx, case, mode, reporter)| async move {
|
||||
let leader_compiler = <L::Compiler as SolidityCompiler>::new(
|
||||
args,
|
||||
mode.version.clone().map(Into::into),
|
||||
)
|
||||
.await
|
||||
.inspect_err(|err| error!(?err, "Failed to instantiate the leader compiler"))
|
||||
.ok()?;
|
||||
is_allowed
|
||||
})
|
||||
// Filter the test out if the metadata file is ignored.
|
||||
.filter(|test| {
|
||||
if test.metadata.ignore.is_some_and(|ignore| ignore) {
|
||||
debug!(
|
||||
file_path = %test.metadata.relative_path().display(),
|
||||
"Metadata file is ignored, throwing case out"
|
||||
);
|
||||
test
|
||||
.reporter
|
||||
.report_test_ignored_event(
|
||||
"Metadata file is ignored, therefore all cases are ignored",
|
||||
IndexMap::new(),
|
||||
)
|
||||
.expect("Can't fail");
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
// Filter the test case if the case is ignored.
|
||||
.filter(|test| {
|
||||
if test.case.ignore.is_some_and(|ignore| ignore) {
|
||||
debug!(
|
||||
file_path = %test.metadata.relative_path().display(),
|
||||
case_idx = %test.case_idx,
|
||||
"Case is ignored, throwing case out"
|
||||
);
|
||||
test
|
||||
.reporter
|
||||
.report_test_ignored_event(
|
||||
"Case is ignored",
|
||||
IndexMap::new(),
|
||||
)
|
||||
.expect("Can't fail");
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
// Filtering based on the EVM version compatibility
|
||||
.filter(|test| {
|
||||
if let Some(evm_version_requirement) = test.metadata.required_evm_version {
|
||||
let leader_compatibility = evm_version_requirement
|
||||
.matches(&<L::Blockchain as revive_dt_node::Node>::evm_version());
|
||||
let follower_compatibility = evm_version_requirement
|
||||
.matches(&<F::Blockchain as revive_dt_node::Node>::evm_version());
|
||||
let is_allowed = leader_compatibility && follower_compatibility;
|
||||
|
||||
let follower_compiler = <F::Compiler as SolidityCompiler>::new(
|
||||
args,
|
||||
mode.version.clone().map(Into::into),
|
||||
)
|
||||
.await
|
||||
.inspect_err(|err| error!(?err, "Failed to instantiate the follower compiler"))
|
||||
.ok()?;
|
||||
|
||||
let leader_node = leader_node_pool.round_robbin();
|
||||
let follower_node = follower_node_pool.round_robbin();
|
||||
|
||||
Some(Test::<L, F> {
|
||||
metadata: metadata_file,
|
||||
metadata_file_path: metadata_file.metadata_file_path.as_path(),
|
||||
mode: mode.clone(),
|
||||
case_idx: CaseIdx::new(case_idx),
|
||||
case,
|
||||
leader_node,
|
||||
follower_node,
|
||||
leader_compiler,
|
||||
follower_compiler,
|
||||
reporter,
|
||||
})
|
||||
},
|
||||
)
|
||||
.filter_map(move |test| async move {
|
||||
match test.check_compatibility() {
|
||||
Ok(()) => Some(test),
|
||||
Err((reason, additional_information)) => {
|
||||
if !is_allowed {
|
||||
debug!(
|
||||
metadata_file_path = %test.metadata.metadata_file_path.display(),
|
||||
file_path = %test.metadata.relative_path().display(),
|
||||
case_idx = %test.case_idx,
|
||||
mode = %test.mode,
|
||||
reason,
|
||||
additional_information =
|
||||
serde_json::to_string(&additional_information).unwrap(),
|
||||
|
||||
"Ignoring Test Case"
|
||||
leader_compatibility,
|
||||
follower_compatibility,
|
||||
"EVM Version is incompatible, throwing case out"
|
||||
);
|
||||
test.reporter
|
||||
test
|
||||
.reporter
|
||||
.report_test_ignored_event(
|
||||
reason.to_string(),
|
||||
additional_information
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k.into(), v))
|
||||
.collect::<IndexMap<_, _>>(),
|
||||
"EVM version is incompatible with either the leader or the follower",
|
||||
IndexMap::from_iter([
|
||||
(
|
||||
"test_desired_evm_version".to_string(),
|
||||
serde_json::to_value(test.metadata.required_evm_version)
|
||||
.expect("Can't fail")
|
||||
),
|
||||
(
|
||||
"leader_compatibility".to_string(),
|
||||
serde_json::to_value(leader_compatibility)
|
||||
.expect("Can't fail")
|
||||
),
|
||||
(
|
||||
"follower_compatibility".to_string(),
|
||||
serde_json::to_value(follower_compatibility)
|
||||
.expect("Can't fail")
|
||||
)
|
||||
])
|
||||
)
|
||||
.expect("Can't fail");
|
||||
None
|
||||
}
|
||||
|
||||
is_allowed
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
.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 {
|
||||
debug!(
|
||||
file_path = %test.metadata.relative_path().display(),
|
||||
leader_support,
|
||||
follower_support,
|
||||
"Compilers do not support this, throwing case out"
|
||||
);
|
||||
test
|
||||
.reporter
|
||||
.report_test_ignored_event(
|
||||
"Compilers do not support this mode either for the leader or for the follower.",
|
||||
IndexMap::from_iter([
|
||||
(
|
||||
"leader_support".to_string(),
|
||||
serde_json::to_value(leader_support)
|
||||
.expect("Can't fail")
|
||||
),
|
||||
(
|
||||
"follower_support".to_string(),
|
||||
serde_json::to_value(follower_support)
|
||||
.expect("Can't fail")
|
||||
)
|
||||
])
|
||||
)
|
||||
.expect("Can't fail");
|
||||
}
|
||||
|
||||
is_allowed.then_some(test)
|
||||
})
|
||||
}
|
||||
|
||||
async fn start_driver_task<'a, L, F>(
|
||||
args: &Arguments,
|
||||
tests: impl Stream<Item = Test<'a, L, F>>,
|
||||
tests: impl Iterator<Item = Test<'a>>,
|
||||
) -> anyhow::Result<impl Future<Output = ()>>
|
||||
where
|
||||
L: Platform,
|
||||
F: Platform,
|
||||
L::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
F::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
L::Compiler: 'a,
|
||||
F::Compiler: 'a,
|
||||
{
|
||||
info!("Starting driver task");
|
||||
|
||||
let leader_nodes = Arc::new(
|
||||
NodePool::<L::Blockchain>::new(args).context("Failed to initialize leader node pool")?,
|
||||
);
|
||||
let follower_nodes = Arc::new(
|
||||
NodePool::<F::Blockchain>::new(args).context("Failed to initialize follower node pool")?,
|
||||
);
|
||||
let number_concurrent_tasks = args.number_of_concurrent_tasks();
|
||||
let cached_compiler = Arc::new(
|
||||
CachedCompiler::new(
|
||||
@@ -343,7 +439,7 @@ where
|
||||
.context("Failed to initialize cached compiler")?,
|
||||
);
|
||||
|
||||
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.
|
||||
@@ -353,26 +449,38 @@ where
|
||||
// this number will automatically be low enough to address (2). The user can override this.
|
||||
Some(number_concurrent_tasks),
|
||||
move |test| {
|
||||
let leader_nodes = leader_nodes.clone();
|
||||
let follower_nodes = follower_nodes.clone();
|
||||
let cached_compiler = cached_compiler.clone();
|
||||
|
||||
async move {
|
||||
let leader_node = leader_nodes.round_robbin();
|
||||
let follower_node = follower_nodes.round_robbin();
|
||||
|
||||
test.reporter
|
||||
.report_leader_node_assigned_event(
|
||||
test.leader_node.id(),
|
||||
*L::config_id(),
|
||||
test.leader_node.connection_string(),
|
||||
leader_node.id(),
|
||||
L::config_id(),
|
||||
leader_node.connection_string(),
|
||||
)
|
||||
.expect("Can't fail");
|
||||
test.reporter
|
||||
.report_follower_node_assigned_event(
|
||||
test.follower_node.id(),
|
||||
*F::config_id(),
|
||||
test.follower_node.connection_string(),
|
||||
follower_node.id(),
|
||||
F::config_id(),
|
||||
follower_node.connection_string(),
|
||||
)
|
||||
.expect("Can't fail");
|
||||
|
||||
let reporter = test.reporter.clone();
|
||||
let result = handle_case_driver::<L, F>(test, cached_compiler).await;
|
||||
let result = handle_case_driver::<L, F>(
|
||||
test,
|
||||
args,
|
||||
cached_compiler,
|
||||
leader_node,
|
||||
follower_node,
|
||||
)
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(steps_executed) => reporter
|
||||
@@ -479,28 +587,37 @@ async fn start_cli_reporting_task(reporter: Reporter) {
|
||||
mode = %test.mode,
|
||||
case_idx = %test.case_idx,
|
||||
case_name = test.case.name.as_deref().unwrap_or("Unnamed Case"),
|
||||
leader_node = test.leader_node.id(),
|
||||
follower_node = test.follower_node.id(),
|
||||
leader_node = leader_node.id(),
|
||||
follower_node = follower_node.id(),
|
||||
)
|
||||
)]
|
||||
async fn handle_case_driver<'a, L, F>(
|
||||
test: Test<'a, L, F>,
|
||||
cached_compiler: Arc<CachedCompiler<'a>>,
|
||||
async fn handle_case_driver<L, F>(
|
||||
test: Test<'_>,
|
||||
config: &Arguments,
|
||||
cached_compiler: Arc<CachedCompiler>,
|
||||
leader_node: &L::Blockchain,
|
||||
follower_node: &F::Blockchain,
|
||||
) -> anyhow::Result<usize>
|
||||
where
|
||||
L: Platform,
|
||||
F: Platform,
|
||||
L::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
F::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
L::Compiler: 'a,
|
||||
F::Compiler: 'a,
|
||||
{
|
||||
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(test.leader_node.id(), NodeDesignation::Leader);
|
||||
.execution_specific_reporter(leader_node.id(), NodeDesignation::Leader);
|
||||
let follower_reporter = test
|
||||
.reporter
|
||||
.execution_specific_reporter(test.follower_node.id(), NodeDesignation::Follower);
|
||||
.execution_specific_reporter(follower_node.id(), NodeDesignation::Follower);
|
||||
|
||||
let (
|
||||
CompilerOutput {
|
||||
@@ -513,18 +630,56 @@ where
|
||||
cached_compiler.compile_contracts::<L>(
|
||||
test.metadata,
|
||||
test.metadata_file_path,
|
||||
test.mode.clone(),
|
||||
solc.clone(),
|
||||
&test.mode,
|
||||
config,
|
||||
None,
|
||||
&test.leader_compiler,
|
||||
&leader_reporter,
|
||||
|is_cached, compiler_input, compiler_output| {
|
||||
leader_reporter
|
||||
.report_pre_link_contracts_compilation_succeeded_event(
|
||||
is_cached,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
},
|
||||
|compiler_input, failure_reason| {
|
||||
leader_reporter
|
||||
.report_pre_link_contracts_compilation_failed_event(
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
failure_reason,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
}
|
||||
),
|
||||
cached_compiler.compile_contracts::<F>(
|
||||
test.metadata,
|
||||
test.metadata_file_path,
|
||||
test.mode.clone(),
|
||||
solc.clone(),
|
||||
&test.mode,
|
||||
config,
|
||||
None,
|
||||
&test.follower_compiler,
|
||||
&follower_reporter
|
||||
|is_cached, compiler_input, compiler_output| {
|
||||
follower_reporter
|
||||
.report_pre_link_contracts_compilation_succeeded_event(
|
||||
is_cached,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
},
|
||||
|compiler_input, failure_reason| {
|
||||
follower_reporter
|
||||
.report_pre_link_contracts_compilation_failed_event(
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
failure_reason,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
}
|
||||
)
|
||||
)
|
||||
.context("Failed to compile pre-link contracts for leader/follower in parallel")?;
|
||||
@@ -597,8 +752,8 @@ where
|
||||
);
|
||||
|
||||
let (leader_receipt, follower_receipt) = try_join!(
|
||||
test.leader_node.execute_transaction(leader_tx),
|
||||
test.follower_node.execute_transaction(follower_tx)
|
||||
leader_node.execute_transaction(leader_tx),
|
||||
follower_node.execute_transaction(follower_tx)
|
||||
)?;
|
||||
|
||||
debug!(
|
||||
@@ -666,30 +821,68 @@ where
|
||||
cached_compiler.compile_contracts::<L>(
|
||||
test.metadata,
|
||||
test.metadata_file_path,
|
||||
test.mode.clone(),
|
||||
solc.clone(),
|
||||
&test.mode,
|
||||
config,
|
||||
leader_deployed_libraries.as_ref(),
|
||||
&test.leader_compiler,
|
||||
&leader_reporter,
|
||||
|is_cached, compiler_input, compiler_output| {
|
||||
leader_reporter
|
||||
.report_post_link_contracts_compilation_succeeded_event(
|
||||
is_cached,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
},
|
||||
|compiler_input, failure_reason| {
|
||||
leader_reporter
|
||||
.report_post_link_contracts_compilation_failed_event(
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
failure_reason,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
}
|
||||
),
|
||||
cached_compiler.compile_contracts::<F>(
|
||||
test.metadata,
|
||||
test.metadata_file_path,
|
||||
test.mode.clone(),
|
||||
solc.clone(),
|
||||
&test.mode,
|
||||
config,
|
||||
follower_deployed_libraries.as_ref(),
|
||||
&test.follower_compiler,
|
||||
&follower_reporter
|
||||
|is_cached, compiler_input, compiler_output| {
|
||||
follower_reporter
|
||||
.report_post_link_contracts_compilation_succeeded_event(
|
||||
is_cached,
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
},
|
||||
|compiler_input, failure_reason| {
|
||||
follower_reporter
|
||||
.report_post_link_contracts_compilation_failed_event(
|
||||
solc.clone(),
|
||||
compiler_input,
|
||||
failure_reason,
|
||||
)
|
||||
.expect("Can't fail")
|
||||
}
|
||||
)
|
||||
)
|
||||
.context("Failed to compile post-link contracts for leader/follower in parallel")?;
|
||||
|
||||
let leader_state = CaseState::<L>::new(
|
||||
test.leader_compiler.version().clone(),
|
||||
solc.version.clone(),
|
||||
leader_post_link_contracts,
|
||||
leader_deployed_libraries.unwrap_or_default(),
|
||||
leader_reporter,
|
||||
);
|
||||
let follower_state = CaseState::<F>::new(
|
||||
test.follower_compiler.version().clone(),
|
||||
solc.version.clone(),
|
||||
follower_post_link_contracts,
|
||||
follower_deployed_libraries.unwrap_or_default(),
|
||||
follower_reporter,
|
||||
@@ -698,8 +891,8 @@ where
|
||||
let mut driver = CaseDriver::<L, F>::new(
|
||||
test.metadata,
|
||||
test.case,
|
||||
test.leader_node,
|
||||
test.follower_node,
|
||||
leader_node,
|
||||
follower_node,
|
||||
leader_state,
|
||||
follower_state,
|
||||
);
|
||||
@@ -728,121 +921,84 @@ async fn execute_corpus(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// this represents a single "test"; a mode, path and collection of cases.
|
||||
#[derive(Clone)]
|
||||
struct Test<'a, L: Platform, F: Platform> {
|
||||
metadata: &'a MetadataFile,
|
||||
metadata_file_path: &'a Path,
|
||||
mode: Cow<'a, Mode>,
|
||||
case_idx: CaseIdx,
|
||||
case: &'a Case,
|
||||
leader_node: &'a <L as Platform>::Blockchain,
|
||||
follower_node: &'a <F as Platform>::Blockchain,
|
||||
leader_compiler: L::Compiler,
|
||||
follower_compiler: F::Compiler,
|
||||
reporter: TestSpecificReporter,
|
||||
async fn compile_corpus(
|
||||
config: &Arguments,
|
||||
tests: &[MetadataFile],
|
||||
platform: &TestingPlatform,
|
||||
reporter: Reporter,
|
||||
report_aggregator_task: impl Future<Output = anyhow::Result<()>>,
|
||||
) {
|
||||
let tests = tests.iter().flat_map(|metadata| {
|
||||
metadata
|
||||
.solc_modes()
|
||||
.into_iter()
|
||||
.map(move |solc_mode| (metadata, solc_mode))
|
||||
});
|
||||
|
||||
let file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
|
||||
let cached_compiler = CachedCompiler::new(file.path(), false)
|
||||
.await
|
||||
.map(Arc::new)
|
||||
.expect("Failed to create the cached compiler");
|
||||
|
||||
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;
|
||||
}
|
||||
TestingPlatform::Kitchensink => {
|
||||
let _ = cached_compiler
|
||||
.compile_contracts::<Kitchensink>(
|
||||
metadata,
|
||||
metadata.metadata_file_path.as_path(),
|
||||
solc,
|
||||
&mode,
|
||||
config,
|
||||
None,
|
||||
|_, _, _| {},
|
||||
|_, _| {},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
let _ = join!(compilation_task, report_aggregator_task);
|
||||
}
|
||||
|
||||
impl<'a, L: Platform, F: Platform> Test<'a, L, F> {
|
||||
/// Checks if this test can be ran with the current configuration.
|
||||
pub fn check_compatibility(&self) -> TestCheckFunctionResult {
|
||||
self.check_metadata_file_ignored()?;
|
||||
self.check_case_file_ignored()?;
|
||||
self.check_target_compatibility()?;
|
||||
self.check_evm_version_compatibility()?;
|
||||
self.check_compiler_compatibility()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Checks if the metadata file is ignored or not.
|
||||
fn check_metadata_file_ignored(&self) -> TestCheckFunctionResult {
|
||||
if self.metadata.ignore.is_some_and(|ignore| ignore) {
|
||||
Err(("Metadata file is ignored.", indexmap! {}))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if the case file is ignored or not.
|
||||
fn check_case_file_ignored(&self) -> TestCheckFunctionResult {
|
||||
if self.case.ignore.is_some_and(|ignore| ignore) {
|
||||
Err(("Case is ignored.", indexmap! {}))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if the leader and the follower both support the desired targets in the metadata file.
|
||||
fn check_target_compatibility(&self) -> TestCheckFunctionResult {
|
||||
let leader_support =
|
||||
<L::Blockchain as Node>::matches_target(self.metadata.targets.as_deref());
|
||||
let follower_support =
|
||||
<F::Blockchain as Node>::matches_target(self.metadata.targets.as_deref());
|
||||
let is_allowed = leader_support && follower_support;
|
||||
|
||||
if is_allowed {
|
||||
Ok(())
|
||||
} else {
|
||||
Err((
|
||||
"Either the leader or the follower do not support the target desired by the test.",
|
||||
indexmap! {
|
||||
"test_desired_targets" => json!(self.metadata.targets.as_ref()),
|
||||
"leader_support" => json!(leader_support),
|
||||
"follower_support" => json!(follower_support),
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
// Checks for the compatibility of the EVM version with the leader and follower nodes.
|
||||
fn check_evm_version_compatibility(&self) -> TestCheckFunctionResult {
|
||||
let Some(evm_version_requirement) = self.metadata.required_evm_version else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let leader_support = evm_version_requirement
|
||||
.matches(&<L::Blockchain as revive_dt_node::Node>::evm_version());
|
||||
let follower_support = evm_version_requirement
|
||||
.matches(&<F::Blockchain as revive_dt_node::Node>::evm_version());
|
||||
let is_allowed = leader_support && follower_support;
|
||||
|
||||
if is_allowed {
|
||||
Ok(())
|
||||
} else {
|
||||
Err((
|
||||
"EVM version is incompatible with either the leader or the follower.",
|
||||
indexmap! {
|
||||
"test_desired_evm_version" => json!(self.metadata.required_evm_version),
|
||||
"leader_support" => json!(leader_support),
|
||||
"follower_support" => json!(follower_support),
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if the leader and follower compilers support the mode that the test is for.
|
||||
fn check_compiler_compatibility(&self) -> TestCheckFunctionResult {
|
||||
let leader_support = self
|
||||
.leader_compiler
|
||||
.supports_mode(self.mode.optimize_setting, self.mode.pipeline);
|
||||
let follower_support = self
|
||||
.follower_compiler
|
||||
.supports_mode(self.mode.optimize_setting, self.mode.pipeline);
|
||||
let is_allowed = leader_support && follower_support;
|
||||
|
||||
if is_allowed {
|
||||
Ok(())
|
||||
} else {
|
||||
Err((
|
||||
"Compilers do not support this mode either for the leader or for the follower.",
|
||||
indexmap! {
|
||||
"mode" => json!(self.mode),
|
||||
"leader_support" => json!(leader_support),
|
||||
"follower_support" => json!(follower_support),
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type TestCheckFunctionResult = Result<(), (&'static str, IndexMap<&'static str, Value>)>;
|
||||
|
||||
@@ -64,7 +64,7 @@ impl Case {
|
||||
pub fn solc_modes(&self) -> Vec<Mode> {
|
||||
match &self.modes {
|
||||
Some(modes) => ParsedMode::many_to_modes(modes.iter()).collect(),
|
||||
None => Mode::all().cloned().collect(),
|
||||
None => Mode::all().collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ impl Metadata {
|
||||
pub fn solc_modes(&self) -> Vec<Mode> {
|
||||
match &self.modes {
|
||||
Some(modes) => ParsedMode::many_to_modes(modes.iter()).collect(),
|
||||
None => Mode::all().cloned().collect(),
|
||||
None => Mode::all().collect(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use anyhow::Context;
|
||||
use regex::Regex;
|
||||
use revive_dt_common::iterators::EitherIter;
|
||||
use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
@@ -177,6 +176,27 @@ impl ParsedMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator that could be either of two iterators.
|
||||
#[derive(Clone, Debug)]
|
||||
enum EitherIter<A, B> {
|
||||
A(A),
|
||||
B(B),
|
||||
}
|
||||
|
||||
impl<A, B> Iterator for EitherIter<A, B>
|
||||
where
|
||||
A: Iterator,
|
||||
B: Iterator<Item = A::Item>,
|
||||
{
|
||||
type Item = A::Item;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self {
|
||||
EitherIter::A(iter) => iter.next(),
|
||||
EitherIter::B(iter) => iter.next(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -27,7 +27,7 @@ sp-core = { workspace = true }
|
||||
sp-runtime = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
temp-dir = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -664,7 +664,7 @@ impl Drop for GethNode {
|
||||
mod tests {
|
||||
use revive_dt_config::Arguments;
|
||||
|
||||
use temp_dir::TempDir;
|
||||
use tempfile::TempDir;
|
||||
|
||||
use crate::{GENESIS_JSON, Node};
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ alloy-primitives = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
paste = { workspace = true }
|
||||
indexmap = { workspace = true, features = ["serde"] }
|
||||
semver = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
serde_with = { workspace = true }
|
||||
|
||||
@@ -4,17 +4,15 @@
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||
fs::OpenOptions,
|
||||
path::PathBuf,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use alloy_primitives::Address;
|
||||
use anyhow::{Context as _, Result};
|
||||
use indexmap::IndexMap;
|
||||
use revive_dt_compiler::{CompilerInput, CompilerOutput, Mode};
|
||||
use revive_dt_compiler::{CompilerInput, CompilerOutput, Mode, SolcCompiler};
|
||||
use revive_dt_config::{Arguments, TestingPlatform};
|
||||
use revive_dt_format::{case::CaseIdx, corpus::Corpus, metadata::ContractInstance};
|
||||
use semver::Version;
|
||||
use serde::Serialize;
|
||||
use serde_with::{DisplayFromStr, serde_as};
|
||||
use tokio::sync::{
|
||||
@@ -300,8 +298,7 @@ impl ReportAggregator {
|
||||
|
||||
execution_information.pre_link_compilation_status = Some(CompilationStatus::Success {
|
||||
is_cached: event.is_cached,
|
||||
compiler_version: event.compiler_version,
|
||||
compiler_path: event.compiler_path,
|
||||
solc_info: event.solc_info,
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
});
|
||||
@@ -329,8 +326,7 @@ impl ReportAggregator {
|
||||
|
||||
execution_information.post_link_compilation_status = Some(CompilationStatus::Success {
|
||||
is_cached: event.is_cached,
|
||||
compiler_version: event.compiler_version,
|
||||
compiler_path: event.compiler_path,
|
||||
solc_info: event.solc_info,
|
||||
compiler_input,
|
||||
compiler_output,
|
||||
});
|
||||
@@ -340,13 +336,20 @@ impl ReportAggregator {
|
||||
&mut self,
|
||||
event: PreLinkContractsCompilationFailedEvent,
|
||||
) {
|
||||
let include_input = self.report.config.report_include_compiler_input;
|
||||
|
||||
let execution_information = self.execution_information(&event.execution_specifier);
|
||||
|
||||
let compiler_input = if include_input {
|
||||
event.compiler_input
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
execution_information.pre_link_compilation_status = Some(CompilationStatus::Failure {
|
||||
reason: event.reason,
|
||||
compiler_version: event.compiler_version,
|
||||
compiler_path: event.compiler_path,
|
||||
compiler_input: event.compiler_input,
|
||||
solc_info: event.solc_info,
|
||||
compiler_input,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -354,13 +357,20 @@ impl ReportAggregator {
|
||||
&mut self,
|
||||
event: PostLinkContractsCompilationFailedEvent,
|
||||
) {
|
||||
let include_input = self.report.config.report_include_compiler_input;
|
||||
|
||||
let execution_information = self.execution_information(&event.execution_specifier);
|
||||
|
||||
let compiler_input = if include_input {
|
||||
event.compiler_input
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
execution_information.post_link_compilation_status = Some(CompilationStatus::Failure {
|
||||
reason: event.reason,
|
||||
compiler_version: event.compiler_version,
|
||||
compiler_path: event.compiler_path,
|
||||
compiler_input: event.compiler_input,
|
||||
solc_info: event.solc_info,
|
||||
compiler_input,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -512,10 +522,8 @@ pub enum CompilationStatus {
|
||||
Success {
|
||||
/// A flag with information on whether the compilation artifacts were cached or not.
|
||||
is_cached: bool,
|
||||
/// The version of the compiler used to compile the contracts.
|
||||
compiler_version: Version,
|
||||
/// The path of the compiler used to compile the contracts.
|
||||
compiler_path: PathBuf,
|
||||
/// The version and path of the solc compiler used to compile the contracts.
|
||||
solc_info: SolcCompiler,
|
||||
/// The input provided to the compiler to compile the contracts. This is only included if
|
||||
/// the appropriate flag is set in the CLI configuration and if the contracts were not
|
||||
/// cached and the compiler was invoked.
|
||||
@@ -530,12 +538,8 @@ pub enum CompilationStatus {
|
||||
Failure {
|
||||
/// The failure reason.
|
||||
reason: String,
|
||||
/// The version of the compiler used to compile the contracts.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
compiler_version: Option<Version>,
|
||||
/// The path of the compiler used to compile the contracts.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
compiler_path: Option<PathBuf>,
|
||||
/// The version and path of the solc compiler used to compile the contracts.
|
||||
solc_info: SolcCompiler,
|
||||
/// The input provided to the compiler to compile the contracts. This is only included if
|
||||
/// the appropriate flag is set in the CLI configuration and if the contracts were not
|
||||
/// cached and the compiler was invoked.
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
//! The types associated with the events sent by the runner to the reporter.
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::{collections::BTreeMap, path::PathBuf, sync::Arc};
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
use alloy_primitives::Address;
|
||||
use anyhow::Context as _;
|
||||
use indexmap::IndexMap;
|
||||
use revive_dt_compiler::{CompilerInput, CompilerOutput};
|
||||
use revive_dt_compiler::{CompilerInput, CompilerOutput, SolcCompiler};
|
||||
use revive_dt_config::TestingPlatform;
|
||||
use revive_dt_format::metadata::Metadata;
|
||||
use revive_dt_format::{corpus::Corpus, metadata::ContractInstance};
|
||||
use semver::Version;
|
||||
use tokio::sync::{broadcast, oneshot};
|
||||
|
||||
use crate::{ExecutionSpecifier, ReporterEvent, TestSpecifier, common::MetadataFilePath};
|
||||
@@ -547,13 +546,11 @@ define_event! {
|
||||
PreLinkContractsCompilationSucceeded {
|
||||
/// A specifier for the execution that's taking place.
|
||||
execution_specifier: Arc<ExecutionSpecifier>,
|
||||
/// The version of the compiler used to compile the contracts.
|
||||
compiler_version: Version,
|
||||
/// The path of the compiler used to compile the contracts.
|
||||
compiler_path: PathBuf,
|
||||
/// A flag of whether the contract bytecode and ABI were cached or if they were compiled
|
||||
/// anew.
|
||||
is_cached: bool,
|
||||
/// The version and path of the solc compiler used to compile the contracts.
|
||||
solc_info: SolcCompiler,
|
||||
/// The input provided to the compiler - this is optional and not provided if the
|
||||
/// contracts were obtained from the cache.
|
||||
compiler_input: Option<CompilerInput>,
|
||||
@@ -565,13 +562,11 @@ define_event! {
|
||||
PostLinkContractsCompilationSucceeded {
|
||||
/// A specifier for the execution that's taking place.
|
||||
execution_specifier: Arc<ExecutionSpecifier>,
|
||||
/// The version of the compiler used to compile the contracts.
|
||||
compiler_version: Version,
|
||||
/// The path of the compiler used to compile the contracts.
|
||||
compiler_path: PathBuf,
|
||||
/// A flag of whether the contract bytecode and ABI were cached or if they were compiled
|
||||
/// anew.
|
||||
is_cached: bool,
|
||||
/// The version and path of the solc compiler used to compile the contracts.
|
||||
solc_info: SolcCompiler,
|
||||
/// The input provided to the compiler - this is optional and not provided if the
|
||||
/// contracts were obtained from the cache.
|
||||
compiler_input: Option<CompilerInput>,
|
||||
@@ -583,10 +578,8 @@ define_event! {
|
||||
PreLinkContractsCompilationFailed {
|
||||
/// A specifier for the execution that's taking place.
|
||||
execution_specifier: Arc<ExecutionSpecifier>,
|
||||
/// The version of the compiler used to compile the contracts.
|
||||
compiler_version: Option<Version>,
|
||||
/// The path of the compiler used to compile the contracts.
|
||||
compiler_path: Option<PathBuf>,
|
||||
/// The version and path of the solc compiler used to compile the contracts.
|
||||
solc_info: SolcCompiler,
|
||||
/// The input provided to the compiler - this is optional and not provided if the
|
||||
/// contracts were obtained from the cache.
|
||||
compiler_input: Option<CompilerInput>,
|
||||
@@ -598,10 +591,8 @@ define_event! {
|
||||
PostLinkContractsCompilationFailed {
|
||||
/// A specifier for the execution that's taking place.
|
||||
execution_specifier: Arc<ExecutionSpecifier>,
|
||||
/// The version of the compiler used to compile the contracts.
|
||||
compiler_version: Option<Version>,
|
||||
/// The path of the compiler used to compile the contracts.
|
||||
compiler_path: Option<PathBuf>,
|
||||
/// The version and path of the solc compiler used to compile the contracts.
|
||||
solc_info: SolcCompiler,
|
||||
/// The input provided to the compiler - this is optional and not provided if the
|
||||
/// contracts were obtained from the cache.
|
||||
compiler_input: Option<CompilerInput>,
|
||||
|
||||
@@ -9,7 +9,6 @@ use std::{
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use semver::Version;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::download::SolcDownloader;
|
||||
@@ -21,7 +20,7 @@ pub(crate) static SOLC_CACHER: LazyLock<Mutex<HashSet<PathBuf>>> = LazyLock::new
|
||||
pub(crate) async fn get_or_download(
|
||||
working_directory: &Path,
|
||||
downloader: &SolcDownloader,
|
||||
) -> anyhow::Result<(Version, PathBuf)> {
|
||||
) -> anyhow::Result<PathBuf> {
|
||||
let target_directory = working_directory
|
||||
.join(SOLC_CACHE_DIRECTORY)
|
||||
.join(downloader.version.to_string());
|
||||
@@ -30,7 +29,7 @@ pub(crate) async fn get_or_download(
|
||||
let mut cache = SOLC_CACHER.lock().await;
|
||||
if cache.contains(&target_file) {
|
||||
tracing::debug!("using cached solc: {}", target_file.display());
|
||||
return Ok((downloader.version.clone(), target_file));
|
||||
return Ok(target_file);
|
||||
}
|
||||
|
||||
create_dir_all(&target_directory).with_context(|| {
|
||||
@@ -49,7 +48,7 @@ pub(crate) async fn get_or_download(
|
||||
})?;
|
||||
cache.insert(target_file.clone());
|
||||
|
||||
Ok((downloader.version.clone(), target_file))
|
||||
Ok(target_file)
|
||||
}
|
||||
|
||||
async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::Result<()> {
|
||||
|
||||
@@ -82,7 +82,7 @@ impl SolcDownloader {
|
||||
.filter(|version| requirement.matches(version))
|
||||
.max()
|
||||
else {
|
||||
anyhow::bail!("Failed to find a version that satisfies {requirement:?}");
|
||||
anyhow::bail!("Failed to find a version that satisfies {requirement}");
|
||||
};
|
||||
Ok(Self {
|
||||
version,
|
||||
|
||||
@@ -3,30 +3,23 @@
|
||||
//!
|
||||
//! [0]: https://binaries.soliditylang.org
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Context;
|
||||
use cache::get_or_download;
|
||||
use download::SolcDownloader;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use revive_dt_common::types::VersionOrRequirement;
|
||||
use semver::Version;
|
||||
|
||||
pub mod cache;
|
||||
pub mod download;
|
||||
pub mod list;
|
||||
|
||||
/// Downloads the solc binary for Wasm is `wasm` is set, otherwise for
|
||||
/// the target platform.
|
||||
///
|
||||
/// Subsequent calls for the same version will use a cached artifact
|
||||
/// and not download it again.
|
||||
pub async fn download_solc(
|
||||
cache_directory: &Path,
|
||||
/// Return a [`SolcDownloader`] which can be used to download a `solc`
|
||||
/// binary or return the resolved version it will download.
|
||||
async fn downloader(
|
||||
version: impl Into<VersionOrRequirement>,
|
||||
wasm: bool,
|
||||
) -> anyhow::Result<(Version, PathBuf)> {
|
||||
let downloader = if wasm {
|
||||
) -> anyhow::Result<SolcDownloader> {
|
||||
if wasm {
|
||||
SolcDownloader::wasm(version).await
|
||||
} else if cfg!(target_os = "linux") {
|
||||
SolcDownloader::linux(version).await
|
||||
@@ -37,7 +30,18 @@ pub async fn download_solc(
|
||||
} else {
|
||||
unimplemented!()
|
||||
}
|
||||
.context("Failed to initialize the Solc Downloader")?;
|
||||
}
|
||||
|
||||
/// Downloads the solc binary for Wasm is `wasm` is set, otherwise for
|
||||
/// the target platform.
|
||||
///
|
||||
/// Subsequent calls for the same version will use a cached artifact
|
||||
/// and not download it again.
|
||||
pub async fn download_solc(
|
||||
cache_directory: &Path,
|
||||
version: impl Into<VersionOrRequirement>,
|
||||
wasm: bool,
|
||||
) -> anyhow::Result<PathBuf> {
|
||||
let downloader = downloader(version, wasm).await?;
|
||||
get_or_download(cache_directory, &downloader).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user