forge-snapshot - Create a snapshot of each test's gas usage.
forge snapshot
[options]
Create a snapshot of each test's gas usage.
The results are written to a file named .gas-snapshot
. You can change the name of the file
by passing --snap <PATH>
.
Fuzz tests are included by default in the snapshot. They use a static seed to achieve deterministic results.
Snapshots can be compared with --diff
and --check
. The first flag will output a diff, and the second
will output a diff and exit with code 1 if the snapshots do not match.
--asc
Sort results by gas used (ascending).
--desc
Sort results by gas used (descending).
--min
min_gas
Only include tests that used more gas that the given amount.
--max
max_gas
Only include tests that used less gas that the given amount.
--tolerance
threshold
Tolerates gas deviations up to the specified percentage (0-100).
--diff
path
Output a diff against a pre-existing snapshot.
By default the comparison is done with .gas-snapshot
.
--check
path
Compare against a pre-existing snapshot, exiting with code 1 if they do not match.
Outputs a diff if the snapshots do not match.
By default the comparison is done with .gas-snapshot
.
--snap
path
Output file for the snapshot. Default: .gas-snapshot
.
{{#include test-options.md}}
{{#include evm-options.md}}
{{#include executor-options.md}}
{{#include core-build-options.md}}
{{#include ../common/display-options.md}}
{{#include common-options.md}}
-
Create a snapshot:
forge snapshot
-
Generate a diff:
forge snapshot --diff
-
Check that the snapshots match:
forge snapshot --check