From 0cf7d01e810c50ee455b4355519328904528aeb9 Mon Sep 17 00:00:00 2001 From: pk1411 Date: Sat, 5 Mar 2022 13:03:32 +0530 Subject: [PATCH] fixes --- hardhat.config.ts | 2 +- package.json | 5 +-- scripts/tests/run-tests.ts | 45 ++++++++++++++------------ scripts/tests/tests-run.ts | 65 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 scripts/tests/tests-run.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index 0b5cbbcc..f353a97c 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -13,7 +13,7 @@ import { HardhatUserConfig } from "hardhat/config"; import { NetworkUserConfig } from "hardhat/types"; import { utils } from "ethers"; import Web3 from "web3"; -import "./scripts/tests/run-tests" +import "./scripts/tests/tests-run" dotenvConfig({ path: resolve(__dirname, "./.env") }); diff --git a/package.json b/package.json index 3d1ad506..bbc80168 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,11 @@ "check": "ts-node status-checks/huskyCheck.ts", "check-husky": "ts-node status-checks/huskyCheck.ts", "deploy": "ts-node scripts/deployConnectorsFromCmd.ts", - "test:runner": "hardhat run_tests_on", + "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", diff --git a/scripts/tests/run-tests.ts b/scripts/tests/run-tests.ts index 50a3039b..d0dcd3be 100644 --- a/scripts/tests/run-tests.ts +++ b/scripts/tests/run-tests.ts @@ -4,29 +4,17 @@ 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) { - +async function testRunner() { + const { chain } = await inquirer.prompt([ + { + name: "chain", + message: "What chain do you want to run tests on?", + type: "list", + choices: ["mainnet", "polygon", "avalanche", "arbitrum"], + }, + ]); const testsPath = join(__dirname, "../../test", chain); await fs.access(testsPath); const availableTests = await fs.readdir(testsPath); @@ -34,6 +22,14 @@ async function testRunner(chain: string, testName: string) { throw new Error(`No tests available for ${chain}`); } + const { testName } = await inquirer.prompt([ + { + name: "testName", + message: "For which connector you want to run the tests?", + type: "list", + choices: ["all", ...availableTests], + }, + ]); start = Date.now(); let path: string; if (testName === "all") { @@ -63,3 +59,10 @@ async function testRunner(chain: string, testName: string) { end = Date.now(); } +testRunner() + .then(() => + console.log( + `🙌 finished the test runner, time taken ${(end - start) / 1000} sec` + ) + ) + .catch((err) => console.error("❌ failed due to error: ", err)); \ No newline at end of file diff --git a/scripts/tests/tests-run.ts b/scripts/tests/tests-run.ts new file mode 100644 index 00000000..fef221e5 --- /dev/null +++ b/scripts/tests/tests-run.ts @@ -0,0 +1,65 @@ +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(); +} +