Skip to content

Commit

Permalink
unit test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-valerio committed Sep 2, 2024
1 parent a62be04 commit 9076970
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion scripts/clippy_fix_fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ echo

echo 'Fixing clippy (might need a "git commit" and a rerun, if "cargo fix" changed the source)'

cargo +nightly clippy --fix --tests --examples --benches --all-features --allow-dirty --allow-staged
cargo +nightly clippy --fix --examples --benches --all-features --allow-dirty --allow-staged

echo "[+] Done fixing clippy"
echo
Expand Down
5 changes: 1 addition & 4 deletions src/cli/ziggy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ impl ZiggyConfig {
f.render_widget(hello_world, chunks[0]);

let ziggy_output = Paragraph::new(Line::from(
app.ziggy_output
.iter()
.map(|line| Span::raw(line))
.collect::<Vec<_>>(),
app.ziggy_output.iter().map(Span::raw).collect::<Vec<_>>(),
))
.scroll((app.ziggy_output.len() as u16, 0))
.block(Block::default().borders(Borders::ALL).title("Ziggy Output"));
Expand Down
2 changes: 1 addition & 1 deletion src/contract/custom/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod custom;
pub mod custom;

use sp_core::storage::Storage;
pub struct Preferences {}
Expand Down
3 changes: 2 additions & 1 deletion src/cover/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ impl InputCoverage {
);
}

#[allow(clippy::unnecessary_cast)]
/// We assume that the instrumentation will never insert more than
/// `2_000` artificial branches This value should be big enough
/// to handle most of smart-contract, even the biggest
seq_macro::seq!(x in 0..= 2_000 {
if flattened_cov.contains(&(x as u64)) {
if flattened_cov.contains(&(x)) {
let _ = black_box(x + 1);
}
});
Expand Down
42 changes: 34 additions & 8 deletions src/fuzzer/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,29 +321,55 @@ fn check_invariants(

#[cfg(test)]
mod tests {
use std::path::Path;

use super::*;

use std::{
path::Path,
process::{
Command,
Stdio,
},
sync::Once,
};

static BUILD: Once = Once::new();

pub fn build() {
println!("executing build.sh");
BUILD.call_once(|| {
let _status = Command::new("bash")
.current_dir("sample") // Change to the 'sample' directory
.arg("build.sh")
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.expect("failed to execute process");
});
}
#[test]
fn test_parse_input() {
build();
let metadata_path = Path::new("sample/dns/target/ink/dns.json");
let transcoder = Mutex::new(
ContractMessageTranscoder::load(metadata_path)
.expect("Failed to load ContractMessageTranscoder"),
.expect("Failed to load `ContractMessageTranscoder`"),
);

let encoded_bytes =
hex::decode("229b553f9400000000000000000027272727272727272700002727272727272727272727")
.expect("Failed to decode hex string");

let hex = transcoder
.lock()
.unwrap()
.decode_contract_message(&mut &encoded_bytes[..])
.expect("Failed to decode contract message");
assert!(
transcoder
.lock()
.unwrap()
.decode_contract_message(&mut &encoded_bytes[..])
.is_ok(),
"Failed to decode contract message"
);

let binding = transcoder.lock().unwrap();
let messages = binding.metadata().spec().messages();
assert!(!messages.is_empty(), "Ther should be some messages here");
}
}
1 change: 1 addition & 0 deletions src/instrumenter/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use syn::{
use walkdir::WalkDir;

/// The objective of this `struct` is to assist Phink in instrumenting ink!
///
/// smart contracts. In a fuzzing context, instrumenting a smart contract
/// involves modifying the target (i.e., the WASM blob), for example, by adding
/// additional code to branches to obtain a coverage map during the execution of
Expand Down
1 change: 0 additions & 1 deletion tests/cli_fuzz_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ mod tests {

// The content of selectors.dict should be
//
//
// # Dictionary file for selectors
// # Lines starting with '#' and empty lines are ignored.
// delimiter="********"
Expand Down
1 change: 1 addition & 0 deletions tests/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use std::{
Instant,
},
};
#[allow(clippy::too_long_first_doc_paragraph)]

pub const DEFAULT_TEST_PHINK_TOML: &str = "phink_temp_test.toml";

Expand Down

0 comments on commit 9076970

Please sign in to comment.