-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2976 from NomicFoundation/francovictorio/hh-937/i…
…mprove-waffle-warning Improve waffle warning and migration guides
- Loading branch information
Showing
11 changed files
with
136 additions
and
98 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
--- | ||
"@nomicfoundation/hardhat-chai-matchers": patch | ||
"@nomiclabs/hardhat-waffle": patch | ||
--- | ||
|
||
Improved the warning shown when both `@nomicfoundation/hardhat-chai-matchers` and `@nomiclabs/hardhat-waffle` are used. |
This file contains 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 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
112 changes: 97 additions & 15 deletions
112
docs/src/content/hardhat-runner/docs/guides/migrating-from-hardhat-waffle.md
This file contains 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 |
---|---|---|
@@ -1,29 +1,111 @@ | ||
# Migrating away from hardhat-waffle | ||
|
||
Our recommended setup used to include [Waffle] using our [`hardhat-waffle`] plugin. | ||
In the past, our recommended setup included [Waffle], by using the [`hardhat-waffle`] plugin. | ||
|
||
We now recommend using our [Hardhat Chai Matchers] and [Hardhat Network Helpers] instead. | ||
However, we now recommend using [Hardhat Toolbox], a plugin that bundles a curated set of useful packages. This set includes [Hardhat Chai Matchers] and [Hardhat Network Helpers], which work as an improved replacement for `hardhat-waffle`. | ||
|
||
Migrating to these packages only takes a few minutes, as they were designed as a drop-in replacement. If you do so, you'll get more functionality, like support for Solidity custom errors and native `bigint` support, and a more reliable testing experience. | ||
Migrating to the Toolbox only takes a few minutes. If you do so, you'll get more functionality, like support for Solidity custom errors and native `bigint` support, and a more reliable testing experience. It will also make it easier for you to keep up to date with our recommended setup. | ||
|
||
To learn how to start using them, read [this guide](../../../hardhat-chai-matchers/docs/migrate-from-waffle.md). | ||
## Migrating to Hardhat Toolbox | ||
|
||
## Using the Hardhat Toolbox | ||
Follow these steps to migrate your project to Hardhat Toolbox. | ||
|
||
You can get our recommended setup by installing [`@nomicfoundation/hardhat-toolbox`], a single plugin that has everything you need. | ||
1. First you'll need to remove some packages from your project. | ||
|
||
When you use it, you'll be able to: | ||
::::tabsgroup{options="npm 7+,npm 6,yarn"} | ||
|
||
- Deploy and interact with your contracts using [ethers.js](https://docs.ethers.io/v5/) and the [`hardhat-ethers`](/hardhat-runner/plugins/nomiclabs-hardhat-ethers) plugin. | ||
- Test your contracts with [Mocha](https://mochajs.org/), [Chai](https://chaijs.com/) and our own [Hardhat Chai Matchers](/hardhat-chai-matchers) plugin. | ||
- Interact with Hardhat Network with our [Hardhat Network Helpers](/hardhat-network-helpers). | ||
- Verify the source code of your contracts with the [hardhat-etherscan](/hardhat-runner/plugins/nomiclabs-hardhat-etherscan) plugin. | ||
- Get metrics on the gas used by your contracts with the [hardhat-gas-reporter](https://github.com/cgewecke/hardhat-gas-reporter) plugin. | ||
- Measure your tests coverage with [solidity-coverage](https://github.com/sc-forks/solidity-coverage). | ||
- And, if you are using TypeScript, get type bindings for your contracts with [Typechain](https://github.com/dethcrypto/TypeChain/). | ||
:::tab{value="npm 7+"} | ||
|
||
``` | ||
npm uninstall @nomiclabs/hardhat-waffle ethereum-waffle @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v5 @ethersproject/abi @ethersproject/providers | ||
``` | ||
|
||
::: | ||
|
||
:::tab{value="npm 6"} | ||
|
||
``` | ||
npm uninstall @nomiclabs/hardhat-waffle ethereum-waffle @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v5 @ethersproject/abi @ethersproject/providers | ||
``` | ||
|
||
::: | ||
|
||
:::tab{value=yarn} | ||
|
||
``` | ||
yarn remove @nomiclabs/hardhat-waffle ethereum-waffle | ||
``` | ||
|
||
::: | ||
|
||
:::: | ||
|
||
2. Then you need to install the Toolbox. If you are using yarn or an old version of npm, you'll also have to install some other packages (the peer dependencies of the Toolbox). | ||
|
||
::::tabsgroup{options="npm 7+,npm 6,yarn"} | ||
|
||
:::tab{value="npm 7+"} | ||
|
||
``` | ||
npm install --save-dev @nomicfoundation/hardhat-toolbox | ||
``` | ||
|
||
::: | ||
|
||
:::tab{value="npm 6"} | ||
|
||
``` | ||
npm install --save-dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v5 @ethersproject/abi @ethersproject/providers | ||
``` | ||
|
||
::: | ||
|
||
:::tab{value="yarn"} | ||
|
||
``` | ||
yarn add --dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v5 @ethersproject/abi @ethersproject/providers | ||
``` | ||
|
||
::: | ||
|
||
:::: | ||
|
||
3. Finally, remove `hardhat-waffle` from your imported plugins and import the Toolbox instead: | ||
|
||
::::tabsgroup{options=TypeScript,JavaScript} | ||
|
||
:::tab{value=TypeScript} | ||
|
||
```diff | ||
- import "@nomiclabs/hardhat-waffle"; | ||
+ import "@nomicfoundation/hardhat-toolbox"; | ||
``` | ||
|
||
::: | ||
|
||
:::tab{value=JavaScript} | ||
|
||
```diff | ||
- require("@nomiclabs/hardhat-waffle"); | ||
+ require("@nomicfoundation/hardhat-toolbox"); | ||
``` | ||
|
||
::: | ||
|
||
:::: | ||
|
||
Adding the Toolbox will make many other imports redundant, so you can remove any of these if you want: | ||
|
||
- `@nomiclabs/hardhat-ethers` | ||
- `@nomiclabs/hardhat-etherscan` | ||
- `hardhat-gas-reporter` | ||
- `solidity-coverage` | ||
- `@typechain/hardhat` | ||
|
||
Check the [Hardhat Chai Matchers] and [Hardhat Network Helpers] docs to learn more about the functionality included in the Toolbox. | ||
|
||
[waffle]: https://getwaffle.io | ||
[`hardhat-waffle`]: ../../plugins/nomiclabs-hardhat-waffle | ||
[`@nomicfoundation/hardhat-toolbox`]: ../../plugins/nomicfoundation-hardhat-toolbox | ||
[hardhat chai matchers]: /hardhat-chai-matchers | ||
[hardhat network helpers]: /hardhat-network-helpers | ||
[hardhat toolbox]: /hardhat-runner/plugins/nomicfoundation-hardhat-toolbox |
This file contains 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 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
15 changes: 0 additions & 15 deletions
15
packages/hardhat-chai-matchers/src/internal/checkIfWaffleIsInstalled.ts
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
packages/hardhat-chai-matchers/src/internal/hardhatWaffleIncompatibilityCheck.ts
This file contains 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,11 @@ | ||
export function hardhatWaffleIncompatibilityCheck() { | ||
if ((global as any).__HARDHAT_WAFFLE_IS_LOADED === true) { | ||
throw new Error( | ||
`You are using both @nomicfoundation/hardhat-chai-matchers and @nomiclabs/hardhat-waffle. They don't work correctly together, so please make sure you only use one. | ||
We recommend you migrate to @nomicfoundation/hardhat-chai-matchers. Learn how to do it here: https://hardhat.org/migrate-from-waffle` | ||
); | ||
} | ||
|
||
(global as any).__HARDHAT_CHAI_MATCHERS_IS_LOADED = true; | ||
} |
This file contains 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
11 changes: 11 additions & 0 deletions
11
packages/hardhat-waffle/src/hardhatChaiMatchersIncompatibilityCheck.ts
This file contains 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,11 @@ | ||
export function hardhatChaiMatchersIncompatibilityCheck() { | ||
if ((global as any).__HARDHAT_CHAI_MATCHERS_IS_LOADED === true) { | ||
throw new Error( | ||
`You are using both @nomiclabs/hardhat-waffle and @nomicfoundation/hardhat-chai-matchers. They don't work correctly together, so please make sure you only use one. | ||
We recommend you migrate to @nomicfoundation/hardhat-chai-matchers. Learn how to do it here: https://hardhat.org/migrate-from-waffle` | ||
); | ||
} | ||
|
||
(global as any).__HARDHAT_WAFFLE_IS_LOADED = true; | ||
} |
This file contains 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