- Notifications
You must be signed in to change notification settings - Fork 1.7k
Write snapshots to .gas-snapshot file with --snapshot flag #7792
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
base: feat/gas-snapshots
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements gas snapshot functionality for Solidity tests by adding a --snapshot flag that writes gas consumption data to a .gas-snapshot file. The implementation extracts gas usage from test results (both standard and fuzz tests), formats them in a human-readable format, and persists them to disk.
Key changes:
- Added gas snapshot extraction, stringification, and file I/O functions
- Implemented
--snapshotflag for the test task that triggers snapshot generation - Refactored plugin dependencies to ensure gas-analytics loads after solidity-test
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| gas-snapshots.ts (test) | Comprehensive test coverage for snapshot extraction, formatting, and file operations |
| task-action.ts (test) | Modified to forward additional arguments to subtasks |
| task-action.ts (solidity-test) | Updated to collect and return suite results for downstream processing |
| runner.ts | Renamed parameter from configArgs to testRunnerConfig for clarity |
| index.ts (solidity-test) | Removed gas-analytics dependency (moved to gas-analytics plugin) |
| helpers.ts | Refactored hex string to bytes conversion using inline helper function |
| index.ts (builtin-plugins) | Reordered plugin initialization to load gas-analytics after solidity-test |
| task-action.ts (gas-analytics) | New task override that generates snapshots when --snapshot flag is present |
| index.ts (gas-analytics) | Added --snapshot flag and task overrides, plus dependencies on test plugins |
| gas-snapshots.ts | Core implementation for extracting, stringifying, and saving gas snapshots |
| gas-analytics-manager.ts | Fixed min/max calculation to handle edge cases with reduce |
| Calculator.t.sol | New comprehensive test file with various test types and gas snapshots |
| hardhat.config.ts | Removed solidity test timeout configuration |
| Counter.t.sol | Enhanced with invariant tests and gas snapshot tests |
| Calculator.sol | New Calculator contract for demonstration/testing |
| .gas-snapshot | Generated snapshot file with gas consumption data |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.ts Show resolved Hide resolved
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.ts Show resolved Hide resolved
3e32473 to a82ec50 Compare
Closes #7770