Repository navigation
Conversation
Prints a gas summary after the test results (tests by gas, functions by self gas, hottest call paths) and writes a folded-stack file per test to <cache>/gas-profile/folded/, for speedscope, inferno and flamegraph.pl. Builds the profile from the call traces EDR already returns. Refuses --coverage (HHE823) and warns when isolation is on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 646bd00 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #8737. A follow-up PR adds the HTML report.
Summary
hardhat test solidity --gas-profileshows where each test's gas goes. After the test results, it prints a summary: tests by gas, functions by self gas, and each test's hottest call path. It also writes one folded-stack file per test to<cache>/gas-profile/folded/. speedscope, inferno, and flamegraph.pl can open these files.The profile is built from the call traces EDR already returns (
TestResult.callTraces()). It needs no EDR change and no new dependency.Changes
New
gasProfileflag ontest solidity. When it is on, the run setsincludeTracestoAllthrough a new optionalincludeTracesparameter inhelpers.ts. The test output is the same as without the flag.gas-profile/model.tsbuilds each test's call tree from its last trace root, sosetUpis left out. It:console.logframes, which report 0 gas;It also computes
refund,minCall/maxCall,kinds, andtags, which the HTML report in the follow-up PR uses.gas-profile/summary.tsprints the terminal summary, withformatTable.gas-profile/index.tswrites the folded files and replaces<cache>/gas-profile/on each run. File names are sanitized, capped at 200 bytes with a hash, and deduplicated case-insensitively.--coveragewith--gas-profileis refused before the build (HHE823), because coverage instruments the bytecode.When isolation is on (
--gas-stats,--gas-stats-json, or theisolatesetting), a warning says that each top-level call then includes its own transaction cost.Writing the profile never changes the exit code. A failure prints a warning.
Fuzz, invariant, and skipped tests are listed as not profiled.
Changeset:
hardhatminor,@nomicfoundation/hardhat-errorspatch.Gas accounting
A frame's gas is its
gasUsed, which includes its calls. Self gas is that value minus its calls'gasUsed. The self gas of all frames adds up to the root'sgasUsed. The root'sgasUsedminusconsumedGasis the refund applied at the end of the test. Recursive calls count once in a function's total.Testing
solidity-test/task-action.tson thesolidity-testfixture:--coverageis refused;testCaseandtestcase,vm.skip, the P256 and BLS precompiles, and labels with<,;, and%.solidity-test,gas-analytics, andcoveragetests: 574 pass.pnpm lintandpnpm buildpass inhardhatandhardhat-errors.Docs: NomicFoundation/hardhat-website#317.
🤖 Generated with Claude Code