Skip to content

Commit

Permalink
chore: unify fetching contract factory
Browse files Browse the repository at this point in the history
Signed-off-by: Jawad Tariq <[email protected]>
  • Loading branch information
JDawg287 committed Jan 5, 2024
1 parent 97035ab commit a14de85
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
11 changes: 7 additions & 4 deletions test/topos-core/Bytes32Sets.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})

Expand Down
19 changes: 14 additions & 5 deletions test/topos-core/ToposCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -70,6 +71,7 @@ describe('ToposCore', () => {
adminThreshold,
defaultCert,
toposCore,
toposCoreProxy,
toposCoreProxyAddress,
toposCoreImplementation,
}
Expand Down Expand Up @@ -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'
)
})
})

Expand All @@ -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
)
Expand Down

0 comments on commit a14de85

Please sign in to comment.