Skip to content

Commit

Permalink
feat(tests): added tests for pubdata chunk publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
koloz193 committed Jan 24, 2024
1 parent abcbaf3 commit fd3fec8
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
67 changes: 67 additions & 0 deletions system-contracts/test/PubdataChunkPublisher.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { expect } from "chai";
import type { BytesLike } from "ethers";

Check failure on line 2 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'BytesLike' is defined but never used

Check failure on line 2 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'BytesLike' is defined but never used

Check failure on line 2 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'BytesLike' is defined but never used
import { BigNumber } from "ethers";

Check failure on line 3 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'BigNumber' is defined but never used

Check failure on line 3 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'BigNumber' is defined but never used

Check failure on line 3 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'BigNumber' is defined but never used
import { ethers, network } from "hardhat";
import type { Wallet } from "zksync-web3";
import * as zksync from "zksync-web3";

Check failure on line 6 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'zksync' is defined but never used

Check failure on line 6 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'zksync' is defined but never used

Check failure on line 6 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'zksync' is defined but never used
import type { PubdataChunkPublisher } from "../typechain";
import { PubdataChunkPublisherFactory } from "../typechain";
import {

Check failure on line 9 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎····TEST_L1_MESSENGER_SYSTEM_CONTRACT_ADDRESS,⏎····TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS,⏎` with `·TEST_L1_MESSENGER_SYSTEM_CONTRACT_ADDRESS,·TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS·`

Check failure on line 9 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎····TEST_L1_MESSENGER_SYSTEM_CONTRACT_ADDRESS,⏎····TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS,⏎` with `·TEST_L1_MESSENGER_SYSTEM_CONTRACT_ADDRESS,·TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS·`

Check failure on line 9 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎····TEST_L1_MESSENGER_SYSTEM_CONTRACT_ADDRESS,⏎····TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS,⏎` with `·TEST_L1_MESSENGER_SYSTEM_CONTRACT_ADDRESS,·TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS·`
TEST_L1_MESSENGER_SYSTEM_CONTRACT_ADDRESS,
TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS,
} from "./shared/constants";
import { encodeCalldata, getMock, prepareEnvironment, setResult } from "./shared/mocks";

Check failure on line 13 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'encodeCalldata' is defined but never used

Check failure on line 13 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'getMock' is defined but never used

Check failure on line 13 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'setResult' is defined but never used

Check failure on line 13 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'encodeCalldata' is defined but never used

Check failure on line 13 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'getMock' is defined but never used

Check failure on line 13 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'setResult' is defined but never used

Check failure on line 13 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'encodeCalldata' is defined but never used

Check failure on line 13 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'getMock' is defined but never used

Check failure on line 13 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'setResult' is defined but never used
import { deployContractOnAddress, getWallets } from "./shared/utils";

describe("PubdataChunkPublisher tests", () => {
let wallet: Wallet;

Check failure on line 17 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 17 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 17 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
let l1MessengerAccount: ethers.Signer;

Check failure on line 18 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `····` with `··`

Check failure on line 18 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `····` with `··`

Check failure on line 18 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `····` with `··`

let pubdataChunkPublisher: PubdataChunkPublisher;

Check failure on line 20 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 20 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 20 in system-contracts/test/PubdataChunkPublisher.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

const genRanHex = size => [...Array(size*2)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
const blobSizeInBytes = 126_976;
const maxNumberBlobs = 2;

before(async () => {
await prepareEnvironment();
wallet = getWallets()[0];

await deployContractOnAddress(TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS, "PubdataChunkPublisher");
pubdataChunkPublisher = PubdataChunkPublisherFactory.connect(TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS, wallet);

l1MessengerAccount = await ethers.getImpersonatedSigner(TEST_L1_MESSENGER_SYSTEM_CONTRACT_ADDRESS);
});

after(async () => {
await network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [TEST_L1_MESSENGER_SYSTEM_CONTRACT_ADDRESS],
});
});

describe("chunkAndPublishPubdata", () => {
it("non-L1Messenger failed to call", async () => {
await expect(pubdataChunkPublisher.chunkAndPublishPubdata("0x1337")).to.be.revertedWith(
"Inappropriate caller"
);
});

it("Too Much Pubdata", async () => {
let pubdata = '0x' + genRanHex(blobSizeInBytes * maxNumberBlobs + 1);
await expect(
pubdataChunkPublisher.connect(l1MessengerAccount).chunkAndPublishPubdata(pubdata)
).to.be.revertedWith("pubdata should fit in 2 blobs");
});

it("Publish 1 Blob", async () => {
let pubdata = '0x' + genRanHex(blobSizeInBytes);
pubdataChunkPublisher.connect(l1MessengerAccount).chunkAndPublishPubdata(pubdata);
});

it("Publish 2 Blobs", async () => {
let pubdata = '0x' + genRanHex(blobSizeInBytes * maxNumberBlobs);
pubdataChunkPublisher.connect(l1MessengerAccount).chunkAndPublishPubdata(pubdata);
});
});
});
1 change: 1 addition & 0 deletions system-contracts/test/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const TEST_ETH_TOKEN_SYSTEM_CONTRACT_ADDRESS = "0x00000000000000000000000
export const TEST_BOOTLOADER_UTILITIES_ADDRESS = "0x000000000000000000000000000000000000900c";
export const TEST_COMPRESSOR_CONTRACT_ADDRESS = "0x000000000000000000000000000000000000900e";
export const TEST_COMPLEX_UPGRADER_CONTRACT_ADDRESS = "0x000000000000000000000000000000000000900f";
export const TEST_PUBDATA_CHUNK_PUBLISHER_ADDRESS = "0x0000000000000000000000000000000000009011";

// event writer should be on the original address because event logs are filtered by address
export const REAL_EVENT_WRITER_CONTRACT_ADDRESS = "0x000000000000000000000000000000000000800d";
Expand Down

0 comments on commit fd3fec8

Please sign in to comment.