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

test: api integration tests for be #147

Merged
merged 33 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d0fd386
test: initial commit with tests
pcheremu Jan 5, 2024
c4c1e61
test: eslint refactoring
pcheremu Jan 5, 2024
4b9e9ac
test: updated contract hash for ui test
pcheremu Jan 5, 2024
e0b9368
test: refactoring
pcheremu Jan 5, 2024
9136685
test: refactoring
pcheremu Jan 5, 2024
6255d26
test: fix unstable api test
pcheremu Jan 5, 2024
f9f98a3
test: fix git ignore output folders
pcheremu Jan 5, 2024
3a0f377
test: refactoring
pcheremu Jan 5, 2024
07e50cf
test: refactoring test name
pcheremu Jan 5, 2024
e8d4697
test: refactoring test name
pcheremu Jan 5, 2024
9a51b1f
tests: refactoring test names
pcheremu Jan 10, 2024
1fbd645
test: refactoring eslint
pcheremu Jan 10, 2024
2d90a71
test: refactoring names
pcheremu Jan 10, 2024
05a5367
test: fix api tests
pcheremu Jan 10, 2024
f0fa0f5
test: refactoring
pcheremu Jan 10, 2024
639ff5e
test: refactoring
pcheremu Jan 10, 2024
d26ca9d
test: refactoring
pcheremu Jan 10, 2024
a7cf0d1
test: refactoring after rebase
pcheremu Jan 10, 2024
6ef5983
test: refactoring eslint
pcheremu Jan 10, 2024
43e7a17
test: fix test names add account test to the workflow
pcheremu Jan 11, 2024
3a546fc
test: fix test names add account test to the workflow
pcheremu Jan 11, 2024
5a2e7ba
Merge branch 'QA-446-replacefixupdate2-api-tests' into QA-577-fix-uns…
abilevych Jan 16, 2024
22ec02a
test: fix eslint
pcheremu Jan 16, 2024
6c5a521
test: fix redirection to documentation
pcheremu Jan 16, 2024
50ddbac
test: fix redirection to documentation
pcheremu Jan 16, 2024
792fc08
test: fix links
pcheremu Jan 17, 2024
4a65808
Merge pull request #148 from matter-labs/QA-577-fix-unstable-tests
abilevych Jan 17, 2024
4a8abdd
test: refactoring
pcheremu Jan 17, 2024
8a14d5e
test: fix portal url
pcheremu Jan 17, 2024
3194485
Update packages/integration-tests/tests/api/accounts.test.ts
pcheremu Jan 18, 2024
86baebb
chore: update the Blocks suite name
abilevych Jan 18, 2024
c975ef7
test: fix names in tests
pcheremu Jan 18, 2024
610df0d
test: refactoring
pcheremu Jan 18, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/integration-tests-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on: pull_request

jobs:
runTests:
name: Run API integration tests
timeout-minutes: 30
runs-on: ubuntu-latest
permissions:
Expand All @@ -14,6 +13,7 @@ jobs:
matrix:
node-version: ['lts/*'] # 18.17.1 or lts/*
test-pattern:
- accounts.test.ts
- addresses.test.ts
- batches.test.ts
- blocks.test.ts
Expand All @@ -22,6 +22,7 @@ jobs:
- stats.test.ts
- tokens.test.ts
abilevych marked this conversation as resolved.
Show resolved Hide resolved
- transactions.test.ts
name: 'API test set: ${{ matrix.test-pattern}} / Node: ${{ matrix.node-version}}'
steps:
- name: Checkout with Submodule
uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ cypress/videos/
cypress/screenshots/
tests/e2e/reports/
**/tests/e2e/artifacts/
**/playbook/artifacts-zk/
abilevych marked this conversation as resolved.
Show resolved Hide resolved
**/playbook/artifacts/
**/playbook/buffer/
**/playbook/cache-zk/
**/playbook/cache/

# Logs
logs
Expand Down
2 changes: 1 addition & 1 deletion packages/app/tests/e2e/features/copying.feature

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: Redirection

Examples:
| Extra button name | url |
| Docs | https://era.zksync.io/docs/dev/ |
| Docs | https://docs.zksync.io/build/ |
| Terms | https://zksync.io/terms |
| Contact | https://zksync.io/contact |

Expand All @@ -32,7 +32,7 @@ Feature: Redirection
@id251
Scenario: Verify redirection for Documentation link
Given I click by text "Documentation"
Then New page have "https://era.zksync.io/docs/dev/" address
Then New page have "https://docs.zksync.io/build/" address

@id252
Scenario Outline: Verify redirection for "<Sub-Section>" in BE menu
Expand Down
21 changes: 21 additions & 0 deletions packages/integration-tests/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { execSync } from "child_process";
import { ethers } from "ethers";
import { promises as fs } from "fs";
import * as path from "path";
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 @@ -35,4 +40,20 @@ export class Helper {
console.log(`There is no the expected file: ${fileName}`);
}
}

async getBalanceETH(walletAddress: string, layer: string) {
let network: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
abilevych marked this conversation as resolved.
Show resolved Hide resolved
let provider: BaseProvider;
if (layer == "L1") {
network = localConfig.L1Network;
provider = ethers.getDefaultProvider(network);
} else if (layer == "L2") {
network = localConfig.L2Network;
provider = new Provider(network);
} else {
console.log(`Wrong layer: ${layer}`);
}
return ethers.utils.formatUnits(await provider.getBalance(walletAddress), "wei");
}
}
109 changes: 109 additions & 0 deletions packages/integration-tests/tests/api/accounts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../src/config";
import { localConfig } from "../../src/config";
import { Token, Wallets } from "../../src/entities";
import { Helper } from "../../src/helper";

describe("/api?module=account", () => {
pcheremu marked this conversation as resolved.
Show resolved Hide resolved
jest.setTimeout(localConfig.standardTimeout);

const helper = new Helper();
//@id1704
abilevych marked this conversation as resolved.
Show resolved Hide resolved
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 })
)
)
.expect((res) =>
expect(res.body.result[1]).toStrictEqual(
expect.objectContaining({ account: mainWalletLowerCase, balance: mainWalletBalance })
)
);
});

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

//@id1705
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"));
});

//@id1702
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}`;

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"));
});
});
6 changes: 3 additions & 3 deletions packages/integration-tests/tests/api/batches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe("/batches", () => {
});

//@id1514
xit("Verify the response via /batches/{batchNumber}", async () => {
await setTimeout(localConfig.standardPause); //works unstable without timeout
it("Verify the response via /batches/{batchNumber}", async () => {
await setTimeout(localConfig.extendedPause); //works unstable without timeout

const batches = await request(environment.blockExplorerAPI).get("/batches");

Expand All @@ -56,6 +56,6 @@ describe("/batches", () => {
.expect((res) => expect(typeof res.body.l1GasPrice).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.l2FairGasPrice).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.size).toStrictEqual("number"))
.expect((res) => expect(res.body.status).toStrictEqual("string"));
.expect((res) => expect(typeof res.body.status).toStrictEqual("string"));
});
});
55 changes: 55 additions & 0 deletions packages/integration-tests/tests/api/blocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,58 @@ describe("/blocks", () => {
);
});
});

describe("/api?module=block", () => {
abilevych marked this conversation as resolved.
Show resolved Hide resolved
//@id1700
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;
const apiRoute = `/api?module=block&action=getblockcountdown&blockno=${blockNumber}`;
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.CurrentBlock).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result.CountdownBlock).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result.RemainingBlock).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result.EstimateTimeInSec).toStrictEqual("string"));
});

//@id1699
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

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"));
});

//@id1701
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;
const apiRoute = `/api?module=block&action=getblockreward&blockno=${blockNumber}`;
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.blockNumber).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result.timeStamp).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result.blockMiner).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result.blockReward).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result.uncleInclusionReward).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result.uncles).toStrictEqual("object"));
});
});
6 changes: 4 additions & 2 deletions packages/integration-tests/tests/api/contracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../src/config";
import { localConfig } from "../../src/config";
import { Buffer, Wallets } from "../../src/entities";
import { Helper } from "../../src/helper";
import { Playbook } from "../../src/playbook/playbook";

describe("Contracts API", () => {
describe("/api?module=contract", () => {
jest.setTimeout(localConfig.standardTimeout);

const helper = new Helper();
Expand All @@ -24,7 +25,8 @@ describe("Contracts API", () => {
});

//@id1696
xit("Verify the response via /api?module=contract&action=getcontractcreation&contractaddresses={address1},{address2}", async () => {
it("Verify /api?module=contract&action=getcontractcreation&contractaddresses={address1},{address2} response", async () => {
await setTimeout(localConfig.standardPause);
paymasterContract = await helper.getStringFromFile(bufferFile + Buffer.paymaster);
paymasterTx = await helper.getStringFromFile(bufferFile + Buffer.paymasterDeployTx);
multicallCallerContract = await helper.getStringFromFile(bufferFile + Buffer.addressMultiCallCaller);
Expand Down
8 changes: 5 additions & 3 deletions packages/integration-tests/tests/api/logs.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../src/config";
import { localConfig } from "../../src/config";
import { Buffer } from "../../src/entities";
import { Helper } from "../../src/helper";
import { Playbook } from "../../src/playbook/playbook";

xdescribe("Logs API", () => {
describe("/api?module=logs", () => {
pcheremu marked this conversation as resolved.
Show resolved Hide resolved
jest.setTimeout(localConfig.standardTimeout); //works unstable without timeout
const helper = new Helper();
const bufferFile = "src/playbook/";
Expand All @@ -21,7 +22,8 @@ xdescribe("Logs API", () => {
});

//@id1808
it("Verify the response via /api?module=logs&action=getLogs&page={page}&offset={offset}0&toBlock={toBlock}&fromBlock={fromBlock}&address={address}", async () => {
it("Verify /api?module=logs&action=getLogs&page={page}&offset={offset}0&toBlock={toBlock}&fromBlock={fromBlock}&address={address} response", async () => {
await setTimeout(localConfig.standardPause);
contractAddress = await helper.getStringFromFile(bufferFile + Buffer.greeterL2);
txHash = await helper.getStringFromFile(bufferFile + Buffer.executeGreeterTx);

Expand All @@ -42,7 +44,7 @@ xdescribe("Logs API", () => {
.expect((res) => expect(res.body.result[0].data.length).toBe(194))
.expect((res) => expect(typeof res.body.result[0].blockNumber).toStrictEqual("string"))
.expect((res) => expect(res.body.result[0].blockNumber.startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].blockNumber.length).toBe(5))
.expect((res) => expect(typeof res.body.result[0].blockNumber.length).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.result[0].timeStamp).toStrictEqual("string"))
.expect((res) => expect(res.body.result[0].timeStamp.startsWith("0x")).toBe(true))
.expect((res) => expect(res.body.result[0].timeStamp.length).toBe(10))
Expand Down
Loading
Loading