瀏覽代碼

merge: pull request #6 from TomAFrench/hardhat-migration

feat: hardhat migration
Tom French 4 年之前
父節點
當前提交
877b72a5d2
共有 14 個文件被更改,包括 253 次插入517 次删除
  1. 4 13
      @types/augmentations.d.ts
  2. 0 3
      @types/buidler-env.d.ts
  3. 3 3
      README.md
  4. 3 2
      contracts/Greeter.sol
  5. 25 17
      hardhat.config.ts
  6. 14 13
      package.json
  7. 4 4
      scripts/deploy.ts
  8. 3 3
      tasks/accounts.ts
  9. 4 4
      tasks/clean.ts
  10. 0 1
      tasks/task-names.ts
  11. 0 33
      tasks/typechain.ts
  12. 2 2
      test/Greeter.ts
  13. 1 1
      tsconfig.json
  14. 190 418
      yarn.lock

+ 4 - 13
@types/augmentations.d.ts

@@ -1,21 +1,12 @@
 import { Greeter } from "../typechain/Greeter";
 
-export interface TypechainConfig {
-  outDir?: string;
-  target?: "ethers-v4" | "ethers-v5" | "truffle-v4" | "truffle-v5" | "web3-v1";
-}
-
-declare module "@nomiclabs/buidler/types" {
-  interface BuidlerConfig {
-    typechain?: TypechainConfig;
-  }
-
+declare module "hardhat/types" {
   interface ProjectPaths {
-    coverage: string;
-    coverageJson: string;
-    typechain: string;
+    // coverage: string;
+    // coverageJson: string;
   }
 }
+
 declare module "mocha" {
   export interface Context {
     greeter: Greeter;

+ 0 - 3
@types/buidler-env.d.ts

@@ -1,3 +0,0 @@
-/// <reference types="@nomiclabs/buidler/types" />
-/// <reference types="@nomiclabs/buidler-ethers/src/type-extensions" />
-/// <reference types="@nomiclabs/buidler-waffle/src/type-extensions" />

+ 3 - 3
README.md

@@ -2,7 +2,7 @@
 
 My favourite setup for writing Solidity smart contracts.
 
-- [Buidler](https://github.com/nomiclabs/buidler): compile and run the smart contracts on a local development network
+- [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
@@ -25,7 +25,7 @@ $ yarn install
 
 ### Compile
 
-Compile the smart contracts with Buidler:
+Compile the smart contracts with Hardhat:
 
 ```sh
 $ yarn compile
@@ -73,7 +73,7 @@ $ yarn coverage
 
 ### Clean
 
-Delete the smart contract artifacts, the coverage reports and the Buidler cache:
+Delete the smart contract artifacts, the coverage reports and the Hardhat cache:
 
 ```sh
 $ yarn clean

+ 3 - 2
contracts/Greeter.sol

@@ -1,7 +1,8 @@
-/* SPDX-License-Identifier: MIT */
+// SPDX-License-Identifier: MIT
+
 pragma solidity ^0.7.0;
 
-import "@nomiclabs/buidler/console.sol";
+import "hardhat/console.sol";
 
 contract Greeter {
     string public greeting;

+ 25 - 17
buidler.config.ts → hardhat.config.ts

@@ -2,20 +2,22 @@ import { config as dotenvConfig } from "dotenv";
 import { resolve } from "path";
 dotenvConfig({ path: resolve(__dirname, "./.env") });
 
-import { BuidlerConfig, usePlugin } from "@nomiclabs/buidler/config";
-import { HDAccountsConfig } from "@nomiclabs/buidler/types";
+import { HardhatNetworkAccountsUserConfig } from "hardhat/types";
+import { HardhatUserConfig } from "hardhat/config";
 import "./tasks/accounts";
 import "./tasks/clean";
-import "./tasks/typechain";
 
-usePlugin("@nomiclabs/buidler-waffle");
-usePlugin("solidity-coverage");
+import "@nomiclabs/hardhat-waffle";
+import "hardhat-typechain";
+import "solidity-coverage";
 
 /**
  * @dev You must have a `.env` file. Follow the example in `.env.example`.
  * @param {string} network The name of the testnet
  */
-function createNetworkConfig(network?: string): { accounts: HDAccountsConfig; url: string | undefined } {
+function createNetworkConfig(
+  network?: string,
+): { accounts: HardhatNetworkAccountsUserConfig; url: string | undefined } {
   if (!process.env.MNEMONIC) {
     throw new Error("Please set your MNEMONIC in a .env file");
   }
@@ -35,14 +37,14 @@ function createNetworkConfig(network?: string): { accounts: HDAccountsConfig; ur
   };
 }
 
-const config: BuidlerConfig = {
-  defaultNetwork: "buidlerevm",
+const config: HardhatUserConfig = {
+  defaultNetwork: "hardhat",
   mocha: {
     /* Without this property set, the "setTimeout" from the Greeter.js file wouldn't work. */
     delay: true,
   },
   networks: {
-    buidlerevm: {
+    hardhat: {
       chainId: 31337,
     },
     coverage: {
@@ -68,23 +70,29 @@ const config: BuidlerConfig = {
   paths: {
     artifacts: "./artifacts",
     cache: "./cache",
-    coverage: "./coverage",
-    coverageJson: "./coverage.json",
+    // coverage: "./coverage",
+    // coverageJson: "./coverage.json",
     sources: "./contracts",
     tests: "./test",
   },
-  solc: {
-    /* https://buidler.dev/buidler-evm/#solidity-optimizer-support */
-    optimizer: {
-      enabled: true,
-      runs: 200,
-    },
+  solidity: {
     version: "0.7.4",
+    /* https://hardhat.org/hardhat-network/#solidity-optimizer-support */
+    settings: {
+      optimizer: {
+        enabled: true,
+        runs: 200,
+      },
+    },
   },
   typechain: {
     outDir: "typechain",
     target: "ethers-v5",
   },
+  spdxLicenseIdentifier: {
+    overwrite: false,
+    runOnCompile: true,
+  },
 };
 
 export default config;

+ 14 - 13
package.json

@@ -11,10 +11,9 @@
     "@commitlint/config-conventional": "^9.1.2",
     "@ethersproject/abstract-signer": "^5.0.6",
     "@ethersproject/bignumber": "^5.0.8",
-    "@nomiclabs/buidler": "^1.4.7",
-    "@nomiclabs/buidler-ethers": "^2.0.2",
-    "@nomiclabs/buidler-waffle": "^2.1.0",
-    "@typechain/ethers-v5": "^1.0.0",
+    "@nomiclabs/hardhat-ethers": "^2.0.0",
+    "@nomiclabs/hardhat-waffle": "^2.0.0",
+    "@typechain/ethers-v5": "^2.0.0",
     "@types/chai": "^4.2.13",
     "@types/fs-extra": "^9.0.1",
     "@types/mocha": "^7.0.2",
@@ -30,6 +29,8 @@
     "ethereum-waffle": "^3.2.0",
     "ethers": "^5.0.17",
     "fs-extra": "^9.0.1",
+    "hardhat": "^2.0.2",
+    "hardhat-typechain": "^0.3.3",
     "husky": "^4.3.0",
     "mocha": "^8.1.3",
     "prettier": "^2.1.2",
@@ -38,10 +39,10 @@
     "solc": "0.7.4",
     "solhint": "^3.2.1",
     "solhint-plugin-prettier": "^0.0.5",
-    "solidity-coverage": "^0.7.11",
-    "ts-generator": "^0.0.8",
+    "solidity-coverage": "^0.7.12",
+    "ts-generator": "^0.1.1",
     "ts-node": "^8.10.2",
-    "typechain": "^2.0.1",
+    "typechain": "^3.0.0",
     "typescript": "^3.9.7"
   },
   "files": [
@@ -58,16 +59,16 @@
     "access": "public"
   },
   "scripts": {
-    "clean": "buidler clean",
+    "clean": "hardhat clean",
     "commit": "git-cz",
-    "compile": "buidler compile",
-    "coverage": "buidler coverage --solcoverjs ./.solcover.js --network coverage --temp artifacts --testfiles \"./test/**/*.ts\"",
-    "lint": "yarn lint:sol && yarn run lint:ts && yarn run prettier:list-different",
+    "compile": "hardhat compile",
+    "coverage": "hardhat coverage --solcoverjs ./.solcover.js --network coverage --temp artifacts --testfiles \"./test/**/*.ts\"",
+    "lint": "yarn run lint:sol && yarn run lint:ts && yarn run prettier:list-different",
     "lint:sol": "solhint --config ./.solhint.json --max-warnings 0 \"contracts/**/*.sol\"",
     "lint:ts": "eslint --config ./.eslintrc.yaml --ignore-path ./.eslintignore --ext .js,.ts .",
     "prettier": "prettier --config .prettierrc --write \"**/*.{js,json,md,sol,ts}\"",
     "prettier:list-different": "prettier --config .prettierrc --list-different \"**/*.{js,json,md,sol,ts}\"",
-    "test": "buidler test",
-    "typechain": "buidler typechain"
+    "test": "hardhat test",
+    "typechain": "hardhat typechain"
   }
 }

+ 4 - 4
scripts/deploy.ts

@@ -1,12 +1,12 @@
-// We require the Buidler Runtime Environment explicitly here. This is optional
+// We require the Hardhat Runtime Environment explicitly here. This is optional
 // but useful for running the script in a standalone fashion through `node <script>`.
-// When running the script with `buidler run <script>` you'll find the Buidler
+// When running the script with `hardhat run <script>` you'll find the Hardhat
 // Runtime Environment's members available in the global scope.
-import { ethers } from "@nomiclabs/buidler";
+import { ethers } from "hardhat";
 import { Contract, ContractFactory } from "ethers";
 
 async function main(): Promise<void> {
-  // Buidler always runs the compile task when running scripts through it.
+  // Hardhat always runs the compile task when running scripts through it.
   // If this runs in a standalone fashion you may want to call compile manually
   // to make sure everything is compiled
   // await run("compile");

+ 3 - 3
tasks/accounts.ts

@@ -1,10 +1,10 @@
 import { Signer } from "@ethersproject/abstract-signer";
-import { task } from "@nomiclabs/buidler/config";
+import { task } from "hardhat/config";
 
 import { TASK_ACCOUNTS } from "./task-names";
 
-task(TASK_ACCOUNTS, "Prints the list of accounts", async (_taskArgs, bre) => {
-  const accounts: Signer[] = await bre.ethers.getSigners();
+task(TASK_ACCOUNTS, "Prints the list of accounts", async (_taskArgs, hre) => {
+  const accounts: Signer[] = await hre.ethers.getSigners();
 
   for (const account of accounts) {
     console.log(await account.getAddress());

+ 4 - 4
tasks/clean.ts

@@ -1,10 +1,10 @@
 import fsExtra from "fs-extra";
-import { TASK_CLEAN } from "@nomiclabs/buidler/builtin-tasks/task-names";
-import { task } from "@nomiclabs/buidler/config";
+import { TASK_CLEAN } from "hardhat/builtin-tasks/task-names";
+import { task } from "hardhat/config";
 
 task(TASK_CLEAN, "Overrides the standard clean task", async function (_taskArgs, { config }, runSuper) {
-  await fsExtra.remove(config.paths.coverage);
-  await fsExtra.remove(config.paths.coverageJson);
+  // await fsExtra.remove(config.paths.coverage);
+  // await fsExtra.remove(config.paths.coverageJson);
   if (config.typechain?.outDir) {
     await fsExtra.remove(config.typechain.outDir);
   }

+ 0 - 1
tasks/task-names.ts

@@ -1,2 +1 @@
 export const TASK_ACCOUNTS: string = "accounts";
-export const TASK_TYPECHAIN: string = "typechain";

+ 0 - 33
tasks/typechain.ts

@@ -1,33 +0,0 @@
-import { TASK_COMPILE } from "@nomiclabs/buidler/builtin-tasks/task-names";
-import { TypeChain } from "typechain/dist/TypeChain";
-import { task } from "@nomiclabs/buidler/config";
-import { tsGenerator } from "ts-generator";
-
-import { TASK_TYPECHAIN } from "./task-names";
-
-task(TASK_TYPECHAIN, "Generate TypeChain typings for compiled contracts", async function (_taskArgs, { config, run }) {
-  if (!config.typechain || !config.typechain?.outDir || !config.typechain?.target) {
-    throw new Error("Invalid TypeChain configuration. Please provide it via buidler.config.ts");
-  }
-
-  await run(TASK_COMPILE);
-
-  console.log(
-    `Creating TypeChain artifacts in directory ${config.typechain.outDir} for target ${config.typechain.target}`,
-  );
-
-  const cwd: string = process.cwd();
-  await tsGenerator(
-    { cwd },
-    new TypeChain({
-      cwd,
-      rawConfig: {
-        files: config.paths.artifacts + "/*.json",
-        outDir: config.typechain.outDir,
-        target: config.typechain.target,
-      },
-    }),
-  );
-
-  console.log(`Successfully generated TypeChain artifacts!`);
-});

+ 2 - 2
test/Greeter.ts

@@ -1,7 +1,7 @@
 import { Signer } from "@ethersproject/abstract-signer";
-import { ethers, waffle } from "@nomiclabs/buidler";
+import { ethers, waffle } from "hardhat";
 
-import GreeterArtifact from "../artifacts/Greeter.json";
+import GreeterArtifact from "../artifacts/contracts/Greeter.sol/Greeter.json";
 
 import { Greeter } from "../typechain/Greeter";
 import { shouldBehaveLikeGreeter } from "./Greeter.behavior";

+ 1 - 1
tsconfig.json

@@ -21,6 +21,6 @@
     "tasks/**/*",
     "test/**/*",
     "typechain/**/*",
-    "buidler.config.ts"
+    "hardhat.config.ts"
   ]
 }

文件差異過大導致無法顯示
+ 190 - 418
yarn.lock


部分文件因文件數量過多而無法顯示