diff --git a/test/shared/types.ts b/test/shared/types.ts index 6ac9c52..9277c3c 100644 --- a/test/shared/types.ts +++ b/test/shared/types.ts @@ -9,6 +9,9 @@ declare module "mocha" { contracts: Contracts; loadFixture: (fixture: Fixture) => Promise; signers: Signers; + + unlockTime: number; + lockedAmount: bigint; } } diff --git a/test/unit/lock/Lock.fixture.ts b/test/unit/lock/Lock.fixture.ts index a553b1f..72afe10 100644 --- a/test/unit/lock/Lock.fixture.ts +++ b/test/unit/lock/Lock.fixture.ts @@ -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 { + 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; - 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 }; }