Skip to content

Commit

Permalink
udpate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
invocamanman committed Feb 16, 2024
1 parent 6d6e661 commit a8e4d10
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 33 deletions.
2 changes: 0 additions & 2 deletions contracts/v2/consensus/validium/PolygonValidiumEtrog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
40 changes: 30 additions & 10 deletions test/contractsv2/PolygonRollupManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -562,7 +566,7 @@ describe("Polygon Rollup Manager", () => {
expectedAccInputHash,
ethers.keccak256(l2txData),
rootSC,
lastBlock?.timestamp,
currentTime,
trustedSequencer.address,
ethers.ZeroHash
);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -1288,7 +1297,7 @@ describe("Polygon Rollup Manager", () => {
expectedAccInputHash,
ethers.keccak256(l2txData),
rootSC,
lastBlock?.timestamp,
currentTime,
trustedSequencer.address,
ethers.ZeroHash
);
Expand Down Expand Up @@ -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");
Expand All @@ -1846,7 +1859,7 @@ describe("Polygon Rollup Manager", () => {
expectedAccInputHash,
ethers.keccak256(l2txData),
rootSC,
lastBlock?.timestamp,
currentTime,
trustedSequencer.address,
ethers.ZeroHash
);
Expand Down Expand Up @@ -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();
Expand All @@ -2410,7 +2430,7 @@ describe("Polygon Rollup Manager", () => {
expectedAccInputHashInitial,
ethers.keccak256(l2txData),
rootSC,
currentTimestampSequenced,
currentTime,
trustedSequencer.address,
ethers.ZeroHash
);
Expand Down
22 changes: 17 additions & 5 deletions test/contractsv2/PolygonRollupManagerUpgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -656,7 +661,7 @@ describe("Polygon Rollup manager upgraded", () => {
expectedAccInputHash,
ethers.keccak256(l2txData),
rootSC,
lastBlock?.timestamp,
currentTime,
trustedSequencer.address,
ethers.ZeroHash
);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -1363,7 +1375,7 @@ describe("Polygon Rollup manager upgraded", () => {
expectedAccInputHash,
ethers.keccak256(l2txData),
rootSC,
lastBlock?.timestamp,
currentTime,
trustedSequencer.address,
ethers.ZeroHash
);
Expand Down
88 changes: 78 additions & 10 deletions test/contractsv2/PolygonValidiumEtrog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand All @@ -618,6 +653,8 @@ describe("PolygonZkEVMEtrog", () => {
forcedBlockHashL1: ethers.ZeroHash,
},
],
currentTime,
currentSequenceNumber,
trustedSequencer.address
)
).to.be.revertedWithCustomError(PolygonZKEVMV2Contract, "TransactionsLengthAboveMax");
Expand All @@ -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;
Expand All @@ -647,7 +691,7 @@ describe("PolygonZkEVMEtrog", () => {
expectedAccInputHash,
ethers.keccak256(l2txData),
await polygonZkEVMGlobalExitRoot.getRoot(),
currentTimestampSequenced,
currentTime,
trustedSequencer.address,
ethers.ZeroHash
);
Expand Down Expand Up @@ -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"
)
Expand All @@ -764,6 +817,8 @@ describe("PolygonZkEVMEtrog", () => {
await expect(
PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium(
hugeBatchArray,
currentTime,
currentSequenceNumber,
trustedSequencer.address,
"0x"
)
Expand All @@ -780,6 +835,8 @@ describe("PolygonZkEVMEtrog", () => {
forcedBlockHashL1: ethers.ZeroHash,
},
],
currentTime,
currentSequenceNumber,
trustedSequencer.address,
"0x"
)
Expand All @@ -788,6 +845,8 @@ describe("PolygonZkEVMEtrog", () => {
await expect(
PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium(
[sequenceValidium],
currentTime,
currentSequenceNumber,
trustedSequencer.address,
"0x1233"
)
Expand Down Expand Up @@ -839,6 +898,8 @@ describe("PolygonZkEVMEtrog", () => {
await expect(
PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium(
[sequenceValidium],
currentTime,
currentSequenceNumber,
trustedSequencer.address,
badDataAvMessage
)
Expand All @@ -847,6 +908,8 @@ describe("PolygonZkEVMEtrog", () => {
await expect(
PolygonZKEVMV2Contract.connect(trustedSequencer).sequenceBatchesValidium(
[sequenceValidium],
currentTime,
currentSequenceNumber,
trustedSequencer.address,
badDataAvMessage.slice(0, -2)
)
Expand All @@ -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
);
Expand Down Expand Up @@ -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"
)
Expand Down
Loading

0 comments on commit a8e4d10

Please sign in to comment.