You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`snapshotGas*` cheatcodes allow you to capture gas usage in your tests. This can be useful to track how much gas your logic is consuming. You can capture the gas usage of the last call by name, capture an arbitrary numerical value by name, or start and stop a snapshot capture of the current gas usage by name.
40
40
41
-
In order to strictly compare gas usage across test runs you can do one of the following:
41
+
In order to strictly compare gas usage across test runs you can set one of the following:
42
42
43
43
- Set the `FORGE_SNAPSHOT_CHECK=true` environment variable
44
44
- Set `gas_snapshot_check = true` in `foundry.toml`
45
45
- Pass `--gas-snapshot-check=true`
46
46
47
-
By default this is not enabled and passing `--gas-snapshot-check=false` will override all others.
47
+
By default this is **not enabled** and passing `--gas-snapshot-check=false` will override all others.
48
48
49
49
This will compare the gas usage of your tests against the last snapshot and fail if the gas usage has changed.
50
50
51
51
It is intended that the `snapshots` directory created when using the `snapshotGas*` cheatcodes is checked into version control. This allows you to track changes in gas usage over time and compare gas usage during code reviews.
52
52
53
+
To disable the emitting of gas snapshots you can set one of the following:
54
+
55
+
- Set the `FORGE_SNAPSHOT_EMIT=false` environment variable.
56
+
- Set `gas_snapshot_emit = false` in `foundry.toml`.
57
+
- Pass `--gas-snapshot-emit=false`
58
+
59
+
By default this is **enabled** and gas snapshots are written to disk.
60
+
53
61
### Examples
54
62
55
63
Capturing the gas usage of a section of code that calls an external contract:
56
64
57
65
```solidity
58
66
contract SnapshotGasTest is Test {
59
-
uint256 public slot0;
60
-
61
67
Flare public flare;
62
68
63
69
function setUp() public {
@@ -78,7 +84,6 @@ Capturing the gas usage of multiple sections of code that modify the internal st
78
84
contract SnapshotGasTest is Test {
79
85
uint256 public slot0;
80
86
81
-
82
87
/// Writes to `snapshots/SnapshotGasTest.json` group with name `internalA`, `internalB`, and `internalC`.
0 commit comments