From 6a09ff90f808bd2bb565e7afff78232b3b9abe8d Mon Sep 17 00:00:00 2001 From: Laia Soler Date: Wed, 24 Jul 2024 17:09:40 +0200 Subject: [PATCH] update contracts tests --- test/contractsv2/PolygonRollupManager.test.ts | 231 +++++++++++------- 1 file changed, 138 insertions(+), 93 deletions(-) diff --git a/test/contractsv2/PolygonRollupManager.test.ts b/test/contractsv2/PolygonRollupManager.test.ts index c2aa2a0de..9b8599d6f 100644 --- a/test/contractsv2/PolygonRollupManager.test.ts +++ b/test/contractsv2/PolygonRollupManager.test.ts @@ -57,7 +57,7 @@ describe("Polygon Rollup Manager", () => { const LEAF_TYPE_MESSAGE = 1; const globalExitRootL2Address = "0xa40d5f56745a118d0906a34e69aec8c0db1cb8fa" as unknown as Address; - + let firstDeployment = true; //roles @@ -183,9 +183,6 @@ describe("Polygon Rollup Manager", () => { expect(await rollupManagerContract.pol()).to.be.equal(polTokenContract.target); expect(await rollupManagerContract.bridgeAddress()).to.be.equal(polygonZkEVMBridgeContract.target); - expect(await rollupManagerContract.pendingStateTimeout()).to.be.equal(pendingStateTimeoutDefault); - expect(await rollupManagerContract.trustedAggregatorTimeout()).to.be.equal(trustedAggregatorTimeout); - expect(await rollupManagerContract.getBatchFee()).to.be.equal(ethers.parseEther("0.1")); expect(await rollupManagerContract.getForcedBatchFee()).to.be.equal(ethers.parseEther("10")); expect(await rollupManagerContract.calculateRewardPerBatch()).to.be.equal(0); @@ -252,8 +249,11 @@ describe("Polygon Rollup Manager", () => { const networkName = "zkevm"; const forkID = 0; const genesisRandom = "0x0000000000000000000000000000000000000000000000000000000000000001"; - const rollupCompatibilityID = 0; - const descirption = "zkevm test"; + const rollupVerifierType = 0; + const description = "zkevm test"; + const programVKey = "0x0000000000000000000000000000000000000000000000000000000000000000"; + const lastPessimisticRoot = "0x0000000000000000000000000000000000000000000000000000000000000000"; + // Native token will be ether const gasTokenAddress = ethers.ZeroAddress; const gasTokenNetwork = 0; @@ -276,9 +276,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ) ).to.be.revertedWithCustomError(rollupManagerContract, "AddressDoNotHaveRequiredRole"); @@ -291,9 +292,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ) ) .to.emit(rollupManagerContract, "AddNewRollupType") @@ -302,9 +304,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ); // assert new rollup type @@ -314,9 +317,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, false, genesisRandom, + programVKey ]; expect(createdRollupType).to.be.deep.equal(expectedRollupType); @@ -336,9 +340,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, true, genesisRandom, + programVKey ]).to.be.deep.equal(await rollupManagerContract.rollupTypeMap(newRollupTypeID)); await snapshot.restore(); @@ -512,11 +517,12 @@ describe("Polygon Rollup Manager", () => { expect(rollupData.lastLocalExitRoot).to.be.equal(ethers.ZeroHash); expect(rollupData.lastBatchSequenced).to.be.equal(newSequencedBatch); expect(rollupData.lastVerifiedBatch).to.be.equal(0); - expect(rollupData.lastPendingState).to.be.equal(0); - expect(rollupData.lastPendingStateConsolidated).to.be.equal(0); + expect(rollupData._legacyPendingStateGap).to.be.equal(0); expect(rollupData.lastVerifiedBatchBeforeUpgrade).to.be.equal(0); expect(rollupData.rollupTypeID).to.be.equal(1); - expect(rollupData.rollupCompatibilityID).to.be.equal(0); + expect(rollupData.rollupVerifierType).to.be.equal(0); + expect(rollupData.lastPessimisticRoot).to.be.equal(lastPessimisticRoot); + expect(rollupData.programVKey).to.be.equal(programVKey); const sequencedBatchData = await rollupManagerContract.getRollupSequencedBatches( newCreatedRollupID, @@ -1030,8 +1036,11 @@ describe("Polygon Rollup Manager", () => { const networkName = "zkevm"; const forkID = 0; const genesisRandom = "0x0000000000000000000000000000000000000000000000000000000000000001"; - const rollupCompatibilityID = 0; - const descirption = "zkevm test"; + const rollupVerifierType = 0; + const description = "zkevm test"; + const programVKey = "0x0000000000000000000000000000000000000000000000000000000000000000"; + const lastPessimisticRoot = "0x0000000000000000000000000000000000000000000000000000000000000000"; + // Native token will be ether // deploy pol @@ -1074,9 +1083,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ) ).to.be.revertedWithCustomError(rollupManagerContract, "AddressDoNotHaveRequiredRole"); @@ -1089,9 +1099,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ) ) .to.emit(rollupManagerContract, "AddNewRollupType") @@ -1100,9 +1111,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ); // assert new rollup type @@ -1112,9 +1124,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, false, genesisRandom, + programVKey ]; expect(createdRollupType).to.be.deep.equal(expectedRollupType); @@ -1134,9 +1147,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, true, genesisRandom, + programVKey ]).to.be.deep.equal(await rollupManagerContract.rollupTypeMap(newRollupTypeID)); await snapshot.restore(); @@ -1310,11 +1324,12 @@ describe("Polygon Rollup Manager", () => { expect(rollupData.lastLocalExitRoot).to.be.equal(ethers.ZeroHash); expect(rollupData.lastBatchSequenced).to.be.equal(newSequencedBatch); expect(rollupData.lastVerifiedBatch).to.be.equal(0); - expect(rollupData.lastPendingState).to.be.equal(0); - expect(rollupData.lastPendingStateConsolidated).to.be.equal(0); + expect(rollupData._legacyPendingStateGap).to.be.equal(0); expect(rollupData.lastVerifiedBatchBeforeUpgrade).to.be.equal(0); expect(rollupData.rollupTypeID).to.be.equal(1); - expect(rollupData.rollupCompatibilityID).to.be.equal(0); + expect(rollupData.rollupVerifierType).to.be.equal(0); + expect(rollupData.lastPessimisticRoot).to.be.equal(lastPessimisticRoot); + expect(rollupData.programVKey).to.be.equal(programVKey); const sequencedBatchData = await rollupManagerContract.getRollupSequencedBatches( newCreatedRollupID, @@ -1637,8 +1652,11 @@ describe("Polygon Rollup Manager", () => { const networkName = "zkevm"; const forkID = 0; const genesisRandom = "0x0000000000000000000000000000000000000000000000000000000000000001"; - const rollupCompatibilityID = 0; - const descirption = "zkevm test"; + const rollupVerifierType = 0; + const description = "zkevm test"; + const programVKey = "0x0000000000000000000000000000000000000000000000000000000000000000"; + const lastPessimisticRoot = "0x0000000000000000000000000000000000000000000000000000000000000000"; + // Native token will be ether // deploy pol @@ -1681,9 +1699,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ) ).to.be.revertedWithCustomError(rollupManagerContract, "AddressDoNotHaveRequiredRole"); @@ -1696,9 +1715,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ) ) .to.emit(rollupManagerContract, "AddNewRollupType") @@ -1707,9 +1727,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ); // assert new rollup type @@ -1719,9 +1740,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, false, genesisRandom, + programVKey ]; expect(createdRollupType).to.be.deep.equal(expectedRollupType); @@ -1741,9 +1763,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, true, genesisRandom, + programVKey ]).to.be.deep.equal(await rollupManagerContract.rollupTypeMap(newRollupTypeID)); await snapshot.restore(); @@ -1918,11 +1941,12 @@ describe("Polygon Rollup Manager", () => { expect(rollupData.lastLocalExitRoot).to.be.equal(ethers.ZeroHash); expect(rollupData.lastBatchSequenced).to.be.equal(newSequencedBatch); expect(rollupData.lastVerifiedBatch).to.be.equal(0); - expect(rollupData.lastPendingState).to.be.equal(0); - expect(rollupData.lastPendingStateConsolidated).to.be.equal(0); + expect(rollupData._legacyPendingStateGap).to.be.equal(0); expect(rollupData.lastVerifiedBatchBeforeUpgrade).to.be.equal(0); expect(rollupData.rollupTypeID).to.be.equal(1); - expect(rollupData.rollupCompatibilityID).to.be.equal(0); + expect(rollupData.rollupVerifierType).to.be.equal(0); + expect(rollupData.lastPessimisticRoot).to.be.equal(lastPessimisticRoot); + expect(rollupData.programVKey).to.be.equal(programVKey); const sequencedBatchData = await rollupManagerContract.getRollupSequencedBatches( newCreatedRollupID, @@ -2252,9 +2276,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMEtrogContract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ) ) .to.emit(rollupManagerContract, "AddNewRollupType") @@ -2263,13 +2288,15 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMEtrogContract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ); - // Add a new rollup type with timelock - const randomType = 3; + // Add a new rollup type (pessimistic) with timelock + const newRandomTypeID = 3; + const rollupVerifierTypeNew = 1; await expect( rollupManagerContract .connect(timelock) @@ -2277,32 +2304,35 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMEtrogContract.target, verifierContract.target, forkID, - randomType, - genesisRandom, - descirption + rollupVerifierTypeNew, + programVKey, + description, + genesisRandom ) ) .to.emit(rollupManagerContract, "AddNewRollupType") .withArgs( - randomType, + newRandomTypeID, PolygonZKEVMEtrogContract.target, verifierContract.target, forkID, - randomType, - genesisRandom, - descirption + rollupVerifierTypeNew, + programVKey, + description, + genesisRandom ); // assert new rollup type - const createdEtrogRollupType = await rollupManagerContract.rollupTypeMap(etrogRollupType); + const createdEtrogRollupType = await rollupManagerContract.rollupTypeMap(newRandomTypeID); const expectedEtrogRollupType = [ PolygonZKEVMEtrogContract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierTypeNew, false, - genesisRandom, + programVKey, + genesisRandom ]; expect(createdEtrogRollupType).to.be.deep.equal(expectedEtrogRollupType); @@ -2349,11 +2379,6 @@ describe("Polygon Rollup Manager", () => { rollupManagerContract.connect(timelock).updateRollup(newZKEVMAddress, 4, "0x") ).to.be.revertedWithCustomError(rollupManagerContract, "RollupTypeDoesNotExist"); - // Try update to not comaptible type - await expect( - rollupManagerContract.connect(timelock).updateRollup(newZKEVMAddress, randomType, "0x") - ).to.be.revertedWithCustomError(rollupManagerContract, "UpdateNotCompatible"); - // obsoleteRollupType, take snapshot for it const snapshotUpdateRollup = await takeSnapshot(); @@ -2388,11 +2413,12 @@ describe("Polygon Rollup Manager", () => { expect(rollupDataFinal.lastLocalExitRoot).to.be.equal(newLocalExitRoot); expect(rollupDataFinal.lastBatchSequenced).to.be.equal(newVerifiedBatch); expect(rollupDataFinal.lastVerifiedBatch).to.be.equal(newVerifiedBatch); - expect(rollupDataFinal.lastPendingState).to.be.equal(0); - expect(rollupDataFinal.lastPendingStateConsolidated).to.be.equal(0); + expect(rollupDataFinal._legacyPendingStateGap).to.be.equal(0); expect(rollupDataFinal.lastVerifiedBatchBeforeUpgrade).to.be.equal(newVerifiedBatch); expect(rollupDataFinal.rollupTypeID).to.be.equal(etrogRollupType); - expect(rollupDataFinal.rollupCompatibilityID).to.be.equal(0); + expect(rollupDataFinal.rollupVerifierType).to.be.equal(0); + expect(rollupDataFinal.lastPessimisticRoot).to.be.equal(lastPessimisticRoot); + expect(rollupDataFinal.programVKey).to.be.equal(programVKey); expect(await upgrades.erc1967.getImplementationAddress(newZKEVMAddress as string)).to.be.equal( PolygonZKEVMEtrogContract.target @@ -2405,8 +2431,11 @@ describe("Polygon Rollup Manager", () => { const networkName = "zkevm"; const forkID = 0; const genesisRandom = "0x0000000000000000000000000000000000000000000000000000000000000001"; - const rollupCompatibilityID = 0; - const descirption = "zkevm test"; + const rollupVerifierType = 0; + const description = "zkevm test"; + const programVKey = "0x0000000000000000000000000000000000000000000000000000000000000000"; + const lastPessimisticRoot = "0x0000000000000000000000000000000000000000000000000000000000000000"; + // Native token will be ether // deploy pol @@ -2452,9 +2481,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ) ) .to.emit(rollupManagerContract, "AddNewRollupType") @@ -2463,9 +2493,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ); // assert new rollup type @@ -2475,9 +2506,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, false, genesisRandom, + programVKey ]; expect(createdRollupType).to.be.deep.equal(expectedRollupType); @@ -2574,12 +2606,12 @@ describe("Polygon Rollup Manager", () => { expect(rollupData.lastLocalExitRoot).to.be.equal(ethers.ZeroHash); expect(rollupData.lastBatchSequenced).to.be.equal(newSequencedBatch); expect(rollupData.lastVerifiedBatch).to.be.equal(0); - expect(rollupData.lastPendingState).to.be.equal(0); - expect(rollupData.lastPendingStateConsolidated).to.be.equal(0); + expect(rollupData._legacyPendingStateGap).to.be.equal(0); expect(rollupData.lastVerifiedBatchBeforeUpgrade).to.be.equal(0); expect(rollupData.rollupTypeID).to.be.equal(1); - expect(rollupData.rollupCompatibilityID).to.be.equal(0); - + expect(rollupData.rollupVerifierType).to.be.equal(0); + expect(rollupData.lastPessimisticRoot).to.be.equal(lastPessimisticRoot); + expect(rollupData.programVKey).to.be.equal(programVKey); const sequencedBatchData = await rollupManagerContract.getRollupSequencedBatches( newCreatedRollupID, newSequencedBatch @@ -2716,8 +2748,11 @@ describe("Polygon Rollup Manager", () => { const networkName = "zkevm"; const forkID = 0; const genesisRandom = "0x0000000000000000000000000000000000000000000000000000000000000001"; - const rollupCompatibilityID = 0; - const descirption = "zkevm test"; + const rollupVerifierType = 0; + const description = "zkevm test"; + const programVKey = "0x0000000000000000000000000000000000000000000000000000000000000000"; + const lastPessimisticRoot = "0x0000000000000000000000000000000000000000000000000000000000000000"; + // Native token will be ether const gasTokenAddress = ethers.ZeroAddress; const gasTokenNetwork = 0; @@ -2775,7 +2810,8 @@ describe("Polygon Rollup Manager", () => { forkID, chainID, genesisRandom, - rollupCompatibilityID + rollupVerifierType, + programVKey ) ).to.be.revertedWithCustomError(rollupManagerContract, "AddressDoNotHaveRequiredRole"); @@ -2787,7 +2823,8 @@ describe("Polygon Rollup Manager", () => { forkID, 4294967296, // 2**32 genesisRandom, - rollupCompatibilityID + rollupVerifierType, + programVKey ) ).to.be.revertedWithCustomError(rollupManagerContract, "ChainIDOutOfRange"); @@ -2800,11 +2837,12 @@ describe("Polygon Rollup Manager", () => { forkID, chainID, genesisRandom, - rollupCompatibilityID + rollupVerifierType, + programVKey ) ) .to.emit(rollupManagerContract, "AddExistingRollup") - .withArgs(RollupID, forkID, PolygonZKEVMV2Contract.target, chainID, rollupCompatibilityID, 0); + .withArgs(RollupID, forkID, PolygonZKEVMV2Contract.target, chainID, rollupVerifierType, 0, programVKey); await expect( rollupManagerContract @@ -2815,7 +2853,8 @@ describe("Polygon Rollup Manager", () => { forkID, chainID, genesisRandom, - rollupCompatibilityID + rollupVerifierType, + programVKey ) ).to.be.revertedWithCustomError(rollupManagerContract, "ChainIDAlreadyExist"); @@ -2828,7 +2867,8 @@ describe("Polygon Rollup Manager", () => { forkID, chainID + 1, genesisRandom, - rollupCompatibilityID + rollupVerifierType, + programVKey ) ).to.be.revertedWithCustomError(rollupManagerContract, "RollupAddressAlreadyExist"); @@ -3164,8 +3204,10 @@ describe("Polygon Rollup Manager", () => { it("Should test obsolete rollup", async () => { const forkID = 0; const genesisRandom = "0x0000000000000000000000000000000000000000000000000000000000000001"; - const rollupCompatibilityID = 0; - const descirption = "zkevm test"; + const rollupVerifierType = 0; + const description = "zkevm test"; + const programVKey = "0x0000000000000000000000000000000000000000000000000000000000000000"; + const lastPessimisticRoot = "0x0000000000000000000000000000000000000000000000000000000000000000"; // In order to create a new rollup type, create an implementation of the contract @@ -3188,9 +3230,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ) ) .to.emit(rollupManagerContract, "AddNewRollupType") @@ -3199,9 +3242,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, genesisRandom, - descirption + description, + programVKey ); // assert new rollup type @@ -3211,9 +3255,10 @@ describe("Polygon Rollup Manager", () => { PolygonZKEVMV2Contract.target, verifierContract.target, forkID, - rollupCompatibilityID, + rollupVerifierType, false, genesisRandom, + programVKey ]; expect(createdRollupType).to.be.deep.equal(expectedRollupType);