-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: expand snapshot functionality #2056
Description
Component
Forge
Describe the feature you would like
Inspired by this twitter convo
Feature Spec
Right now forge snapshot saves the gas usage of each test to a file called .gas-snapshot. This is useful for things like gas golfing, or ensuring that a changeset does not increase gas costs. Similar functionality can be applied to other properties of a codebase.
I propose modifying forge snapshot as follows:
Instead of being a single command, it now has subcommands to snapshot various things:
forge snapshot gasbehaves likeforge snapshotcurrently does.forge snapshot sizeis equivalent to runningforge build --sizesand saving the output table.forge snapshot <fieldName>would let you snapshot any solc field name supported byforge inspect. By default this would snapshot the field for all contracts in thesrcdirectory
Instead of saving to the project root, these commands save a file called <property>.snapshot to a folder named something like snapshot, snap, or ss. Examples:
forge snapshot gasresults insnapshot/gas.snapshotforge snapshot storage-layoutresults insnapshot/storage-layout.snapshot
The --check, --diff, and --snap options should be supported for each subcommand and behave the same as they do now. Some subcommands may have additional options, such as:
--include-fuzz-testsfor gas snapshots, or always including fuzz tests and just specifying the seed here--ascand--descshould be supported for ones where sorting makes sense, such as gas and size snapshots.
Open questions
- Are we ok with implementing this breaking change to snapshot behavior without waiting for a specific breaking change foundry release? Let's get thoughts from snapshot users, but IMO this is useful enough and a small enough breaking change that we should be ok with it.
forge inspectsupports multiple variants for a given property. For example, you can see thatforge inspect MyContract storage,forge inspect MyContract storageLayout,forge inspect MyContract storage-layout, andforge inspect MyContract storage_layoutall print the storage layout. We'd want to standardize on which name we use for the output files. My suggestion is using the JSON field name output by solc, which for this example I believe isstorage.
Additional context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status