Skip to content

Commit ba87c23

Browse files
authored
chore: add invariant notes re timeout and show_metrics (#1404)
Add invariant notes re timeout and show metrics
1 parent f273256 commit ba87c23

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/forge/invariant-testing.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Invariant testing campaigns have two dimensions, `runs` and `depth`:
99
- `runs`: Number of times that a sequence of function calls is generated and run.
1010
- `depth`: Number of function calls made in a given `run`. Invariants are asserted after each function call is made. If a function call reverts, the `depth` counter still increments.
1111

12+
For long invariant campaigns a `timeout` (in seconds) can be set, ensuring test ends after specified time elapsed.
13+
1214
> ℹ️ **Note**
1315
>
1416
> When implementing invariant tests is important to be aware that for each `invariant_*` function a different EVM executor is created, therefore invariants are not asserted against same EVM state. This means that if `invariant_A()` and `invariant_B()` functions are defined then `invariant_B()` won't be asserted against EVM state of `invariant_A()` (and the other way around).
@@ -168,6 +170,10 @@ targetContract2:
168170

169171
This is something to be mindful of when designing target contracts, as target contracts with less functions will have each function called more often due to this probability distribution.
170172

173+
> ℹ️ **Note**
174+
>
175+
> A good practice is to set `show_metrics = true` in order to get a breakdown of all handler function calls and which functions are reverting/getting discarded (through `vm.assume` cheatcode).
176+
171177
### Invariant Test Helper Functions
172178
Invariant test helper functions are included in [`forge-std`](https://github.com/foundry-rs/forge-std/blob/master/src/StdInvariant.sol) to allow for configurable invariant test setup. The helper functions are outlined below:
173179

0 commit comments

Comments
 (0)