Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
feat: add ToposCore upgrade test (#122)
Browse files Browse the repository at this point in the history
Signed-off-by: Jawad Tariq <[email protected]>
  • Loading branch information
JDawg287 authored Jan 30, 2024
1 parent 08562b0 commit c6cd07f
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions test/topos-core/ToposCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ describe('ToposCore', () => {
)
const toposCoreProxyAddress = await toposCoreProxy.getAddress()

const toposCore = await ToposCore__factory.connect(
toposCoreProxyAddress,
admin
)
const toposCore = ToposCore__factory.connect(toposCoreProxyAddress, admin)
await toposCore.initialize(adminAddresses, adminThreshold)

const altToposCoreImplementation = await new ToposCore__factory(
Expand All @@ -55,7 +52,7 @@ describe('ToposCore', () => {
)
await altToposCoreProxy.waitForDeployment()
const altToposCoreProxyAddress = await altToposCoreProxy.getAddress()
const altToposCore = await ToposCore__factory.connect(
const altToposCore = ToposCore__factory.connect(
altToposCoreProxyAddress,
admin
)
Expand Down Expand Up @@ -313,6 +310,45 @@ describe('ToposCore', () => {
).to.be.revertedWithCustomError(toposCore, 'InvalidCodeHash')
})

it('fetches the certificates from the contract after upgrade', async () => {
const {
admin,
altToposCoreImplementationAddress,
defaultCert,
toposCore,
} = await loadFixture(deployToposCoreFixture)
const oldImplementationAddress = await toposCore.implementation()
await toposCore.pushCertificate(defaultCert, cc.CERT_POS_1)

const CodeHash = await new CodeHash__factory(admin).deploy()
const codeHash = await CodeHash.waitForDeployment()
const implementationCodeHash = await codeHash.getCodeHash(
altToposCoreImplementationAddress
)

await toposCore.upgrade(
altToposCoreImplementationAddress,
implementationCodeHash
)
expect(await toposCore.implementation()).to.not.equal(
oldImplementationAddress
)
const certificate = await toposCore.getCertificate(cc.CERT_ID_1)
const encodedCert = testUtils.encodeCertParam(
certificate.prevId,
certificate.sourceSubnetId,
certificate.stateRoot,
certificate.txRoot,
certificate.receiptRoot,
certificate.targetSubnets,
Number(certificate.verifier),
certificate.certId,
certificate.starkProof,
certificate.signature
)
expect(encodedCert).to.equal(defaultCert)
})

it('emits an upgraded event', async () => {
const { admin, altToposCoreImplementationAddress, toposCore } =
await loadFixture(deployToposCoreFixture)
Expand Down

0 comments on commit c6cd07f

Please sign in to comment.