fix: should be able to run tests without .env

This commit is contained in:
rymnc 2022-11-25 09:41:12 +05:30
parent 299f2b0f1b
commit 538783027d
No known key found for this signature in database
GPG Key ID: C740033EE3F41EBD
1 changed files with 13 additions and 16 deletions

View File

@ -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;