From af196bddfcb272f5bd571aa752c6f1ce3f715932 Mon Sep 17 00:00:00 2001 From: amelnytskyi Date: Fri, 26 Jan 2024 20:02:50 +0200 Subject: [PATCH] test: covering Batches API covering Batches API --- .../tests/api/addresses.test.ts | 3 ++ .../tests/api/batches.test.ts | 18 ++++++++ .../tests/api/transactions.test.ts | 41 +++++++++++++++++ .../tests/ui/transactions.spec.ts | 44 +++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 packages/integration-tests/tests/ui/transactions.spec.ts diff --git a/packages/integration-tests/tests/api/addresses.test.ts b/packages/integration-tests/tests/api/addresses.test.ts index d91b23fa5f..5ae747e404 100644 --- a/packages/integration-tests/tests/api/addresses.test.ts +++ b/packages/integration-tests/tests/api/addresses.test.ts @@ -144,10 +144,13 @@ describe("Address", () => { expect(response.body.items[0]).toEqual(expect.objectContaining({ address: contract })); expect(Array.isArray(response.body.items[0].topics)).toStrictEqual(true); expect(typeof response.body.items[0].data).toStrictEqual("string"); + expect(typeof response.body.items[0].blockNumber).toStrictEqual("number"); + expect(response.body.items[0].blockNumber).toBeGreaterThanOrEqual(1); expect(response.body.items[0]).toEqual(expect.objectContaining({ transactionHash: txHash })); expect(typeof response.body.items[0].transactionIndex).toStrictEqual("number"); expect(typeof response.body.items[0].logIndex).toStrictEqual("number"); expect(typeof response.body.items[0].timestamp).toStrictEqual("string"); + expect(response.body.items[0].timestamp.length).toBe(24); expect(response.body.meta).toEqual(expect.objectContaining({ totalItems: 1 })); expect(response.body.meta).toEqual(expect.objectContaining({ itemCount: 1 })); expect(response.body.meta).toEqual(expect.objectContaining({ itemsPerPage: 10 })); diff --git a/packages/integration-tests/tests/api/batches.test.ts b/packages/integration-tests/tests/api/batches.test.ts index 8a7ccf0f56..26dc85af5c 100644 --- a/packages/integration-tests/tests/api/batches.test.ts +++ b/packages/integration-tests/tests/api/batches.test.ts @@ -14,8 +14,26 @@ describe("Batches", () => { apiRoute = `/batches`; response = await helper.performGETrequest(apiRoute); + expect(response.status).toBe(200); expect(Array.isArray(response.body.items)).toStrictEqual(true); expect(response.body.items.length).toBeGreaterThanOrEqual(1); + expect(typeof response.body.items[0].number).toStrictEqual("number"); + expect(response.body.items[0].number).toBeGreaterThanOrEqual(1); + expect(typeof response.body.items[0].timestamp).toStrictEqual("string"); + expect(response.body.items[0].timestamp.length).toBe(24); + expect(typeof response.body.items[0].rootHash).toStrictEqual("string"); + expect(response.body.items[0].rootHash.length).toBe(66); + expect(response.body.items[0].rootHash.startsWith("0x")).toBe(true); + expect(typeof response.body.items[0].executedAt).toStrictEqual("string"); + expect(response.body.items[0].executedAt.length).toBe(24); + expect(typeof response.body.items[0].l1TxCount).toStrictEqual("number"); + expect(response.body.items[0].l1TxCount).toBeGreaterThanOrEqual(0); + expect(typeof response.body.items[0].l2TxCount).toStrictEqual("number"); + expect(response.body.items[0].l2TxCount).toBeGreaterThanOrEqual(0); + expect(typeof response.body.items[0].size).toStrictEqual("number"); + expect(response.body.items[0].size).toBeGreaterThanOrEqual(0); + expect(typeof response.body.items[0].status).toStrictEqual("string"); + expect(response.body.items[0].status.length).toBeGreaterThanOrEqual(6); expect(typeof response.body.meta.totalItems).toStrictEqual("number"); expect(typeof response.body.meta.itemCount).toStrictEqual("number"); expect(typeof response.body.meta.itemsPerPage).toStrictEqual("number"); diff --git a/packages/integration-tests/tests/api/transactions.test.ts b/packages/integration-tests/tests/api/transactions.test.ts index 56e5fa9df7..5020fb3b14 100644 --- a/packages/integration-tests/tests/api/transactions.test.ts +++ b/packages/integration-tests/tests/api/transactions.test.ts @@ -759,6 +759,47 @@ describe("Transactions", () => { expect(response.status).toBe(200); expect(Array.isArray(response.body.items)).toStrictEqual(true); expect(response.body.items.length).toBe(10); + expect(typeof response.body.items[0].hash).toStrictEqual("string"); + expect(response.body.items[0].hash.length).toBe(66); + expect(typeof response.body.items[0].to).toStrictEqual("string"); + expect(response.body.items[0].to.length).toBe(42); + expect(typeof response.body.items[0].from).toStrictEqual("string"); + expect(response.body.items[0].from.length).toBe(42); + expect(typeof response.body.items[0].data).toStrictEqual("string"); + expect(response.body.items[0].data.length).toBe(138); + expect(response.body.items[0]).toStrictEqual(expect.objectContaining({ value: "0" })); + expect(response.body.items[0]).toStrictEqual(expect.objectContaining({ isL1Originated: false })); + expect(typeof response.body.items[0].fee).toStrictEqual("string"); + expect(response.body.items[0].fee.length).toBe(14); + expect(typeof response.body.items[0].nonce).toStrictEqual("number"); + expect(response.body.items[0].nonce).toBeGreaterThanOrEqual(0); + expect(typeof response.body.items[0].gasLimit).toStrictEqual("string"); + expect(typeof response.body.items[0].gasPrice).toStrictEqual("string"); + expect(typeof response.body.items[0].gasPerPubdata).toStrictEqual("string"); + expect(typeof response.body.items[0].maxFeePerGas).toStrictEqual("string"); + expect(typeof response.body.items[0].maxPriorityFeePerGas).toStrictEqual("string"); + expect(typeof response.body.items[0].blockNumber).toStrictEqual("number"); + expect(response.body.items[0].blockNumber).toBeGreaterThanOrEqual(0); + expect(typeof response.body.items[0].l1BatchNumber).toStrictEqual("number"); + expect(response.body.items[0].l1BatchNumber).toBeGreaterThanOrEqual(0); + expect(typeof response.body.items[0].blockHash).toStrictEqual("string"); + expect(response.body.items[0].blockHash.length).toBe(66); + expect(typeof response.body.items[0].type).toStrictEqual("number"); + expect(response.body.items[0].type).toBeGreaterThanOrEqual(0); + expect(response.body.items[0]).toStrictEqual(expect.objectContaining({ transactionIndex: 0 })); + expect(typeof response.body.items[0].receivedAt).toStrictEqual("string"); + expect(response.body.items[0].receivedAt.length).toBe(24); + expect(response.body.items[0]).toStrictEqual(expect.objectContaining({ error: null })); + expect(typeof response.body.items[0].revertReason).toBe("string" || null); + //expect(response.body.items[0]).toStrictEqual(expect.objectContaining({ revertReason: null })); + expect(typeof response.body.items[0].status).toStrictEqual("string"); + expect(typeof response.body.items[0].commitTxHash).toStrictEqual("string"); + expect(response.body.items[0].commitTxHash.length).toBe(66); + expect(typeof response.body.items[0].executeTxHash).toStrictEqual("string"); + expect(response.body.items[0].executeTxHash.length).toBe(66); + expect(typeof response.body.items[0].proveTxHash).toStrictEqual("string"); + expect(response.body.items[0].proveTxHash.length).toBe(66); + expect(typeof response.body.items[0].isL1BatchSealed).toStrictEqual("boolean"); expect(typeof response.body.meta.totalItems).toStrictEqual("number"); expect(typeof response.body.meta.itemCount).toStrictEqual("number"); expect(typeof response.body.meta.itemsPerPage).toStrictEqual("number"); diff --git a/packages/integration-tests/tests/ui/transactions.spec.ts b/packages/integration-tests/tests/ui/transactions.spec.ts new file mode 100644 index 0000000000..22f923bf1e --- /dev/null +++ b/packages/integration-tests/tests/ui/transactions.spec.ts @@ -0,0 +1,44 @@ +import { expect, test } from "@playwright/test"; + +import { config } from "./config"; +import { BlockExplorer, Buffer } from "../../src/entities"; +import { Helper } from "../../src/helper"; + +import type { Locator } from "@playwright/test"; + +const bufferRoute = "src/playbook/"; +const helper = new Helper(); +let url: string; +let bufferFile; +let failedTxHash: string; +let contract: string; +let element: Locator; +let selector: string; + +//@id1656 +test("Verify failed tx", async ({ page }) => { + bufferFile = bufferRoute + Buffer.failedState; + failedTxHash = await helper.getStringFromFile(bufferFile); + url = BlockExplorer.baseUrl + `/tx/${failedTxHash}` + BlockExplorer.localNetwork; + + await page.goto(url); + + selector = `text=Failed`; + element = await page.locator(selector); + + await expect(element).toBeVisible(config.extraTimeout); +}); + +//@id1655 +test("Verify deployed the own ERC20 token contract", async ({ page }) => { + bufferFile = bufferRoute + Buffer.L2; + contract = await helper.getStringFromFile(bufferFile); + url = BlockExplorer.baseUrl + `/address/${contract}` + BlockExplorer.localNetwork; + + await page.goto(url); + + selector = `text=${contract}`; + element = await page.locator(selector).first(); + + await expect(element).toBeVisible(config.extraTimeout); +});