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 UI tests for Deposit #185

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions packages/integration-tests/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export enum Buffer {
emptyWalletAddress = "./buffer/emptyWalletAddress.txt",
failedState = "./buffer/failedState.txt",
customToken = "./buffer/customToken.txt",
txEthDeposit = "./buffer/txEthDeposit.txt",
txERC20Deposit = "./buffer/txERC20Deposit.txt",
}

export enum Logger {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ethProvider = ethers.getDefaultProvider(localConfig.L1Network);
const syncWallet = new zksync.Wallet(localConfig.privateKey, syncProvider, ethProvider);
const playbookRoot = "src/playbook";
const bufferFile = playbookRoot + "/" + Buffer.L2deposited;
abilevych marked this conversation as resolved.
Show resolved Hide resolved
const bufferDepositErc20File = playbookRoot + "/" + Buffer.txERC20Deposit;

export const depositERC20 = async function (sum = "0.5", tokenAddress: string, units = 18) {
const deposit = await syncWallet.deposit({
Expand All @@ -23,15 +24,14 @@ export const depositERC20 = async function (sum = "0.5", tokenAddress: string, u
overrides: localConfig.gasLimit,
});

const txHash = deposit.hash;

await deposit.wait(1);
await deposit.waitL1Commit(1);

const l2TokenAddress = await syncProvider.l2TokenAddress(tokenAddress);
console.log("L2 token address ", l2TokenAddress);
await fs.writeFile(bufferFile, l2TokenAddress);
abilevych marked this conversation as resolved.
Show resolved Hide resolved
await helper.txHashLogger(Logger.deposit, txHash, "ERC20 token");
const txHash = await deposit.waitFinalize();
await helper.txHashLogger(Logger.deposit, txHash.transactionHash, "ERC20 token");
await fs.writeFile(bufferDepositErc20File, txHash.transactionHash);

return txHash;
};
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

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

export const depositEth = async function (sum = "0.000009") {
const helper = new Helper();
const syncProvider = new zksync.Provider(localConfig.L2Network);
const ethProvider = ethers.getDefaultProvider(localConfig.L1Network);
const syncWallet = new zksync.Wallet(localConfig.privateKey, syncProvider, ethProvider);
const playbookRoot = "src/playbook/";
const bufferFile = playbookRoot + Buffer.txEthDeposit;

const deposit = await syncWallet.deposit({
token: zksync.utils.ETH_ADDRESS,
amount: ethers.utils.parseEther(sum),
l2GasLimit: localConfig.l2GasLimit,
});

const txHash = deposit.hash;
abilevych marked this conversation as resolved.
Show resolved Hide resolved

await deposit.wait(1);
await helper.txHashLogger(Logger.deposit, txHash, "ETH");
const txHash = await deposit.waitFinalize();
await helper.txHashLogger(Logger.deposit, txHash.transactionHash, "ETH");
await fs.writeFile(bufferFile, txHash.transactionHash);

return txHash;
};
52 changes: 52 additions & 0 deletions packages/integration-tests/tests/ui/deposit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect, test } from "@playwright/test";

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

const bufferRoute = "src/playbook/";
const helper = new Helper();
let url: string;
let bufferFile;
let depositTxHash: string;
let fromAddress: string;
abilevych marked this conversation as resolved.
Show resolved Hide resolved

//@id1660
test("Check Deposit ETH transaction on BE", async ({ page }) => {
bufferFile = bufferRoute + Buffer.txEthDeposit;
depositTxHash = await helper.getStringFromFile(bufferFile);
url = BlockExplorer.baseUrl + `/tx/${depositTxHash}` + BlockExplorer.localNetwork;
fromAddress = Wallets.richWalletAddress;
console.log(url);
abilevych marked this conversation as resolved.
Show resolved Hide resolved

await page.goto(url);

const hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${depositTxHash}"]`).first();
abilevych marked this conversation as resolved.
Show resolved Hide resolved
const fromAddressElement = await page.locator(`text=${fromAddress}`).first();
const ethValue = await page.locator(`text=0.0000001`).first();

await expect(hash).toBeVisible(config.extraTimeout);
await expect(ethValue).toBeVisible(config.extraTimeout);
abilevych marked this conversation as resolved.
Show resolved Hide resolved
await expect(fromAddressElement).toBeVisible(config.extraTimeout);
});

//@id1681
test("Check on BE Deposit the custom ERC-20 token", async ({ page }) => {
bufferFile = bufferRoute + Buffer.txERC20Deposit;
depositTxHash = await helper.getStringFromFile(bufferFile);
url = BlockExplorer.baseUrl + `/tx/${depositTxHash}` + BlockExplorer.localNetwork;
fromAddress = Wallets.richWalletAddress;
console.log(url);

await page.goto(url);

const hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${depositTxHash}"]`).first();
const fromAddressElement = await page.locator(
`//*[text()="From"]/..//*[text()="L1"]/..//*[text()="0x36615Cf349d...c049"]`
);
const erc20Value = await page.locator(`//*[text()="0x36615Cf349d...c049"]/..//..//*[text()="100"]`);

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