Skip to content

Support inline configuration for Solidity tests#8073

Merged
alcuadrado merged 31 commits intomainfrom
sol-tests-inline-config
Mar 30, 2026
Merged

Support inline configuration for Solidity tests#8073
alcuadrado merged 31 commits intomainfrom
sol-tests-inline-config

Conversation

@schaable
Copy link
Copy Markdown
Member

@schaable schaable commented Mar 20, 2026

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 both hardhat-config: and Foundry-compatible forge-config: prefixes.

Issue: #7355

Design Doc: https://www.notion.so/nomicfoundation/Support-inline-configuration-for-Solidity-tests-306578cdeaf580dfab09fdb6c6397723

Docs: NomicFoundation/hardhat-website#243

@schaable schaable self-assigned this Mar 20, 2026
Copilot AI review requested due to automatic review settings March 20, 2026 20:59
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: 136a2ce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@nomicfoundation/hardhat-errors Patch
@nomicfoundation/hardhat-utils Patch
hardhat Minor

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI review requested due to automatic review settings March 25, 2026 16:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

@schaable schaable force-pushed the sol-tests-inline-config branch from 6c60c17 to f393b62 Compare March 25, 2026 17:53
@schaable schaable force-pushed the sol-tests-inline-config branch from f393b62 to a55b617 Compare March 26, 2026 11:45
Copilot AI review requested due to automatic review settings March 26, 2026 11:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings March 26, 2026 15:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings March 30, 2026 10:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 now getBuildInfosAndOutputs. 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.
Copy link
Copy Markdown
Member

@kanej kanej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI review requested due to automatic review settings March 30, 2026 16:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to getBuildInfosAndOutputs. 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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

@alcuadrado alcuadrado enabled auto-merge March 30, 2026 19:22
@alcuadrado alcuadrado added this pull request to the merge queue Mar 30, 2026
Merged via the queue into main with commit 10bc4ef Mar 30, 2026
258 checks passed
@alcuadrado alcuadrado deleted the sol-tests-inline-config branch March 30, 2026 19:34
@github-actions github-actions bot mentioned this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants