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: covering Contract API and Logs API endpoints #92

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions packages/integration-tests/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum Buffer {
L2 = "./buffer/L2.txt",
L2deposited = "./buffer/L2deposited.txt",
paymaster = "./buffer/paymaster.txt",
paymasterDeployTx = "./buffer/paymasterDeployTx.txt",
abilevych marked this conversation as resolved.
Show resolved Hide resolved
paymasterTx = "./buffer/paymasterTx.txt",
addressMultiTransferETH = "./buffer/multiTransferETH.txt",
txMultiTransferETH = "./buffer/txMultiTransferETH.txt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default async function (hre: HardhatRuntimeEnvironment) {

const deployTransaction = await paymaster.deployTransaction;
console.log(`Paymaster deploy transaction: ${deployTransaction.hash}`);
await fs.writeFile(Buffer.paymasterDeployTx, deployTransaction.hash);

await (
await deployer.zkWallet.sendTransaction({
Expand Down
43 changes: 43 additions & 0 deletions packages/integration-tests/tests/api/contracts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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";

describe("Contracts", () => {
abilevych marked this conversation as resolved.
Show resolved Hide resolved
jest.setTimeout(localConfig.standardTimeout);

const helper = new Helper();
const bufferFile = "src/playbook/";
let paymasterContract: string;
let paymasterTx: string;

beforeAll(async () => {
paymasterContract = await helper.getStringFromFile(bufferFile + Buffer.paymaster);
abilevych marked this conversation as resolved.
Show resolved Hide resolved
paymasterTx = await helper.getStringFromFile(bufferFile + Buffer.paymasterDeployTx);
});

describe("/api?module=contract&action=getcontractcreation", () => {
abilevych marked this conversation as resolved.
Show resolved Hide resolved
jest.setTimeout(localConfig.standardTimeout); //works unstable without timeout
abilevych marked this conversation as resolved.
Show resolved Hide resolved

//@id1696
it("Verify the response via /api?module=contract&action=getcontractcreation", async () => {
await setTimeout(localConfig.extendedPause); //works unstable without timeout
abilevych marked this conversation as resolved.
Show resolved Hide resolved
const apiRoute = `/api?module=contract&action=getcontractcreation&contractaddresses=${paymasterContract}`;
return request(environment.blockExplorerAPI)
abilevych marked this conversation as resolved.
Show resolved Hide resolved
.get(apiRoute)
.expect(200)
.expect((res) =>
expect(res.body.result[0]).toStrictEqual(expect.objectContaining({ contractAddress: paymasterContract }))
)
.expect((res) =>
expect(res.body.result[0]).toStrictEqual(
expect.objectContaining({ contractCreator: Wallets.richWalletAddress })
)
)
.expect((res) => expect(res.body.result[0]).toStrictEqual(expect.objectContaining({ txHash: paymasterTx })));
});
});
});
43 changes: 43 additions & 0 deletions packages/integration-tests/tests/api/logs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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";

describe("Logs", () => {
jest.setTimeout(localConfig.standardTimeout); //works unstable without timeout
const helper = new Helper();
const bufferFile = "src/playbook/";
let contractAddress: string;

beforeAll(async () => {
contractAddress = await helper.getStringFromFile(bufferFile + Buffer.customToken);
});

describe("/api?module=logs&action=getLogs", () => {
abilevych marked this conversation as resolved.
Show resolved Hide resolved
//@id1808
it("Verify the response via /api?module=logs&action=getLogs", async () => {
await setTimeout(localConfig.extendedPause); //works unstable without timeout

const apiRoute = `/api?module=logs&action=getLogs&page=1&offset=1&toBlock=1000&fromBlock=1&address=${contractAddress}`;

return request(environment.blockExplorerAPI)
.get(apiRoute)
.expect(200)
.expect((res) =>
expect(res.body.result[0]).toStrictEqual(expect.objectContaining({ address: contractAddress }))
)
.expect((res) => expect(typeof res.body.result[0].topics[0]).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].data).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].blockNumber).toStrictEqual("string"))
abilevych marked this conversation as resolved.
Show resolved Hide resolved
.expect((res) => expect(typeof res.body.result[0].timeStamp).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].gasPrice).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].gasUsed).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].logIndex).toStrictEqual("string"))
abilevych marked this conversation as resolved.
Show resolved Hide resolved
.expect((res) => expect(typeof res.body.result[0].transactionHash).toStrictEqual("string"))
.expect((res) => expect(typeof res.body.result[0].transactionIndex).toStrictEqual("string"));
abilevych marked this conversation as resolved.
Show resolved Hide resolved
});
});
});
Loading