From dfbd5d89e0cd7ddbd85703471255ddb103dd2034 Mon Sep 17 00:00:00 2001 From: amelnytskyi Date: Fri, 17 Nov 2023 12:23:25 +0200 Subject: [PATCH 1/3] test: covering Contract API and Logs API endpoints --- packages/integration-tests/src/entities.ts | 1 + .../src/playbook/deploy/deploy-paymaster.ts | 1 + .../tests/api/contracts.test.ts | 43 +++++++++++++++++++ .../integration-tests/tests/api/logs.test.ts | 43 +++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 packages/integration-tests/tests/api/contracts.test.ts create mode 100644 packages/integration-tests/tests/api/logs.test.ts diff --git a/packages/integration-tests/src/entities.ts b/packages/integration-tests/src/entities.ts index 4bf2a48e8a..83b391a60f 100644 --- a/packages/integration-tests/src/entities.ts +++ b/packages/integration-tests/src/entities.ts @@ -7,6 +7,7 @@ export enum Buffer { L2 = "./buffer/L2.txt", L2deposited = "./buffer/L2deposited.txt", paymaster = "./buffer/paymaster.txt", + paymasterDeployTx = "./buffer/paymasterDeployTx.txt", paymasterTx = "./buffer/paymasterTx.txt", addressMultiTransferETH = "./buffer/multiTransferETH.txt", txMultiTransferETH = "./buffer/txMultiTransferETH.txt", diff --git a/packages/integration-tests/src/playbook/deploy/deploy-paymaster.ts b/packages/integration-tests/src/playbook/deploy/deploy-paymaster.ts index a8148f5b33..468e7cc9d5 100644 --- a/packages/integration-tests/src/playbook/deploy/deploy-paymaster.ts +++ b/packages/integration-tests/src/playbook/deploy/deploy-paymaster.ts @@ -31,6 +31,7 @@ export default async function (hre: HardhatRuntimeEnvironment) { const deployTransaction = await paymaster.deployTransaction; console.log(`Paymaster deploy transaction: ${deployTransaction.hash}`); + await fs.writeFile(Buffer.paymasterDeployTx, deployTransaction.hash); await ( await deployer.zkWallet.sendTransaction({ diff --git a/packages/integration-tests/tests/api/contracts.test.ts b/packages/integration-tests/tests/api/contracts.test.ts new file mode 100644 index 0000000000..89944d1ce2 --- /dev/null +++ b/packages/integration-tests/tests/api/contracts.test.ts @@ -0,0 +1,43 @@ +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"; + +describe("Contracts", () => { + jest.setTimeout(localConfig.standardTimeout); + + const helper = new Helper(); + 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); + }); + + describe("/api?module=contract&action=getcontractcreation", () => { + jest.setTimeout(localConfig.standardTimeout); //works unstable without timeout + + //@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}`; + return request(environment.blockExplorerAPI) + .get(apiRoute) + .expect(200) + .expect((res) => + expect(res.body.result[0]).toStrictEqual(expect.objectContaining({ contractAddress: paymasterContract })) + ) + .expect((res) => + expect(res.body.result[0]).toStrictEqual( + expect.objectContaining({ contractCreator: Wallets.richWalletAddress }) + ) + ) + .expect((res) => expect(res.body.result[0]).toStrictEqual(expect.objectContaining({ txHash: paymasterTx }))); + }); + }); +}); diff --git a/packages/integration-tests/tests/api/logs.test.ts b/packages/integration-tests/tests/api/logs.test.ts new file mode 100644 index 0000000000..1ba605c089 --- /dev/null +++ b/packages/integration-tests/tests/api/logs.test.ts @@ -0,0 +1,43 @@ +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"; + +describe("Logs", () => { + jest.setTimeout(localConfig.standardTimeout); //works unstable without timeout + const helper = new Helper(); + const bufferFile = "src/playbook/"; + let contractAddress: string; + + beforeAll(async () => { + contractAddress = await helper.getStringFromFile(bufferFile + Buffer.customToken); + }); + + describe("/api?module=logs&action=getLogs", () => { + //@id1808 + it("Verify the response via /api?module=logs&action=getLogs", async () => { + await setTimeout(localConfig.extendedPause); //works unstable without timeout + + const apiRoute = `/api?module=logs&action=getLogs&page=1&offset=1&toBlock=1000&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(typeof res.body.result[0].topics[0]).toStrictEqual("string")) + .expect((res) => expect(typeof res.body.result[0].data).toStrictEqual("string")) + .expect((res) => expect(typeof res.body.result[0].blockNumber).toStrictEqual("string")) + .expect((res) => expect(typeof res.body.result[0].timeStamp).toStrictEqual("string")) + .expect((res) => expect(typeof res.body.result[0].gasPrice).toStrictEqual("string")) + .expect((res) => expect(typeof res.body.result[0].gasUsed).toStrictEqual("string")) + .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")); + }); + }); +}); From 8b057b12994adc1aab408b9ac3ccfcb416245dc5 Mon Sep 17 00:00:00 2001 From: amelnytskyi Date: Fri, 17 Nov 2023 12:42:02 +0200 Subject: [PATCH 2/3] test: covering Contract API and Logs API endpoints Removed obsolete Wallet import --- packages/integration-tests/tests/api/logs.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integration-tests/tests/api/logs.test.ts b/packages/integration-tests/tests/api/logs.test.ts index 1ba605c089..71db8049db 100644 --- a/packages/integration-tests/tests/api/logs.test.ts +++ b/packages/integration-tests/tests/api/logs.test.ts @@ -3,7 +3,7 @@ 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"; describe("Logs", () => { From 1bc3563b755bed5a048e681ad8ba701ebb6c2b2f Mon Sep 17 00:00:00 2001 From: amelnytskyi Date: Tue, 21 Nov 2023 11:57:20 +0200 Subject: [PATCH 3/3] test: covering Contract API and Logs API endpoints Fixed text suites/cases naming, adjusted beforeAll preconditions, added more checks to Logs TC --- .../tests/api/contracts.test.ts | 41 ++++++++++++------ .../integration-tests/tests/api/logs.test.ts | 43 ++++++++++++++----- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/packages/integration-tests/tests/api/contracts.test.ts b/packages/integration-tests/tests/api/contracts.test.ts index 89944d1ce2..9611fa9427 100644 --- a/packages/integration-tests/tests/api/contracts.test.ts +++ b/packages/integration-tests/tests/api/contracts.test.ts @@ -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) @@ -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 })) + ); }); }); }); diff --git a/packages/integration-tests/tests/api/logs.test.ts b/packages/integration-tests/tests/api/logs.test.ts index 71db8049db..5e5a3b0e4b 100644 --- a/packages/integration-tests/tests/api/logs.test.ts +++ b/packages/integration-tests/tests/api/logs.test.ts @@ -1,27 +1,31 @@ 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) @@ -29,15 +33,32 @@ describe("Logs", () => { .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)); }); }); });