mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
command line args
This commit is contained in:
parent
d7de7333b0
commit
1f4b376674
|
@ -13,6 +13,7 @@ import { HardhatUserConfig } from "hardhat/config";
|
||||||
import { NetworkUserConfig } from "hardhat/types";
|
import { NetworkUserConfig } from "hardhat/types";
|
||||||
import { utils } from "ethers";
|
import { utils } from "ethers";
|
||||||
import Web3 from "web3";
|
import Web3 from "web3";
|
||||||
|
import "./scripts/tests/tests-run"
|
||||||
|
|
||||||
dotenvConfig({ path: resolve(__dirname, "./.env") });
|
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 POLYGONSCAN_API = process.env.POLYGON_API_KEY;
|
||||||
const ARBISCAN_API = process.env.ARBISCAN_API_KEY;
|
const ARBISCAN_API = process.env.ARBISCAN_API_KEY;
|
||||||
const SNOWTRACE_API = process.env.SNOWTRACE_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 =
|
const mnemonic =
|
||||||
process.env.MNEMONIC ??
|
process.env.MNEMONIC ??
|
||||||
"test test test test test test test test test test test junk";
|
"test test test test test test test test test test test junk";
|
||||||
|
|
||||||
const networkGasPriceConfig: Record<string, string> = {
|
const networkGasPriceConfig: Record<string, Number> = {
|
||||||
"mainnet": "160",
|
"mainnet": 160,
|
||||||
"polygon": "50",
|
"polygon": 50,
|
||||||
"avalanche": "50",
|
"avalanche": 25,
|
||||||
"arbitrum": "2"
|
"arbitrum":1,
|
||||||
|
"fantom": 1700,
|
||||||
|
"optimism": 0.001,
|
||||||
}
|
}
|
||||||
|
|
||||||
function createConfig(network: string) {
|
function createConfig(network: string) {
|
||||||
return {
|
return {
|
||||||
url: getNetworkUrl(network),
|
url: getNetworkUrl(network),
|
||||||
accounts: !!PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : { mnemonic },
|
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}`;
|
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
|
* @type import('hardhat/config').HardhatUserConfig
|
||||||
|
@ -123,7 +122,14 @@ const config: HardhatUserConfig = {
|
||||||
tests: "./test",
|
tests: "./test",
|
||||||
},
|
},
|
||||||
etherscan: {
|
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: {
|
typechain: {
|
||||||
outDir: "typechain",
|
outDir: "typechain",
|
||||||
|
|
43313
package-lock.json
generated
43313
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -12,7 +12,8 @@
|
||||||
"test:runner": "hardhat run scripts/tests/run-tests.ts",
|
"test:runner": "hardhat run scripts/tests/run-tests.ts",
|
||||||
"typechain": "hardhat typechain",
|
"typechain": "hardhat typechain",
|
||||||
"compile": "hardhat compile",
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -42,7 +43,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nomiclabs/hardhat-ethers": "^2.0.3",
|
"@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-waffle": "^2.0.1",
|
||||||
"@nomiclabs/hardhat-web3": "^2.0.0",
|
"@nomiclabs/hardhat-web3": "^2.0.0",
|
||||||
"@openzeppelin/test-helpers": "^0.5.15",
|
"@openzeppelin/test-helpers": "^0.5.15",
|
||||||
|
|
64
scripts/tests/tests-run.ts
Normal file
64
scripts/tests/tests-run.ts
Normal 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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user