Skip to content

Commit

Permalink
Revert "fix: fuzz console log (#7781)" (#7935)
Browse files Browse the repository at this point in the history
This reverts commit a470d63.
  • Loading branch information
grandizzy authored May 16, 2024
1 parent 20feac7 commit 467aff3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 45 deletions.
16 changes: 4 additions & 12 deletions crates/evm/evm/src/executors/fuzz/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::executors::{Executor, RawCallResult};
use alloy_dyn_abi::JsonAbiExt;
use alloy_json_abi::Function;
use alloy_primitives::{Address, Bytes, Log, U256};
use alloy_primitives::{Address, Bytes, U256};
use eyre::Result;
use foundry_config::FuzzConfig;
use foundry_evm_core::{
Expand Down Expand Up @@ -87,9 +87,6 @@ impl FuzzedExecutor {
dictionary_weight => fuzz_calldata_from_state(func.clone(), &state),
];

//Stores logs for all fuzz cases
let logs: RefCell<Vec<Log>> = RefCell::default();

debug!(func=?func.name, should_fail, "fuzzing");
let run_result = self.runner.clone().run(&strat, |calldata| {
let fuzz_res = self.single_fuzz(address, should_fail, calldata)?;
Expand All @@ -107,7 +104,6 @@ impl FuzzedExecutor {
}
traces.borrow_mut().push(call_traces);
}
logs.borrow_mut().extend(case.logs);

if let Some(prev) = coverage.take() {
// Safety: If `Option::or` evaluates to `Some`, then `call.coverage` must
Expand All @@ -131,7 +127,6 @@ impl FuzzedExecutor {
// to run at least one more case to find a minimal failure
// case.
let call_res = _counterexample.1.result.clone();
logs.borrow_mut().extend(_counterexample.1.logs.clone());
*counterexample.borrow_mut() = _counterexample;
// HACK: we have to use an empty string here to denote `None`
let reason = rd.maybe_decode(&call_res, Some(status));
Expand All @@ -145,16 +140,14 @@ impl FuzzedExecutor {
let mut traces = traces.into_inner();
let last_run_traces = if run_result.is_ok() { traces.pop() } else { call.traces.clone() };

let inner_logs = logs.into_inner();

let mut result = FuzzTestResult {
first_case: first_case.take().unwrap_or_default(),
gas_by_case: gas_by_case.take(),
success: run_result.is_ok(),
reason: None,
counterexample: None,
decoded_logs: decode_console_logs(&inner_logs),
logs: inner_logs,
decoded_logs: decode_console_logs(&call.logs),
logs: call.logs,
labeled_addresses: call.labels,
traces: last_run_traces,
gas_report_traces: traces,
Expand Down Expand Up @@ -214,7 +207,7 @@ impl FuzzedExecutor {

// When the `assume` cheatcode is called it returns a special string
if call.result.as_ref() == MAGIC_ASSUME {
return Err(TestCaseError::reject(FuzzError::AssumeReject));
return Err(TestCaseError::reject(FuzzError::AssumeReject))
}

let breakpoints = call
Expand All @@ -236,7 +229,6 @@ impl FuzzedExecutor {
coverage: call.coverage,
debug: call.debug,
breakpoints,
logs: call.logs,
}))
} else {
Ok(FuzzOutcome::CounterExample(CounterExampleOutcome {
Expand Down
4 changes: 1 addition & 3 deletions crates/evm/evm/src/executors/fuzz/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::executors::RawCallResult;
use alloy_primitives::{Bytes, Log};
use alloy_primitives::Bytes;
use foundry_common::evm::Breakpoints;
use foundry_evm_core::debug::DebugArena;
use foundry_evm_coverage::HitMaps;
Expand All @@ -20,8 +20,6 @@ pub struct CaseOutcome {
pub debug: Option<DebugArena>,
/// Breakpoints char pc map
pub breakpoints: Breakpoints,
/// logs of a single fuzz test case
pub logs: Vec<Log>,
}

/// Returned by a single fuzz when a counterexample has been discovered
Expand Down
31 changes: 1 addition & 30 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains various tests for `forge test`.
use foundry_config::{Config, FuzzConfig};
use foundry_config::Config;
use foundry_test_utils::{
rpc,
util::{OutputExt, OTHER_SOLC_VERSION, SOLC_VERSION},
Expand Down Expand Up @@ -544,32 +544,3 @@ contract Dummy {
cmd.args(["test", "--match-path", "src/dummy.sol"]);
cmd.assert_success()
});

// tests that `forge test` for fuzz tests will display `console.log` info
forgetest_init!(can_test_fuzz_with_console_log, |prj, cmd| {
prj.wipe_contracts();

// run fuzz test 3 times
let config =
Config { fuzz: { FuzzConfig { runs: 3, ..Default::default() } }, ..Default::default() };
prj.write_config(config);
let config = cmd.config();
assert_eq!(config.fuzz.runs, 3);

prj.add_test(
"ContractFuzz.t.sol",
r#"pragma solidity 0.8.24;
import {Test, console2} from "forge-std/Test.sol";
contract ContractFuzz is Test {
function testFuzzConsoleLog(uint256 x) public {
console2.log("inside fuzz test, x is:", x);
}
}
"#,
)
.unwrap();
cmd.args(["test", "-vv"]);
let stdout = cmd.stdout_lossy();
assert!(stdout.contains("inside fuzz test, x is:"), "\n{stdout}");
});

0 comments on commit 467aff3

Please sign in to comment.