From 09dda16e385941c97f278541c36082c783cee974 Mon Sep 17 00:00:00 2001 From: invocamanman Date: Fri, 16 Feb 2024 13:15:39 +0100 Subject: [PATCH] udpate tests --- .../validium/PolygonValidiumEtrog.sol | 2 - test/contractsv2/PolygonRollupManager.test.ts | 40 ++++++--- .../PolygonRollupManagerUpgrade.test.ts | 22 +++-- test/contractsv2/PolygonValidiumEtrog.test.ts | 88 ++++++++++++++++--- test/contractsv2/PolygonZkEVMEtrog.test.ts | 54 ++++++++++-- .../ClaimCompressor.test.ts | 2 +- 6 files changed, 175 insertions(+), 33 deletions(-) rename test/contractsv2/{ => claimCompressor}/ClaimCompressor.test.ts (99%) diff --git a/contracts/v2/consensus/validium/PolygonValidiumEtrog.sol b/contracts/v2/consensus/validium/PolygonValidiumEtrog.sol index 3dda2c85b..a38e4b6c3 100644 --- a/contracts/v2/consensus/validium/PolygonValidiumEtrog.sol +++ b/contracts/v2/consensus/validium/PolygonValidiumEtrog.sol @@ -5,8 +5,6 @@ import "../../lib/PolygonRollupBaseEtrog.sol"; import "../../interfaces/IDataAvailabilityProtocol.sol"; import "../../interfaces/IPolygonValidium.sol"; -// MAKvalidum upgradable D: TTT -// Make a reiniitalize that's able to get teh previosu data commitee and set to 0 afterwarfs /** * Contract responsible for managing the states and the updates of L2 network. * There will be a trusted sequencer, which is able to send transactions. diff --git a/test/contractsv2/PolygonRollupManager.test.ts b/test/contractsv2/PolygonRollupManager.test.ts index 2eaec4d78..b5ac3f572 100644 --- a/test/contractsv2/PolygonRollupManager.test.ts +++ b/test/contractsv2/PolygonRollupManager.test.ts @@ -540,8 +540,12 @@ describe("Polygon Rollup Manager", () => { ).to.be.revertedWithCustomError(rollupManagerContract, "MustSequenceSomeBatch"); // Sequence Batches + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + let currentSequenceNumber = 0; await expect( - newZkEVMContract.connect(trustedSequencer).sequenceBatches([sequence], trustedSequencer.address) + newZkEVMContract + .connect(trustedSequencer) + .sequenceBatches([sequence], currentTime, currentSequenceNumber++, trustedSequencer.address) ).to.emit(newZkEVMContract, "SequenceBatches"); const lastBlock = await ethers.provider.getBlock("latest"); @@ -562,7 +566,7 @@ describe("Polygon Rollup Manager", () => { expectedAccInputHash, ethers.keccak256(l2txData), rootSC, - lastBlock?.timestamp, + currentTime, trustedSequencer.address, ethers.ZeroHash ); @@ -874,7 +878,9 @@ describe("Polygon Rollup Manager", () => { const snapshot3 = await takeSnapshot(); // Sequence Batches await expect( - newZkEVMContract.connect(trustedSequencer).sequenceBatches([sequenceForced], trustedSequencer.address) + newZkEVMContract + .connect(trustedSequencer) + .sequenceBatches([sequenceForced], currentTime, currentSequenceNumber++, trustedSequencer.address) ).to.emit(newZkEVMContract, "SequenceBatches"); const expectedAccInputHash3 = calculateAccInputHashetrog( @@ -1264,9 +1270,12 @@ describe("Polygon Rollup Manager", () => { ); // Sequence Batches + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + let currentSequenceNumber = 0; + const txSequenceBatches = await newZkEVMContract .connect(trustedSequencer) - .sequenceBatches([sequence], trustedSequencer.address); + .sequenceBatches([sequence], currentTime, currentSequenceNumber++, trustedSequencer.address); const lastBlock = await ethers.provider.getBlock("latest"); const lastBlockHash = lastBlock?.parentHash; @@ -1288,7 +1297,7 @@ describe("Polygon Rollup Manager", () => { expectedAccInputHash, ethers.keccak256(l2txData), rootSC, - lastBlock?.timestamp, + currentTime, trustedSequencer.address, ethers.ZeroHash ); @@ -1834,8 +1843,12 @@ describe("Polygon Rollup Manager", () => { ); // Sequence Batches + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + let currentSequenceNumber = 0; await expect( - newZkEVMContract.connect(trustedSequencer).sequenceBatches([sequence], trustedSequencer.address) + newZkEVMContract + .connect(trustedSequencer) + .sequenceBatches([sequence], currentTime, currentSequenceNumber++, trustedSequencer.address) ).to.emit(newZkEVMContract, "SequenceBatches"); const lastBlock = await ethers.provider.getBlock("latest"); @@ -1846,7 +1859,7 @@ describe("Polygon Rollup Manager", () => { expectedAccInputHash, ethers.keccak256(l2txData), rootSC, - lastBlock?.timestamp, + currentTime, trustedSequencer.address, ethers.ZeroHash ); @@ -2399,8 +2412,15 @@ describe("Polygon Rollup Manager", () => { ).to.emit(polTokenContract, "Approval"); // Sequence Batches - await expect( - PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches([sequence], trustedSequencer.address) + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + let currentSequenceNumber = 0; + await expect( + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + [sequence], + currentTime, + currentSequenceNumber++, + trustedSequencer.address + ) ).to.emit(PolygonZKEVMV2Contract, "SequenceBatches"); const rootSC = await polygonZkEVMGlobalExitRoot.getRoot(); @@ -2410,7 +2430,7 @@ describe("Polygon Rollup Manager", () => { expectedAccInputHashInitial, ethers.keccak256(l2txData), rootSC, - currentTimestampSequenced, + currentTime, trustedSequencer.address, ethers.ZeroHash ); diff --git a/test/contractsv2/PolygonRollupManagerUpgrade.test.ts b/test/contractsv2/PolygonRollupManagerUpgrade.test.ts index 2fa8145dc..3e3604244 100644 --- a/test/contractsv2/PolygonRollupManagerUpgrade.test.ts +++ b/test/contractsv2/PolygonRollupManagerUpgrade.test.ts @@ -634,8 +634,13 @@ describe("Polygon Rollup manager upgraded", () => { ); // Sequence Batches + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + let currentSequenceNumber = 0; + await expect( - newZkEVMContract.connect(trustedSequencer).sequenceBatches([sequence], trustedSequencer.address) + newZkEVMContract + .connect(trustedSequencer) + .sequenceBatches([sequence], currentTime, currentSequenceNumber++, trustedSequencer.address) ).to.emit(newZkEVMContract, "SequenceBatches"); const lastBlock = await ethers.provider.getBlock("latest"); @@ -656,7 +661,7 @@ describe("Polygon Rollup manager upgraded", () => { expectedAccInputHash, ethers.keccak256(l2txData), rootSC, - lastBlock?.timestamp, + currentTime, trustedSequencer.address, ethers.ZeroHash ); @@ -978,7 +983,9 @@ describe("Polygon Rollup manager upgraded", () => { const snapshot3 = await takeSnapshot(); // Sequence Batches await expect( - newZkEVMContract.connect(trustedSequencer).sequenceBatches([sequenceForced], trustedSequencer.address) + newZkEVMContract + .connect(trustedSequencer) + .sequenceBatches([sequenceForced], currentTime, currentSequenceNumber++, trustedSequencer.address) ).to.emit(newZkEVMContract, "SequenceBatches"); const expectedAccInputHash3 = calculateAccInputHashetrog( @@ -1340,8 +1347,13 @@ describe("Polygon Rollup manager upgraded", () => { ); // Sequence Batches + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + const currentSequenceNumber = 0; + await expect( - newZkEVMContract.connect(trustedSequencer).sequenceBatches([sequence], trustedSequencer.address) + newZkEVMContract + .connect(trustedSequencer) + .sequenceBatches([sequence], currentTime, currentSequenceNumber, trustedSequencer.address) ).to.emit(newZkEVMContract, "SequenceBatches"); const sequencedBatchData2 = await rollupManagerContract.getRollupSequencedBatches(newCreatedRollupID, 2); @@ -1363,7 +1375,7 @@ describe("Polygon Rollup manager upgraded", () => { expectedAccInputHash, ethers.keccak256(l2txData), rootSC, - lastBlock?.timestamp, + currentTime, trustedSequencer.address, ethers.ZeroHash ); diff --git a/test/contractsv2/PolygonValidiumEtrog.test.ts b/test/contractsv2/PolygonValidiumEtrog.test.ts index d24d74587..bd1501d8a 100644 --- a/test/contractsv2/PolygonValidiumEtrog.test.ts +++ b/test/contractsv2/PolygonValidiumEtrog.test.ts @@ -579,21 +579,51 @@ describe("PolygonZkEVMEtrog", () => { ).to.emit(polTokenContract, "Approval"); // Sequence Batches + const currentSequenceNumber = 0; await expect( - PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches([sequence], trustedSequencer.address) + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + [sequence], + 0, + currentSequenceNumber, + trustedSequencer.address + ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "SequenceWithDataAvailabilityNotAllowed"); await expect(PolygonZKEVMV2Contract.connect(admin).switchSequenceWithDataAvailability(true)).to.emit( PolygonZKEVMV2Contract, "SwitchSequenceWithDataAvailability" ); + + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + + await ethers.provider.send("evm_setNextBlockTimestamp", [currentTime + 1]); + await expect( - PolygonZKEVMV2Contract.sequenceBatches([sequence], trustedSequencer.address) + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + [sequence], + currentTime + 38, + currentSequenceNumber, + trustedSequencer.address + ) + ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "MaxTimestampSequenceInvalid"); + + await expect( + PolygonZKEVMV2Contract.sequenceBatches( + [sequence], + currentTime, + currentSequenceNumber, + trustedSequencer.address + ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "OnlyTrustedSequencer"); await expect( - PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches([], trustedSequencer.address) + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + [], + currentTime, + currentSequenceNumber, + trustedSequencer.address + ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "SequenceZeroBatches"); const hugeBatchArray = new Array(_MAX_VERIFY_BATCHES + 1).fill({ @@ -604,7 +634,12 @@ describe("PolygonZkEVMEtrog", () => { }); await expect( - PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches(hugeBatchArray, trustedSequencer.address) + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + hugeBatchArray, + currentTime, + currentSequenceNumber, + trustedSequencer.address + ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "ExceedMaxVerifyBatches"); // Create a huge sequence @@ -618,6 +653,8 @@ describe("PolygonZkEVMEtrog", () => { forcedBlockHashL1: ethers.ZeroHash, }, ], + currentTime, + currentSequenceNumber, trustedSequencer.address ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "TransactionsLengthAboveMax"); @@ -633,12 +670,19 @@ describe("PolygonZkEVMEtrog", () => { forcedBlockHashL1: ethers.ZeroHash, }, ], + currentTime, + currentSequenceNumber, trustedSequencer.address ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "ForcedDataDoesNotMatch"); await expect( - PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches([sequence], trustedSequencer.address) + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + [sequence], + currentTime, + currentSequenceNumber, + trustedSequencer.address + ) ).to.emit(PolygonZKEVMV2Contract, "SequenceBatches"); const currentTimestampSequenced = (await ethers.provider.getBlock("latest"))?.timestamp; @@ -647,7 +691,7 @@ describe("PolygonZkEVMEtrog", () => { expectedAccInputHash, ethers.keccak256(l2txData), await polygonZkEVMGlobalExitRoot.getRoot(), - currentTimestampSequenced, + currentTime, trustedSequencer.address, ethers.ZeroHash ); @@ -741,14 +785,23 @@ describe("PolygonZkEVMEtrog", () => { ).to.emit(polTokenContract, "Approval"); // Sequence Batches - + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + const currentSequenceNumber = 0; await expect( - PolygonZKEVMV2Contract.sequenceBatchesValidium([sequenceValidium], trustedSequencer.address, "0x1233") + PolygonZKEVMV2Contract.sequenceBatchesValidium( + [sequenceValidium], + currentTime, + currentSequenceNumber, + trustedSequencer.address, + "0x1233" + ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "OnlyTrustedSequencer"); await expect( PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium( [], + currentTime, + currentSequenceNumber, trustedSequencer.address, "0x1233" ) @@ -764,6 +817,8 @@ describe("PolygonZkEVMEtrog", () => { await expect( PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium( hugeBatchArray, + currentTime, + currentSequenceNumber, trustedSequencer.address, "0x" ) @@ -780,6 +835,8 @@ describe("PolygonZkEVMEtrog", () => { forcedBlockHashL1: ethers.ZeroHash, }, ], + currentTime, + currentSequenceNumber, trustedSequencer.address, "0x" ) @@ -788,6 +845,8 @@ describe("PolygonZkEVMEtrog", () => { await expect( PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium( [sequenceValidium], + currentTime, + currentSequenceNumber, trustedSequencer.address, "0x1233" ) @@ -839,6 +898,8 @@ describe("PolygonZkEVMEtrog", () => { await expect( PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium( [sequenceValidium], + currentTime, + currentSequenceNumber, trustedSequencer.address, badDataAvMessage ) @@ -847,6 +908,8 @@ describe("PolygonZkEVMEtrog", () => { await expect( PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium( [sequenceValidium], + currentTime, + currentSequenceNumber, trustedSequencer.address, badDataAvMessage.slice(0, -2) ) @@ -855,17 +918,18 @@ describe("PolygonZkEVMEtrog", () => { await expect( PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium( [sequenceValidium], + currentTime, + currentSequenceNumber, trustedSequencer.address, dataAvailabilityMessage ) ).to.emit(PolygonZKEVMV2Contract, "SequenceBatches"); - const currentTimestampSequenced = (await ethers.provider.getBlock("latest"))?.timestamp; const expectedAccInputHash2 = calculateAccInputHashetrog( expectedAccInputHash, hashedData, await polygonZkEVMGlobalExitRoot.getRoot(), - currentTimestampSequenced, + currentTime, trustedSequencer.address, ethers.ZeroHash ); @@ -1240,9 +1304,13 @@ describe("PolygonZkEVMEtrog", () => { .to.emit(PolygonDataCommitee, "CommitteeUpdated") .withArgs(commiteeHash); + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + const currentSequenceNumber = 0; await expect( PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium( [sequenceForced], + currentTime, + currentSequenceNumber, trustedSequencer.address, "0x12" ) diff --git a/test/contractsv2/PolygonZkEVMEtrog.test.ts b/test/contractsv2/PolygonZkEVMEtrog.test.ts index 53a9f14e9..9d93c385b 100644 --- a/test/contractsv2/PolygonZkEVMEtrog.test.ts +++ b/test/contractsv2/PolygonZkEVMEtrog.test.ts @@ -412,13 +412,43 @@ describe("PolygonZkEVMEtrog", () => { ).to.emit(polTokenContract, "Approval"); // Sequence Batches + const currentTime = Number((await ethers.provider.getBlock("latest"))?.timestamp); + const currentSequenceNumber = 0; await expect( - PolygonZKEVMV2Contract.sequenceBatches([sequence], trustedSequencer.address) + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + [sequence], + currentTime + 38, + currentSequenceNumber, + trustedSequencer.address + ) + ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "MaxTimestampSequenceInvalid"); + + await expect( + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + [sequence], + currentTime + 10, + 1, + trustedSequencer.address + ) + ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "SequenceNumberInvalid"); + + await expect( + PolygonZKEVMV2Contract.sequenceBatches( + [sequence], + currentTime, + currentSequenceNumber, + trustedSequencer.address + ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "OnlyTrustedSequencer"); await expect( - PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches([], trustedSequencer.address) + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + [], + currentTime, + currentSequenceNumber, + trustedSequencer.address + ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "SequenceZeroBatches"); const hugeBatchArray = new Array(_MAX_VERIFY_BATCHES + 1).fill({ @@ -429,7 +459,12 @@ describe("PolygonZkEVMEtrog", () => { }); await expect( - PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches(hugeBatchArray, trustedSequencer.address) + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + hugeBatchArray, + currentTime, + currentSequenceNumber, + trustedSequencer.address + ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "ExceedMaxVerifyBatches"); // Create a huge sequence @@ -443,6 +478,8 @@ describe("PolygonZkEVMEtrog", () => { forcedBlockHashL1: ethers.ZeroHash, }, ], + currentTime, + currentSequenceNumber, trustedSequencer.address ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "TransactionsLengthAboveMax"); @@ -458,12 +495,19 @@ describe("PolygonZkEVMEtrog", () => { forcedBlockHashL1: ethers.ZeroHash, }, ], + currentTime, + currentSequenceNumber, trustedSequencer.address ) ).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "ForcedDataDoesNotMatch"); await expect( - PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches([sequence], trustedSequencer.address) + PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatches( + [sequence], + currentTime, + currentSequenceNumber, + trustedSequencer.address + ) ).to.emit(PolygonZKEVMV2Contract, "SequenceBatches"); const currentTimestampSequenced = (await ethers.provider.getBlock("latest"))?.timestamp; @@ -472,7 +516,7 @@ describe("PolygonZkEVMEtrog", () => { expectedAccInputHash, ethers.keccak256(l2txData), await polygonZkEVMGlobalExitRoot.getRoot(), - currentTimestampSequenced, + currentTime, trustedSequencer.address, ethers.ZeroHash ); diff --git a/test/contractsv2/ClaimCompressor.test.ts b/test/contractsv2/claimCompressor/ClaimCompressor.test.ts similarity index 99% rename from test/contractsv2/ClaimCompressor.test.ts rename to test/contractsv2/claimCompressor/ClaimCompressor.test.ts index 29c79a0b3..b85115642 100644 --- a/test/contractsv2/ClaimCompressor.test.ts +++ b/test/contractsv2/claimCompressor/ClaimCompressor.test.ts @@ -21,7 +21,7 @@ import {MemDB, ZkEVMDB, getPoseidon, smtUtils, processorUtils} from "@0xpolygonh import {deploy} from "@openzeppelin/hardhat-upgrades/dist/utils"; import {parse} from "yargs"; -describe("PolygonZkEVMBridge Contract", () => { +describe("Claim Compressor Contract", () => { upgrades.silenceWarnings(); let claimCompressor: ClaimCompressor;