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: new automation tests for accounts API #163

Merged
Changes from 1 commit
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
Next Next commit
fix: first try
  • Loading branch information
olehbairak committed Feb 5, 2024
commit 718a6c9784a7973de64f402de667797657ab29cc
187 changes: 186 additions & 1 deletion packages/integration-tests/tests/api/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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");
});
});

pcheremu marked this conversation as resolved.
Show resolved Hide resolved
//@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");
});
});
});
Loading