浏览代码

modify docs and re-add env variable for test scenario

Christopher Dedominici 1 年之前
父节点
当前提交
ca72766786
共有 4 个文件被更改,包括 23 次插入22 次删除
  1. 7 7
      .github/workflows/ci.yml
  2. 9 14
      README.md
  3. 6 1
      hardhat.config.ts
  4. 1 0
      package.json

+ 7 - 7
.github/workflows/ci.yml

@@ -4,14 +4,14 @@ name: "CI"
 # https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions
 
 env:
-  HARDHAT_VAR_INFURA_API_KEY: ${{ secrets.InfuraApiKey }}
   HARDHAT_VAR_MNEMONIC: ${{ secrets.Mnemonic }}
-  HARDHAT_VAR_ARBISCAN_API_KEY: ${{ secrets.ArbiscanApiKey }}
-  HARDHAT_VAR_BSCSCAN_API_KEY: ${{ secrets.BscscanApiKey }}
-  HARDHAT_VAR_ETHERSCAN_API_KEY: ${{ secrets.EtherscanApiKey }}
-  HARDHAT_VAR_OPTIMISM_API_KEY: ${{ secrets.OptimismApiKey }}
-  HARDHAT_VAR_POLYGONSCAN_API_KEY: ${{ secrets.PolygonscanApiKey }}
-  HARDHAT_VAR_SNOWTRACE_API_KEY: ${{ secrets.SnowtraceApiKey }}
+  # HARDHAT_VAR_INFURA_API_KEY: ${{ secrets.InfuraApiKey }}
+  # HARDHAT_VAR_ARBISCAN_API_KEY: ${{ secrets.ArbiscanApiKey }}
+  # HARDHAT_VAR_BSCSCAN_API_KEY: ${{ secrets.BscscanApiKey }}
+  # HARDHAT_VAR_ETHERSCAN_API_KEY: ${{ secrets.EtherscanApiKey }}
+  # HARDHAT_VAR_OPTIMISM_API_KEY: ${{ secrets.OptimismApiKey }}
+  # HARDHAT_VAR_POLYGONSCAN_API_KEY: ${{ secrets.PolygonscanApiKey }}
+  # HARDHAT_VAR_SNOWTRACE_API_KEY: ${{ secrets.SnowtraceApiKey }}
 
 on:
   workflow_dispatch:

+ 9 - 14
README.md

@@ -72,19 +72,17 @@ First, you need to install the dependencies:
 $ pnpm install
 ```
 
-Then, you need to set up all the required configuration variables and, if necessary, the optional ones. To assist with
-the setup process, run `npx hardhat vars setup`. For example, to set a BIP-39 compatible mnemonic variable, execute
-`npx hardhat vars set MNEMONIC`. If you do not already have a mnemonic, you can generate one using this
-[website](https://iancoleman.io/bip39/).
-
-Example:
+Then, you need to set up all the required
+[Hardhat Configuration Variables](https://hardhat.org/hardhat-runner/docs/guides/configuration-variables) and, if
+necessary, the optional ones. To assist with the setup process, run `npx hardhat vars setup`. For example, to set a
+BIP-39 compatible mnemonic variable, execute:
 
 ```sh
-npx hardhat vars set MNEMONIC "here is where your twelve words mnemonic should be put my friend"
+$ npx hardhat vars set MNEMONIC
+? Enter value: ‣ "here is where your twelve words mnemonic should be put my friend"
 ```
 
-For more info on how to set the `Hardhat Configuration Variables` visit the docs
-[here](https://hardhat.org/hardhat-runner/docs/guides/configuration-variables).
+If you do not already have a mnemonic, you can generate one using this [website](https://iancoleman.io/bip39/).
 
 ### Compile
 
@@ -136,15 +134,12 @@ $ pnpm coverage
 
 ### Report Gas
 
-See the gas usage per unit test and average gas per method call by providing the optional configuration variable
-`REPORT_GAS`:
+See the gas usage per unit test and average gas per method call:
 
 ```sh
-$ HARDHAT_VAR_REPORT_GAS=true pnpm test
+$ REPORT_GAS=true pnpm test
 ```
 
-The prefix `HARDHAT_VAR_` is needed to temporarily set a Hardhat Configuration Variable via ENV variables.
-
 ### Clean
 
 Delete the smart contract artifacts, the coverage reports and the Hardhat cache:

+ 6 - 1
hardhat.config.ts

@@ -1,13 +1,18 @@
 import "@nomicfoundation/hardhat-toolbox";
+import { config as dotenvConfig } from "dotenv";
 import "hardhat-deploy";
 import type { HardhatUserConfig } from "hardhat/config";
 import { vars } from "hardhat/config";
 import type { NetworkUserConfig } from "hardhat/types";
+import { resolve } from "path";
 
 import "./tasks/accounts";
 import "./tasks/greet";
 import "./tasks/taskDeploy";
 
+const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || "./.env";
+dotenvConfig({ path: resolve(__dirname, dotenvConfigPath) });
+
 // Run 'npx hardhat vars setup' to see the list of variables that need to be set
 
 const mnemonic: string = vars.get("MNEMONIC");
@@ -68,7 +73,7 @@ const config: HardhatUserConfig = {
   },
   gasReporter: {
     currency: "USD",
-    enabled: vars.has("REPORT_GAS"),
+    enabled: process.env.REPORT_GAS ? true : false,
     excludeContracts: [],
     src: "./contracts",
   },

+ 1 - 0
package.json

@@ -23,6 +23,7 @@
     "@typescript-eslint/parser": "^5.44.0",
     "chai": "^4.3.7",
     "cross-env": "^7.0.3",
+    "dotenv": "^16.0.3",
     "eslint": "^8.28.0",
     "eslint-config-prettier": "^8.5.0",
     "ethers": "^6.4.0",