Skip to content

Commit

Permalink
test: covering Contract API and Logs API endpoints
Browse files Browse the repository at this point in the history
Fixed text suites/cases naming, adjusted beforeAll preconditions, added more checks to Logs TC
  • Loading branch information
amelnytskyi authored and pcheremu committed Dec 13, 2023
1 parent 359399d commit ea94965
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 23 deletions.
41 changes: 29 additions & 12 deletions packages/integration-tests/tests/api/contracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
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 { Helper } from "../../src/helper";
import { Playbook } from "../../src/playbook/playbook";

describe("Contracts", () => {
describe("Contracts API", () => {
jest.setTimeout(localConfig.standardTimeout);

const helper = new Helper();
const playbook = new Playbook();
const bufferFile = "src/playbook/";
let paymasterContract: string;
let paymasterTx: string;

beforeAll(async () => {
paymasterContract = await helper.getStringFromFile(bufferFile + Buffer.paymaster);
paymasterTx = await helper.getStringFromFile(bufferFile + Buffer.paymasterDeployTx);
});
let multicallCallerContract: string;
let multicallCallerTx: string;

describe("/api?module=contract&action=getcontractcreation", () => {
jest.setTimeout(localConfig.standardTimeout); //works unstable without timeout
beforeAll(async () => {
await playbook.deployViaPaymaster();
await playbook.deployMultiCallContracts();
});

//@id1696
it("Verify the response via /api?module=contract&action=getcontractcreation", async () => {
await setTimeout(localConfig.extendedPause); //works unstable without timeout
const apiRoute = `/api?module=contract&action=getcontractcreation&contractaddresses=${paymasterContract}`;
it("Verify the response via /api?module=contract&action=getcontractcreation&contractaddresses={address1},{address2}", async () => {
paymasterContract = await helper.getStringFromFile(bufferFile + Buffer.paymaster);
paymasterTx = await helper.getStringFromFile(bufferFile + Buffer.paymasterDeployTx);
multicallCallerContract = await helper.getStringFromFile(bufferFile + Buffer.addressMultiCallCaller);
multicallCallerTx = await helper.getStringFromFile(bufferFile + Buffer.txMultiCallCaller);
const apiRoute = `/api?module=contract&action=getcontractcreation&contractaddresses=${paymasterContract},${multicallCallerContract}`;
return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
Expand All @@ -37,7 +41,20 @@ describe("Contracts", () => {
expect.objectContaining({ contractCreator: Wallets.richWalletAddress })
)
)
.expect((res) => expect(res.body.result[0]).toStrictEqual(expect.objectContaining({ txHash: paymasterTx })));
.expect((res) => expect(res.body.result[0]).toStrictEqual(expect.objectContaining({ txHash: paymasterTx })))
.expect((res) =>
expect(res.body.result[1]).toStrictEqual(
expect.objectContaining({ contractAddress: multicallCallerContract })
)
)
.expect((res) =>
expect(res.body.result[1]).toStrictEqual(
expect.objectContaining({ contractCreator: Wallets.richWalletAddress })
)
)
.expect((res) =>
expect(res.body.result[1]).toStrictEqual(expect.objectContaining({ txHash: multicallCallerTx }))
);
});
});
});
43 changes: 32 additions & 11 deletions packages/integration-tests/tests/api/logs.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,64 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

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

describe("Logs", () => {
describe("Logs API", () => {
jest.setTimeout(localConfig.standardTimeout); //works unstable without timeout
const helper = new Helper();
const bufferFile = "src/playbook/";
const playbook = new Playbook();
let contractAddress: string;

beforeAll(async () => {
contractAddress = await helper.getStringFromFile(bufferFile + Buffer.customToken);
});
let txHash: string;

describe("/api?module=logs&action=getLogs", () => {
beforeAll(async () => {
await playbook.deployGreeterToL2();
await playbook.useGreeter();
});

//@id1808
it("Verify the response via /api?module=logs&action=getLogs", async () => {
await setTimeout(localConfig.extendedPause); //works unstable without timeout
it("Verify the response via /api?module=logs&action=getLogs&page={page}&offset={offset}0&toBlock={toBlock}&fromBlock={fromBlock}&address={address}", async () => {
contractAddress = await helper.getStringFromFile(bufferFile + Buffer.greeterL2);
txHash = await helper.getStringFromFile(bufferFile + Buffer.executeGreeterTx);

const apiRoute = `/api?module=logs&action=getLogs&page=1&offset=1&toBlock=1000&fromBlock=1&address=${contractAddress}`;
const apiRoute = `/api?module=logs&action=getLogs&page=1&offset=10&toBlock=10000&fromBlock=1&address=${contractAddress}`;

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) =>
expect(res.body.result[0]).toStrictEqual(expect.objectContaining({ address: contractAddress }))
)
.expect((res) => expect(Array.isArray(res.body.result[0].topics)).toStrictEqual(true))
.expect((res) => expect(typeof res.body.result[0].topics[0]).toStrictEqual("string"))
.expect((res) => expect(res.body.result[0].topics[0].startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].topics[0].length).toBe(66))
.expect((res) => expect(typeof res.body.result[0].data).toStrictEqual("string"))
.expect((res) => expect(res.body.result[0].data.startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].data.length).toBe(194))
.expect((res) => expect(typeof res.body.result[0].blockNumber).toStrictEqual("string"))
.expect((res) => expect(res.body.result[0].blockNumber.startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].blockNumber.length).toBe(5))
.expect((res) => expect(typeof res.body.result[0].timeStamp).toStrictEqual("string"))
.expect((res) => expect(res.body.result[0].timeStamp.startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].timeStamp.length).toBe(10))
.expect((res) => expect(typeof res.body.result[0].gasPrice).toStrictEqual("string"))
.expect((res) => expect(res.body.result[0].gasPrice.startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].gasPrice.length).toBe(9))
.expect((res) => expect(typeof res.body.result[0].gasUsed).toStrictEqual("string"))
.expect((res) => expect(res.body.result[0].gasUsed.startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].gasUsed.length).toBe(7))
.expect((res) => expect(typeof res.body.result[0].logIndex).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].transactionHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].transactionIndex).toStrictEqual("string"));
.expect((res) => expect(res.body.result[0].logIndex.startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].logIndex.length).toBe(3))
.expect((res) => expect(res.body.result[0]).toStrictEqual(expect.objectContaining({ transactionHash: txHash })))
.expect((res) => expect(typeof res.body.result[0].transactionIndex).toStrictEqual("string"))
.expect((res) => expect(res.body.result[0].transactionIndex.startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].transactionIndex.length).toBe(3));
});
});
});

0 comments on commit ea94965

Please sign in to comment.