Browse Source

refactor: migrate to hardhat-chai-matchers and hardhat-toolbox

* chore: resolve conflicts

* refactor: migrate to hardhat chai matchers with loadFixture from hardhat helpers

* refactor: update deps and use hardhat toolbox

* docs: remove waffle related stuff
Ahmed Ali 3 years ago
parent
commit
28c8b3159a
6 changed files with 144 additions and 1087 deletions
  1. 0 9
      README.md
  2. 1 5
      hardhat.config.ts
  3. 3 2
      package.json
  4. 20 6
      test/greeter/Greeter.ts
  5. 2 1
      test/types.ts
  6. 118 1064
      yarn.lock

+ 0 - 9
README.md

@@ -5,7 +5,6 @@ My favorite setup for writing Solidity smart contracts.
 - [Hardhat](https://github.com/nomiclabs/hardhat): compile and run the smart contracts on a local development network
 - [TypeChain](https://github.com/ethereum-ts/TypeChain): generate TypeScript types for smart contracts
 - [Ethers](https://github.com/ethers-io/ethers.js/): renowned Ethereum library and wallet implementation
-- [Waffle](https://github.com/EthWorks/Waffle): tooling for writing comprehensive smart contract tests
 - [Solhint](https://github.com/protofire/solhint): linter
 - [Solcover](https://github.com/sc-forks/solidity-coverage): code coverage
 - [Prettier Plugin Solidity](https://github.com/prettier-solidity/prettier-plugin-solidity): code formatter
@@ -101,14 +100,6 @@ $ yarn deploy --greeting "Bonjour, le monde!"
 
 If you use VSCode, you can get Solidity syntax highlighting via the [vscode-solidity](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity) extension.
 
-## Caveats
-
-### Ethers and Waffle
-
-If you can't get the [Waffle matchers](https://ethereum-waffle.readthedocs.io/en/latest/matchers.html) to work, try to
-make your `ethers` package version match the version used by the `@ethereum-waffle/chai` package. See
-[#111](https://github.com/paulrberg/solidity-template/issues/111) for more details.
-
 ## License
 
 [Unlicense](./LICENSE.md)

+ 1 - 5
hardhat.config.ts

@@ -1,12 +1,8 @@
-import "@nomiclabs/hardhat-etherscan";
-import "@nomiclabs/hardhat-waffle";
-import "@typechain/hardhat";
+import "@nomicfoundation/hardhat-toolbox";
 import { config as dotenvConfig } from "dotenv";
-import "hardhat-gas-reporter";
 import { HardhatUserConfig } from "hardhat/config";
 import { NetworkUserConfig } from "hardhat/types";
 import { resolve } from "path";
-import "solidity-coverage";
 
 import "./tasks/accounts";
 import "./tasks/deploy";

+ 3 - 2
package.json

@@ -14,9 +14,11 @@
     "@ethersproject/bignumber": "^5.6.2",
     "@ethersproject/bytes": "^5.6.1",
     "@ethersproject/providers": "^5.6.8",
+    "@nomicfoundation/hardhat-chai-matchers": "^1.0.1",
+    "@nomicfoundation/hardhat-network-helpers": "^1.0.2",
+    "@nomicfoundation/hardhat-toolbox": "^1.0.1",
     "@nomiclabs/hardhat-ethers": "^2.1.0",
     "@nomiclabs/hardhat-etherscan": "^3.1.0",
-    "@nomiclabs/hardhat-waffle": "^2.0.3",
     "@trivago/prettier-plugin-sort-imports": "^3.2.0",
     "@typechain/ethers-v5": "^10.1.0",
     "@typechain/hardhat": "^6.1.2",
@@ -33,7 +35,6 @@
     "dotenv": "^16.0.1",
     "eslint": "^8.19.0",
     "eslint-config-prettier": "^8.5.0",
-    "ethereum-waffle": "^3.4.4",
     "ethers": "^5.6.9",
     "fs-extra": "^10.1.0",
     "hardhat": "^2.10.0",

+ 20 - 6
test/greeter/Greeter.ts

@@ -1,24 +1,38 @@
+import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
 import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signer-with-address";
-import { artifacts, ethers, waffle } from "hardhat";
-import type { Artifact } from "hardhat/types";
+import { ethers } from "hardhat";
 
 import type { Greeter } from "../../src/types/Greeter";
-import { Signers } from "../types";
+import type { Greeter__factory } from "../../src/types/factories/Greeter__factory";
+import type { Signers } from "../types";
 import { shouldBehaveLikeGreeter } from "./Greeter.behavior";
 
 describe("Unit tests", function () {
+  async function deployGreeterFixture(): Promise<{ greeter: Greeter }> {
+    const signers: SignerWithAddress[] = await ethers.getSigners();
+    const admin: SignerWithAddress = signers[0];
+
+    const greeting: string = "Hello, world!";
+    const greeterFactory: Greeter__factory = <Greeter__factory>await ethers.getContractFactory("Greeter");
+    const greeter: Greeter = <Greeter>await greeterFactory.connect(admin).deploy(greeting);
+    await greeter.deployed();
+
+    return { greeter };
+  }
+
   before(async function () {
     this.signers = {} as Signers;
 
     const signers: SignerWithAddress[] = await ethers.getSigners();
     this.signers.admin = signers[0];
+
+    this.loadFixture = loadFixture;
   });
 
   describe("Greeter", function () {
     beforeEach(async function () {
-      const greeting: string = "Hello, world!";
-      const greeterArtifact: Artifact = await artifacts.readArtifact("Greeter");
-      this.greeter = <Greeter>await waffle.deployContract(this.signers.admin, greeterArtifact, [greeting]);
+      const { greeter } = await this.loadFixture(deployGreeterFixture);
+      this.greeter = greeter;
     });
 
     shouldBehaveLikeGreeter();

+ 2 - 1
test/types.ts

@@ -1,8 +1,9 @@
 import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signer-with-address";
-import type { Fixture } from "ethereum-waffle";
 
 import type { Greeter } from "../src/types/Greeter";
 
+type Fixture<T> = () => Promise<T>;
+
 declare module "mocha" {
   export interface Context {
     greeter: Greeter;

File diff suppressed because it is too large
+ 118 - 1064
yarn.lock


Some files were not shown because too many files changed in this diff