assume
Signature
Section titled “Signature”function assume(bool) external;Description
Section titled “Description”If the boolean expression evaluates to false, the fuzzer will discard the current fuzz inputs and start a new fuzz run.
The assume cheatcode should mainly be used for very narrow checks.
Broad checks will slow down tests as it will take a while to find valid values, and the test may fail if you hit the max number of rejects.
You can configure the rejection thresholds by setting fuzz.maxTestRejects in your Solidity tests configuration.
For broad checks, such as ensuring a uint256 falls within a certain range, you can bound your input with the modulo operator or Forge Standard’s bound method.
More information on filtering via assume can be found here.
Examples
Section titled “Examples”// Good example of using assumefunction testSomething(uint256 a) public { vm.assume(a != 1); require(a != 1); // [PASS]}// In this case assume is not a great fit, so you should bound inputs manuallyfunction testSomethingElse(uint256 a) public { a = bound(a, 100, 1e36); require(a >= 100 && a <= 1e36); // [PASS]}SEE ALSO
Section titled “SEE ALSO”Forge Standard Library