foundry icon indicating copy to clipboard operation
foundry copied to clipboard

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

Open 0xPhaze opened this issue 1 year ago • 1 comments

Component

Forge

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

  • [X] Foundry
  • [X] 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.

0xPhaze avatar Apr 26 '23 21:04 0xPhaze