Skip to content

Commit

Permalink
test: re-structure test suites for batches, stats, blocks endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
abilevych committed Oct 31, 2023
1 parent f18702f commit d2ea0e9
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 182 deletions.
146 changes: 0 additions & 146 deletions packages/integration-tests/tests/api/common/endpoints.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../../../src/config";
import { localConfig } from "../../../../src/config";

describe("/batches", () => {
jest.setTimeout(localConfig.standardTimeout);
//@id1513
it("Verify the response via /batches", async () => {
const apiRoute = `/batches`;

await setTimeout(localConfig.standardPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(Array.isArray(res.body.items)).toStrictEqual(true))
.expect((res) => expect(res.body.items.length).toBeGreaterThanOrEqual(1))
.expect((res) => expect(typeof res.body.meta.totalItems).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemsPerPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.totalPages).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.currentPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.links.first).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.previous).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.next).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.last).toStrictEqual("string"));
});

//@id1514
it("Verify the response via /batches/{batchNumber}", async () => {
const batches = await request(environment.blockExplorerAPI).get("/batches");

const batchNumber = batches.body.items[0].number;

const apiRoute = `/batches/${batchNumber}`;

await setTimeout(localConfig.standardPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.number).toStrictEqual(batchNumber))
.expect((res) => expect(typeof res.body.timestamp).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.rootHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.executedAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.l1TxCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.l2TxCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.commitTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.committedAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.proveTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.provenAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.executeTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.l1GasPrice).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.l2FairGasPrice).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.size).toStrictEqual("number"))
.expect((res) => expect(res.body.status).toStrictEqual("verified"));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../../../src/config";
import { localConfig } from "../../../../src/config";

describe("/blocks", () => {
jest.setTimeout(localConfig.standardTimeout);

//@id1511
it("Verify the response via /blocks", async () => {
const apiRoute = `/blocks`;

await setTimeout(localConfig.extendedPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(Array.isArray(res.body.items)).toStrictEqual(true))
.expect((res) => expect(res.body.items.length).toBeGreaterThan(1))
.expect((res) => expect(typeof res.body.meta.totalItems).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemsPerPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.totalPages).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.currentPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.links.first).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.previous).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.next).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.last).toStrictEqual("string"));
});

//@id1512
it("Verify the response via /blocks/{/blockNumber}", async () => {
const blocks = await request(environment.blockExplorerAPI).get("/blocks");

const blockNumber = blocks.body.items[0].number;

const apiRoute = `/blocks/${blockNumber}`;

await setTimeout(localConfig.extendedPause); //works unstable without timeout

return (
request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.number).toStrictEqual(blockNumber))
.expect((res) => expect(typeof res.body.hash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.timestamp).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.gasUsed).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.l1BatchNumber).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.l1TxCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.l2TxCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.parentHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.gasLimit).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.baseFeePerGas).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.extraData).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.size).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.status).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.isL1BatchSealed).toStrictEqual("boolean"))
.expect((res) => expect(typeof res.body.commitTxHash).toStrictEqual("string"))
// .expect((res) => expect(typeof res.body.commitTxHash).toStrictEqual("string")) //unstable on a CI
.expect((res) => expect(typeof res.body.proveTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.committedAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.executedAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.provenAt).toStrictEqual("string"))
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../../../src/config";
import { localConfig } from "../../../../src/config";

describe("/stats", () => {
jest.setTimeout(localConfig.standardTimeout);
//@id1515
it("Verify the response via /stats", async () => {
const apiRoute = `/stats`;

await setTimeout(localConfig.standardPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(typeof res.body.lastSealedBatch).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.lastVerifiedBatch).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.lastSealedBlock).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.lastVerifiedBlock).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.totalTransactions).toStrictEqual("number"));
});
});
4 changes: 0 additions & 4 deletions packages/integration-tests/tests/api/common/nft.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../../src/config";
import { localConfig } from "../../../src/config";
import { Logger } from "../../../src/entities";
import { Playbook } from "../../../src/playbook/playbook";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../../src/config";
import { localConfig } from "../../../src/config";
import { Buffer, Wallets } from "../../../src/entities";
import { Buffer } from "../../../src/entities";
import { Helper } from "../../../src/helper";
import { Playbook } from "../../../src/playbook/playbook";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment, localConfig } from "../../../src/config";
import { localConfig } from "../../../src/config";
import { Buffer, Token, Wallets } from "../../../src/entities";
import { Logger } from "../../../src/entities";
import { Helper } from "../../../src/helper";
Expand All @@ -12,7 +9,6 @@ describe("Withdrawal", () => {
const helper = new Helper();
const playbookRoot = "src/playbook";
const l2Token = playbookRoot + "/" + Buffer.L2deposited;
const l1Token = playbookRoot + "/" + Buffer.L1;

let result: string;
jest.setTimeout(localConfig.extendedTimeout);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment, localConfig } from "../../../src/config";
import { Buffer, Logger, Token, TransactionsType, Wallets } from "../../../src/entities";
import { Helper } from "../../../src/helper";
import { localConfig } from "../../../src/config";
import { Logger } from "../../../src/entities";
import { Playbook } from "../../../src/playbook/playbook";

describe("Multicall transactions", () => {
jest.setTimeout(localConfig.extendedTimeout);
const playbook = new Playbook();
const helper = new Helper();
const bufferRoute = "src/playbook/";
let txHash: string;
let txMulticall: string;
let contract: string;

//@id689
it("Deploy the Multicall contracts", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment, localConfig } from "../../../src/config";
import { Buffer, Logger, Token, TransactionsType, Wallets } from "../../../src/entities";
import { localConfig } from "../../../src/config";
import { Buffer, Logger } from "../../../src/entities";
import { Helper } from "../../../src/helper";
import { Playbook } from "../../../src/playbook/playbook";

Expand All @@ -11,9 +8,7 @@ describe("Mulitransfer ETH", () => {
const playbook = new Playbook();
const helper = new Helper();
const bufferRoute = "src/playbook/";
let txHash: string;
let txMultiTransfer: string[];
let token: string;
let contract: string;

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment, localConfig } from "../../../src/config";
import { Buffer, Logger, Token, TransactionsStatus, TransactionsType, Wallets } from "../../../src/entities";
import { localConfig } from "../../../src/config";
import { Buffer, Logger } from "../../../src/entities";
import { Helper } from "../../../src/helper";
import { Playbook } from "../../../src/playbook/playbook";

Expand Down

0 comments on commit d2ea0e9

Please sign in to comment.