-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* - add preserve_state invariant config: useful for handlers that change state (e.g. using cheatcodes like roll, warp), see #6694 - active only in conjunction with fail_on_revert true * Add test from issue 6694
- Loading branch information
Showing
7 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
testdata/fuzz/invariant/common/InvariantPreserveState.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity 0.8.18; | ||
|
||
import "ds-test/test.sol"; | ||
import "../../../cheats/Vm.sol"; | ||
|
||
struct FuzzSelector { | ||
address addr; | ||
bytes4[] selectors; | ||
} | ||
|
||
// https://github.com/foundry-rs/foundry/issues/7219 | ||
|
||
contract Handler is DSTest { | ||
Vm constant vm = Vm(HEVM_ADDRESS); | ||
|
||
function thisFunctionReverts() external { | ||
if (block.number < 10) {} else { | ||
revert(); | ||
} | ||
} | ||
|
||
function advanceTime(uint256 blocks) external { | ||
blocks = blocks % 10; | ||
vm.roll(block.number + blocks); | ||
vm.warp(block.timestamp + blocks * 12); | ||
} | ||
} | ||
|
||
contract InvariantPreserveState is DSTest { | ||
Handler handler; | ||
|
||
function setUp() public { | ||
handler = new Handler(); | ||
} | ||
|
||
function targetSelectors() public returns (FuzzSelector[] memory) { | ||
FuzzSelector[] memory targets = new FuzzSelector[](1); | ||
bytes4[] memory selectors = new bytes4[](2); | ||
selectors[0] = handler.thisFunctionReverts.selector; | ||
selectors[1] = handler.advanceTime.selector; | ||
targets[0] = FuzzSelector(address(handler), selectors); | ||
return targets; | ||
} | ||
|
||
function invariant_preserve_state() public { | ||
assertTrue(true); | ||
} | ||
} |