Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: negative test cases Accounts API + Logs #277

Open
wants to merge 6 commits into
base: integration-tests-ether-migration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/integration-tests/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ export enum BlockExplorer {
baseUrl = "http://localhost:3010",
localNetwork = "/?network=local",
}

export enum Values {
incorrectAddressFormat = "0xE4ce1da467a7Ca37727eb7e19857e5167DE25966123",
}
298 changes: 297 additions & 1 deletion packages/integration-tests/tests/api/accounts.test.ts

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions packages/integration-tests/tests/api/blocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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&timestamp=${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&timestamp=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].",
})
);
});
});
});
});
72 changes: 71 additions & 1 deletion packages/integration-tests/tests/api/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("API module: Logs", () => {
expect(response.body.result[0].data.length).toBe(194);
expect(typeof response.body.result[0].blockNumber).toStrictEqual("string");
expect(response.body.result[0].blockNumber.startsWith("0x")).toBe(true);
expect(response.body.result[0].blockNumber.length).toBe(3);
expect(response.body.result[0].blockNumber.length).toBeGreaterThan(2);
expect(typeof response.body.result[0].timeStamp).toStrictEqual("string");
expect(response.body.result[0].timeStamp.startsWith("0x")).toBe(true);
expect(response.body.result[0].timeStamp.length).toBe(10);
Expand All @@ -58,5 +58,75 @@ describe("API module: Logs", () => {
expect(response.body.result[0].transactionIndex.length).toBe(3);
});
});
//@id1953:I
it("Verify /api?module=logs&action=getLogs response - Invalid address format", async () => {
await helper.retryTestAction(async () => {
apiRoute = `/api?module=logs&action=getLogs&page=1&offset=10&toBlock=99999999&fromBlock=0&address=0x8A63F953e19aA4Ce3ED90621EeF61sE17A95c6594`;
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 address format" }));
});
});

//@id1953:II
it("Verify /api?module=logs&action=getLogs response - No record found", async () => {
await helper.retryTestAction(async () => {
apiRoute = `/api?module=logs&action=getLogs&page=1&offset=10&toBlock=99999999&fromBlock=0&address=0x8A63F953e19aA4Ce3ED90621EeF61E17A95c6594`;
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 record found" }));
expect(response.body).toStrictEqual(expect.objectContaining({ result: [] }));
});
});

//@id1953:III
it("Verify /api?module=logs&action=getLogs response - Validation failed", async () => {
await helper.retryTestAction(async () => {
apiRoute = `/api?module=logs&action=getLogs&page=1&offset=10&toBlock=999999999999999999999999999&fromBlock=0&address=0xbf2A1ACE3B12b81bab4985f05E850AcFCCb416E0`;
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: "Validation failed (numeric string is expected)" })
);
});
});

//@id1953:IV
it("Verify /api?module=logs&action=getLogs response - offset must not be less than 1", async () => {
await helper.retryTestAction(async () => {
apiRoute = `/api?module=logs&action=getLogs&page=1&offset=0&toBlock=999999999999&fromBlock=0&address=0xbf2A1ACE3B12b81bab4985f05E850AcFCCb416E0`;
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: "offset must not be less than 1" }));
});
});

//@id1953:V
it("Verify /api?module=logs&action=getLogs response - Validation failed: specified int is out of defined boundaries", async () => {
await helper.retryTestAction(async () => {
apiRoute = `/api?module=logs&action=getLogs&page=1&offset=10&toBlock=999999999999&fromBlock=-1&address=0xbf2A1ACE3B12b81bab4985f05E850AcFCCb416E0`;
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: "Validation failed: specified int is out of defined boundaries: [0;9007199254740991].",
})
);
});
});
});
});
13 changes: 13 additions & 0 deletions packages/integration-tests/tests/api/stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }));
});
});
});
28 changes: 28 additions & 0 deletions packages/integration-tests/tests/api/tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@ describe("Tokens", () => {
await playbook.usePaymaster();
});

//@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: [] }));
});
});

//@id1448
it("Verify the custom ERC20 token transfer via /tokens/{address}/transfers", async () => {
await helper.retryTestAction(async () => {
Expand Down
38 changes: 38 additions & 0 deletions packages/integration-tests/tests/api/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }));
});
});
});
});
Loading