Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Mar 19, 2024
1 parent e1f8a95 commit 12c4e0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/common/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl TestFunctionExt for str {
}

fn is_fixtures(&self) -> bool {
self.starts_with("fixtures")
self.starts_with("fixtures_")
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/evm/evm/src/executors/fuzz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl FuzzedExecutor {
pub fn fuzz(
&self,
func: &Function,
fuzz_fixtures: FuzzFixtures,
fuzz_fixtures: &FuzzFixtures,
address: Address,
should_fail: bool,
rd: &RevertDecoder,
Expand Down Expand Up @@ -86,7 +86,7 @@ impl FuzzedExecutor {
let dictionary_weight = self.config.dictionary.dictionary_weight.min(100);

let strat = proptest::prop_oneof![
100 - dictionary_weight => fuzz_calldata(func.clone(), &fuzz_fixtures),
100 - dictionary_weight => fuzz_calldata(func.clone(), fuzz_fixtures),
dictionary_weight => fuzz_calldata_from_state(func.clone(), &state),
];

Expand Down
6 changes: 3 additions & 3 deletions crates/evm/evm/src/executors/invariant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ impl<'a> InvariantExecutor<'a> {
pub fn invariant_fuzz(
&mut self,
invariant_contract: InvariantContract<'_>,
fuzz_fixtures: FuzzFixtures,
fuzz_fixtures: &FuzzFixtures,
) -> Result<InvariantFuzzTestResult> {
// Throw an error to abort test run if the invariant function accepts input params
if !invariant_contract.invariant_function.inputs.is_empty() {
return Err(eyre!("Invariant test function should have no inputs"))
}

let (fuzz_state, targeted_contracts, strat) =
self.prepare_fuzzing(&invariant_contract, fuzz_fixtures.clone())?;
self.prepare_fuzzing(&invariant_contract, fuzz_fixtures)?;

// Stores the consumed gas and calldata of every successful fuzz call.
let fuzz_cases: RefCell<Vec<FuzzedCases>> = RefCell::new(Default::default());
Expand Down Expand Up @@ -346,7 +346,7 @@ impl<'a> InvariantExecutor<'a> {
fn prepare_fuzzing(
&mut self,
invariant_contract: &InvariantContract<'_>,
fuzz_fixtures: FuzzFixtures,
fuzz_fixtures: &FuzzFixtures,
) -> eyre::Result<InvariantPreparation> {
// Finds out the chosen deployed contracts and/or senders.
self.select_contract_artifacts(invariant_contract.address)?;
Expand Down
24 changes: 12 additions & 12 deletions crates/forge/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,17 @@ impl<'a> ContractRunner<'a> {
/// current test.
fn fuzz_fixtures(&mut self, address: Address) -> FuzzFixtures {
// collect test fixtures param:array of values
let fixtures_fns: Vec<_> =
self.contract.functions().filter(|func| func.name.is_fixtures()).collect();
let mut fixtures = HashMap::new();
fixtures_fns.iter().for_each(|func| {
if let Ok(CallResult { raw: _, decoded_result }) =
self.executor.call(CALLER, address, func, &[], U256::ZERO, None)
{
fixtures.insert(
func.name.strip_prefix("fixtures_").unwrap().to_string(),
decoded_result,
);
self.contract.functions().for_each(|func| {
if func.name.is_fixtures() {
if let Ok(CallResult { raw: _, decoded_result }) =
self.executor.call(CALLER, address, func, &[], U256::ZERO, None)
{
fixtures.insert(
func.name.strip_prefix("fixtures_").unwrap().to_string(),
decoded_result,
);
}
}
});
FuzzFixtures::new(fixtures)
Expand Down Expand Up @@ -538,7 +538,7 @@ impl<'a> ContractRunner<'a> {
InvariantContract { address, invariant_function: func, abi: self.contract };

let InvariantFuzzTestResult { error, cases, reverts, last_run_inputs, gas_report_traces } =
match evm.invariant_fuzz(invariant_contract.clone(), fuzz_fixtures) {
match evm.invariant_fuzz(invariant_contract.clone(), &fuzz_fixtures) {
Ok(x) => x,
Err(e) => {
return TestResult {
Expand Down Expand Up @@ -665,7 +665,7 @@ impl<'a> ContractRunner<'a> {
);
let state = fuzzed_executor.build_fuzz_state();
let result =
fuzzed_executor.fuzz(func, fuzz_fixtures, address, should_fail, self.revert_decoder);
fuzzed_executor.fuzz(func, &fuzz_fixtures, address, should_fail, self.revert_decoder);

let mut debug = Default::default();
let mut breakpoints = Default::default();
Expand Down

0 comments on commit 12c4e0c

Please sign in to comment.