Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-valerio committed Aug 30, 2024
1 parent bb6e02e commit db766ba
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 21 deletions.
30 changes: 30 additions & 0 deletions sample/build.sh
Original file line number Diff line number Diff line change
@@ -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."

9 changes: 7 additions & 2 deletions sample/dummy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -46,7 +52,6 @@ mod dummy {
Ok(())
}
}

#[cfg(feature = "phink")]
#[ink(impl)]
impl MyBuggedContract {
Expand Down
10 changes: 9 additions & 1 deletion src/contract/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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]
Expand Down
20 changes: 16 additions & 4 deletions tests/cli_fuzz_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 4 additions & 14 deletions tests/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down

0 comments on commit db766ba

Please sign in to comment.