Skip to content

Commit

Permalink
chore(fuzz): improve override_call_strat (#7477)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Mar 22, 2024
1 parent f73d855 commit f9da73d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions crates/evm/fuzz/src/strategies/invariants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ pub fn override_call_strat(
let fuzz_state = fuzz_state.clone();
let calldata_fuzz_config = calldata_fuzz_config.clone();

let contracts = &contracts.lock();
let (_, abi, functions) = contracts.get(&target_address).unwrap_or({
// Choose a random contract if target selected by lazy strategy is not in fuzz run
// identified contracts. This can happen when contract is created in `setUp` call
// but is not included in targetContracts.
let rand_index = rand::thread_rng().gen_range(0..contracts.iter().len());
let (_, contract_specs) = contracts.iter().nth(rand_index).unwrap();
contract_specs
});
let func = {
let contracts = contracts.lock();
let (_, abi, functions) = contracts.get(&target_address).unwrap_or_else(|| {
// Choose a random contract if target selected by lazy strategy is not in fuzz run
// identified contracts. This can happen when contract is created in `setUp` call
// but is not included in targetContracts.
let rand_index = rand::thread_rng().gen_range(0..contracts.len());
let (_, contract_specs) = contracts.iter().nth(rand_index).unwrap();
contract_specs
});
select_random_function(abi, functions)
};

let func = select_random_function(abi, functions);
func.prop_flat_map(move |func| {
fuzz_contract_with_calldata(&fuzz_state, &calldata_fuzz_config, target_address, func)
})
Expand Down

0 comments on commit f9da73d

Please sign in to comment.