command line args

This commit is contained in:
pk1411 2022-03-14 14:01:54 +05:30
parent d7de7333b0
commit 1f4b376674
4 changed files with 5812 additions and 37602 deletions

View File

@ -13,6 +13,7 @@ import { HardhatUserConfig } from "hardhat/config";
import { NetworkUserConfig } from "hardhat/types";
import { utils } from "ethers";
import Web3 from "web3";
import "./scripts/tests/tests-run"
dotenvConfig({ path: resolve(__dirname, "./.env") });
@ -36,22 +37,26 @@ const ETHERSCAN_API = process.env.ETHERSCAN_API_KEY;
const POLYGONSCAN_API = process.env.POLYGON_API_KEY;
const ARBISCAN_API = process.env.ARBISCAN_API_KEY;
const SNOWTRACE_API = process.env.SNOWTRACE_API_KEY;
const OPTIMISM_API = process.env.OPTIMISM_API_KEY;
const FANTOM_API = process.env.FANTOM_API_KEY;
const mnemonic =
process.env.MNEMONIC ??
"test test test test test test test test test test test junk";
const networkGasPriceConfig: Record<string, string> = {
"mainnet": "160",
"polygon": "50",
"avalanche": "50",
"arbitrum": "2"
const networkGasPriceConfig: Record<string, Number> = {
"mainnet": 160,
"polygon": 50,
"avalanche": 25,
"arbitrum":1,
"fantom": 1700,
"optimism": 0.001,
}
function createConfig(network: string) {
return {
url: getNetworkUrl(network),
accounts: !!PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : { mnemonic },
// gasPrice: 1000000, // 0.0001 GWEI
gasPrice: Number(networkGasPriceConfig[network])*1e9,
};
}
@ -67,12 +72,6 @@ function getNetworkUrl(networkType: string) {
else return `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`;
}
function getScanApiKey(networkType: string) {
if (networkType === "avalanche") return SNOWTRACE_API;
else if (networkType === "polygon") return POLYGONSCAN_API;
else if (networkType === "arbitrum") return ARBISCAN_API;
else return ETHERSCAN_API;
}
/**
* @type import('hardhat/config').HardhatUserConfig
@ -123,7 +122,14 @@ const config: HardhatUserConfig = {
tests: "./test",
},
etherscan: {
apiKey: getScanApiKey(String(process.env.networkType)),
apiKey: {
mainnet: String(ETHERSCAN_API),
polygon: String(POLYGONSCAN_API),
arbitrumOne: String(ARBISCAN_API),
avalanche: String(SNOWTRACE_API),
optimisticEthereum: String(OPTIMISM_API),
opera: String(FANTOM_API),
}
},
typechain: {
outDir: "typechain",

43313
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,8 @@
"test:runner": "hardhat run scripts/tests/run-tests.ts",
"typechain": "hardhat typechain",
"compile": "hardhat compile",
"deploy:runner": "hardhat run scripts/deployment/deployConnectorsFromCmd.ts"
"deploy:runner": "hardhat run scripts/deployment/deployConnectorsFromCmd.ts",
"runner:tests": "hardhat run_tests_on"
},
"repository": {
"type": "git",
@ -42,7 +43,7 @@
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.3",
"@nomiclabs/hardhat-etherscan": "^2.1.8",
"@nomiclabs/hardhat-etherscan": "^3.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/test-helpers": "^0.5.15",

View File

@ -0,0 +1,64 @@
import inquirer from "inquirer";
import { promises as fs } from "fs";
import { join } from "path";
import { execScript } from "./command";
import { task } from "hardhat/config";
let start: number, end: number;
task("run_tests_on", "runs specified test on a specified chain")
.addPositionalParam("chain")
.addPositionalParam("test")
.setAction(async (taskArgs) => {
const chain = taskArgs.chain;
const test = taskArgs.test;
await testRunner(chain,test)
.then(() =>
console.log(
`🙌 finished the test runner, time taken ${(end - start) / 1000} sec`
)
)
.catch((err) => console.error("❌ failed due to error: ", err));
});
async function testRunner(chain: string, testName: string) {
const testsPath = join(__dirname, "../../test", chain);
await fs.access(testsPath);
const availableTests = await fs.readdir(testsPath);
if (availableTests.length === 0) {
throw new Error(`No tests available for ${chain}`);
}
start = Date.now();
let path: string;
if (testName === "all") {
for (let test of availableTests) {
path = join(testsPath, test);
path += "/*";
await execScript({
cmd: "npx",
args: ["hardhat", "test", path],
env: {
networkType: chain,
},
}).catch((err)=>console.log(`failed ${test}`))
}
} else {
path = join(testsPath, testName);
path += "/*";
await execScript({
cmd: "npx",
args: ["hardhat", "test", path],
env: {
networkType: chain,
},
});
}
end = Date.now();
}