Skip to content

Commit

Permalink
Create testing for create rollup tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Dec 31, 2024
1 parent c40411d commit 3195aa5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docker/scripts/v2/tests-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set -e
docker run -p 8545:8545 -d --name docker_test hermeznetwork/geth-zkevm-contracts
# Run docker tests
npx hardhat test docker/docker-tests.test.ts --network localhost
# Run tooling tests to docker
npx hardhat test docker/tools-docker-tests.test.ts --network localhost
# stop container
docker stop docker_test
# remove container
Expand Down
83 changes: 83 additions & 0 deletions docker/tools-docker-tests.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {expect} from "chai";
import {ethers} from "hardhat";
import fs from "fs";
import path from "path";
import shelljs from "shelljs";
import {ConsensusContracts} from "../src/pessimistic-utils";

const deployOutput = JSON.parse(fs.readFileSync(path.join(__dirname, "./deploymentOutput/deploy_output.json"), "utf8"));
const {polygonRollupManagerAddress, polygonZkEVMBridgeAddress, polygonZkEVMGlobalExitRootAddress, polTokenAddress} =
deployOutput;
const createRollupOutput = JSON.parse(
fs.readFileSync(path.join(__dirname, "./deploymentOutput/create_rollup_output.json"), "utf8")
);
const {rollupAddress} = createRollupOutput;
import {
PolygonRollupManager,
PolygonPessimisticConsensus,
PolygonValidiumEtrog,
PolygonZkEVMEtrog,
} from "../typechain-types";

describe("Tooling docker build tests Contract", () => {
it("Create a new rollup", async () => {
// Read docker deployment output
const dockerDeploymentOutput = JSON.parse(
fs.readFileSync(path.join(__dirname, "./deploymentOutput/create_rollup_output.json"), "utf8")
);
// Read create rollup config file
const createRollupConfig = JSON.parse(
fs.readFileSync(path.join(__dirname, "../tools/createNewRollup/create_new_rollup.json.example"), "utf8")
);

// Update example config from docker deployment output
createRollupConfig.consensusContractName = dockerDeploymentOutput.consensusContract;
createRollupConfig.gasTokenAddress = dockerDeploymentOutput.gasTokenAddress;
createRollupConfig.outputPath = "create_new_rollup_output.json";
createRollupConfig.chainID = 12;
fs.writeFileSync(
path.join(__dirname, "../tools/createNewRollup/create_new_rollup.json"),
JSON.stringify(createRollupConfig, null, 2)
);

// Run tool
shelljs.exec("npx hardhat run ./tools/createNewRollup/createNewRollup.ts --network localhost");

// Read create rollup output
const createRollupOutput = JSON.parse(
fs.readFileSync(path.join(__dirname, "../tools/createNewRollup/create_new_rollup_output.json"), "utf8")
);
// Check output values with current docker environment
const PolygonRollupManagerFactory = await ethers.getContractFactory("PolygonRollupManager");
const rollupManagerContract = PolygonRollupManagerFactory.attach(
createRollupOutput.rollupManagerAddress
) as PolygonRollupManager;

expect(createRollupConfig.rollupManagerAddress).to.equal(rollupManagerContract.target);
// Get rollup data
const rollupId = await rollupManagerContract.rollupAddressToID(createRollupOutput.rollupAddress);
expect(Number(rollupId)).to.equal(createRollupOutput.rollupID);
expect(await rollupManagerContract.chainIDToRollupID(createRollupConfig.chainID)).to.equal(
createRollupOutput.rollupID
);
const rollupFactory = (await ethers.getContractFactory(createRollupConfig.consensusContractName)) as any;
let rollupContract;
switch (createRollupConfig.consensusContractName) {
case ConsensusContracts.PolygonZkEVMEtrog:
rollupContract = rollupFactory.attach(createRollupOutput.rollupAddress) as PolygonZkEVMEtrog;
break;
case ConsensusContracts.PolygonValidiumEtrog:
rollupContract = rollupFactory.attach(createRollupOutput.rollupAddress) as PolygonValidiumEtrog;
break;
case ConsensusContracts.PolygonPessimisticConsensus:
rollupContract = rollupFactory.attach(createRollupOutput.rollupAddress) as PolygonPessimisticConsensus;
break;
default:
throw new Error("Invalid consensus contract");
}

expect(await rollupContract.rollupManager()).to.equal(createRollupConfig.rollupManagerAddress);
expect(await rollupContract.gasTokenAddress()).to.equal(createRollupConfig.gasTokenAddress);
expect(await rollupContract.trustedSequencer()).to.equal(createRollupConfig.trustedSequencer);
});
});
4 changes: 1 addition & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#v8.0.0-fork.12",
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"@openzeppelin/contracts": "4.8.2",
"shelljs": "^0.8.5",
"@openzeppelin/contracts-upgradeable": "4.8.2",
"@openzeppelin/contracts5": "npm:@openzeppelin/[email protected]",
"@openzeppelin/hardhat-upgrades": "^2.5.1",
Expand Down

0 comments on commit 3195aa5

Please sign in to comment.