My Test for Stateful Fuzzing isn't catching the invariant #267
-
StatefulFuzzCatches.sol // SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
// INVARIANT: doMoreMathAgain should never return 0
contract StatefulFuzzCatches {
uint256 public myValue = 1;
uint256 public storedValue = 100;
/*
* @dev Should never return 0
*/
function doMoreMathAgain(uint128 myNumber) public returns (uint256) {
uint256 response = (uint256(myNumber) / 1) + myValue;
storedValue = response;
return response;
}
function changeValue(uint256 newValue) public {
myValue = newValue;
}
} StatefulFuzzCatches.t.sol // SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {Test} from "forge-std/Test.sol";
import {StdInvariant} from "forge-std/StdInvariant.sol";
import {StatefulFuzzCatches} from "../../src/invariant-break/StatefulFuzzCatches.sol";
contract StatefulFuzzCatchTest is StdInvariant, Test {
StatefulFuzzCatches sfc;
function setUp() public {
sfc = new StatefulFuzzCatches();
targetContract(address(sfc));
}
function statefulFuzz_catchesInvariant() public view {
assert(sfc.storedValue() != 0);
}
} The output I get after compiling the test
I don't know where the issue is from |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 28 replies
-
Hello @BlackAnon22, what is the issue? |
Beta Was this translation helpful? Give feedback.
-
I'm not actually, that's why I sent the script and also my output earlier |
Beta Was this translation helpful? Give feedback.
-
I ran into this today where the stateful fuzz test was passing. I know it was mentioned above with increasing runs but that is the answer. Either updates to foundry or my platform (WSL) causes the randomness to "change" even with the same seed as Patrick. Update number of runs in [invariant]
- runs = 64
+ runs = 1000
depth = 32
fail_on_revert = false It catches it on run 367 so 64 runs would miss it.
|
Beta Was this translation helpful? Give feedback.
I ran into this today where the stateful fuzz test was passing. I know it was mentioned above with increasing runs but that is the answer. Either updates to foundry or my platform (WSL) causes the randomness to "change" even with the same seed as Patrick.
Update number of runs in
foundry.toml
for invariant.It catches it on run 367 so 64 runs would miss it.