Support inline configuration for Solidity tests#8073
Conversation
🦋 Changeset detectedLatest commit: 136a2ce The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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 |
8aecd9d to
5989adf
Compare
There was a problem hiding this comment.
Pull request overview
Adds support for parsing per-test inline configuration from Solidity NatSpec comments and forwarding those overrides into the Solidity test runner configuration.
Changes:
- Introduces inline-config extraction/validation from solc AST + build info outputs, producing EDR
TestFunctionOverrides. - Wires computed overrides into the Solidity test task and runner config args.
- Adds byte utilities to efficiently scan build-info bytes for inline-config prefixes, plus unit tests and new Hardhat error descriptors.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| v-next/hardhat/test/internal/builtin-plugins/solidity-test/inline-config.ts | Adds unit tests covering inline-config parsing, validation, AST extraction, and end-to-end override generation. |
| v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts | Collects test-scope build infos and passes computed testFunctionOverrides into the runner config. |
| v-next/hardhat/src/internal/builtin-plugins/solidity-test/inline-config.ts | Implements inline-config detection, parsing, validation, AST extraction, and override building. |
| v-next/hardhat/src/internal/builtin-plugins/solidity-test/helpers.ts | Extends runner config arg construction to include optional testFunctionOverrides. |
| v-next/hardhat-utils/test/bytes.ts | Adds tests for new bytesToUtf8String and bytesIncludesUtf8String helpers. |
| v-next/hardhat-utils/src/internal/bytes.ts | Adds KMP LPS table builder used by byte-search utility. |
| v-next/hardhat-utils/src/bytes.ts | Adds bytesToUtf8String and KMP-based bytesIncludesUtf8String for scanning build-info bytes efficiently. |
| v-next/hardhat-errors/src/descriptors.ts | Adds new Solidity-tests inline-config error descriptors. |
v-next/hardhat/src/internal/builtin-plugins/solidity-test/inline-config.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity-test/inline-config.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity-test/inline-config.ts
Outdated
Show resolved
Hide resolved
6c60c17 to
f393b62
Compare
f393b62 to
a55b617
Compare
v-next/hardhat/src/internal/builtin-plugins/solidity-test/inline-config.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity-test/inline-config.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity-test/inline-config.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
v-next/hardhat/src/internal/builtin-plugins/solidity-test/edr-artifacts.ts:44
- This comment still refers to
getBuildInfos, but the function is nowgetBuildInfosAndOutputs. Updating the wording would avoid confusion about which usage pattern the invariants rely on.
// This is only safe because of how we currently interact with getBuildInfos
// i.e. we call it immediately after a build which should ensure both
// the build info and build info output exist. If the usage pattern of this
// function changes, these invariants might not hold anymore and should be
// transformed into other errors instead.
The initial implementation only stripped profiles for Foundry, as Hardhat has not concept of test profiles. However, this can cause an issue if you just do a search and replace of `foundry-config` for `hardhat-config`. So we have opted to profile strip on both prefixes.
kanej
left a comment
There was a problem hiding this comment.
I have done a round of manual tests:
- check casing - _ - Capital
- check both and mixed versions of prefix
- check running a single file vs suite
- check the revert config option as special
- check it works with coverage
- check it works with gas stats
- check inline validation errors
- check overloads for fuzz tests
I have also tested the new inline config against the OpenZeppelin contracts repo.
The only issue was that profiles were not being stripped for hardhat-config: prefixes, and we have opted to use the same logic as we use for foundry-config. That change has been pushed.
…actually analyze from each of them.
v-next/hardhat/test/internal/builtin-plugins/solidity-test/inline-config/index.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/test/internal/builtin-plugins/solidity-test/inline-config/index.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/builtin-plugins/solidity-test/inline-config/index.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
v-next/hardhat/src/internal/builtin-plugins/solidity-test/edr-artifacts.ts:42
- The inline comment still refers to
getBuildInfos, but the function has been renamed togetBuildInfosAndOutputs. Updating the comment would avoid confusion for future readers (especially since the comment explains important invariants about how this function is used).
// This is only safe because of how we currently interact with getBuildInfos
// i.e. we call it immediately after a build which should ensure both
// the build info and build info output exist. If the usage pattern of this
This PR adds support for configuring per-test settings (fuzz runs, invariant depth, timeouts, etc.) directly in Solidity test functions via NatSpec comments (e.g.
/// hardhat-config: fuzz.runs=100). Supports bothhardhat-config:and Foundry-compatibleforge-config:prefixes.Issue: #7355
Design Doc: https://www.notion.so/nomicfoundation/Support-inline-configuration-for-Solidity-tests-306578cdeaf580dfab09fdb6c6397723
Docs: NomicFoundation/hardhat-website#243