Skip to content

Commit

Permalink
reverting
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-valerio committed Jun 25, 2024
1 parent 3ea040f commit b2a8259
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/contract/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use sp_core::{crypto::AccountId32, storage::Storage, H256};
use sp_runtime::{BuildStorage, DispatchError};

use crate::contract::runtime::AccountId;
use crate::fuzzer::instrument::InstrumenterEngine;
use crate::{
contract::payload,
contract::runtime::{BalancesConfig, Contracts, Runtime, RuntimeGenesisConfig},
Expand Down
14 changes: 7 additions & 7 deletions src/fuzzer/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ pub type CoverageTrace = Vec<u8>;
#[derive(Clone)]
pub struct Coverage {
branches: Vec<CoverageTrace>,
max_coverage: u32,
}

impl Coverage {
pub fn new() -> Self {
pub fn new(max_coverage: u32) -> Self {
Coverage {
branches: Vec::new(),
max_coverage,
}
}

Expand All @@ -33,24 +35,22 @@ impl Coverage {
}

/// This function create an artificial coverage to convince ziggy that a message is interesting or not.
/// TODO! Refactor the 300, it should change depending the contract
pub fn redirect_coverage(self) {
let flatten_cov: Vec<u8> = self.branches.into_iter().flatten().collect();
let coverage_str = utils::deduplicate(&String::from_utf8_lossy(&flatten_cov));
let coverage_lines: Vec<&str> = coverage_str.split('\n').collect();
let max_cov = coverage_lines.len();

println!("[🚧DEBUG TRACE] : {:?}", coverage_lines);
println!("[🚧MAX REACHABLE COVERAGE] : {:?}", max_cov);
for _ in 0..max_cov {
seq_macro::seq!(x in 0..=1 {
println!("[🚧MAX REACHABLE COVERAGE] : {:?}", &self.max_coverage);
seq_macro::seq!(x in 0..=500 {
let target = format!("COV={}", x);

if coverage_lines.contains(&target.as_str()) {
let _ = black_box(x + 1);
println!(" A ");
}
});
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/fuzzer/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl FuzzerEngine for Fuzzer {
let mut chain = BasicExternalities::new(client.setup.genesis.clone());
chain.execute_with(|| <Fuzzer as FuzzerEngine>::timestamp(0));

let mut coverage: Coverage = Coverage::new();
let mut coverage: Coverage = Coverage::new(9); //todo
let mut all_msg_responses: Vec<FullContractResponse> = Vec::new();

chain.execute_with(|| {
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,13 @@ fn execute_harness(engine: &mut InstrumenterEngine, fuzzing_mode: FuzzingMode) {
}
}
Err(e) => {
eprintln!("🙅 Error reading WASM file. {:?}", e);
eprintln!(
"🙅 Error reading WASM file. Maybe the JSON file is not equal to the WASM file ?\
Please, ensure that both are identitical.\
Example: mycontract.wasm and mycontract.json.\
(more details: {})",
e
);
}
}
}

0 comments on commit b2a8259

Please sign in to comment.