Skip to content

Commit

Permalink
feat: integration tests setup (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Romsters authored and pcheremu committed Feb 9, 2024
1 parent 023b679 commit 34a6694
Show file tree
Hide file tree
Showing 9 changed files with 1,783 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/integration-tests/tests/api/before-all/deposit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { localConfig } from "../../../src/config";
import { Buffer } from "../../../src/entities";
import { Logger } from "../../../src/entities";
import { Helper } from "../../../src/helper";
import { Playbook } from "../../../src/playbook/playbook";

describe("Deposit", () => {
const playbook = new Playbook();
const helper = new Helper();
const bufferRoute = "src/playbook/";

let result: string;
let token: string;
jest.setTimeout(localConfig.extendedTimeout);

//@id633
it("Make a deposit with 0.0000001 ETH ", async () => {
result = await playbook.depositETH("0.0000001");
await expect(result).not.toBeUndefined();
await expect(result.includes(Logger.txHashStartsWith)).toBe(true);
});

//@id638
it("Make a deposit with the Custom token ", async () => {
const bufferFile = bufferRoute + Buffer.L1;
token = await helper.getStringFromFile(bufferFile);
result = await playbook.depositERC20("100", token, 18);
await expect(result).not.toBeUndefined();
await expect(result.includes(Logger.txHashStartsWith)).toBe(true);
});
});
48 changes: 48 additions & 0 deletions packages/integration-tests/tests/api/before-all/tokens.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../../src/config";
import { localConfig } from "../../../src/config";
import { Logger, Token } from "../../../src/entities";
import { Playbook } from "../../../src/playbook/playbook";

describe("Tokens", () => {
jest.setTimeout(localConfig.standardTimeout);

let deployedToken: string;

describe("Deploy/check the custom ERC20 tokens", () => {
const playbook = new Playbook();

//@id603
it("Deploy custom ERC20 token to L2", async () => {
deployedToken = await playbook.deployERC20toL2();
expect(deployedToken).toContain(Logger.txHashStartsWith);
});

//@id1456
it("Verify deployed to L2 custom token via /tokens/{tokenAddress}", async () => {
await setTimeout(localConfig.extendedPause); //works unstable without timeout
const apiRoute = `/tokens/${deployedToken}`;

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) =>
expect(res.body).toStrictEqual({
l2Address: deployedToken,
l1Address: null,
symbol: Token.customL2TokenSymbol,
name: Token.customL2TokenName,
decimals: Token.customL2TokenDecimals,
})
);
});

//@id657
it("Deploy custom ERC20 token to L1", async () => {
deployedToken = await playbook.deployERC20toL1();
expect(deployedToken).toContain(Logger.txHashStartsWith);
});
});
});
185 changes: 185 additions & 0 deletions packages/integration-tests/tests/api/common/endpoints.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

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

describe("Endpoints", () => {
const helper = new Helper();
const bufferRoute = "src/playbook/";

jest.setTimeout(localConfig.extendedTimeout);

describe("/stats", () => {
//@id1515
it("Verify the response via /stats", async () => {
const apiRoute = `/stats`;

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

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(typeof res.body.lastSealedBatch).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.lastVerifiedBatch).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.lastSealedBlock).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.lastVerifiedBlock).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.totalTransactions).toStrictEqual("number"));
});
});

describe("/tokens", () => {
//@id1508
it("Verify the response via /tokens", async () => {
const l2DepositedToken = await helper.getStringFromFile(bufferRoute + Buffer.L2deposited);
const l1Token = await helper.getStringFromFile(bufferRoute + Buffer.L1);
const l2Token = await helper.getStringFromFile(bufferRoute + Buffer.L2);

const apiRoute = `/tokens`;

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

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(Array.isArray(res.body.items)).toStrictEqual(true))
.expect((res) =>
expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ l2Address: l2DepositedToken }))
)
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ l1Address: l1Token })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ symbol: "L1" })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ name: "L1 ERC20 token" })))
.expect((res) => expect(res.body.items[0]).toStrictEqual(expect.objectContaining({ decimals: 18 })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ l2Address: l2Token })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ l1Address: null })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ symbol: "L2" })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ name: "L2 ERC20 token" })))
.expect((res) => expect(res.body.items[1]).toStrictEqual(expect.objectContaining({ decimals: 18 })))
.expect((res) => expect(typeof res.body.meta.totalItems).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemsPerPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.totalPages).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.currentPage).toStrictEqual("number"))
.expect((res) => expect(res.body.links.first).toStrictEqual("tokens?limit=10"))
.expect((res) => expect(res.body.links.previous).toStrictEqual(""))
.expect((res) => expect(typeof res.body.links.next).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.last).toStrictEqual("string"));
});
});

describe("/batches", () => {
//@id1513
it("Verify the response via /batches", async () => {
const apiRoute = `/batches`;

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

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(Array.isArray(res.body.items)).toStrictEqual(true))
.expect((res) => expect(res.body.items.length).toBeGreaterThanOrEqual(1))
.expect((res) => expect(typeof res.body.meta.totalItems).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemsPerPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.totalPages).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.currentPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.links.first).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.previous).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.next).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.last).toStrictEqual("string"));
});

//@id1514
it("Verify the response via /batches/{batchNumber}", async () => {
const batches = await request(environment.blockExplorerAPI).get("/batches");

const batchNumber = batches.body.items[0].number;

const apiRoute = `/batches/${batchNumber}`;

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

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.number).toStrictEqual(batchNumber))
.expect((res) => expect(typeof res.body.timestamp).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.rootHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.executedAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.l1TxCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.l2TxCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.commitTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.committedAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.proveTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.provenAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.executeTxHash).toStrictEqual("string"))
.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("verified"));
});
});

describe("/blocks", () => {
//@id1511
it("Verify the response via /blocks", async () => {
const apiRoute = `/blocks`;

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

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(Array.isArray(res.body.items)).toStrictEqual(true))
.expect((res) => expect(res.body.items.length).toBeGreaterThan(1))
.expect((res) => expect(typeof res.body.meta.totalItems).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.itemsPerPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.totalPages).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.meta.currentPage).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.links.first).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.previous).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.next).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.links.last).toStrictEqual("string"));
});

//@id1512
it("Verify the response via /blocks/{/blockNumber}", async () => {
const blocks = await request(environment.blockExplorerAPI).get("/blocks");

const blockNumber = blocks.body.items[0].number;

const apiRoute = `/blocks/${blockNumber}`;

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

return (
request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.number).toStrictEqual(blockNumber))
.expect((res) => expect(typeof res.body.hash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.timestamp).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.gasUsed).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.l1BatchNumber).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.l1TxCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.l2TxCount).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.parentHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.gasLimit).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.baseFeePerGas).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.extraData).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.size).toStrictEqual("number"))
.expect((res) => expect(typeof res.body.status).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.isL1BatchSealed).toStrictEqual("boolean"))
.expect((res) => expect(typeof res.body.commitTxHash).toStrictEqual("string"))
// .expect((res) => expect(typeof res.body.commitTxHash).toStrictEqual("string")) //unstable on a CI
.expect((res) => expect(typeof res.body.proveTxHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.committedAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.executedAt).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.provenAt).toStrictEqual("string"))
);
});
});
});
54 changes: 54 additions & 0 deletions packages/integration-tests/tests/api/common/nft.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as request from "supertest";
import { setTimeout } from "timers/promises";

import { environment } from "../../../src/config";
import { localConfig } from "../../../src/config";
import { Logger } from "../../../src/entities";
import { Playbook } from "../../../src/playbook/playbook";

describe("NFTs", () => {
jest.setTimeout(localConfig.standardTimeout);

let deployedToken: string;

describe("Deploy/check the NFT", () => {
jest.setTimeout(localConfig.standardTimeout);
const playbook = new Playbook();

//@id672
it("Deploy the NFT to L1", async () => {
deployedToken = await playbook.deployNFTtoL1();
expect(deployedToken).toContain(Logger.txHashStartsWith);
});

//@id671
it("Deploy the NFT to L2", async () => {
deployedToken = await playbook.deployNFTtoL2();
expect(deployedToken).toContain(Logger.txHashStartsWith);
});

//@id1457
it("Verify deployed to L2 NFT via /address/{address}", async () => {
await setTimeout(localConfig.extendedPause);
const apiRoute = `/address/${deployedToken}`;

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) =>
expect(res.body).toEqual(
expect.objectContaining({
type: "contract",
address: deployedToken,
balances: {
[`${deployedToken}`]: {
balance: "1",
token: null,
},
},
})
)
);
});
});
});
59 changes: 59 additions & 0 deletions packages/integration-tests/tests/api/common/transfers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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("Transfer", () => {
jest.setTimeout(localConfig.standardTimeout);
const helper = new Helper();
const playbook = new Playbook();
const bufferFile = "src/playbook/" + Buffer.L2;
let txHashEth: string;
let txHashCust: string;
let token: string;

beforeAll(async () => {
token = await helper.getStringFromFile(bufferFile);
txHashEth = await playbook.transferETH("0.000001");
txHashCust = await playbook.transferERC20("0.01", token, "L2");

return [txHashCust, txHashEth];
});

//@id1447
it("Verify transfer ETH L2-L2 via /transactions/{transactionHash}/transfers", async () => {
const apiRoute = `/transactions/${txHashEth}/transfers`;
await setTimeout(localConfig.standardPause);

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.items[1].from).toBe(Wallets.richWalletAddress))
.expect((res) => expect(res.body.items[1].to).toBe(Wallets.mainWalletAddress))
.expect((res) => expect(res.body.items[1].transactionHash).toBe(txHashEth))
.expect((res) => expect(res.body.items[1].amount).toBe("1000000000000"))
.expect((res) => expect(res.body.items[1].type).toBe("transfer"));
});

//@id1448
it("Verify the custom ERC20 token transfer via /tokens/{address}/transfers", async () => {
const apiRoute = `/tokens/${token}/transfers?page=1&limit=10`;
token = await helper.getStringFromFile(bufferFile);

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

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) => expect(res.body.items[0].amount).toBe("10000000000000000"))
.expect((res) => expect(res.body.items[0].from).toBe(Wallets.richWalletAddress))
.expect((res) => expect(res.body.items[0].to).toBe(Wallets.secondWalletAddress))
.expect((res) => expect(res.body.items[0].token).toEqual(expect.objectContaining({ l2Address: token })))
.expect((res) => expect(res.body.items[0]).toEqual(expect.objectContaining({ transactionHash: txHashCust })))
.expect((res) => expect(res.body.items[0]).toEqual(expect.objectContaining({ type: "transfer" })));
});
});
Loading

0 comments on commit 34a6694

Please sign in to comment.