-
Notifications
You must be signed in to change notification settings - Fork 2k
bug: snapshot/revertTo causes tests to pass unexpectedly #3055
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
that sounds right, need to make a check for |
with #3087 this now results in ~/git/rust/foundry/target/debug/forge test ! master
[⠢] Compiling...
No files changed, compilation skipped
Running 1 test for test/Counter.t.sol:MyTest
[FAIL. Reason: Assertion failed.] test_snapshot() (gas: 15534)
Test result: FAILED. 0 passed; 1 failed; finished in 2.71ms
Failing tests:
Encountered 1 failing test in test/Counter.t.sol:MyTest
[FAIL. Reason: Assertion failed.] test_snapshot() (gas: 15534)
Encountered a total of 1 failing tests, 0 tests succeeded |
This still doesn't work. But after modifying a few lines in forge-std, it works. foundry-rs/forge-std#241 @mattsse |
@mattsse I was able to reproduce the issue from @graykode, any idea on the cause? The forge-std fix in foundry-rs/forge-std#241 does resolve the issue, but I'm not sure why. Regardless though, seems this should be fixed upstream here in foundry instead? |
looks strange, I have to take a closer look |
@mattsse, see foundry-rs/forge-std#241 (review). The underlying issue needs to be identified. |
Hey ! I'm still facing this issue on forge std // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import "forge-std/Test.sol";
contract TestMe is Test {
function testMe() public {
uint256 snapshot = vm.snapshot();
assertTrue(false);
vm.revertTo(snapshot);
assertTrue(true);
}
} This outputs the following:
The only was to view the failing test is using a more verbose mode like |
For those facing this issue, you may wish to use the following as a temp workaround: function _revertTo(uint256 aSnapshot) private {
require(!failed(), "Fail flag triggered, aborting revert");
vm.revertTo(aSnapshot);
} |
hmm, I'm not quite sure what the issue is here, because both examples fail. or is the problem that the first assertion doesn't stop execution? this behavior has ds-test legacy reasons but I'm skeptical that this is any good... |
@mattsse It appears that fuzz testing breaks whatever code was introduced to persist the failure state. That said, I vaguely remember seeing this fail prior to fuzzing. However, perhaps they share the same root cause. This minimal repro should make it easier to track down: |
thanks, will check! |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (48d5d79 2022-09-01T00:10:22.933552Z)
What command(s) is the bug in?
forge test
Operating System
No response
Describe the bug
If you run this test, it passes. If you comment out the
vm.revertTo
line it fails. Failure is expected in both cases since the assertion should fail. It seems like the cause is that reverting the state also reverts thefailed
flag: https://github.com/dapphub/ds-test/blob/9310e879db8ba3ea6d5c6489a579118fd264a3f5/src/test.sol#L47-L63The text was updated successfully, but these errors were encountered: