From 571632f67a5cec98404cf6cc93aad230d85fb5c6 Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Tue, 27 Feb 2024 23:02:44 -0800 Subject: [PATCH 1/2] sanctuary fixes - reset git state before running tests - fix a bunch of nits with string/error reporting in CI - trim null terminators from input files --- crates/solidity/testing/sanctuary/src/datasets.rs | 6 ++++++ crates/solidity/testing/sanctuary/src/events.rs | 6 +++++- crates/solidity/testing/sanctuary/src/reporting.rs | 6 ++---- crates/solidity/testing/sanctuary/src/tests.rs | 2 ++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/solidity/testing/sanctuary/src/datasets.rs b/crates/solidity/testing/sanctuary/src/datasets.rs index d776c96186..f7e59ac36a 100644 --- a/crates/solidity/testing/sanctuary/src/datasets.rs +++ b/crates/solidity/testing/sanctuary/src/datasets.rs @@ -61,6 +61,12 @@ impl DataSet { } pub fn checkout_directory(&self, directory: &str) -> Result<&Vec> { + Command::new("git") + .arg("reset") + .flag("--hard") + .current_dir(&self.repo_dir) + .run()?; + let relative_path = format!("contracts/{network}/{directory}", network = self.network); Command::new("git") diff --git a/crates/solidity/testing/sanctuary/src/events.rs b/crates/solidity/testing/sanctuary/src/events.rs index 1c051520bd..93d67b3634 100644 --- a/crates/solidity/testing/sanctuary/src/events.rs +++ b/crates/solidity/testing/sanctuary/src/events.rs @@ -2,6 +2,7 @@ use std::cmp; use console::Color; use indicatif::ProgressBar; +use infra_utils::github::GitHub; use crate::reporting::Reporter; @@ -82,7 +83,10 @@ impl Events { self.all_directories.inc(1); self.reporter.hide(); - self.reporter.print_full_report(); + + GitHub::collapse_group("Statistics:", || { + self.reporter.print_full_report(); + }); } pub fn test(&self, outcome: TestOutcome) { diff --git a/crates/solidity/testing/sanctuary/src/reporting.rs b/crates/solidity/testing/sanctuary/src/reporting.rs index 982668c978..271fe85dad 100644 --- a/crates/solidity/testing/sanctuary/src/reporting.rs +++ b/crates/solidity/testing/sanctuary/src/reporting.rs @@ -1,4 +1,3 @@ -use std::io::Write; use std::time::Duration; use console::{style, Color, Term}; @@ -67,9 +66,8 @@ impl Reporter { self.parent.set_draw_target(ProgressDrawTarget::hidden()); - std::io::stdout() - .write_all(&buffer.contents_formatted()[..]) - .unwrap(); + let contents = String::from_utf8(buffer.contents_formatted()).unwrap(); + println!("{contents}"); } pub fn add_blank(&mut self) { diff --git a/crates/solidity/testing/sanctuary/src/tests.rs b/crates/solidity/testing/sanctuary/src/tests.rs index 0432d82327..8b2dd67078 100644 --- a/crates/solidity/testing/sanctuary/src/tests.rs +++ b/crates/solidity/testing/sanctuary/src/tests.rs @@ -73,6 +73,8 @@ pub fn run_test(file: &SourceFile, events: &Events) -> Result<()> { let source = file .path .read_to_string()? + // Some files are null terminated, remove the null character: + .trim_end_matches('\0') // Remove unicode character inserted by sanctuary (illegal in Solidity): .replace("[email protected]", "[email-protected]"); From 3bf29f87fee1fe3614f775e8d0592fde559474ed Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Tue, 27 Feb 2024 23:48:48 -0800 Subject: [PATCH 2/2] pr feedback --- crates/solidity/testing/sanctuary/src/datasets.rs | 1 + crates/solidity/testing/sanctuary/src/reporting.rs | 8 ++++++-- crates/solidity/testing/sanctuary/src/tests.rs | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/solidity/testing/sanctuary/src/datasets.rs b/crates/solidity/testing/sanctuary/src/datasets.rs index f7e59ac36a..08666f73cf 100644 --- a/crates/solidity/testing/sanctuary/src/datasets.rs +++ b/crates/solidity/testing/sanctuary/src/datasets.rs @@ -61,6 +61,7 @@ impl DataSet { } pub fn checkout_directory(&self, directory: &str) -> Result<&Vec> { + // Make sure to reset any local changes, in case some were made during local development/debugging: Command::new("git") .arg("reset") .flag("--hard") diff --git a/crates/solidity/testing/sanctuary/src/reporting.rs b/crates/solidity/testing/sanctuary/src/reporting.rs index 271fe85dad..699b8cb8e4 100644 --- a/crates/solidity/testing/sanctuary/src/reporting.rs +++ b/crates/solidity/testing/sanctuary/src/reporting.rs @@ -1,3 +1,4 @@ +use std::io::Write; use std::time::Duration; use console::{style, Color, Term}; @@ -66,8 +67,11 @@ impl Reporter { self.parent.set_draw_target(ProgressDrawTarget::hidden()); - let contents = String::from_utf8(buffer.contents_formatted()).unwrap(); - println!("{contents}"); + std::io::stdout() + .write_all(buffer.contents_formatted().as_slice()) + .unwrap(); + + println!(); } pub fn add_blank(&mut self) { diff --git a/crates/solidity/testing/sanctuary/src/tests.rs b/crates/solidity/testing/sanctuary/src/tests.rs index 8b2dd67078..1942151af2 100644 --- a/crates/solidity/testing/sanctuary/src/tests.rs +++ b/crates/solidity/testing/sanctuary/src/tests.rs @@ -73,9 +73,11 @@ pub fn run_test(file: &SourceFile, events: &Events) -> Result<()> { let source = file .path .read_to_string()? - // Some files are null terminated, remove the null character: + // Some files are null terminated. Remove the null character: + // https://github.com/tintinweb/smart-contract-sanctuary/issues/30 .trim_end_matches('\0') // Remove unicode character inserted by sanctuary (illegal in Solidity): + // https://github.com/tintinweb/smart-contract-sanctuary/issues/31 .replace("[email protected]", "[email-protected]"); let language = Language::new(version.to_owned())?;