From a14de85bc69d3eb952f34d5cc8400e852f3dc467 Mon Sep 17 00:00:00 2001 From: Jawad Tariq Date: Fri, 5 Jan 2024 16:58:38 -0500 Subject: [PATCH] chore: unify fetching contract factory Signed-off-by: Jawad Tariq --- test/topos-core/Bytes32Sets.test.ts | 11 +++++++---- test/topos-core/ToposCore.test.ts | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/test/topos-core/Bytes32Sets.test.ts b/test/topos-core/Bytes32Sets.test.ts index 5dd371f..3f4eb18 100644 --- a/test/topos-core/Bytes32Sets.test.ts +++ b/test/topos-core/Bytes32Sets.test.ts @@ -1,16 +1,19 @@ -import { Contract } from 'ethers' import { ethers } from 'hardhat' import { expect } from 'chai' +import { Bytes32SetsTest__factory } from '../../typechain-types/factories/contracts/topos-core/Bytes32Sets.sol/Bytes32SetsTest__factory' +import { Bytes32SetsTest } from '../../typechain-types/contracts/topos-core/Bytes32Sets.sol/Bytes32SetsTest' + describe('Bytes32Sets', () => { - let bytes32SetsTest: Contract + let bytes32SetsTest: Bytes32SetsTest const key1 = ethers.encodeBytes32String('key1') const key2 = ethers.encodeBytes32String('key2') beforeEach(async () => { - const Bytes32SetsTest = await ethers.getContractFactory('Bytes32SetsTest') - bytes32SetsTest = await Bytes32SetsTest.deploy() + const [admin] = await ethers.getSigners() + const Bytes32SetsTest = await new Bytes32SetsTest__factory(admin).deploy() + bytes32SetsTest = await Bytes32SetsTest.waitForDeployment() await bytes32SetsTest.waitForDeployment() }) diff --git a/test/topos-core/ToposCore.test.ts b/test/topos-core/ToposCore.test.ts index 2e1e15e..aa205c4 100644 --- a/test/topos-core/ToposCore.test.ts +++ b/test/topos-core/ToposCore.test.ts @@ -4,6 +4,8 @@ import { expect } from 'chai' import { ToposCore__factory } from '../../typechain-types/factories/contracts/topos-core/ToposCore__factory' import { ToposCoreProxy__factory } from '../../typechain-types/factories/contracts/topos-core/ToposCoreProxy__factory' +import { CodeHash__factory } from '../../typechain-types/factories/contracts/topos-core/CodeHash__factory' +import { ToposCoreProxy } from '../../typechain-types/contracts/topos-core/ToposCoreProxy' import * as cc from './shared/constants/certificates' import * as testUtils from './shared/utils/common' @@ -33,7 +35,6 @@ describe('ToposCore', () => { const toposCoreProxy = await new ToposCoreProxy__factory(admin).deploy( toposCoreImplementationAddress ) - await toposCoreProxy.waitForDeployment() const toposCoreProxyAddress = await toposCoreProxy.getAddress() const toposCore = await ToposCore__factory.connect( @@ -70,6 +71,7 @@ describe('ToposCore', () => { adminThreshold, defaultCert, toposCore, + toposCoreProxy, toposCoreProxyAddress, toposCoreImplementation, } @@ -287,8 +289,15 @@ describe('ToposCore', () => { describe('proxy', () => { it('reverts if the ToposCore implementation contract is not present', async () => { - const ToposCoreProxy = await ethers.getContractFactory('ToposCoreProxy') - await expect(ToposCoreProxy.deploy(ethers.ZeroAddress)).to.be.reverted + const { admin, toposCoreProxy } = await loadFixture( + deployToposCoreFixture + ) + await expect( + new ToposCoreProxy__factory(admin).deploy(ethers.ZeroAddress) + ).to.be.revertedWithCustomError( + toposCoreProxy as ToposCoreProxy, + 'InvalidImplementation' + ) }) }) @@ -311,8 +320,8 @@ describe('ToposCore', () => { altToposCoreImplementationAddress ) - const CodeHash = await ethers.getContractFactory('CodeHash') - const codeHash = await CodeHash.deploy() + const CodeHash = await new CodeHash__factory(admin).deploy() + const codeHash = await CodeHash.waitForDeployment() const implementationCodeHash = await codeHash.getCodeHash( altToposCoreImplementationAddress )