Skip to content

bug(cheatcodes): expectEmit behaves weirdlyΒ #10463

Open
@MathisGD

Description

@MathisGD

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

1.1.0-stable

What version of Foundryup are you on?

0.3.3

What command(s) is the bug in?

forge t

Operating System

None

Describe the bug

in a call following a expectEmit, if a reverts happens before the event emission the test will fail with log != expected log. It seems way more natural to fail with EvmError: Revert for two reasons: nobody should be testing even emission on failing paths (events are not emitted if the call reverted), and reverts are "more important" than wrong log. Also the inconsistent behaviour if the event is emitted before the revert is weird (the event will not be emitted if the call reverts).

minimal example:

    event Foo();

    function revertingBefore() external {
        revert();
        emit Foo();
    }

    function revertingAfter() external {
        emit Foo();
        revert();
    }

    // this test fails with `log != expected log`
    function testBefore() public {
        vm.expectEmit();
        emit Foo();
        this.revertingBefore(); // reverting call
    }

    // this test fails with `EvmError: Revert`
    function testAfter() public {
        vm.expectEmit();
        emit Foo();
        this.revertingAfter(); // reverting call
    }

https://github.com/MathisGD/forge-expect-emit-bug/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions