-
Notifications
You must be signed in to change notification settings - Fork 110
docs: add documentation for inline config for solidity tests #243
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
94ca93e
docs: add documentation for inline config for solidity tests
schaable 50e1e63
Update src/content/docs/docs/guides/testing/inline-configuration.mdx
schaable c95816e
Update src/content/docs/docs/guides/testing/inline-configuration.mdx
schaable e708b30
Update src/content/docs/docs/guides/testing/using-solidity.mdx
schaable e3afc66
Update src/content/docs/docs/guides/testing/inline-configuration.mdx
schaable f59c82c
apply review changes
schaable 23dfbe8
Linter fixes
alcuadrado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
63 changes: 63 additions & 0 deletions
63
src/content/docs/docs/guides/testing/inline-configuration.mdx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| --- | ||
| title: Inline configuration for Solidity tests | ||
| description: How to override fuzz and invariant test settings | ||
|
schaable marked this conversation as resolved.
Outdated
|
||
| sidebar: | ||
| label: Inline configuration | ||
|
schaable marked this conversation as resolved.
Outdated
|
||
| order: 3 | ||
|
schaable marked this conversation as resolved.
Outdated
|
||
| --- | ||
|
|
||
| Hardhat lets you override fuzz and invariant test settings on a per-function basis using NatSpec comments. This is useful when different tests need different parameters. For example, running more fuzz iterations on a critical function, or increasing the depth of an invariant test. | ||
|
schaable marked this conversation as resolved.
Outdated
|
||
|
|
||
| Inline overrides take precedence over the global settings defined in your [Solidity tests configuration](/docs/reference/configuration#solidity-tests-configuration). | ||
|
|
||
| ## Syntax | ||
|
|
||
| Each override is a single line inside a NatSpec comment block, following the format `hardhat-config: <key> = <value>`: | ||
|
schaable marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```solidity | ||
| /// hardhat-config: fuzz.runs = 10000 | ||
| /// hardhat-config: fuzz.maxTestRejects = 500 | ||
| function testTransferFuzz(uint256 amount) public { | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| Block comments are also supported: | ||
|
|
||
| ```solidity | ||
| /** | ||
| * hardhat-config: invariant.runs = 100 | ||
| * hardhat-config: invariant.depth = 50 | ||
| * hardhat-config: invariant.failOnRevert = true | ||
| */ | ||
| function invariantBalanceAlwaysPositive() public { | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| ## Supported configuration keys | ||
|
schaable marked this conversation as resolved.
|
||
|
|
||
| | Key | Description | | ||
| | --------------------------- | --------------------------------------------------------------- | | ||
| | `fuzz.runs` | Number of fuzz iterations to run | | ||
| | `fuzz.maxTestRejects` | Maximum number of rejected inputs before aborting | | ||
| | `fuzz.showLogs` | Whether to show console logs during fuzzing | | ||
| | `fuzz.timeout` | Timeout for the fuzz test | | ||
| | `invariant.runs` | Number of invariant test runs | | ||
| | `invariant.depth` | Number of calls per run to attempt to break the invariant | | ||
| | `invariant.failOnRevert` | Whether to fail the invariant if a revert occurs | | ||
| | `invariant.callOverride` | Whether to override unsafe external calls | | ||
| | `invariant.timeout` | Timeout for the invariant test | | ||
|
schaable marked this conversation as resolved.
Outdated
|
||
| | `allowInternalExpectRevert` | Allow expecting reverts at the same callstack depth as the test | | ||
|
|
||
|
schaable marked this conversation as resolved.
Outdated
|
||
| ## Foundry compatibility | ||
|
|
||
| Hardhat also accepts the `forge-config:` prefix, kebab-case keys, and the `default` profile, so existing Foundry inline configuration works without changes: | ||
|
schaable marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```solidity | ||
| /// forge-config: default.fuzz.runs = 10000 | ||
| /// forge-config: fuzz.max-test-rejects = 500 | ||
|
schaable marked this conversation as resolved.
|
||
| function testTransferFuzz(uint256 amount) public { | ||
| // ... | ||
| } | ||
| ``` | ||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.