Skip to content

Commit

Permalink
tests: refactoring test names
Browse files Browse the repository at this point in the history
  • Loading branch information
pcheremu committed Jan 10, 2024
1 parent e8d4697 commit 9a51b1f
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 141 deletions.
7 changes: 4 additions & 3 deletions packages/integration-tests/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Provider } from "zksync-web3";
import { localConfig } from "./config";
import { Logger } from "./entities";

import type { BaseProvider } from "@ethersproject/providers/src.ts/base-provider";

export class Helper {
async txHashLogger(txType: string, txValue: string, tokenName?: string) {
const logMessage = `TxHash for ${txType} ${Logger.textSeparator} ${txValue}`;
Expand Down Expand Up @@ -42,7 +44,7 @@ export class Helper {
async getBalanceETH(walletAddress: string, layer: string) {
let network: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let provider: any;
let provider: BaseProvider;
if (layer == "L1") {
network = localConfig.L1Network;
provider = ethers.getDefaultProvider(network);
Expand All @@ -52,7 +54,6 @@ export class Helper {
} else {
console.log(`Wrong layer: ${layer}`);
}
const balanceEth = ethers.utils.formatUnits(await provider.getBalance(walletAddress), "wei");
return balanceEth;
return ethers.utils.formatUnits(await provider.getBalance(walletAddress), "wei");
}
}
182 changes: 83 additions & 99 deletions packages/integration-tests/tests/api/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,120 +6,104 @@ import { localConfig } from "../../src/config";
import { Token, Wallets } from "../../src/entities";
import { Helper } from "../../src/helper";

describe("Accounts API", () => {
describe("/api", () => {
jest.setTimeout(localConfig.standardTimeout);

const helper = new Helper();
//@id1704
it(
"Verify /api?module=account&action=balancemulti response returns elements" +
" balancemulti => balancemulti&address={account_address1},{account_address2}",
async () => {
const apiRoute = `/api?module=account&action=balancemulti&address=${Wallets.richWalletAddress},${Wallets.mainWalletAddress}`;
const richWalletBalance = await helper.getBalanceETH(Wallets.richWalletAddress, "L2");
const mainWalletBalance = await helper.getBalanceETH(Wallets.mainWalletAddress, "L2");
const richWalletLowerCase = Wallets.richWalletAddress.toLowerCase();
const mainWalletLowerCase = Wallets.mainWalletAddress.toLowerCase();
await setTimeout(localConfig.extendedPause); //works unstable without timeout
it("Verify /api?module=account&action=balancemulti response", async () => {
const apiRoute = `/api?module=account&action=balancemulti&address=${Wallets.richWalletAddress},${Wallets.mainWalletAddress}`;
const richWalletBalance = await helper.getBalanceETH(Wallets.richWalletAddress, "L2");
const mainWalletBalance = await helper.getBalanceETH(Wallets.mainWalletAddress, "L2");
const richWalletLowerCase = Wallets.richWalletAddress.toLowerCase();
const mainWalletLowerCase = Wallets.mainWalletAddress.toLowerCase();
await setTimeout(localConfig.extendedPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.result.length).toBeGreaterThan(1))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) =>
expect(res.body.result[0]).toStrictEqual(
expect.objectContaining({ account: richWalletLowerCase, balance: richWalletBalance })
)
return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.result.length).toBeGreaterThan(1))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) =>
expect(res.body.result[0]).toStrictEqual(
expect.objectContaining({ account: richWalletLowerCase, balance: richWalletBalance })
)
.expect((res) =>
expect(res.body.result[1]).toStrictEqual(
expect.objectContaining({ account: mainWalletLowerCase, balance: mainWalletBalance })
)
);
}
);
)
.expect((res) =>
expect(res.body.result[1]).toStrictEqual(
expect.objectContaining({ account: mainWalletLowerCase, balance: mainWalletBalance })
)
);
});

//@id1703
it(
"Verify /api?module=account&action=balance response returns elements" +
"balance => balance&address={account_address}",
async () => {
const apiRoute = `/api?module=account&action=balance&address=${Wallets.richWalletAddress}`;
const balance = await helper.getBalanceETH(Wallets.richWalletAddress, "L2");
await setTimeout(localConfig.extendedPause); //works unstable without timeout
it("Verify /api?module=account&action=balance response", async () => {
const apiRoute = `/api?module=account&action=balance&address=${Wallets.richWalletAddress}`;
const balance = await helper.getBalanceETH(Wallets.richWalletAddress, "L2");
await setTimeout(localConfig.extendedPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ result: balance })));
}
);
return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ result: balance })));
});

//@id1705
it(
"Verify /api?module=account&action=tokenbalance response returns elements" +
" tokenbalance => tokenbalance&contractaddress={contract_address}&address={account_address}",
async () => {
const apiRoute = `/api?module=account&action=tokenbalance&contractaddress=${Token.ETHER_ERC20_Address}&address=${Wallets.richWalletAddress}`;
await setTimeout(localConfig.extendedPause); //works unstable without timeout
it("Verify /api?module=account&action=tokenbalance response", async () => {
const apiRoute = `/api?module=account&action=tokenbalance&contractaddress=${Token.ETHER_ERC20_Address}&address=${Wallets.richWalletAddress}`;
await setTimeout(localConfig.extendedPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) => expect(typeof res.body.result).toStrictEqual("string"));
}
);
return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) => expect(typeof res.body.result).toStrictEqual("string"));
});

//@id1702
it(
"Verify /api?module=account&action=txlist response returns elements" +
" txlist => txlist&page=1&offset=10&sort=desc&endblock{block_number}&startblock=0&address={account_address}",
async () => {
const blocks = await request(environment.blockExplorerAPI).get("/blocks");
it("Verify /api?module=account&action=txlist response", async () => {
const blocks = await request(environment.blockExplorerAPI).get("/blocks");

const blockNumber = blocks.body.items[0].number;
const apiRoute = `/api?module=account&action=txlist&page=1&offset=10&sort=desc&endblock${blockNumber}&startblock=0&address=${Wallets.richWalletAddress}`;
const blockNumber = blocks.body.items[0].number;
const apiRoute = `/api?module=account&action=txlist&page=1&offset=10&sort=desc&endblock${blockNumber}&startblock=0&address=${Wallets.richWalletAddress}`;

await setTimeout(localConfig.extendedPause); //works unstable without timeout
await setTimeout(localConfig.extendedPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.result.length).toBeGreaterThan(1))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.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].hash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].nonce).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].blockHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].transactionIndex).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].from).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].to).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].value).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].gas).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].gasPrice).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].isError).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].txreceipt_status).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].input).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].contractAddress).toBeTruthy()) // can be null
.expect((res) => expect(typeof res.body.result[0].cumulativeGasUsed).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].gasUsed).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].confirmations).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].fee).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].commitTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].proveTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].executeTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].isL1Originated).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].l1BatchNumber).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].methodId).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].functionName).toStrictEqual("string"));
}
);
return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.result.length).toBeGreaterThan(1))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.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].hash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].nonce).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].blockHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].transactionIndex).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].from).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].to).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].value).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].gas).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].gasPrice).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].isError).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].txreceipt_status).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].input).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].contractAddress).toBeTruthy()) // can be null
.expect((res) => expect(typeof res.body.result[0].cumulativeGasUsed).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].gasUsed).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].confirmations).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].fee).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].commitTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].proveTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].executeTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].isL1Originated).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].l1BatchNumber).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].methodId).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].functionName).toStrictEqual("string"));
});
});
8 changes: 4 additions & 4 deletions packages/integration-tests/tests/api/blocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ describe("/blocks", () => {
});
});

describe("Block API", () => {
describe("/api", () => {
//@id1700
it("Verify /api?module=block&action=getblockcountdown&blockno={block_number} response returns elements", async () => {
it("Verify /api?module=block&action=getblockcountdown&blockno={block_number} response", async () => {
const blocks = await request(environment.blockExplorerAPI).get("/blocks");

const blockNumber = blocks.body.items[0].number + 1;
Expand All @@ -88,7 +88,7 @@ describe("Block API", () => {
});

//@id1699
it("Verify /api?module=block&action=getblocknobytime&closest=before&timestamp={timestamp} response returns elements", async () => {
it("Verify /api?module=block&action=getblocknobytime&closest=before&timestamp={timestamp} response", async () => {
const apiRoute = `/api?module=block&action=getblocknobytime&closest=before&timestamp=1635934550`;
await setTimeout(localConfig.extendedPause); //works unstable without timeout

Expand All @@ -101,7 +101,7 @@ describe("Block API", () => {
});

//@id1701
it("Verify /api?module=block&action=getblockreward&blockno={blockNumber} response returns elements", async () => {
it("Verify /api?module=block&action=getblockreward&blockno={blockNumber} response", async () => {
const blocks = await request(environment.blockExplorerAPI).get("/blocks");

const blockNumber = blocks.body.items[0].number;
Expand Down
62 changes: 27 additions & 35 deletions packages/integration-tests/tests/api/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -998,43 +998,35 @@ describe("Transactions", () => {
});
});

describe("Transactions API", () => {
describe("/api", () => {
//@id1697
it(
"Verify /api?module=transaction&action=getstatus response returns elements" +
" getstatus => getstatus&txhash={tx_hash}",
async () => {
txHash = await helper.getStringFromFile(bufferFile + Buffer.txEthTransfer);
const apiRoute = `/api?module=transaction&action=getstatus&txhash=${txHash}`;
await setTimeout(localConfig.extendedPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) =>
expect(res.body.result).toStrictEqual(expect.objectContaining({ isError: "0", errDescription: "" }))
);
}
);
it("Verify /api?module=transaction&action=getstatus response",async () => {
txHash = await helper.getStringFromFile(bufferFile + Buffer.txEthTransfer);
const apiRoute = `/api?module=transaction&action=getstatus&txhash=${txHash}`;
await setTimeout(localConfig.extendedPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) =>
expect(res.body.result).toStrictEqual(expect.objectContaining({ isError: "0", errDescription: "" }))
);
});

//@id1698
it(
"Verify /api?module=transaction&action=gettxreceiptstatus response returns elements" +
" gettxreceiptstatus => gettxreceiptstatus&txhash={tx_hash}",
async () => {
txHash = await helper.getStringFromFile(bufferFile + Buffer.txEthTransfer);
const apiRoute = `/api?module=transaction&action=gettxreceiptstatus&txhash=${txHash}`;
await setTimeout(localConfig.extendedPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) => expect(typeof res.body.result.status).toStrictEqual("string"));
}
);
it("Verify /api?module=transaction&action=gettxreceiptstatus response",async () => {
txHash = await helper.getStringFromFile(bufferFile + Buffer.txEthTransfer);
const apiRoute = `/api?module=transaction&action=gettxreceiptstatus&txhash=${txHash}`;
await setTimeout(localConfig.extendedPause); //works unstable without timeout

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ status: "1" })))
.expect((res) => expect(res.body).toStrictEqual(expect.objectContaining({ message: "OK" })))
.expect((res) => expect(typeof res.body.result.status).toStrictEqual("string"));
});
});
});

0 comments on commit 9a51b1f

Please sign in to comment.