diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts index 037eb3b215..da5917e373 100644 --- a/contracts/hardhat.config.ts +++ b/contracts/hardhat.config.ts @@ -84,6 +84,9 @@ const config: HardhatUserConfig = { etherscan: { apiKey: process.env.ETHERSCAN_API_KEY, }, + mocha: { + timeout: 10000000, + }, dodoc: { runOnCompile: true, keepFileStructure: false, diff --git a/contracts/integration-test/ScrollChain.spec.ts b/contracts/integration-test/ScrollChain.spec.ts index 8a0bd02675..cc2fb3030d 100644 --- a/contracts/integration-test/ScrollChain.spec.ts +++ b/contracts/integration-test/ScrollChain.spec.ts @@ -1,5 +1,6 @@ /* eslint-disable node/no-unpublished-import */ /* eslint-disable node/no-missing-import */ +import { concat } from "ethers/lib/utils"; import { constants } from "ethers"; import { ethers } from "hardhat"; import { ScrollChain, L1MessageQueue } from "../typechain"; @@ -11,22 +12,27 @@ describe("ScrollChain", async () => { beforeEach(async () => { const [deployer] = await ethers.getSigners(); - const L1MessageQueue = await ethers.getContractFactory("L1MessageQueue", deployer); - queue = await L1MessageQueue.deploy(); - await queue.deployed(); + const ProxyAdmin = await ethers.getContractFactory("ProxyAdmin", deployer); + const admin = await ProxyAdmin.deploy(); + await admin.deployed(); + + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy", deployer); - const RollupVerifier = await ethers.getContractFactory("RollupVerifier", deployer); - const verifier = await RollupVerifier.deploy(); - await verifier.deployed(); + const L1MessageQueue = await ethers.getContractFactory("L1MessageQueue", deployer); + const queueImpl = await L1MessageQueue.deploy(); + await queueImpl.deployed(); + const queueProxy = await TransparentUpgradeableProxy.deploy(queueImpl.address, admin.address, "0x"); + await queueProxy.deployed(); + queue = await ethers.getContractAt("L1MessageQueue", queueProxy.address, deployer); - const ScrollChain = await ethers.getContractFactory("ScrollChain", { - signer: deployer, - libraries: { RollupVerifier: verifier.address }, - }); - chain = await ScrollChain.deploy(0); - await chain.deployed(); + const ScrollChain = await ethers.getContractFactory("ScrollChain", deployer); + const chainImpl = await ScrollChain.deploy(0); + await chainImpl.deployed(); + const chainProxy = await TransparentUpgradeableProxy.deploy(chainImpl.address, admin.address, "0x"); + await chainProxy.deployed(); + chain = await ethers.getContractAt("ScrollChain", chainProxy.address, deployer); - await chain.initialize(queue.address, constants.AddressZero, 44); + await chain.initialize(queue.address, constants.AddressZero, 100); await chain.addSequencer(deployer.address); await queue.initialize( constants.AddressZero, @@ -38,79 +44,54 @@ describe("ScrollChain", async () => { }); // @note skip this benchmark tests - /* - it("should succeed", async () => { - await chain.importGenesisBatch({ - blocks: [ - { - blockHash: "0x92826bd3aad2ef70d8061dc4e25150b305d1233d9cd7579433a77d6eb01dae1c", - parentHash: constants.HashZero, - blockNumber: 0, - timestamp: 1639724192, - baseFee: 1000000000, - gasLimit: 940000000, - numTransactions: 0, - numL1Messages: 0, - }, - ], - prevStateRoot: constants.HashZero, - newStateRoot: "0x1b186a7a90ec3b41a2417062fe44dce8ce82ae76bfbb09eae786a4f1be1895f5", - withdrawTrieRoot: constants.HashZero, - batchIndex: 0, - parentBatchHash: constants.HashZero, - l2Transactions: [], - }); - const parentBatchHash = await chain.lastFinalizedBatchHash(); + it.skip("should succeed", async () => { + const batchHeader0 = new Uint8Array(89); + batchHeader0[25] = 1; + await chain.importGenesisBatch(batchHeader0, "0x0000000000000000000000000000000000000000000000000000000000000001"); + const parentBatchHash = await chain.committedBatches(0); console.log("genesis batch hash:", parentBatchHash); + console.log(`ChunkPerBatch`, `BlockPerChunk`, `TxPerBlock`, `BytesPerTx`, `TotalBytes`, `EstimateGas`); + for (let numChunks = 3; numChunks <= 6; ++numChunks) { + for (let numBlocks = 1; numBlocks <= 5; ++numBlocks) { + for (let numTx = 20; numTx <= Math.min(30, 100 / numBlocks); ++numTx) { + for (let txLength = 800; txLength <= 1000; txLength += 100) { + const txs: Array = []; + for (let i = 0; i < numTx; i++) { + const tx = new Uint8Array(4 + txLength); + let offset = 3; + for (let x = txLength; x > 0; x = Math.floor(x / 256)) { + tx[offset] = x % 256; + offset -= 1; + } + tx.fill(1, 4); + txs.push(tx); + } + const chunk = new Uint8Array(1 + 60 * numBlocks); + chunk[0] = numBlocks; + for (let i = 0; i < numBlocks; i++) { + chunk[1 + i * 60 + 57] = numTx; + } + const chunks: Array = []; + for (let i = 0; i < numChunks; i++) { + const txsInChunk: Array = []; + for (let j = 0; j < numBlocks; j++) { + txsInChunk.push(concat(txs)); + } + chunks.push(concat([chunk, concat(txsInChunk)])); + } - for (let numTx = 1; numTx <= 25; ++numTx) { - for (let txLength = 100; txLength <= 1000; txLength += 100) { - const txs: Array = []; - for (let i = 0; i < numTx; i++) { - const tx = new Uint8Array(4 + txLength); - let offset = 3; - for (let x = txLength; x > 0; x = Math.floor(x / 256)) { - tx[offset] = x % 256; - offset -= 1; + const estimateGas = await chain.estimateGas.commitBatch(0, batchHeader0, chunks, "0x"); + console.log( + `${numChunks}`, + `${numBlocks}`, + `${numTx}`, + `${txLength}`, + `${numChunks * numBlocks * numTx * (txLength + 1)}`, + `${estimateGas.toString()}` + ); } - tx.fill(1, 4); - txs.push(tx); } - const batch = { - blocks: [ - { - blockHash: "0xb5baa665b2664c3bfed7eb46e00ebc110ecf2ebd257854a9bf2b9dbc9b2c08f6", - parentHash: "0x92826bd3aad2ef70d8061dc4e25150b305d1233d9cd7579433a77d6eb01dae1c", - blockNumber: 1, - timestamp: numTx * 100000 + txLength, - baseFee: 0, - gasLimit: 0, - numTransactions: 0, - numL1Messages: 0, - }, - ], - prevStateRoot: "0x1b186a7a90ec3b41a2417062fe44dce8ce82ae76bfbb09eae786a4f1be1895f5", - newStateRoot: "0xb5baa665b2664c3bfed7eb46e00ebc110ecf2ebd257854a9bf2b9dbc9b2c08f6", - withdrawTrieRoot: "0xb5baa665b2664c3bfed7eb46e00ebc110ecf2ebd257854a9bf2b9dbc9b2c08f6", - batchIndex: 1, - parentBatchHash: parentBatchHash, - l2Transactions: concat(txs), - }; - const estimateGas = await chain.estimateGas.commitBatch(batch); - const tx = await chain.commitBatch(batch, { gasLimit: estimateGas.mul(12).div(10) }); - const receipt = await tx.wait(); - console.log( - "Commit batch with l2TransactionsBytes:", - numTx * (txLength + 4), - "gasLimit:", - tx.gasLimit.toString(), - "estimateGas:", - estimateGas.toString(), - "gasUsed:", - receipt.gasUsed.toString() - ); } } }); - */ });