foundry: `fail_on_revert` does not fail test suite when revert happens inside handler function
Component
Forge
Have you ensured that all of these are up to date?
- Foundry
- Foundryup
What version of Foundry are you on?
forge 0.2.0 (95a93cd 2023-08-25T00:25:25.985662923Z)
What command(s) is the bug in?
forge test
Operating System
None
Describe the bug
The following test passes:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "forge-std/Test.sol";
contract BrokenInvariantTest is Test {
bytes4[] internal selectors;
function setUp() public {
selectors.push(this.doSomething.selector);
targetSelector(FuzzSelector({addr: address(this), selectors: selectors}));
}
function doSomething() public {
require(false);
}
function invariantBroken() public {}
}
using the command: forge test
Expected behavior would be: the test suite fails because there’s a revert in a handler function
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Reactions: 2
- Comments: 17 (8 by maintainers)
Hey folks - ACKing the issue and thanks for the repros. We’ll fix. We are in the middle of the alloy transition so some things have been slower, appreciate the patience. We’ll prio this in next week’s sprint, so should be solved soon.
@Evalir @gakonst can this bugfix be prioritized pls? The reproducible example is the simplest possible and it is confirmed by several independent developers. This is definitely not an expected behavior of foundry
Hey all! fix is on #6199 and will go on main soon—would be great to get some testers!
I also just ran into this. The workaround for now is just to consider any reverts as a failed test, even though it says pass. For CI/CD you’d have to read the text of the number of reverts, and if it’s not 0 consider it failed.
This regression may have been introduced in #5676
I can confirm that the issue is still happening on version:
forge 0.2.0 (893fc9f 2023-09-12T00:22:45.184609469Z)I just had to run the following test contract (as described in this issue’s description):
Output is:
Same would have expected this to fail with
fail_on_revertset true. Updated the example @Rubilmax posted to use the assertion helper which does post in the logs an assertion failure but the test suite passes.Code:
We did ask for this behaviour in https://github.com/foundry-rs/foundry/issues/4718 with the solution implemented in https://github.com/foundry-rs/foundry/pull/5445.