Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
0xPhaze opened this issue Apr 26, 2023 · 3 comments · Fixed by #4945
Closed
2 tasks done

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

0xPhaze opened this issue Apr 26, 2023 · 3 comments · Fixed by #4945
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test T-bug Type: bug T-likely-breaking Type: requires changes that can be breaking
Milestone

Comments

@0xPhaze
Copy link

0xPhaze commented Apr 26, 2023

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.

@0xPhaze 0xPhaze added the T-bug Type: bug label Apr 26, 2023
@gakonst gakonst added this to Foundry Apr 26, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Apr 26, 2023
@0xPhaze
Copy link
Author

0xPhaze commented Apr 30, 2023

Here is another strange case (though possibly related):

https://github.com/0xPhaze/solnum/blob/d05fbe538c2dc610103a0b44c2ad8737407effbc/test/Random.t.sol#L71-L76

    function test_addRandn_revert_Overflow() public {
        Random r = seed(0);
        vm.expectRevert(N32x32_Overflow.selector);

        r.addRandn(sn.zeros(1, 100), sn.ONE);
    }

This function passes. It also passes when I remove the line containing vm.expectRevert which is strange. When I switch out the line r.addRandn(... for something else, like Random r = seed(0); it reverts (as expected). I tried quickly reproducing this in a simpler setup, but couldn't pin it down (there it worked as it should).

@grandizzy
Copy link
Collaborator

@0xPhaze the testFun behavior is inline now using latest build, showing proper failure

Encountered 1 failing test in test/Counter.t.sol:CounterTest
[FAIL: assertion failed: 1 != 2] testFun() (gas: 3070)

The 2nd test traces show to be decoding an identity precompile call, not sure if that's expected?

[PASS] test_addRandn_revert_Overflow() (gas: 20851)
Traces:
  [20851] TestRandom::test_addRandn_revert_Overflow()
    ├─ [90] PRECOMPILES::identity(0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) [staticcall]
    │   └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    └─ ← [Stop]

@grandizzy
Copy link
Collaborator

optimistically close this per comment above, @0xPhaze please reopen if still an issue. thank you!

@grandizzy grandizzy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 31, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test T-bug Type: bug T-likely-breaking Type: requires changes that can be breaking
Projects
Archived in project
4 participants