Repository navigation
Document Solidity test profiles #297
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91bd04c
docs: add a Solidity test profiles guide
schaable 702ee64
docs: document test.solidity.profiles in the config reference
schaable 68cec9a
docs: link to the Solidity test profiles guide
schaable 11493b6
docs: document profile-scoped inline test configuration
schaable db8e50d
docs: document migrating Foundry profiles
schaable af8afd2
Potential fix for pull request finding
schaable 11ce089
apply review suggestions
schaable b41b3bf
apply review suggestions
schaable 6ba1b91
apply review suggestions
schaable 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
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
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
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,102 @@ | ||
| --- | ||
| title: Test Profiles | ||
| description: How to use Test Profiles in Hardhat 3 | ||
| sidebar: | ||
| label: Solidity Test Profiles | ||
| order: 5 | ||
| --- | ||
|
|
||
| import Run from "@hh/Run.astro"; | ||
|
|
||
| Test Profiles let you use different settings to run your Solidity tests. For example, you might use one Test Profile while iterating locally and another in CI, each with the number of fuzz runs that suits that workflow. | ||
|
|
||
| ## Configuring a Test Profile | ||
|
|
||
| To configure a Test Profile, use this extended version of the `test.solidity` settings in your config: | ||
|
|
||
| ```ts ins={8-15} | ||
| // hardhat.config.ts | ||
| import { defineConfig } from "hardhat/config"; | ||
|
|
||
| export default defineConfig({ | ||
| //... | ||
| test: { | ||
| solidity: { | ||
| profiles: { | ||
| default: { | ||
| fuzz: { runs: 256 }, | ||
| }, | ||
| ci: { | ||
| fuzz: { runs: 10_000 }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| Each Test Profile can use the full [Solidity tests configuration](/docs/reference/configuration#solidity-tests-configuration). | ||
|
|
||
| When using `profiles`, a `default` profile is always required. | ||
|
|
||
| Profile names can contain letters, numbers, underscores, and dashes. They can't be `fuzz`, `invariant`, `isolate`, `evmVersion`, or `allowInternalExpectRevert`, as those would be ambiguous with [inline configuration](/docs/guides/testing/inline-configuration) keys. | ||
|
|
||
| If you define your Solidity tests config without explicitly defining Test Profiles, you're actually configuring the default behavior. | ||
|
|
||
| ## Choosing a Test Profile | ||
|
|
||
| Use the `--test-profile` argument to choose which Test Profile to use when running your tests. | ||
|
|
||
| For example, to run your Solidity tests with the `ci` profile: | ||
|
|
||
| <Run command="hardhat test solidity --test-profile ci" /> | ||
|
|
||
| It also works on the `test` task, where it only affects the Solidity tests: | ||
|
|
||
| <Run command="hardhat test --test-profile ci" /> | ||
|
|
||
| Set the `HARDHAT_TEST_PROFILE` environment variable to select a profile: | ||
|
|
||
| <Run prefix="HARDHAT_TEST_PROFILE=ci" command="hardhat test" /> | ||
|
|
||
| If you provide both, the argument takes precedence. If you don't specify a profile, Hardhat uses `default`. | ||
|
|
||
| ## Sharing default values between Test Profiles | ||
|
|
||
| To use the same settings in several profiles, define them once in your config file and spread them into each profile: | ||
|
|
||
| ```ts ins={4-7,14-15} | ||
| // hardhat.config.ts | ||
| import { defineConfig } from "hardhat/config"; | ||
|
|
||
| const base = { | ||
| isolate: true, | ||
| fuzz: { runs: 256 }, | ||
| }; | ||
|
|
||
| export default defineConfig({ | ||
| //... | ||
| test: { | ||
| solidity: { | ||
| profiles: { | ||
| default: base, | ||
| ci: { ...base, fuzz: { runs: 10_000 } }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| Each Test Profile is resolved on its own, starting from Hardhat's defaults, the same way [Build Profiles](/docs/guides/writing-contracts/build-profiles) are. A profile that only sets `fuzz.runs` gets the default value for every other setting, not the value from `default`. | ||
|
|
||
| ## Test Profiles and Build Profiles | ||
|
|
||
| Test Profiles and [Build Profiles](/docs/guides/writing-contracts/build-profiles) are independent: Test Profiles only affect how your tests run, and Build Profiles only affect how your contracts are compiled. | ||
|
|
||
| Switching Test Profiles doesn't cause your contracts to be recompiled, so you can switch between profiles freely. If you want to change both profiles, you need to pass both arguments: | ||
|
|
||
| <Run command="hardhat test --build-profile production --test-profile ci" /> | ||
|
|
||
| ## Overriding settings for a single test | ||
|
|
||
| Test Profiles apply to your entire test suite. To override settings for a single test function, use [inline configuration](/docs/guides/testing/inline-configuration), which can also be scoped to a Test Profile. | ||
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
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.