diff --git a/core/test/AcreRouter.test.ts b/core/test/AcreRouter.test.ts index af3e358b9..a457b9b16 100644 --- a/core/test/AcreRouter.test.ts +++ b/core/test/AcreRouter.test.ts @@ -1,4 +1,4 @@ -import { ethers, getUnnamedAccounts, getNamedAccounts } from "hardhat" +import { getUnnamedAccounts } from "hardhat" import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers" import { Address } from "hardhat-deploy/types" import { expect } from "chai" @@ -7,33 +7,28 @@ import { takeSnapshot, } from "@nomicfoundation/hardhat-toolbox/network-helpers" import type { AcreRouter } from "../typechain" +import { deployment } from "./helpers/context" +import { getNamedSigner, getUnnamedSigner } from "./helpers/signer" describe("AcreRouter", () => { let snapshot: SnapshotRestorer let acreRouter: AcreRouter - let deployerSigner: HardhatEthersSigner - let governanceSigner: HardhatEthersSigner - let thirdPartySigner: HardhatEthersSigner + let governance: HardhatEthersSigner + let thirdParty: HardhatEthersSigner let vault1: Address let vault2: Address let vault3: Address let vault4: Address - // TODO: - // Put some of this setup to deployment scripts and/or helpers e.g. ownership - // transfer, acreRouter deployment etc. See: https://github.com/thesis/acre/pull/58 - // and https://github.com/thesis/acre/pull/64 before(async () => { const accounts = await getUnnamedAccounts() ;[vault1, vault2, vault3, vault4] = accounts - const { deployer, governance } = await getNamedAccounts() - deployerSigner = await ethers.getSigner(deployer) - governanceSigner = await ethers.getSigner(governance) - thirdPartySigner = await ethers.getSigner(accounts[0]) - const AcreRouter = await ethers.getContractFactory("AcreRouter") - acreRouter = await AcreRouter.connect(deployerSigner).deploy() - acreRouter.transferOwnership(governance) + + governance = (await getNamedSigner()).governance + ;[thirdParty] = await getUnnamedSigner() + + acreRouter = (await deployment()).acreRouter }) beforeEach(async () => { @@ -48,7 +43,7 @@ describe("AcreRouter", () => { context("when caller is not a governance account", () => { it("should revert when adding a vault", async () => { await expect( - acreRouter.connect(thirdPartySigner).addVault(vault1), + acreRouter.connect(thirdParty).addVault(vault1), ).to.be.revertedWithCustomError( acreRouter, "OwnableUnauthorizedAccount", @@ -58,9 +53,9 @@ describe("AcreRouter", () => { context("when caller is a governance account", () => { it("should be able to add vaults", async () => { - await acreRouter.connect(governanceSigner).addVault(vault1) - await acreRouter.connect(governanceSigner).addVault(vault2) - await acreRouter.connect(governanceSigner).addVault(vault3) + await acreRouter.connect(governance).addVault(vault1) + await acreRouter.connect(governance).addVault(vault2) + await acreRouter.connect(governance).addVault(vault3) expect(await acreRouter.vaults(0)).to.equal(vault1) const isVault1Approved = await acreRouter.vaultsInfo(vault1) @@ -76,14 +71,14 @@ describe("AcreRouter", () => { }) it("should not be able to add the same vault twice", async () => { - await acreRouter.connect(governanceSigner).addVault(vault1) + await acreRouter.connect(governance).addVault(vault1) await expect( - acreRouter.connect(governanceSigner).addVault(vault1), + acreRouter.connect(governance).addVault(vault1), ).to.be.revertedWith("Vault already approved") }) it("should emit an event when adding a vault", async () => { - await expect(acreRouter.connect(governanceSigner).addVault(vault1)) + await expect(acreRouter.connect(governance).addVault(vault1)) .to.emit(acreRouter, "VaultAdded") .withArgs(vault1) }) @@ -92,15 +87,15 @@ describe("AcreRouter", () => { describe("removeVault", () => { beforeEach(async () => { - await acreRouter.connect(governanceSigner).addVault(vault1) - await acreRouter.connect(governanceSigner).addVault(vault2) - await acreRouter.connect(governanceSigner).addVault(vault3) + await acreRouter.connect(governance).addVault(vault1) + await acreRouter.connect(governance).addVault(vault2) + await acreRouter.connect(governance).addVault(vault3) }) context("when caller is not a governance account", () => { it("should revert when adding a vault", async () => { await expect( - acreRouter.connect(thirdPartySigner).removeVault(vault1), + acreRouter.connect(thirdParty).removeVault(vault1), ).to.be.revertedWithCustomError( acreRouter, "OwnableUnauthorizedAccount", @@ -110,7 +105,7 @@ describe("AcreRouter", () => { context("when caller is a governance account", () => { it("should be able to remove vaults", async () => { - await acreRouter.connect(governanceSigner).removeVault(vault1) + await acreRouter.connect(governance).removeVault(vault1) // Last vault replaced the first vault in the 'vaults' array expect(await acreRouter.vaults(0)).to.equal(vault3) @@ -118,7 +113,7 @@ describe("AcreRouter", () => { expect(isVault1Approved).to.equal(false) expect(await acreRouter.vaultsLength()).to.equal(2) - await acreRouter.connect(governanceSigner).removeVault(vault2) + await acreRouter.connect(governance).removeVault(vault2) // Last vault (vault2) was removed from the 'vaults' array expect(await acreRouter.vaults(0)).to.equal(vault3) @@ -126,7 +121,7 @@ describe("AcreRouter", () => { const isVault2Approved = await acreRouter.vaultsInfo(vault2) expect(isVault2Approved).to.equal(false) - await acreRouter.connect(governanceSigner).removeVault(vault3) + await acreRouter.connect(governance).removeVault(vault3) expect(await acreRouter.vaultsLength()).to.equal(0) const isVault3Approved = await acreRouter.vaultsInfo(vault3) expect(isVault3Approved).to.equal(false) @@ -134,12 +129,12 @@ describe("AcreRouter", () => { it("should not be able to remove a vault that is not approved", async () => { await expect( - acreRouter.connect(governanceSigner).removeVault(vault4), + acreRouter.connect(governance).removeVault(vault4), ).to.be.revertedWith("Not a vault") }) it("should emit an event when removing a vault", async () => { - await expect(acreRouter.connect(governanceSigner).removeVault(vault1)) + await expect(acreRouter.connect(governance).removeVault(vault1)) .to.emit(acreRouter, "VaultRemoved") .withArgs(vault1) })