Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expand snapshot functionality #2056

Open
mds1 opened this issue Jun 21, 2022 · 3 comments
Open

feat: expand snapshot functionality #2056

mds1 opened this issue Jun 21, 2022 · 3 comments
Labels
A-gas-snapshots Area: gas snapshotting/reporting C-forge Command: forge T-feature Type: feature

Comments

@mds1
Copy link
Collaborator

mds1 commented Jun 21, 2022

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

@mds1 mds1 added the T-feature Type: feature label Jun 21, 2022
@onbjerg
Copy link
Member

onbjerg commented Jun 21, 2022

Ref #137 #1795

Also might complicate #1980 because of command arg flattening, see #1980 (comment)

Edit: Another consideration is that snapshot files are nameable right now, so it's possible to have e.g. a .fuzz-snapshot and a .unit-snapshot that you diff/check separately and we should probably preserve that behavior

One final consideration is that there's been some talk of merging snapshot/gas report but I can't find the convo

Edit 2: Given all above points an alternative suggestion (no strong preference, just wanted to add context to the issue):

  • forge snapshot/gas report merge. Gas reports already support writing to files, so tweaking the layout and adding diff/check should be sufficient to become up to date. For a while forge snapshot could be an alias of gas reporting so we don't have breaking changes
  • Introduce diff/check/save to file behavior for forge inspect to fill 2nd use case

@onbjerg onbjerg added C-forge Command: forge A-gas-snapshots Area: gas snapshotting/reporting labels Jun 21, 2022
@maurelian
Copy link

Only comment is that we'd definitely love to see this given I was speccing out a similar script for ourselves around the time this issue was created. For now I will likely follow the approach used by nomad.

@mds1
Copy link
Collaborator Author

mds1 commented May 18, 2023

Some other ideas for gas snapshots specifically can be found in #137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-gas-snapshots Area: gas snapshotting/reporting C-forge Command: forge T-feature Type: feature
Projects
No open projects
Status: Todo
Development

No branches or pull requests

3 participants