Skip to content

bug: console.log values are not emitted on fuzz tests's last run at any verbosity level #11039

@zerosnacks

Description

@zerosnacks

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

v1, stable, nightly

What version of Foundryup are you on?

foundryup: 1.3.0

What command(s) is the bug in?

forge test

Operating System

None

Describe the bug

I noticed when debugging that we currently don't emit console.log's when we are running a fuzz test on the final run

Does not look like this is a regression, stable and v1 also don't do this

To reproduce:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";

contract CounterTest is Test {
    Counter public counter;

    function setUp() public {
        counter = new Counter();
        counter.setNumber(0);
    }

    function test_Increment() public {
        counter.increment();
        assertEq(counter.number(), 1);
        console.log(counter.number());
    }

    function testFuzz_SetNumber(uint256 x) public {
        counter.setNumber(x);
        assertEq(counter.number(), x);
        console.log(counter.number());
    }
}
forge test -vv
forge test -vvv
forge test -vvvv
forge test -vvvvv

Result:

Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 36170, ~: 36481)
[PASS] test_Increment() (gas: 35978)
Logs:
  1

Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 6.25ms (6.02ms CPU time)

Ran 1 test suite in 6.78ms (6.25ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 36170, ~: 36481)
Traces:
  [36481] CounterTest::testFuzz_SetNumber(5557)
    ├─ [22492] Counter::setNumber(5557)
    │   └─ ← [Stop] 
    ├─ [424] Counter::number() [staticcall]
    │   └─ ← [Return] 5557
    ├─ [0] VM::assertEq(5557, 5557) [staticcall]
    │   └─ ← [Return] 
    ├─ [424] Counter::number() [staticcall]
    │   └─ ← [Return] 5557
    ├─ [0] console::log(5557) [staticcall]
    │   └─ ← [Stop] 
    └─ ← [Stop] 

[PASS] test_Increment() (gas: 35978)
Logs:
  1

Traces:
  [35978] CounterTest::test_Increment()
    ├─ [22418] Counter::increment()
    │   └─ ← [Stop] 
    ├─ [424] Counter::number() [staticcall]
    │   └─ ← [Return] 1
    ├─ [0] VM::assertEq(1, 1) [staticcall]
    │   └─ ← [Return] 
    ├─ [424] Counter::number() [staticcall]
    │   └─ ← [Return] 1
    ├─ [0] console::log(1) [staticcall]
    │   └─ ← [Stop] 
    └─ ← [Stop] 

Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 7.90ms (7.52ms CPU time)

Ran 1 test suite in 8.51ms (7.90ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)

Notice no Logs: section above fuzz test traces, the

Logs:
  1

is from the unit test test_Increment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions