From 36675b0beb54c1d54f3c69f8cdee20d1e8a72560 Mon Sep 17 00:00:00 2001 From: amelnytskyi Date: Fri, 23 Feb 2024 19:47:45 +0200 Subject: [PATCH 1/2] test: covering UI tests for Deposit --- packages/integration-tests/src/entities.ts | 2 + .../scenarios/deposit/depositERC20.ts | 8 +-- .../playbook/scenarios/deposit/depositETH.ts | 12 +++-- .../tests/ui/deposit.spec.ts | 52 +++++++++++++++++++ 4 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 packages/integration-tests/tests/ui/deposit.spec.ts diff --git a/packages/integration-tests/src/entities.ts b/packages/integration-tests/src/entities.ts index 5c1879e5b1..f5008ddbf5 100644 --- a/packages/integration-tests/src/entities.ts +++ b/packages/integration-tests/src/entities.ts @@ -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 { diff --git a/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts b/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts index f18724a450..7d4338a61f 100644 --- a/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts +++ b/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts @@ -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; +const bufferDepositErc20File = playbookRoot + "/" + Buffer.txERC20Deposit; export const depositERC20 = async function (sum = "0.5", tokenAddress: string, units = 18) { const deposit = await syncWallet.deposit({ @@ -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); - 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; }; diff --git a/packages/integration-tests/src/playbook/scenarios/deposit/depositETH.ts b/packages/integration-tests/src/playbook/scenarios/deposit/depositETH.ts index e35e6b6259..f15e27b30b 100644 --- a/packages/integration-tests/src/playbook/scenarios/deposit/depositETH.ts +++ b/packages/integration-tests/src/playbook/scenarios/deposit/depositETH.ts @@ -1,8 +1,9 @@ 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") { @@ -10,17 +11,18 @@ export const depositEth = async function (sum = "0.000009") { 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; - 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; }; diff --git a/packages/integration-tests/tests/ui/deposit.spec.ts b/packages/integration-tests/tests/ui/deposit.spec.ts new file mode 100644 index 0000000000..1663c0cc07 --- /dev/null +++ b/packages/integration-tests/tests/ui/deposit.spec.ts @@ -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; + +//@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); + + await page.goto(url); + + const hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${depositTxHash}"]`).first(); + 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); + 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); +}); From 4babcacb7c0c540a5cebeecbe01712f7dafdf566 Mon Sep 17 00:00:00 2001 From: amelnytskyi Date: Mon, 4 Mar 2024 19:08:36 +0200 Subject: [PATCH 2/2] test: covering UI tests for Deposit Changed timeout value in Deposit UI tests Renamed variables to suggested values as per review results Removed obsolete console.log --- .../scenarios/deposit/depositERC20.ts | 8 ++--- .../tests/ui/deposit.spec.ts | 35 ++++++++++--------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts b/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts index 7d4338a61f..0d3a48d1cb 100644 --- a/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts +++ b/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts @@ -11,8 +11,8 @@ 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.L2deposited; -const bufferDepositErc20File = playbookRoot + "/" + Buffer.txERC20Deposit; +const bufferAddressL2DepositedFile = playbookRoot + "/" + Buffer.L2deposited; +const bufferTxErc20DepositFile = playbookRoot + "/" + Buffer.txERC20Deposit; export const depositERC20 = async function (sum = "0.5", tokenAddress: string, units = 18) { const deposit = await syncWallet.deposit({ @@ -28,10 +28,10 @@ export const depositERC20 = async function (sum = "0.5", tokenAddress: string, u const l2TokenAddress = await syncProvider.l2TokenAddress(tokenAddress); console.log("L2 token address ", l2TokenAddress); - await fs.writeFile(bufferFile, l2TokenAddress); const txHash = await deposit.waitFinalize(); await helper.txHashLogger(Logger.deposit, txHash.transactionHash, "ERC20 token"); - await fs.writeFile(bufferDepositErc20File, txHash.transactionHash); + await fs.writeFile(bufferAddressL2DepositedFile, l2TokenAddress); + await fs.writeFile(bufferTxErc20DepositFile, txHash.transactionHash); return txHash; }; diff --git a/packages/integration-tests/tests/ui/deposit.spec.ts b/packages/integration-tests/tests/ui/deposit.spec.ts index 1663c0cc07..5d6f5f2431 100644 --- a/packages/integration-tests/tests/ui/deposit.spec.ts +++ b/packages/integration-tests/tests/ui/deposit.spec.ts @@ -4,30 +4,32 @@ import { config } from "./config"; import { BlockExplorer, Buffer, Wallets } from "../../src/entities"; import { Helper } from "../../src/helper"; +import type { Locator } from "@playwright/test"; + const bufferRoute = "src/playbook/"; const helper = new Helper(); let url: string; let bufferFile; let depositTxHash: string; -let fromAddress: string; +let initiatorAddress: string; +let hash, initiatorAddressElement, ethValue, erc20Value: Locator; //@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); + initiatorAddress = Wallets.richWalletAddress; await page.goto(url); - const hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${depositTxHash}"]`).first(); - const fromAddressElement = await page.locator(`text=${fromAddress}`).first(); - const ethValue = await page.locator(`text=0.0000001`).first(); + hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${depositTxHash}"]`).first(); + initiatorAddressElement = await page.locator(`text=${initiatorAddress}`).first(); + ethValue = await page.locator(`text=0.0000001`).first(); - await expect(hash).toBeVisible(config.extraTimeout); - await expect(ethValue).toBeVisible(config.extraTimeout); - await expect(fromAddressElement).toBeVisible(config.extraTimeout); + await expect(hash).toBeVisible(config.defaultTimeout); + await expect(ethValue).toBeVisible(config.defaultTimeout); + await expect(initiatorAddressElement).toBeVisible(config.defaultTimeout); }); //@id1681 @@ -35,18 +37,17 @@ 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); + initiatorAddress = Wallets.richWalletAddress; await page.goto(url); - const hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${depositTxHash}"]`).first(); - const fromAddressElement = await page.locator( + hash = await page.locator(`//*[text()="Transaction Hash"]/..//..//*[text()="${depositTxHash}"]`).first(); + initiatorAddressElement = await page.locator( `//*[text()="From"]/..//*[text()="L1"]/..//*[text()="0x36615Cf349d...c049"]` ); - const erc20Value = await page.locator(`//*[text()="0x36615Cf349d...c049"]/..//..//*[text()="100"]`); + 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); + await expect(hash).toBeVisible(config.defaultTimeout); + await expect(erc20Value).toBeVisible(config.defaultTimeout); + await expect(initiatorAddressElement).toBeVisible(config.defaultTimeout); });