Skip to content

Commit 578f6fc

Browse files
authored
chore: document new way of disabling the emittance of gas snapshots to disk (#1442)
document foundry-rs/foundry#9710
1 parent c6f2923 commit 578f6fc

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/cheatcodes/gas-snapshots.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,32 @@ function snapshotGasLastCall(string calldata group, string calldata name) extern
3838

3939
`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.
4040

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:
4242

4343
- Set the `FORGE_SNAPSHOT_CHECK=true` environment variable
4444
- Set `gas_snapshot_check = true` in `foundry.toml`
4545
- Pass `--gas-snapshot-check=true`
4646

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.
4848

4949
This will compare the gas usage of your tests against the last snapshot and fail if the gas usage has changed.
5050

5151
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.
5252

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+
5361
### Examples
5462

5563
Capturing the gas usage of a section of code that calls an external contract:
5664

5765
```solidity
5866
contract SnapshotGasTest is Test {
59-
uint256 public slot0;
60-
6167
Flare public flare;
6268
6369
function setUp() public {
@@ -78,7 +84,6 @@ Capturing the gas usage of multiple sections of code that modify the internal st
7884
contract SnapshotGasTest is Test {
7985
uint256 public slot0;
8086
81-
8287
/// Writes to `snapshots/SnapshotGasTest.json` group with name `internalA`, `internalB`, and `internalC`.
8388
function testSnapshotGas() public {
8489
vm.startSnapshotGas("internalA");

0 commit comments

Comments
 (0)