Skip to content

bug(forge): vm.expectRevert without external call makes assertEq pass #4832

@0xPhaze

Description

@0xPhaze

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

No response

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

This test passes.

    function testFun() public {
        assertEq(uint256(1), 2);

        vm.expectRevert();
        revert();
    }
Running 1 test for test/Contract.t.sol:ContractTest
[PASS] testFun() (gas: 15068)
Logs:
  Error: a == b not satisfied [uint]
        Left: 1
       Right: 2

Test result: ok. 1 passed; 0 failed; finished in 283.88µs

I know vm.expectRevert is not intended to be used on anything but external calls, but I still like using it for testing free functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions