From 718a6c9784a7973de64f402de667797657ab29cc Mon Sep 17 00:00:00 2001 From: Oleh Bairak Date: Mon, 5 Feb 2024 15:14:58 +0100 Subject: [PATCH] fix: first try --- .../tests/api/accounts.test.ts | 187 +++++++++++++++++- 1 file changed, 186 insertions(+), 1 deletion(-) diff --git a/packages/integration-tests/tests/api/accounts.test.ts b/packages/integration-tests/tests/api/accounts.test.ts index 534ab7e184..e17416cd35 100644 --- a/packages/integration-tests/tests/api/accounts.test.ts +++ b/packages/integration-tests/tests/api/accounts.test.ts @@ -2,15 +2,17 @@ import * as request from "supertest"; import { environment } from "../../src/config"; import { localConfig } from "../../src/config"; -import { Token, Wallets } from "../../src/entities"; +import { Buffer, Token, Wallets } from "../../src/entities"; import { Helper } from "../../src/helper"; describe("API module: Account", () => { jest.setTimeout(localConfig.standardTimeout); const helper = new Helper(); + const bufferFile = "src/playbook/"; let apiRoute: string; let response; + let txHash: string; //@id1704 it("Verify /api?module=account&action=balancemulti response", async () => { @@ -102,4 +104,187 @@ describe("API module: Account", () => { expect(typeof response.body.result[0].functionName).toStrictEqual("string"); }); }); + + //@id1852 + it("Verify /api?module=account&action=txlistinternal&address=", async () => { + await helper.retryTestAction(async () => { + const blocks = await request(environment.blockExplorerAPI).get("/blocks"); + const blockNumber = blocks.body.items[0].number; + apiRoute = `/api?module=account&action=txlistinternal&page=1&offset=10&sort=desc&endblock${blockNumber}&startblock=0&address=${Wallets.richWalletAddress}`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "1" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "OK" })); + expect(response.body.result.length).toBeGreaterThan(1); + expect(typeof response.body.result[0].blockNumber).toStrictEqual("string"); + expect(typeof response.body.result[0].timeStamp).toStrictEqual("string"); + expect(typeof response.body.result[0].hash).toStrictEqual("string"); + expect(typeof response.body.result[0].from).toStrictEqual("string"); + expect(typeof response.body.result[0].to).toStrictEqual("string"); + expect(typeof response.body.result[0].value).toStrictEqual("string"); + expect(typeof response.body.result[0].gas).toStrictEqual("string"); + expect(typeof response.body.result[0].input).toStrictEqual("string"); + expect(typeof response.body.result[0].type).toStrictEqual("string"); + expect(typeof response.body.result[0].contractAddress).toBeTruthy(); + expect(typeof response.body.result[0].gasUsed).toStrictEqual("string"); + expect(typeof response.body.result[0].fee).toStrictEqual("string"); + expect(typeof response.body.result[0].l1BatchNumber).toStrictEqual("string"); + expect(typeof response.body.result[0].traceId).toBeTruthy(); + expect(typeof response.body.result[0].transactionType).toStrictEqual("string"); + expect(typeof response.body.result[0].isError).toStrictEqual("string"); + expect(typeof response.body.result[0].errCode).toStrictEqual("string"); + }); + }); + + //@id1804 + it("Verify /api?module=account&action=txlistinternal", async () => { + await helper.retryTestAction(async () => { + const blocks = await request(environment.blockExplorerAPI).get("/blocks"); + const blockNumber = blocks.body.items[0].number; + apiRoute = `/api?module=account&action=txlistinternal&page=1&offset=10&sort=desc&endblock=${blockNumber}&startblock=1`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "1" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "OK" })); + expect(response.body.result.length).toBeGreaterThan(1); + expect(typeof response.body.result[0].blockNumber).toStrictEqual("string"); + expect(typeof response.body.result[0].timeStamp).toStrictEqual("string"); + expect(typeof response.body.result[0].hash).toBeTruthy(); //can be null + expect(typeof response.body.result[0].from).toStrictEqual("string"); + expect(typeof response.body.result[0].to).toStrictEqual("string"); + expect(typeof response.body.result[0].value).toStrictEqual("string"); + expect(typeof response.body.result[0].input).toStrictEqual("string"); + expect(typeof response.body.result[0].type).toStrictEqual("string"); + expect(typeof response.body.result[0].traceId).toBeTruthy(); + expect(typeof response.body.result[0].isError).toStrictEqual("string"); + expect(typeof response.body.result[0].errCode).toStrictEqual("string"); + }); + }); + + //@id1805 + it("Verify /api?module=account&action=tokentx", async () => { + await helper.retryTestAction(async () => { + const blocks = await request(environment.blockExplorerAPI).get("/blocks"); + const blockNumber = blocks.body.items[0].number; + apiRoute = `/api?module=account&action=tokentx&page=1&offset=10&sort=desc&endblock${blockNumber}&startblock=0&contractaddress=${Token.ETHER_ERC20_Address}&address=${Wallets.richWalletAddress}`; + response = await helper.performGETrequest(apiRoute); + + console.log(response.body); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "1" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "OK" })); + expect(response.body.result.length).toBeGreaterThan(1); + expect(typeof response.body.result[0].blockNumber).toStrictEqual("string"); + expect(typeof response.body.result[0].timeStamp).toStrictEqual("string"); + expect(typeof response.body.result[0].hash).toStrictEqual("string"); + expect(typeof response.body.result[0].nonce).toStrictEqual("string"); + expect(typeof response.body.result[0].blockHash).toStrictEqual("string"); + expect(typeof response.body.result[0].transactionIndex).toStrictEqual("string"); + expect(typeof response.body.result[0].from).toStrictEqual("string"); + expect(typeof response.body.result[0].to).toStrictEqual("string"); + expect(typeof response.body.result[0].value).toStrictEqual("string"); + expect(typeof response.body.result[0].tokenName).toStrictEqual("string"); + expect(typeof response.body.result[0].tokenSymbol).toStrictEqual("string"); + expect(typeof response.body.result[0].tokenDecimal).toStrictEqual("string"); + expect(typeof response.body.result[0].gas).toStrictEqual("string"); + expect(typeof response.body.result[0].gasPrice).toStrictEqual("string"); + expect(typeof response.body.result[0].input).toStrictEqual("string"); + expect(typeof response.body.result[0].contractAddress).toStrictEqual("string"); + expect(typeof response.body.result[0].cumulativeGasUsed).toStrictEqual("string"); + expect(typeof response.body.result[0].contractAddress).toBeTruthy(); + expect(typeof response.body.result[0].gasUsed).toStrictEqual("string"); + expect(typeof response.body.result[0].confirmations).toStrictEqual("string"); + expect(typeof response.body.result[0].fee).toStrictEqual("string"); + expect(typeof response.body.result[0].l1BatchNumber).toBeTruthy(); + expect(typeof response.body.result[0].transactionType).toStrictEqual("string"); + }); + }); + + //@id1806 + + it("Verify /api?module=account&action=tokennfttx", async () => { + await helper.retryTestAction(async () => { + const blocks = await request(environment.blockExplorerAPI).get("/blocks"); + const blockNumber = blocks.body.items[0].number; + const nftAddress = await helper.getStringFromFile(bufferFile + Buffer.NFTtoL2); + apiRoute = `/api?module=account&action=tokennfttx&page=1&offset=10&sort=desc&endblock${blockNumber}&startblock=0&contractaddress=${nftAddress}&address=${nftAddress}`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "1" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "OK" })); + expect(typeof response.body.result[0].blockNumber).toStrictEqual("string"); + expect(typeof response.body.result[0].timeStamp).toStrictEqual("string"); + expect(typeof response.body.result[0].hash).toStrictEqual("string"); + expect(typeof response.body.result[0].nonce).toStrictEqual("string"); + expect(typeof response.body.result[0].blockHash).toStrictEqual("string"); + expect(typeof response.body.result[0].transactionIndex).toStrictEqual("string"); + expect(typeof response.body.result[0].from).toStrictEqual("string"); + expect(typeof response.body.result[0].to).toStrictEqual("string"); + expect(typeof response.body.result[0].tokenID).toStrictEqual("string"); + expect(typeof response.body.result[0].gas).toStrictEqual("string"); + expect(typeof response.body.result[0].gasPrice).toStrictEqual("string"); + expect(typeof response.body.result[0].input).toStrictEqual("string"); + expect(typeof response.body.result[0].contractAddress).toStrictEqual("string"); + expect(typeof response.body.result[0].cumulativeGasUsed).toStrictEqual("string"); + expect(typeof response.body.result[0].gasUsed).toStrictEqual("string"); + expect(typeof response.body.result[0].confirmations).toStrictEqual("string"); + expect(typeof response.body.result[0].fee).toStrictEqual("string"); + expect(typeof response.body.result[0].l1BatchNumber).toBeTruthy(); + expect(typeof response.body.result[0].transactionType).toStrictEqual("string"); + }); + }); + + //@id1807 + it("Verify /api?module=account&action=getminedblocks", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=account&action=getminedblocks&page=1&offset=10&address=0x0000000000000000000000000000000000000000`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "1" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "OK" })); + expect(response.body.result.length).toBeGreaterThan(1); + expect(typeof response.body.result[0].blockNumber).toStrictEqual("string"); + expect(typeof response.body.result[0].timeStamp).toStrictEqual("string"); + expect(typeof response.body.result[0].blockReward).toStrictEqual("string"); + }); + }); + + //@id1854 + it("Verify /api?module=account&action=txlistinternal&txhash=", async () => { + await helper.retryTestAction(async () => { + const blocks = await request(environment.blockExplorerAPI).get("/blocks"); + //txHash = await helper.getStringFromFile(bufferFile + Buffer.txEthTransfer); + const blockNumber = blocks.body.items[0].number; + apiRoute = `/api?module=account&action=txlistinternal&page=1&offset=10&sort=desc&endblock=${blockNumber}&startblock=0&txhash=0x2fe80424c49a9d6f05561947fbc1e6b77bf8982f08dc57883d1ee083c534d30d`; + response = await helper.performGETrequest(apiRoute); + + console.log(txHash); + console.log(response.body); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "1" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "OK" })); + expect(response.body.result.length).toBeGreaterThan(1); + expect(typeof response.body.result[0].blockNumber).toStrictEqual("string"); + expect(typeof response.body.result[0].timeStamp).toStrictEqual("string"); + expect(typeof response.body.result[0].hash).toStrictEqual("string"); + expect(typeof response.body.result[0].from).toStrictEqual("string"); + expect(typeof response.body.result[0].to).toStrictEqual("string"); + expect(typeof response.body.result[0].value).toStrictEqual("string"); + expect(typeof response.body.result[0].gas).toStrictEqual("string"); + expect(typeof response.body.result[0].input).toStrictEqual("string"); + expect(typeof response.body.result[0].type).toStrictEqual("string"); + expect(typeof response.body.result[0].contractAddress).toBeTruthy(); + expect(typeof response.body.result[0].gasUsed).toStrictEqual("string"); + expect(typeof response.body.result[0].fee).toStrictEqual("string"); + expect(typeof response.body.result[0].l1BatchNumber).toStrictEqual("string"); + expect(typeof response.body.result[0].traceId).toBeTruthy(); + expect(typeof response.body.result[0].isError).toStrictEqual("string"); + }); + }); });