Skip to content

Commit

Permalink
test: covering Batches API and partially covered Transactions (#156)
Browse files Browse the repository at this point in the history
covering Batches API

# What ❔

1506 [Transactions] /transactions response returns elements (wasn't
covered fully)
1513 [Batches] /batches response returns elements (wasn't covered fully)
1510 [Transactions] /address/{address}/logs response returns elements
(wasn't covered fully)
1656 [Transactions] Verify failed tx (new test)
1655 [Transactions] Verify deployed the own ERC20 token contract in BE
(new test)

## Why ❔

Why are these changes done? - expanding test coverage

## Checklist

- [ +] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ +] Tests for the changes have been added / updated.
- [ n/a] Documentation comments have been added / updated.
  • Loading branch information
amelnytskyi authored and pcheremu committed Feb 15, 2024
1 parent 0259377 commit fde87c4
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/integration-tests/tests/api/addresses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("Address", () => {

describe("/address/{address}", () => {
beforeAll(async () => {
await playbook.deployNFTtoL1();
await playbook.deployNFTtoL2();
await playbook.deployMultiCallContracts();
await playbook.deployMultiTransferETH();
Expand Down Expand Up @@ -144,10 +145,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 }));
Expand Down
18 changes: 18 additions & 0 deletions packages/integration-tests/tests/api/batches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
41 changes: 41 additions & 0 deletions packages/integration-tests/tests/api/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
44 changes: 44 additions & 0 deletions packages/integration-tests/tests/ui/transactions.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit fde87c4

Please sign in to comment.