mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-24 06:37:58 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f4fadf7b1 | |||
| f2045db0e9 | |||
| 5a11f44673 | |||
| 46aea0890d |
@@ -0,0 +1,38 @@
|
||||
//! Implements a cached file system that allows for files to be read once into memory and then when
|
||||
//! they're requested to be read again they will be returned from the cache.
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
path::{Path, PathBuf},
|
||||
sync::{Arc, LazyLock},
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
static CACHE: LazyLock<Arc<RwLock<HashMap<PathBuf, Vec<u8>>>>> = LazyLock::new(Default::default);
|
||||
|
||||
pub struct CachedFileSystem;
|
||||
|
||||
impl CachedFileSystem {
|
||||
pub async fn read(path: impl AsRef<Path>) -> Result<Vec<u8>> {
|
||||
let cache_read_lock = CACHE.read().await;
|
||||
match cache_read_lock.get(path.as_ref()) {
|
||||
Some(entry) => Ok(entry.clone()),
|
||||
None => {
|
||||
drop(cache_read_lock);
|
||||
|
||||
let content = std::fs::read(&path)?;
|
||||
let mut cache_write_lock = CACHE.write().await;
|
||||
cache_write_lock.insert(path.as_ref().to_path_buf(), content.clone());
|
||||
Ok(content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn read_to_string(path: impl AsRef<Path>) -> Result<String> {
|
||||
let content = Self::read(path).await?;
|
||||
String::from_utf8(content).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
mod cached_file_system;
|
||||
mod clear_dir;
|
||||
|
||||
pub use cached_file_system::*;
|
||||
pub use clear_dir::*;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::read_to_string,
|
||||
hash::Hash,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
@@ -16,7 +15,7 @@ use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use revive_common::EVMVersion;
|
||||
use revive_dt_common::types::VersionOrRequirement;
|
||||
use revive_dt_common::{fs::CachedFileSystem, types::VersionOrRequirement};
|
||||
use revive_dt_config::Arguments;
|
||||
|
||||
pub mod revive_js;
|
||||
@@ -55,6 +54,7 @@ pub struct CompilerInput {
|
||||
pub base_path: Option<PathBuf>,
|
||||
pub sources: HashMap<PathBuf, String>,
|
||||
pub libraries: HashMap<PathBuf, HashMap<String, Address>>,
|
||||
pub revert_string_handling: Option<RevertString>,
|
||||
}
|
||||
|
||||
/// The generic compilation output configuration.
|
||||
@@ -91,6 +91,7 @@ where
|
||||
base_path: Default::default(),
|
||||
sources: Default::default(),
|
||||
libraries: Default::default(),
|
||||
revert_string_handling: Default::default(),
|
||||
},
|
||||
additional_options: T::Options::default(),
|
||||
}
|
||||
@@ -121,10 +122,11 @@ where
|
||||
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())?);
|
||||
pub async fn with_source(mut self, path: impl AsRef<Path>) -> anyhow::Result<Self> {
|
||||
self.input.sources.insert(
|
||||
path.as_ref().to_path_buf(),
|
||||
CachedFileSystem::read_to_string(path.as_ref()).await?,
|
||||
);
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
@@ -142,6 +144,14 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_revert_string_handling(
|
||||
mut self,
|
||||
revert_string_handling: impl Into<Option<RevertString>>,
|
||||
) -> Self {
|
||||
self.input.revert_string_handling = revert_string_handling.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_additional_options(mut self, options: impl Into<T::Options>) -> Self {
|
||||
self.additional_options = options.into();
|
||||
self
|
||||
@@ -160,3 +170,15 @@ where
|
||||
self.input.clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// Defines how the compiler should handle revert strings.
|
||||
#[derive(
|
||||
Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
|
||||
)]
|
||||
pub enum RevertString {
|
||||
#[default]
|
||||
Default,
|
||||
Debug,
|
||||
Strip,
|
||||
VerboseDebug,
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ impl SolidityCompiler for Resolc {
|
||||
base_path,
|
||||
sources,
|
||||
libraries,
|
||||
// TODO: this is currently not being handled since there is no way to pass it into
|
||||
// resolc. So, we need to go back to this later once it's supported.
|
||||
revert_string_handling: _,
|
||||
}: CompilerInput,
|
||||
additional_options: Self::Options,
|
||||
) -> anyhow::Result<CompilerOutput> {
|
||||
|
||||
@@ -42,6 +42,7 @@ impl SolidityCompiler for Solc {
|
||||
base_path,
|
||||
sources,
|
||||
libraries,
|
||||
revert_string_handling,
|
||||
}: CompilerInput,
|
||||
_: Self::Options,
|
||||
) -> anyhow::Result<CompilerOutput> {
|
||||
@@ -87,6 +88,15 @@ impl SolidityCompiler for Solc {
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
debug: revert_string_handling.map(|revert_string_handling| DebuggingSettings {
|
||||
revert_strings: match revert_string_handling {
|
||||
crate::RevertString::Default => Some(RevertStrings::Default),
|
||||
crate::RevertString::Debug => Some(RevertStrings::Debug),
|
||||
crate::RevertString::Strip => Some(RevertStrings::Strip),
|
||||
crate::RevertString::VerboseDebug => Some(RevertStrings::VerboseDebug),
|
||||
},
|
||||
debug_info: Default::default(),
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
|
||||
@@ -96,10 +96,19 @@ pub struct Arguments {
|
||||
#[arg(long, default_value = "1")]
|
||||
pub number_of_nodes: usize,
|
||||
|
||||
/// Determines the amount of threads that will will be used.
|
||||
#[arg(long, default_value = "12")]
|
||||
/// Determines the amount of tokio worker threads that will will be used.
|
||||
#[arg(
|
||||
long,
|
||||
default_value_t = std::thread::available_parallelism()
|
||||
.map(|n| n.get())
|
||||
.unwrap_or(1)
|
||||
)]
|
||||
pub number_of_threads: usize,
|
||||
|
||||
/// Determines the amount of concurrent tasks that will be spawned to run tests. Defaults to 10 x the number of nodes.
|
||||
#[arg(long)]
|
||||
pub number_concurrent_tasks: Option<usize>,
|
||||
|
||||
/// Extract problems back to the test corpus.
|
||||
#[arg(short, long = "extract-problems")]
|
||||
pub extract_problems: bool,
|
||||
@@ -134,6 +143,13 @@ impl Arguments {
|
||||
panic!("should have a workdir configured")
|
||||
}
|
||||
|
||||
/// Return the number of concurrent tasks to run. This is provided via the
|
||||
/// `--number-concurrent-tasks` argument, and otherwise defaults to --number-of-nodes * 20.
|
||||
pub fn number_of_concurrent_tasks(&self) -> usize {
|
||||
self.number_concurrent_tasks
|
||||
.unwrap_or(20 * self.number_of_nodes)
|
||||
}
|
||||
|
||||
/// Try to parse `self.account` into a [PrivateKeySigner],
|
||||
/// panicing on error.
|
||||
pub fn wallet(&self) -> EthereumWallet {
|
||||
|
||||
+192
-183
@@ -1,6 +1,6 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
path::Path,
|
||||
path::{Path, PathBuf},
|
||||
sync::{Arc, LazyLock},
|
||||
time::Instant,
|
||||
};
|
||||
@@ -18,7 +18,7 @@ use revive_dt_common::iterators::FilesWithExtensionIterator;
|
||||
use revive_dt_node_interaction::EthereumNode;
|
||||
use semver::Version;
|
||||
use temp_dir::TempDir;
|
||||
use tokio::sync::{Mutex, RwLock};
|
||||
use tokio::sync::{Mutex, RwLock, mpsc};
|
||||
use tracing::{Instrument, Level};
|
||||
use tracing_subscriber::{EnvFilter, FmtSubscriber};
|
||||
|
||||
@@ -41,20 +41,33 @@ use revive_dt_report::reporter::{Report, Span};
|
||||
|
||||
static TEMP_DIR: LazyLock<TempDir> = LazyLock::new(|| TempDir::new().unwrap());
|
||||
|
||||
type CompilationCache<'a> = Arc<
|
||||
type CompilationCache = Arc<
|
||||
RwLock<
|
||||
HashMap<
|
||||
(&'a Path, SolcMode, TestingPlatform),
|
||||
(PathBuf, SolcMode, TestingPlatform),
|
||||
Arc<Mutex<Option<Arc<(Version, CompilerOutput)>>>>,
|
||||
>,
|
||||
>,
|
||||
>;
|
||||
|
||||
/// this represents a single "test"; a mode, path and collection of cases.
|
||||
#[derive(Clone)]
|
||||
struct Test {
|
||||
metadata: Metadata,
|
||||
path: PathBuf,
|
||||
mode: SolcMode,
|
||||
case_idx: usize,
|
||||
case: Case,
|
||||
}
|
||||
|
||||
/// This represents the results that we gather from running test cases.
|
||||
type CaseResult = Result<usize, anyhow::Error>;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let args = init_cli()?;
|
||||
|
||||
let body = async {
|
||||
for (corpus, tests) in collect_corpora(&args)? {
|
||||
for (corpus, tests) in collect_corpora(&args).await? {
|
||||
let span = Span::new(corpus, args.clone())?;
|
||||
match &args.compile_only {
|
||||
Some(platform) => compile_corpus(&args, &tests, platform, span).await,
|
||||
@@ -104,13 +117,13 @@ fn init_cli() -> anyhow::Result<Arguments> {
|
||||
Ok(args)
|
||||
}
|
||||
|
||||
fn collect_corpora(args: &Arguments) -> anyhow::Result<HashMap<Corpus, Vec<MetadataFile>>> {
|
||||
async fn collect_corpora(args: &Arguments) -> anyhow::Result<HashMap<Corpus, Vec<MetadataFile>>> {
|
||||
let mut corpora = HashMap::new();
|
||||
|
||||
for path in &args.corpus {
|
||||
let corpus = Corpus::try_from_path(path)?;
|
||||
tracing::info!("found corpus: {}", path.display());
|
||||
let tests = corpus.enumerate_tests();
|
||||
let tests = corpus.enumerate_tests().await;
|
||||
tracing::info!("corpus '{}' contains {} tests", &corpus.name, tests.len());
|
||||
corpora.insert(corpus, tests);
|
||||
}
|
||||
@@ -120,7 +133,7 @@ fn collect_corpora(args: &Arguments) -> anyhow::Result<HashMap<Corpus, Vec<Metad
|
||||
|
||||
async fn run_driver<L, F>(
|
||||
args: &Arguments,
|
||||
tests: &[MetadataFile],
|
||||
metadata_files: &[MetadataFile],
|
||||
span: Span,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
@@ -129,10 +142,25 @@ 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)?;
|
||||
let follower_nodes = NodePool::<F::Blockchain>::new(args)?;
|
||||
let (report_tx, report_rx) = mpsc::unbounded_channel::<(Test, CaseResult)>();
|
||||
|
||||
let test_cases = tests
|
||||
let tests = prepare_tests::<L, F>(metadata_files);
|
||||
let driver_task = start_driver_task::<L, F>(args, tests, span, report_tx).await?;
|
||||
let status_reporter_task = start_reporter_task(report_rx);
|
||||
|
||||
tokio::join!(status_reporter_task, driver_task);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prepare_tests<L, F>(metadata_files: &[MetadataFile]) -> impl Iterator<Item = Test>
|
||||
where
|
||||
L: Platform,
|
||||
F: Platform,
|
||||
L::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
F::Blockchain: revive_dt_node::Node + Send + Sync + 'static,
|
||||
{
|
||||
metadata_files
|
||||
.iter()
|
||||
.flat_map(
|
||||
|MetadataFile {
|
||||
@@ -198,188 +226,159 @@ where
|
||||
}
|
||||
None => true,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let metadata_case_status = Arc::new(RwLock::new(test_cases.iter().fold(
|
||||
HashMap::<_, HashMap<_, _>>::new(),
|
||||
|mut map, (path, _, case_idx, case, solc_mode)| {
|
||||
map.entry((path.to_path_buf(), solc_mode.clone()))
|
||||
.or_default()
|
||||
.insert((CaseIdx::new(*case_idx), case.name.clone()), None::<bool>);
|
||||
map
|
||||
},
|
||||
)));
|
||||
let status_reporter_task = {
|
||||
let metadata_case_status = metadata_case_status.clone();
|
||||
let start = Instant::now();
|
||||
async move {
|
||||
const GREEN: &str = "\x1B[32m";
|
||||
const RED: &str = "\x1B[31m";
|
||||
const RESET: &str = "\x1B[0m";
|
||||
|
||||
let mut entries_to_delete = Vec::new();
|
||||
let mut number_of_successes = 0;
|
||||
let mut number_of_failures = 0;
|
||||
loop {
|
||||
let metadata_case_status_read = metadata_case_status.read().await;
|
||||
if metadata_case_status_read.is_empty() {
|
||||
break;
|
||||
}
|
||||
|
||||
for ((metadata_file_path, solc_mode), case_status) in
|
||||
metadata_case_status_read.iter()
|
||||
{
|
||||
if case_status.values().any(|value| value.is_none()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let contains_failures = case_status
|
||||
.values()
|
||||
.any(|value| value.is_some_and(|value| !value));
|
||||
|
||||
if !contains_failures {
|
||||
eprintln!(
|
||||
"{}Succeeded:{} {} - {:?}",
|
||||
GREEN,
|
||||
RESET,
|
||||
metadata_file_path.display(),
|
||||
solc_mode
|
||||
)
|
||||
} else {
|
||||
eprintln!(
|
||||
"{}Failed:{} {} - {:?}",
|
||||
RED,
|
||||
RESET,
|
||||
metadata_file_path.display(),
|
||||
solc_mode
|
||||
)
|
||||
};
|
||||
|
||||
number_of_successes += case_status
|
||||
.values()
|
||||
.filter(|value| value.is_some_and(|value| value))
|
||||
.count();
|
||||
number_of_failures += case_status
|
||||
.values()
|
||||
.filter(|value| value.is_some_and(|value| !value))
|
||||
.count();
|
||||
|
||||
let mut case_status = case_status
|
||||
.iter()
|
||||
.map(|((case_idx, case_name), case_status)| {
|
||||
(case_idx.into_inner(), case_name, case_status.unwrap())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
case_status.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
for (case_idx, case_name, case_status) in case_status.into_iter() {
|
||||
if case_status {
|
||||
eprintln!(
|
||||
" {GREEN}Case Succeeded:{RESET} {} - Case Idx: {case_idx}",
|
||||
case_name
|
||||
.as_ref()
|
||||
.map(|string| string.as_str())
|
||||
.unwrap_or("Unnamed case")
|
||||
)
|
||||
} else {
|
||||
eprintln!(
|
||||
" {RED}Case Failed:{RESET} {} - Case Idx: {case_idx}",
|
||||
case_name
|
||||
.as_ref()
|
||||
.map(|string| string.as_str())
|
||||
.unwrap_or("Unnamed case")
|
||||
)
|
||||
};
|
||||
}
|
||||
eprintln!();
|
||||
|
||||
entries_to_delete.push((metadata_file_path.clone(), solc_mode.clone()));
|
||||
}
|
||||
|
||||
drop(metadata_case_status_read);
|
||||
let mut metadata_case_status_write = metadata_case_status.write().await;
|
||||
for entry in entries_to_delete.drain(..) {
|
||||
metadata_case_status_write.remove(&entry);
|
||||
}
|
||||
|
||||
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
|
||||
.map(|(metadata_file_path, metadata, case_idx, case, solc_mode)| {
|
||||
Test {
|
||||
metadata: metadata.clone(),
|
||||
path: metadata_file_path.to_path_buf(),
|
||||
mode: solc_mode,
|
||||
case_idx,
|
||||
case: case.clone(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
eprintln!(
|
||||
"{GREEN}{}{RESET} cases succeeded, {RED}{}{RESET} cases failed in {} seconds",
|
||||
number_of_successes,
|
||||
number_of_failures,
|
||||
elapsed.as_secs()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
async fn start_driver_task<L, F>(
|
||||
args: &Arguments,
|
||||
tests: impl Iterator<Item = Test>,
|
||||
span: Span,
|
||||
report_tx: mpsc::UnboundedSender<(Test, CaseResult)>,
|
||||
) -> 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,
|
||||
{
|
||||
let leader_nodes = Arc::new(NodePool::<L::Blockchain>::new(args).await?);
|
||||
let follower_nodes = Arc::new(NodePool::<F::Blockchain>::new(args).await?);
|
||||
let compilation_cache = Arc::new(RwLock::new(HashMap::new()));
|
||||
let driver_task = futures::stream::iter(test_cases).for_each_concurrent(
|
||||
None,
|
||||
|(metadata_file_path, metadata, case_idx, case, solc_mode)| {
|
||||
let number_concurrent_tasks = args.number_of_concurrent_tasks();
|
||||
|
||||
Ok(futures::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.
|
||||
// 2. We don't want to open too many files at once, leading to the OS running out of file descriptors.
|
||||
//
|
||||
// By default, we allow maximum of 10 ongoing requests per node in order to limit (1), and assume that
|
||||
// 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 compilation_cache = compilation_cache.clone();
|
||||
let leader_node = leader_nodes.round_robbin();
|
||||
let follower_node = follower_nodes.round_robbin();
|
||||
let tracing_span = tracing::span!(
|
||||
Level::INFO,
|
||||
"Running driver",
|
||||
metadata_file_path = %metadata_file_path.display(),
|
||||
case_idx = case_idx,
|
||||
solc_mode = ?solc_mode,
|
||||
);
|
||||
let metadata_case_status = metadata_case_status.clone();
|
||||
let report_tx = report_tx.clone();
|
||||
|
||||
async move {
|
||||
let leader_node = leader_nodes.round_robbin();
|
||||
let follower_node = follower_nodes.round_robbin();
|
||||
|
||||
let tracing_span = tracing::span!(
|
||||
Level::INFO,
|
||||
"Running driver",
|
||||
metadata_file_path = %test.path.display(),
|
||||
case_idx = ?test.case_idx,
|
||||
solc_mode = ?test.mode,
|
||||
);
|
||||
|
||||
let result = handle_case_driver::<L, F>(
|
||||
metadata_file_path.as_path(),
|
||||
metadata,
|
||||
case_idx.into(),
|
||||
case,
|
||||
solc_mode.clone(),
|
||||
&test.path,
|
||||
&test.metadata,
|
||||
test.case_idx.into(),
|
||||
&test.case,
|
||||
test.mode.clone(),
|
||||
args,
|
||||
compilation_cache.clone(),
|
||||
leader_node,
|
||||
follower_node,
|
||||
span,
|
||||
)
|
||||
.instrument(tracing_span)
|
||||
.await;
|
||||
let mut metadata_case_status = metadata_case_status.write().await;
|
||||
match result {
|
||||
Ok(inputs_executed) => {
|
||||
tracing::info!(inputs_executed, "Execution succeeded");
|
||||
metadata_case_status
|
||||
.entry((metadata_file_path.clone(), solc_mode))
|
||||
.or_default()
|
||||
.insert((CaseIdx::new(case_idx), case.name.clone()), Some(true));
|
||||
}
|
||||
Err(error) => {
|
||||
metadata_case_status
|
||||
.entry((metadata_file_path.clone(), solc_mode))
|
||||
.or_default()
|
||||
.insert((CaseIdx::new(case_idx), case.name.clone()), Some(false));
|
||||
tracing::error!(%error, "Execution failed")
|
||||
}
|
||||
}
|
||||
tracing::info!("Execution completed");
|
||||
|
||||
report_tx
|
||||
.send((test, result))
|
||||
.expect("Failed to send report");
|
||||
}
|
||||
.instrument(tracing_span)
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
async fn start_reporter_task(mut report_rx: mpsc::UnboundedReceiver<(Test, CaseResult)>) {
|
||||
let start = Instant::now();
|
||||
|
||||
const GREEN: &str = "\x1B[32m";
|
||||
const RED: &str = "\x1B[31m";
|
||||
const COLOUR_RESET: &str = "\x1B[0m";
|
||||
const BOLD: &str = "\x1B[1m";
|
||||
const BOLD_RESET: &str = "\x1B[22m";
|
||||
|
||||
let mut number_of_successes = 0;
|
||||
let mut number_of_failures = 0;
|
||||
let mut failures = vec![];
|
||||
|
||||
// Wait for reports to come from our test runner. When the channel closes, this ends.
|
||||
while let Some((test, case_result)) = report_rx.recv().await {
|
||||
let case_name = test.case.name.as_deref().unwrap_or("unnamed_case");
|
||||
let case_idx = test.case_idx;
|
||||
let test_path = test.path.display();
|
||||
let test_mode = test.mode.clone();
|
||||
|
||||
match case_result {
|
||||
Ok(_inputs) => {
|
||||
number_of_successes += 1;
|
||||
eprintln!(
|
||||
"{GREEN}Case Succeeded:{COLOUR_RESET} {test_path} -> {case_name}:{case_idx} (mode: {test_mode:?})"
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
number_of_failures += 1;
|
||||
eprintln!(
|
||||
"{RED}Case Failed:{COLOUR_RESET} {test_path} -> {case_name}:{case_idx} (mode: {test_mode:?})"
|
||||
);
|
||||
failures.push((test, err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eprintln!();
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
// Now, log the failures with more complete errors at the bottom, like `cargo test` does, so
|
||||
// that we don't have to scroll through the entire output to find them.
|
||||
if !failures.is_empty() {
|
||||
eprintln!("{BOLD}Failures:{BOLD_RESET}\n");
|
||||
|
||||
for failure in failures {
|
||||
let (test, err) = failure;
|
||||
let case_name = test.case.name.as_deref().unwrap_or("unnamed_case");
|
||||
let case_idx = test.case_idx;
|
||||
let test_path = test.path.display();
|
||||
let test_mode = test.mode.clone();
|
||||
|
||||
eprintln!(
|
||||
"---- {RED}Case Failed:{COLOUR_RESET} {test_path} -> {case_name}:{case_idx} (mode: {test_mode:?}) ----\n\n{err}\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Summary at the end.
|
||||
eprintln!(
|
||||
"{} cases: {GREEN}{number_of_successes}{COLOUR_RESET} cases succeeded, {RED}{number_of_failures}{COLOUR_RESET} cases failed in {} seconds",
|
||||
number_of_successes + number_of_failures,
|
||||
elapsed.as_secs()
|
||||
);
|
||||
|
||||
tokio::join!(status_reporter_task, driver_task);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn handle_case_driver<'a, L, F>(
|
||||
metadata_file_path: &'a Path,
|
||||
metadata: &'a Metadata,
|
||||
async fn handle_case_driver<L, F>(
|
||||
metadata_file_path: &Path,
|
||||
metadata: &Metadata,
|
||||
case_idx: CaseIdx,
|
||||
case: &Case,
|
||||
mode: SolcMode,
|
||||
config: &Arguments,
|
||||
compilation_cache: CompilationCache<'a>,
|
||||
compilation_cache: CompilationCache,
|
||||
leader_node: &L::Blockchain,
|
||||
follower_node: &F::Blockchain,
|
||||
_: Span,
|
||||
@@ -520,11 +519,9 @@ where
|
||||
);
|
||||
|
||||
let Some(leader_library_address) = leader_receipt.contract_address else {
|
||||
tracing::error!("Contract deployment transaction didn't return an address");
|
||||
anyhow::bail!("Contract deployment didn't return an address");
|
||||
};
|
||||
let Some(follower_library_address) = follower_receipt.contract_address else {
|
||||
tracing::error!("Contract deployment transaction didn't return an address");
|
||||
anyhow::bail!("Contract deployment didn't return an address");
|
||||
};
|
||||
|
||||
@@ -554,8 +551,16 @@ where
|
||||
.any(|(code, _)| !code.chars().all(|char| char.is_ascii_hexdigit()));
|
||||
let (leader_compiled_contracts, follower_compiled_contracts) =
|
||||
if metadata_file_contains_libraries && compiled_contracts_require_linking {
|
||||
let leader_key = (metadata_file_path, mode.clone(), L::config_id());
|
||||
let follower_key = (metadata_file_path, mode.clone(), L::config_id());
|
||||
let leader_key = (
|
||||
metadata_file_path.to_path_buf(),
|
||||
mode.clone(),
|
||||
L::config_id(),
|
||||
);
|
||||
let follower_key = (
|
||||
metadata_file_path.to_path_buf(),
|
||||
mode.clone(),
|
||||
F::config_id(),
|
||||
);
|
||||
{
|
||||
let mut cache = compilation_cache.write().await;
|
||||
cache.remove(&leader_key);
|
||||
@@ -609,15 +614,19 @@ where
|
||||
driver.execute().await
|
||||
}
|
||||
|
||||
async fn get_or_build_contracts<'a, P: Platform>(
|
||||
metadata: &'a Metadata,
|
||||
metadata_file_path: &'a Path,
|
||||
async fn get_or_build_contracts<P: Platform>(
|
||||
metadata: &Metadata,
|
||||
metadata_file_path: &Path,
|
||||
mode: SolcMode,
|
||||
config: &Arguments,
|
||||
compilation_cache: CompilationCache<'a>,
|
||||
compilation_cache: CompilationCache,
|
||||
deployed_libraries: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
) -> anyhow::Result<Arc<(Version, CompilerOutput)>> {
|
||||
let key = (metadata_file_path, mode.clone(), P::config_id());
|
||||
let key = (
|
||||
metadata_file_path.to_path_buf(),
|
||||
mode.clone(),
|
||||
P::config_id(),
|
||||
);
|
||||
if let Some(compilation_artifact) = compilation_cache.read().await.get(&key).cloned() {
|
||||
let mut compilation_artifact = compilation_artifact.lock().await;
|
||||
match *compilation_artifact {
|
||||
@@ -684,12 +693,12 @@ async fn compile_contracts<P: Platform>(
|
||||
"Compiling contracts"
|
||||
);
|
||||
|
||||
let compiler = Compiler::<P::Compiler>::new()
|
||||
let mut compiler = Compiler::<P::Compiler>::new()
|
||||
.with_allow_path(metadata.directory()?)
|
||||
.with_optimization(mode.solc_optimize());
|
||||
let mut compiler = metadata
|
||||
.files_to_compile()?
|
||||
.try_fold(compiler, |compiler, path| compiler.with_source(&path))?;
|
||||
for path in metadata.files_to_compile()? {
|
||||
compiler = compiler.with_source(path).await?;
|
||||
}
|
||||
for (library_instance, (library_address, _)) in deployed_libraries.iter() {
|
||||
let library_ident = &metadata
|
||||
.contracts
|
||||
|
||||
@@ -39,9 +39,9 @@ impl Corpus {
|
||||
}
|
||||
|
||||
/// Scan the corpus base directory and return all tests found.
|
||||
pub fn enumerate_tests(&self) -> Vec<MetadataFile> {
|
||||
pub async fn enumerate_tests(&self) -> Vec<MetadataFile> {
|
||||
let mut tests = Vec::new();
|
||||
collect_metadata(&self.path, &mut tests);
|
||||
collect_metadata(&self.path, &mut tests).await;
|
||||
tests
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ impl Corpus {
|
||||
/// Found tests are inserted into `tests`.
|
||||
///
|
||||
/// `path` is expected to be a directory.
|
||||
pub fn collect_metadata(path: &Path, tests: &mut Vec<MetadataFile>) {
|
||||
pub async fn collect_metadata(path: &Path, tests: &mut Vec<MetadataFile>) {
|
||||
if path.is_dir() {
|
||||
let dir_entry = match std::fs::read_dir(path) {
|
||||
Ok(dir_entry) => dir_entry,
|
||||
@@ -73,12 +73,12 @@ pub fn collect_metadata(path: &Path, tests: &mut Vec<MetadataFile>) {
|
||||
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
collect_metadata(&path, tests);
|
||||
Box::pin(collect_metadata(&path, tests)).await;
|
||||
continue;
|
||||
}
|
||||
|
||||
if path.is_file() {
|
||||
if let Some(metadata) = MetadataFile::try_from_file(&path) {
|
||||
if let Some(metadata) = MetadataFile::try_from_file(&path).await {
|
||||
tests.push(metadata)
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ pub fn collect_metadata(path: &Path, tests: &mut Vec<MetadataFile>) {
|
||||
return;
|
||||
};
|
||||
if extension.eq_ignore_ascii_case("sol") || extension.eq_ignore_ascii_case("json") {
|
||||
if let Some(metadata) = MetadataFile::try_from_file(path) {
|
||||
if let Some(metadata) = MetadataFile::try_from_file(path).await {
|
||||
tests.push(metadata)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::{
|
||||
cmp::Ordering,
|
||||
collections::BTreeMap,
|
||||
fmt::Display,
|
||||
fs::{File, read_to_string},
|
||||
ops::Deref,
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
@@ -11,7 +10,9 @@ use std::{
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use revive_common::EVMVersion;
|
||||
use revive_dt_common::{iterators::FilesWithExtensionIterator, macros::define_wrapper_type};
|
||||
use revive_dt_common::{
|
||||
fs::CachedFileSystem, iterators::FilesWithExtensionIterator, macros::define_wrapper_type,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
case::Case,
|
||||
@@ -29,8 +30,8 @@ pub struct MetadataFile {
|
||||
}
|
||||
|
||||
impl MetadataFile {
|
||||
pub fn try_from_file(path: &Path) -> Option<Self> {
|
||||
Metadata::try_from_file(path).map(|metadata| Self {
|
||||
pub async fn try_from_file(path: &Path) -> Option<Self> {
|
||||
Metadata::try_from_file(path).await.map(|metadata| Self {
|
||||
path: path.to_owned(),
|
||||
content: metadata,
|
||||
})
|
||||
@@ -75,6 +76,12 @@ pub struct Metadata {
|
||||
/// be run of the evm version of the nodes match the evm version specified here.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub required_evm_version: Option<EvmVersionRequirement>,
|
||||
|
||||
/// A set of compilation directives that will be passed to the compiler whenever the contracts for
|
||||
/// the test are being compiled. Note that this differs from the [`Mode`]s in that a [`Mode`] is
|
||||
/// just a filter for when a test can run whereas this is an instruction to the compiler.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub compiler_directives: Option<CompilationDirectives>,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
@@ -145,7 +152,7 @@ impl Metadata {
|
||||
///
|
||||
/// # Panics
|
||||
/// Expects the supplied `path` to be a file.
|
||||
pub fn try_from_file(path: &Path) -> Option<Self> {
|
||||
pub async fn try_from_file(path: &Path) -> Option<Self> {
|
||||
assert!(path.is_file(), "not a file: {}", path.display());
|
||||
|
||||
let Some(file_extension) = path.extension() else {
|
||||
@@ -154,19 +161,20 @@ impl Metadata {
|
||||
};
|
||||
|
||||
if file_extension == METADATA_FILE_EXTENSION {
|
||||
return Self::try_from_json(path);
|
||||
return Self::try_from_json(path).await;
|
||||
}
|
||||
|
||||
if file_extension == SOLIDITY_CASE_FILE_EXTENSION {
|
||||
return Self::try_from_solidity(path);
|
||||
return Self::try_from_solidity(path).await;
|
||||
}
|
||||
|
||||
tracing::debug!("ignoring invalid corpus file: {}", path.display());
|
||||
None
|
||||
}
|
||||
|
||||
fn try_from_json(path: &Path) -> Option<Self> {
|
||||
let file = File::open(path)
|
||||
async fn try_from_json(path: &Path) -> Option<Self> {
|
||||
let content = CachedFileSystem::read(path)
|
||||
.await
|
||||
.inspect_err(|error| {
|
||||
tracing::error!(
|
||||
"opening JSON test metadata file '{}' error: {error}",
|
||||
@@ -175,7 +183,7 @@ impl Metadata {
|
||||
})
|
||||
.ok()?;
|
||||
|
||||
match serde_json::from_reader::<_, Metadata>(file) {
|
||||
match serde_json::from_slice::<Metadata>(content.as_slice()) {
|
||||
Ok(mut metadata) => {
|
||||
metadata.file_path = Some(path.to_path_buf());
|
||||
Some(metadata)
|
||||
@@ -190,8 +198,9 @@ impl Metadata {
|
||||
}
|
||||
}
|
||||
|
||||
fn try_from_solidity(path: &Path) -> Option<Self> {
|
||||
let spec = read_to_string(path)
|
||||
async fn try_from_solidity(path: &Path) -> Option<Self> {
|
||||
let spec = CachedFileSystem::read_to_string(path)
|
||||
.await
|
||||
.inspect_err(|error| {
|
||||
tracing::error!(
|
||||
"opening JSON test metadata file '{}' error: {error}",
|
||||
@@ -490,6 +499,31 @@ impl From<EvmVersionRequirement> for String {
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of compilation directives that will be passed to the compiler whenever the contracts for
|
||||
/// the test are being compiled. Note that this differs from the [`Mode`]s in that a [`Mode`] is
|
||||
/// just a filter for when a test can run whereas this is an instruction to the compiler.
|
||||
/// Defines how the compiler should handle revert strings.
|
||||
#[derive(
|
||||
Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
|
||||
)]
|
||||
pub struct CompilationDirectives {
|
||||
/// Defines how the revert strings should be handled.
|
||||
pub revert_string_handling: Option<RevertString>,
|
||||
}
|
||||
|
||||
/// Defines how the compiler should handle revert strings.
|
||||
#[derive(
|
||||
Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
|
||||
)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum RevertString {
|
||||
#[default]
|
||||
Default,
|
||||
Debug,
|
||||
Strip,
|
||||
VerboseDebug,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//! This crate implements concurrent handling of testing node.
|
||||
|
||||
use std::{
|
||||
fs::read_to_string,
|
||||
sync::atomic::{AtomicUsize, Ordering},
|
||||
thread,
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use revive_dt_common::fs::CachedFileSystem;
|
||||
use revive_dt_config::Arguments;
|
||||
|
||||
use crate::Node;
|
||||
@@ -23,12 +23,11 @@ where
|
||||
T: Node + Send + 'static,
|
||||
{
|
||||
/// Create a new Pool. This will start as many nodes as there are workers in `config`.
|
||||
pub fn new(config: &Arguments) -> anyhow::Result<Self> {
|
||||
pub async fn new(config: &Arguments) -> anyhow::Result<Self> {
|
||||
let nodes = config.number_of_nodes;
|
||||
let genesis = read_to_string(&config.genesis_file).context(format!(
|
||||
"can not read genesis file: {}",
|
||||
config.genesis_file.display()
|
||||
))?;
|
||||
let genesis = CachedFileSystem::read_to_string(&config.genesis_file)
|
||||
.await
|
||||
.context("Failed to read genesis file")?;
|
||||
|
||||
let mut handles = Vec::with_capacity(nodes);
|
||||
for _ in 0..nodes {
|
||||
|
||||
Reference in New Issue
Block a user