Skip to content

feat: expand snapshot functionality #2056

@mds1

Description

@mds1

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 gas behaves like forge snapshot currently does.
  • forge snapshot size is equivalent to running forge build --sizes and saving the output table.
  • forge snapshot <fieldName> would let you snapshot any solc field name supported by forge inspect. By default this would snapshot the field for all contracts in the src directory

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 gas results in snapshot/gas.snapshot
  • forge snapshot storage-layout results in snapshot/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-tests for gas snapshots, or always including fuzz tests and just specifying the seed here
  • --asc and --desc should be supported for ones where sorting makes sense, such as gas and size snapshots.

Open questions

  1. 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.
  2. forge inspect supports multiple variants for a given property. For example, you can see that forge inspect MyContract storage, forge inspect MyContract storageLayout, forge inspect MyContract storage-layout, and forge inspect MyContract storage_layout all 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 is storage.

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Completed

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions