From 5bf3da0170034a1f24c40641e3a967d17a449448 Mon Sep 17 00:00:00 2001 From: Oleh Bairak Date: Thu, 22 Aug 2024 21:10:54 +0500 Subject: [PATCH] fix: new tests --- .../tests/api/blocks.test.ts | 59 +++++++++++++++++++ .../integration-tests/tests/api/stats.test.ts | 13 ++++ .../tests/api/tokens.test.ts | 28 +++++++++ .../tests/api/transactions.test.ts | 38 ++++++++++++ 4 files changed, 138 insertions(+) diff --git a/packages/integration-tests/tests/api/blocks.test.ts b/packages/integration-tests/tests/api/blocks.test.ts index 6e058da87d..4106222627 100644 --- a/packages/integration-tests/tests/api/blocks.test.ts +++ b/packages/integration-tests/tests/api/blocks.test.ts @@ -114,5 +114,64 @@ describe("Blocks", () => { expect(typeof response.body.result.uncles).toStrictEqual("object"); }); }); + + it("Verify /getblocknobytime - No closest block present", async () => { + await helper.retryTestAction(async () => { + const blocks = await helper.performGETrequest("/blocks"); + const blockTimestamp = blocks.body.items[0].timestamp; + const timestampMilliseconds: number = new Date(blockTimestamp).getTime(); + const timestampSeconds: number = Math.floor(timestampMilliseconds / 1000) + 10000; + + apiRoute = `/api?module=block&action=getblocknobytime&closest=after×tamp=${timestampSeconds}`; + response = await helper.performGETrequest(apiRoute); + + expect(response.body).toStrictEqual(expect.objectContaining({ status: "1" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "NOTOK" })); + expect(response.body).toStrictEqual(expect.objectContaining({ result: "Error! No closest block found" })); + }); + }); + + it("Verify /getblocknobytime - Incorrect timestamp format", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=block&action=getblocknobytime&closest=before×tamp=9999999999999`; + response = await helper.performGETrequest(apiRoute); + + expect(response.body).toStrictEqual(expect.objectContaining({ status: "0" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "NOTOK" })); + expect(response.body).toStrictEqual(expect.objectContaining({ result: "Error! Invalid parameter" })); + }); + }); + + //id1948 + it("Verify /getblockreward - No record found", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=block&action=getblockreward&blockno=999999999999999`; + response = await helper.performGETrequest(apiRoute); + + expect(response.body).toStrictEqual(expect.objectContaining({ status: "0" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "No record found" })); + expect(response.body.result).toStrictEqual(expect.objectContaining({ blockNumber: null })); + expect(response.body.result).toStrictEqual(expect.objectContaining({ timeStamp: null })); + expect(response.body.result).toStrictEqual(expect.objectContaining({ blockMiner: null })); + expect(response.body.result).toStrictEqual(expect.objectContaining({ blockReward: null })); + expect(response.body.result).toStrictEqual(expect.objectContaining({ uncles: null })); + expect(response.body.result).toStrictEqual(expect.objectContaining({ uncleInclusionReward: null })); + }); + }); + + it("Verify /getblockreward - Validation error for block number", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=block&action=getblockreward&blockno=123123123123123123123`; + response = await helper.performGETrequest(apiRoute); + + expect(response.body).toStrictEqual(expect.objectContaining({ status: "0" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "NOTOK" })); + expect(response.body).toStrictEqual( + expect.objectContaining({ + result: "Validation failed: specified int is out of defined boundaries: [0;9007199254740991].", + }) + ); + }); + }); }); }); diff --git a/packages/integration-tests/tests/api/stats.test.ts b/packages/integration-tests/tests/api/stats.test.ts index 5f2704ea35..90e6fbdf4e 100644 --- a/packages/integration-tests/tests/api/stats.test.ts +++ b/packages/integration-tests/tests/api/stats.test.ts @@ -22,4 +22,17 @@ describe("Stats", () => { expect(typeof response.body.totalTransactions).toStrictEqual("number"); }); }); + + //@id1955 + it("Verify the response via /action=ethprice endpoint - incorrect token name", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=stats&action=ethprisce2`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "0" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "NOTOK" })); + expect(response.body).toStrictEqual(expect.objectContaining({ result: "Error! Missing Or invalid Action name" })); + }); + }); }); diff --git a/packages/integration-tests/tests/api/tokens.test.ts b/packages/integration-tests/tests/api/tokens.test.ts index b708f03f21..65211cd22a 100644 --- a/packages/integration-tests/tests/api/tokens.test.ts +++ b/packages/integration-tests/tests/api/tokens.test.ts @@ -156,6 +156,34 @@ describe("Tokens", () => { `tokens/${decapitalizedTokenAddress}/transfers?page=1&limit=10` ); }); + + //@id1956:I + it("Verify the /tokeninfo endpoint - Invalid contract address format", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=token&action=tokeninfo&contractaddress=0x0faF6df7054946141266420b4ww3783387A78d82A9`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "0" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "NOTOK" })); + expect(response.body).toStrictEqual( + expect.objectContaining({ result: "Error! Invalid contract address format" }) + ); + }); + }); + + //@id1956:II + it("Verify the /tokeninfo endpoint - No data found", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=token&action=tokeninfo&contractaddress=${Wallets.richWalletAddress}`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "0" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "No data found" })); + expect(response.body).toStrictEqual(expect.objectContaining({ result: [] })); + }); + }); }); }); }); diff --git a/packages/integration-tests/tests/api/transactions.test.ts b/packages/integration-tests/tests/api/transactions.test.ts index 58cd120031..ecc2006cd2 100644 --- a/packages/integration-tests/tests/api/transactions.test.ts +++ b/packages/integration-tests/tests/api/transactions.test.ts @@ -1174,5 +1174,43 @@ describe("Transactions", () => { expect(typeof response.body.result.status).toStrictEqual("string"); }); }); + //@id1958 + it("Verify /api?module=transaction&action=getstatus response - incorrect transaction hash format", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=transaction&action=getstatus&txhash=0x04a4757cd59681b037c1e7bdd2402cc45a23c66ed7497614879376719d34e020a`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "0" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "NOTOK" })); + expect(response.body).toStrictEqual(expect.objectContaining({ result: "Invalid transaction hash format" })); + }); + }); + + //@id1957:I + it("Verify /api?module=transaction&action=gettxreceiptstatus response - Invalid transaction hash format", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=transaction&action=gettxreceiptstatus&txhash=0x04a4757cd59681b037c1e7bd2402cc45a23c66ed7497614879376719d34e020as`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "0" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "NOTOK" })); + expect(response.body).toStrictEqual(expect.objectContaining({ result: "Invalid transaction hash format" })); + }); + }); + + //@id1957:II + it("Verify /api?module=transaction&action=gettxreceiptstatus response - Invalid transaction hash format", async () => { + await helper.retryTestAction(async () => { + apiRoute = `/api?module=transaction&action=gettxreceiptstatus&txhash=`; + response = await helper.performGETrequest(apiRoute); + + expect(response.status).toBe(200); + expect(response.body).toStrictEqual(expect.objectContaining({ status: "0" })); + expect(response.body).toStrictEqual(expect.objectContaining({ message: "NOTOK" })); + expect(response.body).toStrictEqual(expect.objectContaining({ result: "Invalid transaction hash format" })); + }); + }); }); });