This commit is contained in:
pk1411 2022-03-05 13:03:32 +05:30
parent c7f9181296
commit 0cf7d01e81
4 changed files with 93 additions and 24 deletions

View File

@ -13,7 +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/run-tests" import "./scripts/tests/tests-run"
dotenvConfig({ path: resolve(__dirname, "./.env") }); dotenvConfig({ path: resolve(__dirname, "./.env") });

View File

@ -9,10 +9,11 @@
"check": "ts-node status-checks/huskyCheck.ts", "check": "ts-node status-checks/huskyCheck.ts",
"check-husky": "ts-node status-checks/huskyCheck.ts", "check-husky": "ts-node status-checks/huskyCheck.ts",
"deploy": "ts-node scripts/deployConnectorsFromCmd.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", "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",

View File

@ -4,29 +4,17 @@ import { promises as fs } from "fs";
import { join } from "path"; import { join } from "path";
import { execScript } from "./command"; import { execScript } from "./command";
import { task } from "hardhat/config";
let start: number, end: number; let start: number, end: number;
task("run_tests_on", "runs specified test on a specified chain") async function testRunner() {
.addPositionalParam("chain") const { chain } = await inquirer.prompt([
.addPositionalParam("test") {
.setAction(async (taskArgs) => { name: "chain",
const chain = taskArgs.chain; message: "What chain do you want to run tests on?",
const test = taskArgs.test; type: "list",
await testRunner(chain,test) choices: ["mainnet", "polygon", "avalanche", "arbitrum"],
.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); const testsPath = join(__dirname, "../../test", chain);
await fs.access(testsPath); await fs.access(testsPath);
const availableTests = await fs.readdir(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}`); 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(); start = Date.now();
let path: string; let path: string;
if (testName === "all") { if (testName === "all") {
@ -63,3 +59,10 @@ async function testRunner(chain: string, testName: string) {
end = Date.now(); 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));

View File

@ -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();
}