Skip to content

Commit

Permalink
feat: use ignition in fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedali8 committed Sep 19, 2024
1 parent 2eb0868 commit 9c9c23d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
3 changes: 3 additions & 0 deletions test/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ declare module "mocha" {
contracts: Contracts;
loadFixture: <T>(fixture: Fixture<T>) => Promise<T>;
signers: Signers;

unlockTime: number;
lockedAmount: bigint;
}
}

Expand Down
42 changes: 22 additions & 20 deletions test/unit/lock/Lock.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import type { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { time } from "@nomicfoundation/hardhat-network-helpers";
import { ethers } from "hardhat";
import { ignition } from "hardhat";

import LockModule from "../../../ignition/modules/Lock";
import type { Lock } from "../../../types/Lock";
import type { Lock__factory } from "../../../types/factories/Lock__factory";

const ONE_YEAR_IN_SECS = time.duration.years(1);
const ONE_GWEI = 1_000_000_000n;

async function getUnlockTime(): Promise<number> {
return (await time.latest()) + ONE_YEAR_IN_SECS;
}

export async function lockFixture(): Promise<{
lock: Lock;
unlockTime: number;
lockedAmount: number;
lockedAmount: bigint;
}> {
const signers = await ethers.getSigners();
const deployer: SignerWithAddress = signers[0];

const LockFactory: Lock__factory = (await ethers.getContractFactory("Lock")) as Lock__factory;

const ONE_YEAR_IN_SECS = time.duration.years(1);
const ONE_GWEI = 1_000_000_000;

const lockedAmount = ONE_GWEI;
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;

type DeployArgs = Parameters<typeof LockFactory.deploy>;
const args: DeployArgs = [unlockTime, { value: lockedAmount }];

const lock: Lock = (await LockFactory.connect(deployer).deploy(...args)) as Lock;
await lock.waitForDeployment();
const lockedAmount: bigint = ONE_GWEI;
const unlockTime: number = await getUnlockTime();

const deployedLock = await ignition.deploy(LockModule, {
parameters: {
Lock: {
unlockTime,
lockedAmount,
},
},
});
const lock = deployedLock.lock as unknown as Lock;

return { lock, unlockTime, lockedAmount };
}

0 comments on commit 9c9c23d

Please sign in to comment.