mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	Merge pull request #200 from Instadapp/add-test-script
Added test runner script
This commit is contained in:
		
						commit
						9e0768ce98
					
				| 
						 | 
				
			
			@ -6,7 +6,6 @@ import "@nomiclabs/hardhat-web3";
 | 
			
		|||
import "hardhat-deploy";
 | 
			
		||||
import "hardhat-deploy-ethers";
 | 
			
		||||
import "@typechain/hardhat";
 | 
			
		||||
 | 
			
		||||
import { resolve } from "path";
 | 
			
		||||
import { config as dotenvConfig } from "dotenv";
 | 
			
		||||
import { HardhatUserConfig } from "hardhat/config";
 | 
			
		||||
| 
						 | 
				
			
			@ -15,6 +14,7 @@ import { utils } from "ethers";
 | 
			
		|||
import Web3 from "web3";
 | 
			
		||||
import { network } from "hardhat";
 | 
			
		||||
import bigNumber from "bignumber.js";
 | 
			
		||||
import "./scripts/tests/run_test_through_cmd";
 | 
			
		||||
 | 
			
		||||
dotenvConfig({ path: resolve(__dirname, "./.env") });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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",
 | 
			
		||||
    "tests": "hardhat run_tests"
 | 
			
		||||
  },
 | 
			
		||||
  "repository": {
 | 
			
		||||
    "type": "git",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										63
									
								
								scripts/tests/run_test_through_cmd.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								scripts/tests/run_test_through_cmd.ts
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,63 @@
 | 
			
		|||
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", "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