Skip to content

Commit

Permalink
Wrote tests. Cleaned up a project
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR committed Jan 31, 2024
1 parent a7ded58 commit 912d315
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 20 deletions.
1 change: 1 addition & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"file": ["test/setup.ts"],
"require": "ts-node/register/files",
"ignore": ["test/fixture-projects/**/*"],
"timeout": 10000
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solarity/hardhat-migrate",
"version": "2.1.1",
"version": "2.1.0",
"description": "Automatic deployment and verification of smart contracts",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/deployer/Deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Deployer {
return adapter.toInstance(contract, contractAddress!, {});
}

public async saveContract<T, A = T, I = any>(
public async save<T, A = T, I = any>(
contract: Instance<A, I> | (T extends Truffle.Contract<I> ? T : never) | string,
contractAddress: string,
) {
Expand Down
8 changes: 1 addition & 7 deletions test/integration/deployer/base-contract-interaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import chai, { expect } from "chai";
import chaiAsPromised from "chai-as-promised";

chai.use(chaiAsPromised);
import { expect } from "chai";

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

Expand All @@ -16,9 +13,6 @@ import { Migrator } from "../../../src/migrator/Migrator";
import { ethersProvider } from "../../../src/tools/network/EthersProvider";
import { TransactionStorage } from "../../../src/tools/storage/MigrateStorage";

import { resetTransactionRunner } from "../../../src/tools/runners/TransactionRunner";
import { resetReporter } from "../../../src/tools/reporters/Reporter";

describe("deployer", () => {
let deployer: Deployer;

Expand Down
60 changes: 60 additions & 0 deletions test/integration/deployer/save-and-recover.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { expect } from "chai";
import { ethers } from "ethers";

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

import {
ConstructorWithArguments,
ConstructorWithArguments__factory,
} from "../../fixture-projects/hardhat-project-typechain-ethers/typechain-types";

import { Deployer } from "../../../src/deployer/Deployer";
import { Migrator } from "../../../src/migrator/Migrator";

import { ethersProvider } from "../../../src/tools/network/EthersProvider";
import { TransactionStorage } from "../../../src/tools/storage/MigrateStorage";

describe("deployer", () => {
let deployer: Deployer;

describe("default interaction with contracts", () => {
useEnvironment("typechain-ethers");

let contract: ConstructorWithArguments;

beforeEach("setup", async function () {
await Migrator.buildMigrateTaskDeps(this.hre);

deployer = new Deployer(this.hre);

const ContractFactory = new ConstructorWithArguments__factory(await ethersProvider!.getSigner());
contract = await ContractFactory.deploy(2);

TransactionStorage.clear();
});

it("should save and recover contract by name", async function () {
const contractName = "ConstructorWithArguments";

await deployer.save(contractName, await contract.getAddress());

const contractInstance = await deployer.deployed(ConstructorWithArguments__factory, contractName);

expect(await contractInstance.getAddress()).to.equal(await contract.getAddress());
});

it("should save and recover contract by instance", async function () {
await deployer.save(ConstructorWithArguments__factory, await contract.getAddress());

const contractInstance = await deployer.deployed(ConstructorWithArguments__factory);

expect(await contractInstance.getAddress()).to.equal(await contract.getAddress());
});

it("should throw error if contract is not deployed", async function () {
await expect(deployer.save(ConstructorWithArguments__factory, ethers.ZeroAddress)).to.be.rejectedWith(
"Deployer.save(): Contract with address '0x0000000000000000000000000000000000000000' is not deployed",
);
});
});
});
3 changes: 0 additions & 3 deletions test/integration/migration/typechain-truffle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { runWithContinue, runWithoutContinue } from "./helper";

import { useEnvironment } from "../../helpers";
import { resetReporter } from "../../../src/tools/reporters/Reporter";
import { resetTransactionRunner } from "../../../src/tools/runners/TransactionRunner";
import { resetNetworkManager } from "../../../src/tools/network/NetworkManager";

describe("typechain-truffle", () => {
useEnvironment("typechain-truffle");
Expand Down
7 changes: 1 addition & 6 deletions test/integration/tools/transaction-storage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import chai, { assert, expect } from "chai";
import chaiAsPromised from "chai-as-promised";

chai.use(chaiAsPromised);
import { assert, expect } from "chai";

import { ContractFactory, ZeroAddress } from "ethers";

Expand All @@ -20,8 +17,6 @@ import { ContractDeployTxWithName } from "../../../src/types/deployer";

import { TransactionStorage } from "../../../src/tools/storage/MigrateStorage";
import { TransactionProcessor } from "../../../src/tools/storage/TransactionProcessor";
import { resetReporter } from "../../../src/tools/reporters/Reporter";
import { resetTransactionRunner } from "../../../src/tools/runners/TransactionRunner";

describe("TransactionStorage", async () => {
useEnvironment("typechain-ethers");
Expand Down

0 comments on commit 912d315

Please sign in to comment.