From 538783027dabe861a6e600911267f29dc5bfa90a Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Fri, 25 Nov 2022 09:41:12 +0530 Subject: [PATCH] fix: should be able to run tests without .env --- hardhat.config.ts | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index b0ef733..ded01cf 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -4,20 +4,22 @@ import { HardhatUserConfig, task } from "hardhat/config"; import "@nomiclabs/hardhat-waffle"; import "hardhat-gas-reporter"; import "solidity-coverage"; +import { NetworksUserConfig } from "hardhat/types"; dotenv.config(); const {GOERLI_URL,PRIVATE_KEY} = process.env; - -// This is a sample Hardhat task. To learn how to create your own go to -// https://hardhat.org/guides/create-task.html -task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { - const accounts = await hre.ethers.getSigners(); - - for (const account of accounts) { - console.log(account.address); - } -}); +const getNetworkConfig = (): NetworksUserConfig | undefined => { + if (GOERLI_URL && PRIVATE_KEY) { + return { + goerli: { + url: GOERLI_URL, + accounts: [PRIVATE_KEY], + } + }; + } + return undefined; +} // You need to export an object to set up your config // Go to https://hardhat.org/config/ to learn more @@ -30,12 +32,7 @@ const config: HardhatUserConfig = { version: "0.8.15" }], }, - networks: { - goerli: { - url: GOERLI_URL, - accounts: [`${PRIVATE_KEY}`] - } - } + networks: getNetworkConfig() }; export default config; \ No newline at end of file