Skip to content

Comments

expectRevert causing early failure when cheatcodes are called before the reverting call#1109

Closed
anvacaru wants to merge 2 commits intomasterfrom
expect_revert_tweaks
Closed

expectRevert causing early failure when cheatcodes are called before the reverting call#1109
anvacaru wants to merge 2 commits intomasterfrom
expect_revert_tweaks

Conversation

@anvacaru
Copy link
Contributor

When using vm.expectRevert() with cheatcodes like vm.addr() or makeAddr(), Kontrol would incorrectly trigger the revert check on the cheatcode call, leading to tests failing with EVMC_REVERT instead of waiting for the actual reverting call.

    function test_expectRevert_whenDelegating() public {
     ....
        vm.expectRevert();
        cut.delegate(address(vm.addr(1));
     ...
    }

For example, in cases where a function is invoked after an expectRevert, the test would fail prematurely because of the vm.addr() call that causes the #checkRevert mechanism to intervene on the successful vm.addr() call.

The root cause was the foundry.set.expectrevert rules inserting #checkRevert for every opcode call, including cheatcodes, contrary to Foundry’s specification.
OTOH, the overly aggressive cheatcode.call.ignoreCalls rule prevented proper execution and return values of cheatcodes.

The solution involved removing the cheatcode.call.ignoreCalls rule to allow normal execution of cheatcodes and adding guards to the foundry.set.expectrevert rules to skip adding the #checkRevert for calls to the FoundryCheatCode contract address (vm).
This ensures that cheatcodes execute normally during expectRevert, only actual contract calls are monitored, and tests remain consistent with Foundry behavior.

@anvacaru anvacaru marked this pull request as ready for review November 19, 2025 07:11
@anvacaru
Copy link
Contributor Author

Closing as duplicate of #1012.

@anvacaru anvacaru closed this Nov 25, 2025
@anvacaru anvacaru deleted the expect_revert_tweaks branch November 25, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant