-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(cheatcodes): skip gas snapshots if not in isolation mode #9649
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
fix(cheatcodes): skip gas snapshots if not in isolation mode #9649
Conversation
…side effect is that any custom group names or file name changes are not reflected - this is delegated to the end user
…has a certain requirement for running it - in the case of gas snapshotting: isolation mode
… that this will cause staining to occur
|
Would it be possible to add something to foundry.toml that lets us default to isolation mode? Or defaults to using it only for tests with snapshots? Without this feature, to get accurate gas we have to always remember to run with |
you are currently able to add |
|
Decided this requires a different approach / refactor as this PR would not lead to a better user experience as it requires inline configuration of isolate being set manually at every function using gas snapshot cheatcodes or run all tests in isolation. Ideally isolation mode is enabled by default if we detect a gas snapshot cheatcode being used. Considering this is not feasible a better alternative is to enable isolation mode if the user explicitly requests a gas report to be generated. Since this PR was opened a new I propose the following breaking changes instead:
|
Motivation
Opened for visibility
Ref: #9477 (comment)
Gas snapshots are not accurate outside of isolation mode and we've seen users only run gas snapshots with isolation mode enabled for this reason.
When running a test without
--isolateenabled and gas snapshots cheatcodes are active a warning is raised similar to the deprecated cheatcodes (on per cheatcode used per test suite, collected at the end)This PR also fixes the issue where previously a single test from a test suite or custom group would clear out all the other keys. This has now been changed so that we merge with the previous results, replacing existing keys if they were effected. Note: this comes at the cost of now
stainingold values. This was deemed preferable based on feedback we received.Solution
This PR adds a
requireskeyword for the Cheatcodes spec which lets the developer indicate the prerequisites that are required to run a cheatcode. In this can it is isolation mode for the gas snapshots.To do:
Decide whether to requiresnapshotValueto also be ran in isolation mode given it is for arbitrary values. Because of its existence users still run into the "running one test overwrites the all related snapshot results"Not added, this should run regardless
staining!)