Skip to content

Commit

Permalink
Reorganize tests (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Feb 11, 2024
1 parent 373412d commit 732cf8f
Show file tree
Hide file tree
Showing 54 changed files with 95 additions and 213 deletions.
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ typings/
.next

# hardhat-project
test/hardhat-truffle-project/artifacts
test/hardhat-truffle-project/cache
test/hardhat-ethers-project/artifacts
test/hardhat-ethers-project/cache
test/hardhat-waffle-project/artifacts
test/hardhat-waffle-project/cache
test/hardhat-forked-project/artifacts
test/hardhat-forked-project/cache
test/projects/hardhat-truffle-project/artifacts
test/projects/hardhat-truffle-project/cache
test/projects/hardhat-ethers-project/artifacts
test/projects/hardhat-ethers-project/cache
test/projects/hardhat-waffle-project/artifacts
test/projects/hardhat-waffle-project/cache
test/projects/hardhat-forked-project/artifacts
test/projects/hardhat-forked-project/cache
dist/

7 changes: 7 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require" : [
"dotenv/config",
"ts-node/register",
"source-map-support/register"
]
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-truffle5": "^2.0.0",
"@nomiclabs/hardhat-truffle5": "^2.0.7",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@types/chai": "^4.2.14",
Expand All @@ -43,7 +43,6 @@
"dotenv": "^6.2.0",
"ethereum-waffle": "^3.2.1",
"ethers": "^5.0.0",
"ganache-cli": "^6.4.3",
"hardhat": "^2.19.4",
"mocha": "7",
"prettier": "^1.17.0",
Expand Down
66 changes: 25 additions & 41 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,37 @@ set -o errexit
trap cleanup EXIT

cleanup() {
if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then
echo "Killing ganache."
kill -9 $ganache_pid
if [ -n "$hardhat_node_pid" ] && ps -p $hardhat_node_pid > /dev/null; then
echo "Killing Hardhat Node."
kill -9 $hardhat_node_pid
fi

if [ -n "$hardhatevm_pid" ] && ps -p $hardhatevm_pid > /dev/null; then
echo "Killing hardhatevm."
kill -9 $hardhatevm_pid
fi
}

start_ganache() {
echo "Launching ganache..."
node_modules/.bin/ganache-cli > /dev/null &
ganache_pid=$!
sleep 4
}

start_hardhatevm() {
echo "Launching hardhatevm..."
start_hardhat_node() {
echo "Launching Hardhat Node..."
node_modules/.bin/hardhat node > /dev/null &
hardhatevm_pid=$!
hardhat_node_pid=$!
sleep 4
}

# Merge gasRerpoterOutput.json files task
npx mocha test/merge.ts

# Truffle + HardhatEVM
npx mocha test/truffle.ts --timeout 100000 --exit

# Truffle + HardhatEVM + misc reporterOptions
npx mocha test/truffle.options.ts --timeout 100000 --exit

# Ethers + HardhatEVM
npx mocha test/ethers.ts --timeout 100000 --exit

# Waffle + HardhatEVM
npx mocha test/waffle.ts --timeout 100000 --exit

# Forked Network + HardhatEVM
npx mocha test/forked.ts --timeout 100000 --exit

# Ethers + Hardhat Node
start_hardhatevm
npx mocha test/hardhatevm.node.ts --timeout 100000 --exit
########
# Tasks
########
npx mocha test/tasks/merge.ts

################################
# Hardhat EVM (Default Network)
################################
npx mocha test/integration/truffle.ts --timeout 100000 --exit
npx mocha test/integration/options.ts --timeout 100000 --exit
npx mocha test/integration/ethers.ts --timeout 100000 --exit
npx mocha test/integration/waffle.ts --timeout 100000 --exit
npx mocha test/integration/forked.ts --timeout 100000 --exit

##########################
# Hardhat Node (Localhost)
##########################
start_hardhat_node
npx mocha test/integration/node.ts --timeout 100000 --exit

# Waffle + Hardhat Node
npx mocha test/waffle.ts --timeout 100000 --exit
cleanup
13 changes: 0 additions & 13 deletions test/ganache.node.ts

This file was deleted.

6 changes: 4 additions & 2 deletions test/ethers.ts → test/integration/ethers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import path from "path"
import { TASK_TEST } from "hardhat/builtin-tasks/task-names";
// tslint:disable-next-line no-implicit-dependencies
import { assert } from "chai";
import { useEnvironment } from "./helpers";
import { useEnvironment } from "./../helpers";

describe("Ethers plugin", function() {
useEnvironment(__dirname + "/hardhat-ethers-project");
const projectPath = path.resolve(__dirname, "../projects/hardhat-ethers-project");
useEnvironment(projectPath);

it("no options", async function() {
await this.env.run(TASK_TEST, { testFiles: [] });
Expand Down
6 changes: 4 additions & 2 deletions test/forked.ts → test/integration/forked.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import path from "path"
import { TASK_TEST } from "hardhat/builtin-tasks/task-names";
// tslint:disable-next-line no-implicit-dependencies
import { assert } from "chai";

import { useEnvironment } from "./helpers";
import { useEnvironment } from "./../helpers";

describe("Forked Network", function() {
useEnvironment(__dirname + "/hardhat-forked-project");
const projectPath = path.resolve(__dirname, "../projects/hardhat-forked-project");
useEnvironment(projectPath);

it("default", async function() {
await this.env.run(TASK_TEST, { testFiles: [] });
Expand Down
6 changes: 4 additions & 2 deletions test/hardhatevm.node.ts → test/integration/node.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import path from "path"
import { TASK_TEST } from "hardhat/builtin-tasks/task-names";
// tslint:disable-next-line no-implicit-dependencies
import { assert } from "chai";
import { useEnvironment } from "./helpers";
import { useEnvironment } from "./../helpers";

describe("Ethers plugin", function() {
useEnvironment(__dirname + "/hardhat-ethers-project", "localhost");
const projectPath = path.resolve(__dirname, "../projects/hardhat-ethers-project");
useEnvironment(projectPath, "localhost");

it("no options", async function() {
await this.env.run(TASK_TEST, { testFiles: [] });
Expand Down
6 changes: 4 additions & 2 deletions test/truffle.options.ts → test/integration/options.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import path from "path"
import { TASK_TEST } from "hardhat/builtin-tasks/task-names";
// tslint:disable-next-line no-implicit-dependencies
import { assert } from "chai";

import { useEnvironment } from "./helpers";
import { useEnvironment } from "./../helpers";

// A place to test options
describe("Truffle plugin: gasReporter", function() {
useEnvironment(__dirname + "/hardhat-truffle-project");
const projectPath = path.resolve(__dirname, "../projects/hardhat-truffle-project");
useEnvironment(projectPath);

it("gasReporter options", async function() {
// Expect everything in the EtherRouter folder to be missing from report
Expand Down
6 changes: 4 additions & 2 deletions test/truffle.ts → test/integration/truffle.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import path from "path"
import { TASK_TEST } from "hardhat/builtin-tasks/task-names";
// tslint:disable-next-line no-implicit-dependencies
import { assert } from "chai";

import { useEnvironment } from "./helpers";
import { useEnvironment } from "./../helpers";

describe("Truffle plugin", function() {
useEnvironment(__dirname + "/hardhat-truffle-project");
const projectPath = path.resolve(__dirname, "../projects/hardhat-truffle-project");
useEnvironment(projectPath);

it("default", async function() {
await this.env.run(TASK_TEST, { testFiles: [] });
Expand Down
6 changes: 4 additions & 2 deletions test/waffle.ts → test/integration/waffle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import path from "path"
import { TASK_TEST } from "hardhat/builtin-tasks/task-names";
// tslint:disable-next-line no-implicit-dependencies
import { assert } from "chai";
import { useEnvironment } from "./helpers";
import { useEnvironment } from "./../helpers";

describe("Waffle plugin with signers", function() {
useEnvironment(__dirname + "/hardhat-waffle-project");
const projectPath = path.resolve(__dirname, "../projects/hardhat-waffle-project");
useEnvironment(projectPath);

it("no options", async function() {
await this.env.run(TASK_TEST, { testFiles: [] });
Expand Down
3 changes: 0 additions & 3 deletions test/mocha.opts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { HardhatUserConfig } from "hardhat/types";
import "@nomiclabs/hardhat-ethers"

import "../../src/index";
import "../../../src/index";

const config: HardhatUserConfig = {
solidity: "0.5.8",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HardhatUserConfig } from "hardhat/types";
import "@nomiclabs/hardhat-ethers"
import { ABI } from "./abi";

import "../../src/index";
import "../../../src/index";

const config: HardhatUserConfig = {
solidity: "0.4.18",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// We load the plugin here.
import { HardhatUserConfig } from "hardhat/types";

import "../../src/index";
import "../../../src/index";

const config: HardhatUserConfig = {
solidity: "0.5.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@nomiclabs/hardhat-truffle5"
import { HardhatUserConfig } from "hardhat/types";

// We load the plugin here.
import "../../src/index";
import "../../../src/index";

const config: HardhatUserConfig = {
solidity: {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { HardhatUserConfig } from "hardhat/types";
import "@nomiclabs/hardhat-waffle";

import "../../src/index";
import "../../../src/index";

const config: HardhatUserConfig = {
solidity: "0.5.8",
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions test/merge.ts → test/tasks/merge.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import fs from "fs"
import path from "path"
import { TASK_GAS_REPORTER_MERGE } from "../src/task-names";
import { TASK_GAS_REPORTER_MERGE } from "../../src/task-names";
// tslint:disable-next-line no-implicit-dependencies
import { assert } from "chai";
import { useEnvironment } from "./helpers";
import { useEnvironment } from "./../helpers";

const loadJsonFile = (filepath) => JSON.parse(fs.readFileSync(filepath, "utf-8"))

describe("Merge gasRerpoterOutput.json files task", function() {
const projectPath = path.resolve(__dirname, "hardhat-merge-project");
const projectPath = path.resolve(__dirname, "../projects/hardhat-merge-project");

useEnvironment(projectPath);

Expand Down
1 change: 1 addition & 0 deletions test/unit/.placeholder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// placeholder
Loading

0 comments on commit 732cf8f

Please sign in to comment.