From 2d7b8edf5cffa82e9c2bceb5e060371f7ddb6767 Mon Sep 17 00:00:00 2001 From: Victor Alber Date: Mon, 29 Jul 2024 15:25:19 +0200 Subject: [PATCH] tests: Refacto subAccount methods --- .../ledger-live-desktop/tests/enum/Account.ts | 72 +++++++++++ .../tests/enum/Currency.ts | 97 ++++++++++++++ apps/ledger-live-desktop/tests/enum/Token.ts | 25 ---- .../tests/models/Transaction.ts | 16 +-- .../tests/page/account.page.ts | 28 +++-- .../tests/page/drawer/drawer.ts | 4 +- .../tests/page/modal/add.account.modal.ts | 27 ++-- .../tests/page/modal/receive.modal.ts | 6 +- .../tests/page/modal/send.modal.ts | 9 -- .../tests/specs/speculos/send.tx.spec.ts | 118 +++++++++++------- .../tests/specs/speculos/subAccount.spec.ts | 70 +++++------ 11 files changed, 315 insertions(+), 157 deletions(-) delete mode 100644 apps/ledger-live-desktop/tests/enum/Token.ts diff --git a/apps/ledger-live-desktop/tests/enum/Account.ts b/apps/ledger-live-desktop/tests/enum/Account.ts index bc352dc797a0..bad50adcbb5a 100644 --- a/apps/ledger-live-desktop/tests/enum/Account.ts +++ b/apps/ledger-live-desktop/tests/enum/Account.ts @@ -192,4 +192,76 @@ export class Account { "Binance Smart Chain 1", "0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6", ); + + static readonly ETH_USDT = new Account( + Currency.ETH_USDT, + "Ethereum 1", + "0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6", + ); + + static readonly ETH_LIDO = new Account( + Currency.ETH_LIDO, + "Ethereum 1", + "0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6", + ); + + static readonly XLM_USCD = new Account( + Currency.XLM_USCD, + "Stellar 1", + "GCAGRZ7XABYSXV7CPFSFWQIUK6XFXECBPWP2SGMVOB2KFWN7YM4TDGSX", + ); + + static readonly ALGO_USDT_1 = new Account( + Currency.ALGO_USDT, + "Algorand 1", + "HQ6YJWSVG3KVRE56V6UGWMUJLDVNPQUNXJBY7VJ56VMNMGIKVDTC7JEKOU", + ); + + static readonly ALGO_USDT_2 = new Account( + Currency.ALGO_USDT, + "Algorand 2", + "6TFDU3BYQ2FO32SOYQDTHDW5XKGEYH4FCT34ZQRHFPJRVMLEQWOO2OEUU4", + ); + + static readonly ALGO_USDT_3 = new Account( + Currency.ALGO_USDT, + "Algorand 3", + "3ASRTAN6KCZCICTIFQ5N2UBOSSBOZ7WFSOI2CJEJ4ESK532RODQZ7KCSOA", + ); + + static readonly TRX_USDT = new Account( + Currency.TRX_USDT, + "Tron 1", + "TDUKFB9wj3P5f2iNvkRuaDDeWVkTdUVhs1", + ); + + static readonly TRX_BTT = new Account( + Currency.TRX_BTT, + "Tron 1", + "TDUKFB9wj3P5f2iNvkRuaDDeWVkTdUVhs1", + ); + + static readonly BSC_BUSD = new Account( + Currency.BSC_BUSD, + "Binance Smart Chain 1", + "0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6", + ); + + static readonly BSC_SHIBA = new Account( + Currency.BSC_SHIBA, + "Binance Smart Chain 1", + "0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6", + ); + + static readonly MATIC_DAI = new Account( + Currency.MATIC_DAI, + "Polygon 1", + "0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6", + ); + + static readonly MATIC_UNI = new Account( + Currency.MATIC_UNI, + "Polygon 1", + "0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6", + ); } diff --git a/apps/ledger-live-desktop/tests/enum/Currency.ts b/apps/ledger-live-desktop/tests/enum/Currency.ts index 1c42be50a292..4bb3afda3230 100644 --- a/apps/ledger-live-desktop/tests/enum/Currency.ts +++ b/apps/ledger-live-desktop/tests/enum/Currency.ts @@ -7,6 +7,8 @@ export class Currency { public readonly deviceLabel: string, public readonly sendPattern: DeviceLabels[], public readonly receivePattern: DeviceLabels[], + public readonly tokenName?: string, + public readonly tokenTicker?: string, ) {} static readonly BTC = new Currency( "Bitcoin", @@ -152,4 +154,99 @@ export class Currency { [DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT], [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT], ); + static readonly ETH_USDT = new Currency( + "Ethereum", + "ETH", + "Ethereum", + [DeviceLabels.AMOUT, DeviceLabels.TO, DeviceLabels.ACCEPT, DeviceLabels.REJECT], + [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT], + "Tether USD", + "USDT", + ); + static readonly ETH_LIDO = new Currency( + "Ethereum", + "ETH", + "Ethereum", + [DeviceLabels.AMOUT, DeviceLabels.TO, DeviceLabels.ACCEPT, DeviceLabels.REJECT], + [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT], + "LIDO Staked ETH", + "STETH", + ); + static readonly XLM_USCD = new Currency( + "Stellar", + "XLM", + "Stellar", + [DeviceLabels.SEND, DeviceLabels.DESTINATION, DeviceLabels.FINALIZE, DeviceLabels.CANCEL], + [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT], + "USDC", + "usdc", + ); + static readonly ALGO_USDT = new Currency( + "Algorand", + "ALGO", + "Algorand", + [ + DeviceLabels.AMOUT, + DeviceLabels.RECEIVER, + DeviceLabels.CAPS_APPROVE, + DeviceLabels.CAPS_REJECT, + ], + [DeviceLabels.ADDRESS, DeviceLabels.CAPS_APPROVE, DeviceLabels.CAPS_REJECT], + "Tether USDt", + "USDT", + ); + static readonly TRX_USDT = new Currency( + "Tron", + "TRX", + "Tron", + [DeviceLabels.AMOUT, DeviceLabels.TO, DeviceLabels.SIGN, DeviceLabels.CANCEL], + [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.CANCEL], + "Tether USD", + "USDT", + ); + static readonly TRX_BTT = new Currency( + "Tron", + "TRX", + "Tron", + [DeviceLabels.AMOUT, DeviceLabels.TO, DeviceLabels.SIGN, DeviceLabels.CANCEL], + [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.CANCEL], + "BitTorrent", + "BTT", + ); + static readonly BSC_BUSD = new Currency( + "Binance Smart Chain", + "BNB", + "Binance Smart Chain", + [DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT], + [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT], + "Binance-Peg BUSD Token", + "BUSD", + ); + static readonly BSC_SHIBA = new Currency( + "Binance Smart Chain", + "BNB", + "Binance Smart Chain", + [DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT], + [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT], + "Shiba Inu", + "SHIB", + ); + static readonly MATIC_DAI = new Currency( + "Polygon", + "MATIC", + "Polygon", + [DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT], + [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT], + "(PoS) Dai Stablecoin", + "DAI", + ); + static readonly MATIC_UNI = new Currency( + "Polygon", + "MATIC", + "Polygon", + [DeviceLabels.AMOUT, DeviceLabels.ADDRESS, DeviceLabels.ACCEPT, DeviceLabels.REJECT], + [DeviceLabels.ADDRESS, DeviceLabels.APPROVE, DeviceLabels.REJECT], + "Uniswap (PoS)", + "UNI", + ); } diff --git a/apps/ledger-live-desktop/tests/enum/Token.ts b/apps/ledger-live-desktop/tests/enum/Token.ts deleted file mode 100644 index d6de1e5a2067..000000000000 --- a/apps/ledger-live-desktop/tests/enum/Token.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Account } from "./Account"; - -export class Token { - constructor( - public readonly parentAccount: Account, - public readonly tokenName: string, - public readonly tokenTicker: string, - public readonly tokenNetwork: string, - ) {} - static readonly ETH_USDT = new Token(Account.ETH_1, "Tether USD", "USDT", "Ethereum"); - static readonly ETH_LIDO = new Token(Account.ETH_1, "LIDO Staked ETH", "STETH", "Ethereum"); - static readonly XLM_USCD = new Token(Account.XLM_1, "USDC", "usdc", "Stellar"); - static readonly ALGO_USDT = new Token(Account.ALGO_1, "Tether USDt", "USDT", "Algorand"); - static readonly TRON_USDT = new Token(Account.TRX_1, "Tether USD", "USDT", "Tron"); - static readonly TRON_BTT = new Token(Account.TRX_1, "BitTorrent", "BTT", "Tron"); - static readonly BSC_BUSD = new Token( - Account.BSC_1, - "Binance-Peg BUSD Token", - "BUSD", - "Binance Smart Chain", - ); - static readonly BSC_SHIBA = new Token(Account.BSC_1, "SHIBA INU", "SHIB", "Binance Smart Chain"); - static readonly MATIC_DAI = new Token(Account.MATIC_1, "(PoS) Dai Stablecoin", "DAI", "Polygon"); - static readonly MATIC_UNI = new Token(Account.MATIC_1, "Uniswap (PoS)", "UNI", "Polygon"); -} diff --git a/apps/ledger-live-desktop/tests/models/Transaction.ts b/apps/ledger-live-desktop/tests/models/Transaction.ts index 706099a97c71..4be47934afaa 100644 --- a/apps/ledger-live-desktop/tests/models/Transaction.ts +++ b/apps/ledger-live-desktop/tests/models/Transaction.ts @@ -1,8 +1,7 @@ import { Fee } from "tests/enum/Fee"; import { Account } from "../enum/Account"; -import { Token } from "../enum/Token"; -export abstract class Transaction { +export class Transaction { constructor( public readonly accountToDebit: Account, public readonly accountToCredit: Account, @@ -10,16 +9,3 @@ export abstract class Transaction { public readonly speed: Fee, ) {} } -export class BasicTransaction extends Transaction {} -export class TokenTransaction extends Transaction { - constructor( - accountToDebit: Account, - public readonly accountToCredit1: Account, - public readonly accountToCredit2: Account, - amount: string, - speed: Fee, - public readonly token: Token, - ) { - super(accountToDebit, accountToCredit1, amount, speed); - } -} diff --git a/apps/ledger-live-desktop/tests/page/account.page.ts b/apps/ledger-live-desktop/tests/page/account.page.ts index e86698e8f87f..e09e5346585d 100644 --- a/apps/ledger-live-desktop/tests/page/account.page.ts +++ b/apps/ledger-live-desktop/tests/page/account.page.ts @@ -1,7 +1,7 @@ import { expect } from "@playwright/test"; import { step } from "tests/misc/reporters/step"; import { AppPage } from "tests/page/abstractClasses"; -import { Token } from "tests/enum/Token"; +import { Account } from "tests/enum/Account"; export class AccountPage extends AppPage { readonly settingsButton = this.page.getByTestId("account-settings-button"); private settingsDeleteButton = this.page.getByTestId("account-settings-delete-button"); @@ -33,9 +33,11 @@ export class AccountPage extends AppPage { private viewDetailsButton = this.page.getByText("View details"); @step("Navigate to token $0") - async navigateToToken(token: Token) { - await expect(this.tokenValue(token.tokenName)).toBeVisible(); - await this.tokenValue(token.tokenName).click(); + async navigateToToken(SubAccount: Account) { + if (SubAccount.currency.tokenName) { + await expect(this.tokenValue(SubAccount.currency.tokenName)).toBeVisible(); + await this.tokenValue(SubAccount.currency.tokenName).click(); + } } @step("Click `Receive` button") @@ -123,8 +125,8 @@ export class AccountPage extends AppPage { } @step("Expect token Account to be visible") - async expectTokenAccount(token: Token) { - await expect(this.accountbutton(token.parentAccount.accountName)).toBeVisible(); + async expectTokenAccount(Account: Account) { + await expect(this.accountbutton(Account.accountName)).toBeVisible(); } @step("Expect `show more` button to show more operations") @@ -148,15 +150,15 @@ export class AccountPage extends AppPage { } @step("Expect token to be present") - async expectTokenToBePresent(token: Token) { - await expect(this.tokenRow(token.tokenTicker)).toBeVisible(); - const tokenInfos = await this.tokenRow(token.tokenTicker).innerText(); - expect(tokenInfos).toContain(token.tokenName); - expect(tokenInfos).toContain(token.tokenTicker); + async expectTokenToBePresent(SubAccount: Account) { + await expect(this.tokenRow(SubAccount.currency.tokenTicker ?? "")).toBeVisible(); + const tokenInfos = await this.tokenRow(SubAccount.currency.tokenTicker ?? "").innerText(); + expect(tokenInfos).toContain(SubAccount.currency.tokenName); + expect(tokenInfos).toContain(SubAccount.currency.tokenTicker); } @step("navigate to token in account") - async navigateToTokenInAccount(token: Token) { - await this.tokenRow(token.tokenTicker).click(); + async navigateToTokenInAccount(SubAccount: Account) { + await this.tokenRow(SubAccount.currency.tokenTicker ?? "").click(); } } diff --git a/apps/ledger-live-desktop/tests/page/drawer/drawer.ts b/apps/ledger-live-desktop/tests/page/drawer/drawer.ts index 7aac919c33c9..40a6b50fb464 100644 --- a/apps/ledger-live-desktop/tests/page/drawer/drawer.ts +++ b/apps/ledger-live-desktop/tests/page/drawer/drawer.ts @@ -1,6 +1,6 @@ import { Component } from "tests/page/abstractClasses"; import { expect } from "@playwright/test"; -import { BasicTransaction } from "tests/models/Transaction"; +import { Transaction } from "tests/models/Transaction"; import { step } from "tests/misc/reporters/step"; export class Drawer extends Component { @@ -32,7 +32,7 @@ export class Drawer extends Component { } @step("Verify that the information of the transaction is visible") - async expectReceiverInfos(tx: BasicTransaction) { + async expectReceiverInfos(tx: Transaction) { await expect(this.addressValue(tx.accountToDebit.address)).toBeVisible(); await expect(this.addressValue(tx.accountToCredit.address)).toBeVisible(); await expect(this.amountValue(tx.amount)).toBeVisible(); diff --git a/apps/ledger-live-desktop/tests/page/modal/add.account.modal.ts b/apps/ledger-live-desktop/tests/page/modal/add.account.modal.ts index 2c7ddcf8785d..4b4636eb30f4 100644 --- a/apps/ledger-live-desktop/tests/page/modal/add.account.modal.ts +++ b/apps/ledger-live-desktop/tests/page/modal/add.account.modal.ts @@ -1,7 +1,7 @@ import { expect } from "@playwright/test"; import { Modal } from "../../component/modal.component"; import { step } from "tests/misc/reporters/step"; -import { Token } from "tests/enum/Token"; +import { Account } from "tests/enum/Account"; export class AddAccountModal extends Modal { private selectAccount = this.page.locator("text=Choose a crypto asset"); // FIXME: I need an id @@ -13,25 +13,28 @@ export class AddAccountModal extends Modal { readonly closeButton = this.page.getByTestId("modal-close-button"); private infoBox = this.page.getByTestId("add-token-infoBox"); private successAddLabel = this.page.locator("text=Account added successfully"); - private selectTokenNetwork = (token: Token) => + private selectTokenNetwork = (SubAccount: Account) => this.page .getByRole("option", { - name: `${token.tokenName} (${token.tokenTicker}) ${token.tokenNetwork}`, + name: `${SubAccount.currency.tokenName} (${SubAccount.currency.tokenTicker}) ${SubAccount.currency.uiName}`, }) .locator("span"); readonly continueButton = this.page.getByTestId("modal-continue-button"); @step("Select token $0") - async selectToken(token: Token) { + async selectToken(SubAccount: Account) { await this.selectAccount.click(); - await this.selectAccountInput.fill(token.tokenName); - if (await this.selectTokenNetwork(token).isVisible()) { - await this.selectTokenNetwork(token).click(); + await this.selectAccountInput.fill(SubAccount.currency.tokenName ?? ""); + if (await this.selectTokenNetwork(SubAccount).isVisible()) { + await this.selectTokenNetwork(SubAccount).click(); } else { - await this.selectAccountByScrolling(token); + await this.selectAccountByScrolling(SubAccount); await this.dropdownOptions .locator( - this.optionWithTextAndFollowingText(token.tokenTicker.toUpperCase(), token.tokenNetwork), + this.optionWithTextAndFollowingText( + SubAccount.currency.tokenTicker?.toUpperCase() ?? "", + SubAccount.currency.uiName, + ), ) .click(); } @@ -41,12 +44,12 @@ export class AddAccountModal extends Modal { } @step("Select account by scrolling: {0}") - async selectAccountByScrolling(token: Token) { + async selectAccountByScrolling(SubAccount: Account) { await this.scrollUntilOptionIsDisplayed( this.dropdownOptionsList, - this.selectTokenNetwork(token), + this.selectTokenNetwork(SubAccount), ); - await this.selectTokenNetwork(token).isVisible(); + await this.selectTokenNetwork(SubAccount).isVisible(); } @step("Select currency $0") diff --git a/apps/ledger-live-desktop/tests/page/modal/receive.modal.ts b/apps/ledger-live-desktop/tests/page/modal/receive.modal.ts index 82ff7eb95923..b7a393a77a96 100644 --- a/apps/ledger-live-desktop/tests/page/modal/receive.modal.ts +++ b/apps/ledger-live-desktop/tests/page/modal/receive.modal.ts @@ -1,7 +1,7 @@ import { expect } from "@playwright/test"; import { Modal } from "../../component/modal.component"; import { step } from "tests/misc/reporters/step"; -import { Token } from "tests/enum/Token"; +import { Account } from "tests/enum/Account"; export class ReceiveModal extends Modal { private skipDeviceButton = this.page.getByTestId("receive-connect-device-skip-device-button"); @@ -15,9 +15,9 @@ export class ReceiveModal extends Modal { readonly selectAccountInput = this.page.locator('[placeholder="Search"]'); @step("Select token $0") - async selectToken(token: Token) { + async selectToken(SubAccount: Account) { await this.selectAccount.click(); - await this.selectAccountInput.fill(token.tokenName); + await this.selectAccountInput.fill(SubAccount.currency.tokenName ?? ""); await this.selectAccountInput.press("Enter"); } diff --git a/apps/ledger-live-desktop/tests/page/modal/send.modal.ts b/apps/ledger-live-desktop/tests/page/modal/send.modal.ts index d55b7997fcc7..33182a3534b7 100644 --- a/apps/ledger-live-desktop/tests/page/modal/send.modal.ts +++ b/apps/ledger-live-desktop/tests/page/modal/send.modal.ts @@ -14,9 +14,6 @@ export class SendModal extends Modal { private checkTransactionbroadcastLabel = this.page.locator("text=Transaction sent"); private recipientAddressDisplayedValue = this.page.getByTestId("recipient-address"); private amountDisplayedValue = this.page.getByTestId("transaction-amount"); - private ASAErrorMessage = this.page.getByText( - "Recipient account has not opted in the selected ASA.", - ); private invalidAddressErrorMessage = (network: string) => this.page.getByText(`This is not a valid ${network} address`); @@ -64,12 +61,6 @@ export class SendModal extends Modal { await expect(this.checkTransactionbroadcastLabel).toBeVisible(); } - @step("Check continue button disable and ASA error message visible") - async checkASAError() { - await this.checkContinueButtonDisabled(); - await expect(this.ASAErrorMessage).toBeVisible(); - } - @step("Check invalid address error message") async checkInvalidAddressError(tx: Transaction) { await this.checkContinueButtonDisabled(); diff --git a/apps/ledger-live-desktop/tests/specs/speculos/send.tx.spec.ts b/apps/ledger-live-desktop/tests/specs/speculos/send.tx.spec.ts index 0a425844a937..e79969773fa0 100644 --- a/apps/ledger-live-desktop/tests/specs/speculos/send.tx.spec.ts +++ b/apps/ledger-live-desktop/tests/specs/speculos/send.tx.spec.ts @@ -1,63 +1,60 @@ import { test } from "../../fixtures/common"; import { Account } from "../../enum/Account"; -import { Token } from "../../enum/Token"; import { Fee } from "../../enum/Fee"; -import { BasicTransaction, TokenTransaction } from "../../models/Transaction"; +import { Transaction } from "../../models/Transaction"; import { specs } from "../../utils/speculos"; import { addTmsLink } from "tests/utils/allureUtils"; import { getDescription } from "../../utils/customJsonReporter"; -const transaction = new BasicTransaction( - Account.sep_ETH_1, - Account.sep_ETH_2, - "0.00001", - Fee.MEDIUM, -); +const transaction = new Transaction(Account.sep_ETH_1, Account.sep_ETH_2, "0.00001", Fee.MEDIUM); -const transactionETH_BTC = new BasicTransaction( +const transactionInvalidAddress = new Transaction( Account.ETH_1, Account.BTC_1, "0.00001", Fee.MEDIUM, ); -const transactionsToken = new TokenTransaction( - Account.ALGO_1, - Account.ALGO_2, - Account.ALGO_3, +const tokenTransactionInvalid = { + transaction: new Transaction(Account.ALGO_USDT_1, Account.ALGO_USDT_2, "0.1", Fee.MEDIUM), + expectedErrorMessage: "Recipient account has not opted in the selected ASA.", +}; + +const tokenTransactionValid = new Transaction( + Account.ALGO_USDT_1, + Account.ALGO_USDT_3, "0.1", Fee.MEDIUM, - Token.ALGO_USDT, ); const transactionInputValid = [ - new BasicTransaction(Account.ETH_1, Account.ETH_2, "send max", Fee.MEDIUM), - new BasicTransaction(Account.ETH_1, Account.ETH_2, "0.00001", Fee.MEDIUM), + new Transaction(Account.ETH_1, Account.ETH_2, "send max", Fee.MEDIUM), + new Transaction(Account.ETH_1, Account.ETH_2, "0.00001", Fee.MEDIUM), ]; const transactionsInputsInvalid = [ { - transaction: new BasicTransaction(Account.ETH_1, Account.ETH_2, "", Fee.MEDIUM), + transaction: new Transaction(Account.ETH_1, Account.ETH_2, "", Fee.MEDIUM), expectedErrorMessage: null, }, { - transaction: new BasicTransaction(Account.ETH_1, Account.ETH_2, "0", Fee.MEDIUM), + transaction: new Transaction(Account.ETH_1, Account.ETH_2, "0", Fee.MEDIUM), expectedErrorMessage: null, }, { - transaction: new BasicTransaction(Account.XRP_1, Account.XRP_2, "1", Fee.MEDIUM), + transaction: new Transaction(Account.XRP_1, Account.XRP_2, "1", Fee.MEDIUM), expectedErrorMessage: "Recipient address is inactive. Send at least 10 XRP to activate it", }, { - transaction: new BasicTransaction(Account.DOT_1, Account.DOT_2, "1.2", Fee.MEDIUM), + transaction: new Transaction(Account.DOT_1, Account.DOT_2, "1.2", Fee.MEDIUM), expectedErrorMessage: "Balance cannot be below 1 DOT. Send max to empty account.", }, { - transaction: new BasicTransaction(Account.DOT_1, Account.DOT_3, "0.5", Fee.MEDIUM), + transaction: new Transaction(Account.DOT_1, Account.DOT_3, "0.5", Fee.MEDIUM), expectedErrorMessage: "Recipient address is inactive. Send at least 1 DOT to activate it", }, { - transaction: new BasicTransaction(Account.ETH_1, Account.ETH_2, "100", Fee.MEDIUM), + transaction: new Transaction(Account.ETH_1, Account.ETH_2, "100", Fee.MEDIUM), expectedErrorMessage: "Sorry, insufficient funds", }, ]; @@ -107,17 +104,52 @@ test.describe("Send from 1 account to another", () => { ); }); -test.describe("Send token (subAccount) from 1 account to another", () => { +test.describe("Send token (subAccount) - invalid input", () => { + test.use({ + userdata: "speculos-subAccount", + testName: `sendToken_invalid_input_${tokenTransactionInvalid.transaction.accountToDebit.currency.uiName}`, + speculosCurrency: + specs[ + tokenTransactionInvalid.transaction.accountToDebit.currency.deviceLabel.replace(/ /g, "_") + ], + speculosOffset: 0, + }); + + test( + `Send [${tokenTransactionInvalid.transaction.accountToCredit.accountName}] to [${tokenTransactionInvalid.transaction.accountToCredit.accountName}] - invalid input`, + { + annotation: { + type: "TMS", + description: "B2CQA-479", + }, + }, + async ({ app }) => { + await app.layout.goToAccounts(); + await app.accounts.navigateToAccountByName( + tokenTransactionInvalid.transaction.accountToDebit.accountName, + ); + await app.account.navigateToTokenInAccount( + tokenTransactionInvalid.transaction.accountToDebit, + ); + await app.account.clickSend(); + await app.send.fillRecipient(tokenTransactionInvalid.transaction.accountToCredit.address); + await app.send.checkContinueButtonDisabled(); + await app.layout.checkErrorMessage(tokenTransactionInvalid.expectedErrorMessage); + }, + ); +}); + +test.describe("Send token (subAccount) - valid input", () => { test.use({ userdata: "speculos-subAccount", - testName: `sendToken_${transactionsToken.accountToDebit.currency.uiName}`, + testName: `sendToken_valid_input_${tokenTransactionValid.accountToDebit.currency.uiName}`, speculosCurrency: - specs[transactionsToken.accountToDebit.currency.deviceLabel.replace(/ /g, "_")], + specs[tokenTransactionValid.accountToDebit.currency.deviceLabel.replace(/ /g, "_")], speculosOffset: 0, }); test( - `Send [${transactionsToken.accountToCredit1.accountName}] (${transactionsToken.token.tokenTicker}) to [${transactionsToken.accountToCredit2.accountName}]`, + `Send [${tokenTransactionValid.accountToCredit.accountName}] to [${tokenTransactionValid.accountToCredit.accountName}] - valid input`, { annotation: { type: "TMS", @@ -126,29 +158,27 @@ test.describe("Send token (subAccount) from 1 account to another", () => { }, async ({ app }) => { await app.layout.goToAccounts(); - await app.accounts.navigateToAccountByName(transactionsToken.accountToDebit.accountName); - await app.account.navigateToTokenInAccount(transactionsToken.token); + await app.accounts.navigateToAccountByName(tokenTransactionValid.accountToDebit.accountName); + await app.account.navigateToTokenInAccount(tokenTransactionValid.accountToDebit); await app.account.clickSend(); - await app.send.fillRecipient(transactionsToken.accountToCredit1.address); - await app.send.checkASAError(); - await app.send.fillRecipient(transactionsToken.accountToCredit2.address); + await app.send.fillRecipient(tokenTransactionValid.accountToCredit.address); await app.send.checkContinueButtonEnable(); await app.layout.checkInputErrorNotVisible(); }, ); }); -test.describe("Check ETH input error", () => { +test.describe("Check invalid address input error", () => { test.use({ userdata: "speculos-tests-app", - testName: `ETH_input_error_${transactionETH_BTC.accountToDebit.currency.uiName}`, + testName: `Invalid_address_input_error_${transactionInvalidAddress.accountToDebit.currency.uiName}`, speculosCurrency: - specs[transactionETH_BTC.accountToDebit.currency.deviceLabel.replace(/ /g, "_")], + specs[transactionInvalidAddress.accountToDebit.currency.deviceLabel.replace(/ /g, "_")], speculosOffset: 0, }); test( - `Check [${transactionETH_BTC.accountToDebit.currency}] input error`, + `Check [${transactionInvalidAddress.accountToDebit.currency}] invalid address input error`, { annotation: { type: "TMS", @@ -157,27 +187,29 @@ test.describe("Check ETH input error", () => { }, async ({ app }) => { await app.layout.goToAccounts(); - await app.accounts.navigateToAccountByName(transactionETH_BTC.accountToDebit.accountName); + await app.accounts.navigateToAccountByName( + transactionInvalidAddress.accountToDebit.accountName, + ); await app.account.clickSend(); - await app.send.fillRecipient(transactionETH_BTC.accountToCredit.address); - await app.send.checkInvalidAddressError(transactionETH_BTC); + await app.send.fillRecipient(transactionInvalidAddress.accountToCredit.address); + await app.send.checkInvalidAddressError(transactionInvalidAddress); }, ); }); for (const [i, transaction] of transactionsInputsInvalid.entries()) { - test.describe("Check error message for send test (invalid input)", () => { + test.describe("Check invalid amount input error", () => { test.use({ userdata: "speculos-tests-app", - testName: `Send_test_invalid_input_${transaction.transaction.accountToDebit.currency.uiName}`, + testName: `Invalid_amount_input_error_${transaction.transaction.accountToDebit.currency.uiName}`, speculosCurrency: specs[transaction.transaction.accountToDebit.currency.deviceLabel.replace(/ /g, "_")], speculosOffset: i, }); test( - `Check [${transaction.expectedErrorMessage}] for [${transaction.transaction.accountToDebit.currency.uiName}] - Send test invalid input - ${i} `, + `Check [${transaction.expectedErrorMessage}] for [${transaction.transaction.accountToDebit.currency.uiName}] - invalid amount input error - ${i} `, { annotation: { type: "TMS", @@ -202,10 +234,10 @@ for (const [i, transaction] of transactionsInputsInvalid.entries()) { } for (const [i, transaction] of transactionInputValid.entries()) { - test.describe("Check valid input for send test", () => { + test.describe("Check valid amount input", () => { test.use({ userdata: "speculos-tests-app", - testName: `Send_test_valid_input_${transaction.accountToDebit.currency.uiName}`, + testName: `Send_test_valid_amount_${transaction.accountToDebit.currency.uiName}`, speculosCurrency: specs[transaction.accountToDebit.currency.deviceLabel.replace(/ /g, "_")], speculosOffset: i, }); diff --git a/apps/ledger-live-desktop/tests/specs/speculos/subAccount.spec.ts b/apps/ledger-live-desktop/tests/specs/speculos/subAccount.spec.ts index 7aa4ddad0590..839778a0e0cf 100644 --- a/apps/ledger-live-desktop/tests/specs/speculos/subAccount.spec.ts +++ b/apps/ledger-live-desktop/tests/specs/speculos/subAccount.spec.ts @@ -1,40 +1,40 @@ import { test } from "../../fixtures/common"; -import { Token } from "../../enum/Token"; +import { Account } from "../../enum/Account"; import { specs } from "../../utils/speculos"; import { addTmsLink } from "tests/utils/allureUtils"; import { getDescription } from "../../utils/customJsonReporter"; -const tokens: Token[] = [ - Token.ETH_USDT, - Token.XLM_USCD, - Token.ALGO_USDT, - Token.TRON_USDT, - Token.BSC_BUSD, - Token.MATIC_DAI, +const subAccounts: Account[] = [ + Account.ETH_USDT, + Account.XLM_USCD, + Account.ALGO_USDT_1, + Account.TRX_USDT, + Account.BSC_BUSD, + Account.MATIC_DAI, ]; -const tokensReceive: Token[] = [ - Token.ETH_USDT, - Token.ETH_LIDO, - Token.TRON_USDT, - Token.TRON_BTT, - Token.BSC_BUSD, - Token.BSC_SHIBA, - Token.MATIC_DAI, - Token.MATIC_UNI, +const subAccountReceive: Account[] = [ + Account.ETH_USDT, + Account.ETH_LIDO, + Account.TRX_USDT, + Account.TRX_BTT, + Account.BSC_BUSD, + Account.BSC_SHIBA, + Account.MATIC_DAI, + Account.MATIC_UNI, ]; -for (const [i, token] of tokens.entries()) { +for (const [i, token] of subAccounts.entries()) { test.describe("Add subAccount without parent", () => { test.use({ userdata: "skip-onboarding", - testName: `add subAccount without parent (${token.tokenName})`, - speculosCurrency: specs[token.parentAccount.currency.deviceLabel.replace(/ /g, "_")], + testName: `add subAccount without parent (${token.currency.tokenName})`, + speculosCurrency: specs[token.currency.deviceLabel.replace(/ /g, "_")], speculosOffset: i, }); test( - `Add Sub Account without parent (${token.parentAccount.currency.uiName})`, + `Add Sub Account without parent (${token.currency.uiName})`, { annotation: { type: "TMS", @@ -52,7 +52,7 @@ for (const [i, token] of tokens.entries()) { await app.addAccount.done(); await app.layout.goToPortfolio(); - await app.portfolio.navigateToAsset(token.tokenName); + await app.portfolio.navigateToAsset(token.currency.tokenName ?? ""); await app.account.navigateToToken(token); await app.account.expectLastOperationsVisibility(); await app.account.expectTokenAccount(token); @@ -62,17 +62,17 @@ for (const [i, token] of tokens.entries()) { } //Warning 🚨: Test may fail due to the GetAppAndVersion issue - Jira: LIVE-12581 -for (const [i, token] of tokensReceive.entries()) { +for (const [i, token] of subAccountReceive.entries()) { test.describe("Add subAccount when parent exists", () => { test.use({ userdata: "speculos-subAccount", - testName: `Add subAccount when parent exists (${token.tokenName})`, - speculosCurrency: specs[token.parentAccount.currency.deviceLabel.replace(/ /g, "_")], + testName: `Add subAccount when parent exists (${token.currency.tokenName})`, + speculosCurrency: specs[token.currency.deviceLabel.replace(/ /g, "_")], speculosOffset: i, }); test( - `[${token.tokenName}] Add subAccount when parent exists (${token.tokenNetwork})`, + `[${token.currency.tokenName}] Add subAccount when parent exists (${token.currency.uiLabel})`, { annotation: { type: "TMS", @@ -83,33 +83,33 @@ for (const [i, token] of tokensReceive.entries()) { await addTmsLink(getDescription(test.info().annotations).split(", ")); await app.layout.goToAccounts(); - await app.accounts.navigateToAccountByName(token.parentAccount.accountName); - await app.account.expectAccountVisibility(token.parentAccount.accountName); + await app.accounts.navigateToAccountByName(token.accountName); + await app.account.expectAccountVisibility(token.accountName); await app.account.clickAddToken(); await app.receive.selectToken(token); await app.modal.continue(); - await app.receive.expectValidReceiveAddress(token.parentAccount.address); + await app.receive.expectValidReceiveAddress(token.address); - await app.speculos.expectValidReceiveAddress(token.parentAccount); + await app.speculos.expectValidReceiveAddress(token); await app.receive.expectApproveLabel(); }, ); }); } -for (const [i, token] of tokens.entries()) { +for (const [i, token] of subAccounts.entries()) { test.describe("Token visible in parent account", () => { test.use({ userdata: "speculos-subAccount", - testName: `Token visible in parent account (${token.parentAccount.currency.uiName})`, - speculosCurrency: specs[token.parentAccount.currency.deviceLabel.replace(/ /g, "_")], + testName: `Token visible in parent account (${token.currency.uiName})`, + speculosCurrency: specs[token.currency.deviceLabel.replace(/ /g, "_")], speculosOffset: i, }); test( - `Token visible in parent account (${token.parentAccount.currency.uiName})`, + `Token visible in parent account (${token.currency.uiName})`, { annotation: { type: "TMS", @@ -120,7 +120,7 @@ for (const [i, token] of tokens.entries()) { await addTmsLink(getDescription(test.info().annotations).split(", ")); await app.layout.goToAccounts(); - await app.accounts.navigateToAccountByName(token.parentAccount.accountName); + await app.accounts.navigateToAccountByName(token.accountName); await app.account.expectTokenToBePresent(token); }, );