From db766ba1693293df4e9be27da81b3b4c3db08152 Mon Sep 17 00:00:00 2001 From: Kevin Valerio Date: Fri, 30 Aug 2024 17:33:57 +0200 Subject: [PATCH] More tests --- sample/build.sh | 30 ++++++++++++++++++++++++++++++ sample/dummy/lib.rs | 9 +++++++-- src/contract/payload.rs | 10 +++++++++- tests/cli_fuzz_integration_test.rs | 20 ++++++++++++++++---- tests/shared/mod.rs | 18 ++++-------------- 5 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 sample/build.sh diff --git a/sample/build.sh b/sample/build.sh new file mode 100644 index 0000000..cb65495 --- /dev/null +++ b/sample/build.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +echo "We're building every contract :-) see ya! " +for dir in */; do + # Remove trailing slash from directory name + dir=${dir%/} + + # Change to the directory + cd "$dir" + + echo "Building $dir..." + + # Check if the current directory is multi-contract-caller + if [ "$dir" = "multi-contract-caller" ]; then + # Execute build-all.sh for multi-contract-caller + ./build-all.sh + else + # Execute cargo contract build for other directories + cargo contract build --features phink + fi + + # Change back to the parent directory + cd .. + + echo "Finished building $dir" + echo +done + +echo "All builds completed." + diff --git a/sample/dummy/lib.rs b/sample/dummy/lib.rs index 36c5468..bf37aa2 100755 --- a/sample/dummy/lib.rs +++ b/sample/dummy/lib.rs @@ -2,7 +2,13 @@ #[ink::contract] mod dummy { - use ink::{prelude::vec::Vec, storage::Mapping, storage::StorageVec}; + use ink::{ + prelude::vec::Vec, + storage::{ + Mapping, + StorageVec, + }, + }; use ink_prelude::string::String; #[ink(storage)] @@ -46,7 +52,6 @@ mod dummy { Ok(()) } } - #[cfg(feature = "phink")] #[ink(impl)] impl MyBuggedContract { diff --git a/src/contract/payload.rs b/src/contract/payload.rs index c068d33..81912f0 100644 --- a/src/contract/payload.rs +++ b/src/contract/payload.rs @@ -148,6 +148,7 @@ mod test { }, fuzzer::parser::parse_input, }; + use assert_cmd::Command; use contract_transcode::ContractMessageTranscoder; use parity_scale_codec::Encode; use sp_core::hexdisplay::AsBytesRef; @@ -158,6 +159,8 @@ mod test { #[test] fn fetch_good_invariants() { + build(); + let specs = fs::read_to_string("sample/dns/target/ink/dns.json").unwrap(); let extracted: String = PayloadCrafter::extract_invariants(&specs) .unwrap() @@ -166,7 +169,12 @@ mod test { .collect(); // DNS invariants - assert_eq!(extracted, "b587edaf 27d8f137 "); + assert_eq!(extracted, "2093daa4 "); + } + + fn build() { + let bash = Command::new("bash ./sample/build.sh"); + // bash. } #[test] diff --git a/tests/cli_fuzz_integration_test.rs b/tests/cli_fuzz_integration_test.rs index 8e0c35a..23bda16 100644 --- a/tests/cli_fuzz_integration_test.rs +++ b/tests/cli_fuzz_integration_test.rs @@ -65,14 +65,26 @@ mod tests { initial_corpus_len ); + let selector = phink_output.join("selectors.dict"); + ensure!(selector.exists(), "selectors.dict doesn't exist"); + + /// The content of selecotors.dict should be + /// + /// + /// # Dictionary file for selectors + // # Lines starting with '#' and empty lines are ignored. + // delimiter="********" + // "\x9B\xAE\x9D\x5E" + // "\xFA\x80\xC2\xF6" + ensure!( - phink_output.join("selectors.dict").exists(), - "selectors.dict doesn't exist" + fs::read_to_string(selector).unwrap().lines().count() == 5, + "There should be 5 lines in selectors, 2 for crash_with_invariant and phink_assert_dangerous_number, 1 for demimiter, and two comments" ); ensure!( - afl_log_didnt_fail(&config), - "'logs/afl.log' didn't return a successfull backlog " + afl_log_didnt_fail(&phink_output), + "'logs/afl.log' didn't return a successfull dashboard" ); // We don't use allowlist for macos diff --git a/tests/shared/mod.rs b/tests/shared/mod.rs index d44fc14..52e6730 100644 --- a/tests/shared/mod.rs +++ b/tests/shared/mod.rs @@ -136,25 +136,15 @@ where } } -pub fn afl_log_didnt_fail(conf: &Configuration) -> bool { - let log_path = conf - .clone() - .fuzz_output - .unwrap_or_default() - .join("phink") - .join("logs") - .join("afl.log"); +pub fn afl_log_didnt_fail(output: &PathBuf) -> bool { + let log_path = output.join("logs").join("afl.log"); match fs::read_to_string(log_path) { Ok(content) => { // this is a string that is present in AFL dashboard - if content.contains("findings in depth") { - true - } else { - false - } + content.contains("findings in depth") } - Err(_) => false, + _ => false, } }