-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
blockchain_integration/pi_network/pi-network-layer2-scaling/tests/rollups/Rollup.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Rollup.test.js | ||
const { expect } = require("chai"); | ||
const { ethers } = require("hardhat"); | ||
|
||
describe("Rollup Contract", function () { | ||
let Rollup; | ||
let rollup; | ||
let RollupManager; | ||
let rollupManager; | ||
let owner; | ||
let operator; | ||
|
||
beforeEach(async function () { | ||
[owner, operator] = await ethers.getSigners(); | ||
|
||
RollupManager = await ethers.getContractFactory("RollupManager"); | ||
rollupManager = await RollupManager.deploy(); | ||
await rollupManager.deployed(); | ||
|
||
Rollup = await ethers.getContractFactory("Rollup"); | ||
rollup = await Rollup.deploy(rollupManager.address); | ||
await rollup.deployed(); | ||
}); | ||
|
||
it("should create a batch successfully", async function () { | ||
const stateRoot = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("Sample State Root")); | ||
await rollup.connect(operator).createBatch(stateRoot); | ||
|
||
const batch = await rollup.getBatch(0); | ||
expect(batch.stateRoot).to.equal(stateRoot); | ||
expect(batch.index).to.equal(0); | ||
}); | ||
|
||
it("should validate a transaction successfully", async function () { | ||
const stateRoot = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("Sample State Root")); | ||
await rollup.connect(operator).createBatch(stateRoot); | ||
|
||
await rollup.connect(operator).validateTransaction(stateRoot, operator.address); | ||
const isValid = await rollup.isTransactionValid(stateRoot, operator.address); | ||
expect(isValid).to.be.true; | ||
}); | ||
|
||
it("should revert when creating a batch with the same state root", async function () { | ||
const stateRoot = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("Sample State Root")); | ||
await rollup.connect(operator).createBatch(stateRoot); | ||
|
||
await expect(rollup.connect(operator).createBatch(stateRoot)).to.be.revertedWith("Batch already exists"); | ||
}); | ||
}); |