Skip to content

Commit

Permalink
Merge pull request #21 from pradyuman-verma/standardize-test-runner
Browse files Browse the repository at this point in the history
fix: fixed test:runner for multiple blockchain
  • Loading branch information
KaymasJain committed Nov 5, 2021
2 parents 5c91521 + 7efaa9c commit d84e035
Show file tree
Hide file tree
Showing 7 changed files with 7,116 additions and 2,951 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALCHEMY_API_KEY=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
ALCHEMY_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MNEMONIC=here is where your twelve words mnemonic should be put my friend
29 changes: 22 additions & 7 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { resolve } from "path";
import { config as dotenvConfig } from "dotenv";
import { HardhatUserConfig } from "hardhat/config";
import { NetworkUserConfig } from "hardhat/types";
import Web3 from "web3";

dotenvConfig({ path: resolve(__dirname, "./.env") });

Expand All @@ -33,7 +34,7 @@ if (!mnemonic) {

const alchemyApiKey = process.env.ALCHEMY_API_KEY;
if (!alchemyApiKey) {
throw new Error("Please set your ALCHEMY_API_KEY in a .env file");
throw new Error("Please set your ALCHEMY_ETH_API_KEY in a .env file");
}

function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig {
Expand All @@ -50,6 +51,24 @@ function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig
};
}

function getNetworkUrl(networkType: string) {
//console.log(process.env);
if (networkType === "avalanche") return "https://api.avax.network/ext/bc/C/rpc";
else if (networkType === "polygon") return `https://polygon-mainnet.g.alchemy.com/v2/${alchemyApiKey}`;
else if (networkType === "arbitrum") return `https://arb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`;
else return `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`;
}

function getBlockNumber(networkType: string) {
let web3 = new Web3(new Web3.providers.HttpProvider(getNetworkUrl(networkType)));
let blockNumber;
web3.eth.getBlockNumber().then((x: any) => {
blockNumber = x;
});

return blockNumber;
}

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
gasReporter: {
Expand All @@ -65,12 +84,8 @@ const config: HardhatUserConfig = {
},
chainId: chainIds.hardhat,
forking: {
// Avalanche mainnet:
// url: "https://api.avax.network/ext/bc/C/rpc",

// Ethereum mainnet:
url: `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`,
//blockNumber: 12878959,
url: String(getNetworkUrl(String(process.env.networkType))),
blockNumber: getBlockNumber(String(process.env.networkType)),
},
},
goerli: createTestnetConfig("goerli"),
Expand Down
Loading

0 comments on commit d84e035

Please sign in to comment.