Skip to content

Commit

Permalink
test: create autotests for Withdraw and Account test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
amelnytskyi committed Feb 27, 2024
1 parent d8d0a70 commit 02361ca
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/integration-tests/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum Buffer {
paymasterTx = "./buffer/paymasterTx.txt",
addressMultiTransferETH = "./buffer/multiTransferETH.txt",
txMultiTransferETH = "./buffer/txMultiTransferETH.txt",
txMultiTransferCall = "./buffer/txMultiTransferCall.txt",
txMultiTransferCustomTokenI = "./buffer/txMultiTransferCustomTokenI.txt",
txMultiTransferCustomTokenII = "./buffer/txMultiTransferCustomTokenII.txt",
addressMultiCallMiddle = "./buffer/multiCallMiddle.txt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export default async function callMultiTransferETH(hre: HardhatRuntimeEnvironmen
);
if (transferFromContract) {
console.log(`Contract transfer to us!`);
const transferReceipt = await transferFromContract.wait(1);
console.log(`Contract transfer transaction hash: ${transferReceipt.transactionHash}`);

return transferReceipt.transactionHash;
} else {
console.error(`Contract said something unexpected: ${transferFromContract}`);
}
Expand Down Expand Up @@ -98,4 +102,5 @@ export default async function callMultiTransferETH(hre: HardhatRuntimeEnvironmen
await fs.writeFile(Buffer.txMultiTransferETH, ethTransfer);
await fs.writeFile(Buffer.txMultiTransferCustomTokenI, customToken1Transfer);
await fs.writeFile(Buffer.txMultiTransferCustomTokenII, customToken2Transfer);
await fs.writeFile(Buffer.txMultiTransferCall, transferFromContract);
}
32 changes: 32 additions & 0 deletions packages/integration-tests/tests/api/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,37 @@ describe("API module: Account", () => {
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");
const blockNumber = blocks.body.items[0].number;
const txHash = await helper.getStringFromFile(bufferFile + Buffer.txMultiTransferCall);
apiRoute = `/api?module=account&action=txlistinternal&page=1&offset=10&sort=desc&endblock=${blockNumber}&startblock=0&txhash=${txHash}`;
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[0]).toStrictEqual(expect.objectContaining({ hash: txHash }));
expect(response.body.result[0]).toStrictEqual(expect.objectContaining({ to: Wallets.richWalletAddress }));
expect(response.body.result[0]).toStrictEqual(expect.objectContaining({ type: "call" }));
expect(typeof response.body.result[0].blockNumber).toStrictEqual("string");
expect(typeof response.body.result[0].timeStamp).toStrictEqual("string");
expect(typeof response.body.result[0].from).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].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");
});
});
});
});
105 changes: 105 additions & 0 deletions packages/integration-tests/tests/ui/withdraw.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { expect, test } from "@playwright/test";

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

const bufferRoute = "src/playbook/";
const helper = new Helper();
let url: string;
let bufferFile;
let withdrawTxHash: string;
let fromAddress: string;
let toAddress: string;

//@id1661
test("Check Withdraw ETH transaction on BE", async ({ page }) => {
bufferFile = bufferRoute + Buffer.txEthWithdraw;
withdrawTxHash = await helper.getStringFromFile(bufferFile);
url = BlockExplorer.baseUrl + `/tx/${withdrawTxHash}` + BlockExplorer.localNetwork;
fromAddress = Wallets.richWalletAddress;
console.log(url);

await page.goto(url);

const hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${withdrawTxHash}"]`).first();
const fromAddressElement = await page.locator(`text=${fromAddress}`).first();
const toAddressElement = await page
.locator(`//*[text()="To"]/..//..//..//*[text()="L1"]/..//*[text()="0x36615Cf349d...c049"]`)
.first();
const ethValue = await page.locator(`text=0.000009`).first();

await expect(hash).toBeVisible(config.extraTimeout);
await expect(ethValue).toBeVisible(config.extraTimeout);
await expect(fromAddressElement).toBeVisible(config.extraTimeout);
await expect(toAddressElement).toBeVisible(config.extraTimeout);
});

//@id1686
test("Verify the ETH withdrawal to the other address", async ({ page }) => {
bufferFile = bufferRoute + Buffer.txEthWithdrawOtherAddress;
withdrawTxHash = await helper.getStringFromFile(bufferFile);
url = BlockExplorer.baseUrl + `/tx/${withdrawTxHash}` + BlockExplorer.localNetwork;
fromAddress = Wallets.richWalletAddress;
console.log(url);

await page.goto(url);

const hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${withdrawTxHash}"]`).first();
const fromAddressElement = await page.locator(`text=${fromAddress}`).first();
const toAddressElement = await page
.locator(`//*[text()="To"]/..//..//..//*[text()="L1"]/..//*[text()="0x586607935E1...8975"]`)
.first();
const ethValue = await page.locator(`text=0.000009`).first();

await expect(hash).toBeVisible(config.extraTimeout);
await expect(ethValue).toBeVisible(config.extraTimeout);
await expect(fromAddressElement).toBeVisible(config.extraTimeout);
await expect(toAddressElement).toBeVisible(config.extraTimeout);
});

//@id1685
test("Check on BE Withdraw the custom ERC-20 via Portal", async ({ page }) => {
bufferFile = bufferRoute + Buffer.txERC20Withdraw;
withdrawTxHash = await helper.getStringFromFile(bufferFile);
url = BlockExplorer.baseUrl + `/tx/${withdrawTxHash}` + BlockExplorer.localNetwork;
fromAddress = Wallets.richWalletAddress;
console.log(url);

await page.goto(url);

const hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${withdrawTxHash}"]`).first();
const fromAddressElement = await page.locator(`text=${fromAddress}`).first();
const toAddressElement = await page
.locator(`//*[text()="To"]/..//..//..//*[text()="L1"]/..//*[text()="0x36615Cf349d...c049"]`)
.first();
const erc20Value = await page.locator(`//*[text()="0x36615Cf349d...c049"]/..//..//*[text()="0.2"]`).first();

await expect(hash).toBeVisible(config.extraTimeout);
await expect(erc20Value).toBeVisible(config.extraTimeout);
await expect(fromAddressElement).toBeVisible(config.extraTimeout);
await expect(toAddressElement).toBeVisible(config.extraTimeout);
});

//@id1664
test("Check Withdraw transaction on BE for custom ERC-20 token to a different address", async ({ page }) => {
bufferFile = bufferRoute + Buffer.txERC20WithdrawOtherAddress;
withdrawTxHash = await helper.getStringFromFile(bufferFile);
url = BlockExplorer.baseUrl + `/tx/${withdrawTxHash}` + BlockExplorer.localNetwork;
fromAddress = Wallets.richWalletAddress;
console.log(url);

await page.goto(url);

const hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${withdrawTxHash}"]`).first();
const fromAddressElement = await page.locator(`text=${fromAddress}`).first();
const toAddressElement = await page
.locator(`//*[text()="To"]/..//..//..//*[text()="L1"]/..//*[text()="0x586607935E1...8975"]`)
.first();
const erc20Value = await page.locator(`//*[text()="0x586607935E1...8975"]/..//..//*[text()="0.2"]`).first();

await expect(hash).toBeVisible(config.extraTimeout);
await expect(erc20Value).toBeVisible(config.extraTimeout);
await expect(fromAddressElement).toBeVisible(config.extraTimeout);
await expect(toAddressElement).toBeVisible(config.extraTimeout);
});

0 comments on commit 02361ca

Please sign in to comment.