mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-27 17:17:57 +00:00
Parallelize Cases (#109)
* Parallelize over cases * Rename the state and driver * Parallelize execution * Update the default config of the tool * Make codebase async * Fix machete * Fix tests & clear node directories before startup * Cleanup the cleanup logic * Rename geth node
This commit is contained in:
@@ -33,14 +33,14 @@ pub trait SolidityCompiler {
|
||||
&self,
|
||||
input: CompilerInput,
|
||||
additional_options: Self::Options,
|
||||
) -> anyhow::Result<CompilerOutput>;
|
||||
) -> impl Future<Output = anyhow::Result<CompilerOutput>>;
|
||||
|
||||
fn new(solc_executable: PathBuf) -> Self;
|
||||
|
||||
fn get_compiler_executable(
|
||||
config: &Arguments,
|
||||
version: impl Into<VersionOrRequirement>,
|
||||
) -> anyhow::Result<PathBuf>;
|
||||
) -> impl Future<Output = anyhow::Result<PathBuf>>;
|
||||
|
||||
fn version(&self) -> anyhow::Result<Version>;
|
||||
}
|
||||
@@ -147,8 +147,13 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
pub fn try_build(self, compiler_path: impl AsRef<Path>) -> anyhow::Result<CompilerOutput> {
|
||||
T::new(compiler_path.as_ref().to_path_buf()).build(self.input, self.additional_options)
|
||||
pub async fn try_build(
|
||||
self,
|
||||
compiler_path: impl AsRef<Path>,
|
||||
) -> anyhow::Result<CompilerOutput> {
|
||||
T::new(compiler_path.as_ref().to_path_buf())
|
||||
.build(self.input, self.additional_options)
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn input(&self) -> CompilerInput {
|
||||
|
||||
@@ -6,7 +6,6 @@ use std::{
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
use alloy::json_abi::JsonAbi;
|
||||
use revive_dt_common::types::VersionOrRequirement;
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_solc_json_interface::{
|
||||
@@ -17,8 +16,10 @@ use revive_solc_json_interface::{
|
||||
|
||||
use crate::{CompilerInput, CompilerOutput, SolidityCompiler};
|
||||
|
||||
use alloy::json_abi::JsonAbi;
|
||||
use anyhow::Context;
|
||||
use semver::Version;
|
||||
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
||||
|
||||
// TODO: I believe that we need to also pass the solc compiler to resolc so that resolc uses the
|
||||
// specified solc compiler. I believe that currently we completely ignore the specified solc binary
|
||||
@@ -35,7 +36,7 @@ impl SolidityCompiler for Resolc {
|
||||
type Options = Vec<String>;
|
||||
|
||||
#[tracing::instrument(level = "debug", ret)]
|
||||
fn build(
|
||||
async fn build(
|
||||
&self,
|
||||
CompilerInput {
|
||||
enable_optimization,
|
||||
@@ -87,7 +88,7 @@ impl SolidityCompiler for Resolc {
|
||||
},
|
||||
};
|
||||
|
||||
let mut command = Command::new(&self.resolc_path);
|
||||
let mut command = AsyncCommand::new(&self.resolc_path);
|
||||
command
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
@@ -109,9 +110,10 @@ impl SolidityCompiler for Resolc {
|
||||
let mut child = command.spawn()?;
|
||||
|
||||
let stdin_pipe = child.stdin.as_mut().expect("stdin must be piped");
|
||||
serde_json::to_writer(stdin_pipe, &input)?;
|
||||
let serialized_input = serde_json::to_vec(&input)?;
|
||||
stdin_pipe.write_all(&serialized_input).await?;
|
||||
|
||||
let output = child.wait_with_output()?;
|
||||
let output = child.wait_with_output().await?;
|
||||
let stdout = output.stdout;
|
||||
let stderr = output.stderr;
|
||||
|
||||
@@ -195,7 +197,7 @@ impl SolidityCompiler for Resolc {
|
||||
Resolc { resolc_path }
|
||||
}
|
||||
|
||||
fn get_compiler_executable(
|
||||
async fn get_compiler_executable(
|
||||
config: &Arguments,
|
||||
_version: impl Into<VersionOrRequirement>,
|
||||
) -> anyhow::Result<PathBuf> {
|
||||
@@ -233,11 +235,13 @@ impl SolidityCompiler for Resolc {
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn compiler_version_can_be_obtained() {
|
||||
#[tokio::test]
|
||||
async fn compiler_version_can_be_obtained() {
|
||||
// Arrange
|
||||
let args = Arguments::default();
|
||||
let path = Resolc::get_compiler_executable(&args, Version::new(0, 7, 6)).unwrap();
|
||||
let path = Resolc::get_compiler_executable(&args, Version::new(0, 7, 6))
|
||||
.await
|
||||
.unwrap();
|
||||
let compiler = Resolc::new(path);
|
||||
|
||||
// Act
|
||||
|
||||
@@ -21,6 +21,7 @@ use foundry_compilers_artifacts::{
|
||||
solc::*,
|
||||
};
|
||||
use semver::Version;
|
||||
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Solc {
|
||||
@@ -31,7 +32,7 @@ impl SolidityCompiler for Solc {
|
||||
type Options = ();
|
||||
|
||||
#[tracing::instrument(level = "debug", ret)]
|
||||
fn build(
|
||||
async fn build(
|
||||
&self,
|
||||
CompilerInput {
|
||||
enable_optimization,
|
||||
@@ -90,7 +91,7 @@ impl SolidityCompiler for Solc {
|
||||
},
|
||||
};
|
||||
|
||||
let mut command = Command::new(&self.solc_path);
|
||||
let mut command = AsyncCommand::new(&self.solc_path);
|
||||
command
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
@@ -112,8 +113,9 @@ impl SolidityCompiler for Solc {
|
||||
let mut child = command.spawn()?;
|
||||
|
||||
let stdin = child.stdin.as_mut().expect("should be piped");
|
||||
serde_json::to_writer(stdin, &input)?;
|
||||
let output = child.wait_with_output()?;
|
||||
let serialized_input = serde_json::to_vec(&input)?;
|
||||
stdin.write_all(&serialized_input).await?;
|
||||
let output = child.wait_with_output().await?;
|
||||
|
||||
if !output.status.success() {
|
||||
let json_in = serde_json::to_string_pretty(&input)?;
|
||||
@@ -177,11 +179,11 @@ impl SolidityCompiler for Solc {
|
||||
Self { solc_path }
|
||||
}
|
||||
|
||||
fn get_compiler_executable(
|
||||
async fn get_compiler_executable(
|
||||
config: &Arguments,
|
||||
version: impl Into<VersionOrRequirement>,
|
||||
) -> anyhow::Result<PathBuf> {
|
||||
let path = download_solc(config.directory(), version, config.wasm)?;
|
||||
let path = download_solc(config.directory(), version, config.wasm).await?;
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
@@ -216,11 +218,15 @@ impl SolidityCompiler for Solc {
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn compiler_version_can_be_obtained() {
|
||||
#[tokio::test]
|
||||
async fn compiler_version_can_be_obtained() {
|
||||
// Arrange
|
||||
let args = Arguments::default();
|
||||
let path = Solc::get_compiler_executable(&args, Version::new(0, 7, 6)).unwrap();
|
||||
println!("Getting compiler path");
|
||||
let path = Solc::get_compiler_executable(&args, Version::new(0, 7, 6))
|
||||
.await
|
||||
.unwrap();
|
||||
println!("Got compiler path");
|
||||
let compiler = Solc::new(path);
|
||||
|
||||
// Act
|
||||
|
||||
Reference in New Issue
Block a user