feat: contract-level inline configurations in Solidity tests - #1627
feat: contract-level inline configurations in Solidity tests#1627popescuoctavian wants to merge 13 commits into
Conversation
🦋 Changeset detectedLatest commit: b148776 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
Pull request overview
This PR adds contract-level inline configuration directives for Solidity tests, so a NatSpec directive above a contract definition becomes the default for all tests run by that contract (including inherited ones), while function-level directives override per key.
Changes:
- Extend inline-config collection/parsing to capture contract-level directives and merge them beneath function-level overrides.
- Apply contract-level configuration to all ABI-discovered test functions (including inherited) via a new
fill_frommerge helper in config overrides. - Add integration + unit tests and update NAPI/TypeScript types to reflect that directive errors may not have an associated function (contract-level directives).
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| js/integration-tests/solidity-tests/test/fuzz.ts | Adds integration coverage asserting contract-level vs function-level precedence for fuzz runs. |
| js/integration-tests/solidity-tests/test-contracts/ContractLevelInlineConfig.t.sol | New Solidity test contract exercising contract-level hardhat-config directive behavior. |
| crates/edr_solidity_tests/tests/testdata/default/inline/ContractLevelConfig.t.sol | Adds Rust testdata covering contract-level config, function overrides, and inherited tests (plus invariants). |
| crates/edr_solidity_tests/tests/it/inline_config.rs | Adds integration test validating contract-level config applies to direct + inherited tests and invariants. |
| crates/edr_solidity_tests/src/multi_runner.rs | Implements ABI-walk merge of contract-level config underneath per-function overrides. |
| crates/edr_solidity_tests/src/inline_config/provider.rs | Changes provider API to return a contract-level + per-function structure (ContractInlineConfig). |
| crates/edr_solidity_tests/src/inline_config/parse.rs | Switches from locating functions to locating contracts + their functions, enabling contract-level NatSpec scanning. |
| crates/edr_solidity_tests/src/inline_config/overrides.rs | Collects contract-level directives and function directives into ContractInlineConfig, with improved error localization. |
| crates/edr_solidity_tests/src/inline_config/error.rs | Updates error types/rendering to support directive problems without a function (contract-level). |
| crates/edr_solidity_tests/src/inline_config/directives.rs | Adds DirectiveTarget to validate keys differently for contract vs function directives; exposes is_test_function. |
| crates/edr_solidity_tests/src/inline_config.rs | Updates module docs and re-exports new inline-config types/utilities. |
| crates/edr_solidity_tests/src/config.rs | Adds fill_from merging logic for per-key fallback behavior across nested fuzz/invariant sections. |
| crates/edr_napi/src/solidity_tests/inline_config.rs | Makes directive error “function” optional for contract-level directives in the NAPI surface. |
| crates/edr_napi/index.d.ts | Updates TypeScript declarations to match optional function for contract-level directive errors. |
| .changeset/salty-colts-tie.md | Declares a minor release for the new contract-level inline-config feature. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1627 +/- ##
==========================================
- Coverage 80.02% 79.94% -0.09%
==========================================
Files 464 460 -4
Lines 80392 80344 -48
Branches 80392 80344 -48
==========================================
- Hits 64332 64227 -105
- Misses 13855 13904 +49
- Partials 2205 2213 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
16e6dee to
856de5a
Compare
…ch get their overrides
|
/bench hardhat-ref=popescuoctavian/edr-contract-level-inline-config |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
/bench hardhat-ref=popescuoctavian/edr-contract-level-inline-config |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
Note: pending NomicFoundation/hardhat#8575 to pass HH3 regression benchmarks. |
Wodann
left a comment
There was a problem hiding this comment.
Overall, this looks good. I left some comments that you can address without asking for re-review (unless you want to).
| pub function: String, | ||
| /// The test function the directive belongs to; absent for a contract-level | ||
| /// directive. | ||
| pub function: Option<String>, |
There was a problem hiding this comment.
Thought: Can there be a third variant (e.g. file-level)? If so, can we use an union type to discriminate?
There was a problem hiding this comment.
The directives are NatSpec doc comments which bind to declarations (contracts, functions). Something like a file-level directive would require a new parsing mechanism (e.g. pragma-style comments), which I believe is unlikely to be added. Also, even if we switched to a union now, adding another variant would still be a breaking change. I'd leave it as is for now and switch to a union in the future if that's required.
|
I orchestrated some agents for a second pair of eyes on this. They came up with the following suggestions that you can feed to an agent for the topics you agree with: |
…elds are a compile error
…ify that set values win
…cation error message
|
All the other doc-related suggestions were addressed by 4906d21. The other suggestions were either already fixed, unfounded, or require additional work - table test suggestion is valid, but not trivial, and is not yet supported and documented in Hardhat; supporting it with inline config in EDR would silently add support in Hardhat, which I'm not sure is desired. |
Wodann
left a comment
There was a problem hiding this comment.
Thanks for addressing feedback! LGTM!
|
/bench hardhat-ref=popescuoctavian/edr-contract-level-inline-config |
|
🚀 Starting regression benchmark for |
This PR adds support for contract-level inline config directives.
A NatSpec directive above a contract definition now applies to every test the contract runs, with function-level directives taking per-key precedence:
Key points
fuzz.runs, function setsfuzz.maxTestRejects→ both apply).fuzz.*andinvariant.*keys are valid at contract level (each section only affects tests of its kind); all other validation (syntax, keys, values, profiles, duplicates) applies as at function level. The same key at contract and function level is not a duplicate — the function wins.