From 7dcb42071a2b2c5e8d27960cbf757d468f20e988 Mon Sep 17 00:00:00 2001 From: Abdurrahman SASTIM Date: Thu, 19 Dec 2024 17:18:43 +0100 Subject: [PATCH] test: move common code --- .../tests/page/drawer/delegate.drawer.ts | 4 +- .../tests/page/drawer/send.drawer.ts | 2 +- .../tests/page/modal/send.modal.ts | 2 +- .../tests/page/speculos.page.ts | 127 ++---------------- .../tests/specs/speculos/delegate.spec.ts | 2 +- .../tests/specs/speculos/nft.spec.ts | 2 +- .../tests/specs/speculos/send.tx.spec.ts | 2 +- .../tests/specs/speculos/swap.spec.ts | 2 +- .../src/e2e}/families/algorand.ts | 12 +- .../src/e2e}/families/bitcoin.ts | 13 +- .../src/e2e}/families/cardano.ts | 13 +- .../src/e2e}/families/cosmos.ts | 15 +-- .../src/e2e}/families/evm.ts | 13 +- .../src/e2e}/families/near.ts | 13 +- .../src/e2e}/families/polkadot.ts | 12 +- .../src/e2e}/families/solana.ts | 13 +- .../src/e2e}/families/stellar.ts | 12 +- .../src/e2e}/families/tron.ts | 12 +- .../src/e2e}/families/xrp.ts | 12 +- .../src/e2e}/models/Delegate.ts | 2 +- .../src/e2e}/models/Swap.ts | 8 +- .../src/e2e}/models/Transaction.ts | 6 +- libs/ledger-live-common/src/e2e/speculos.ts | 126 +++++++++++++++++ 23 files changed, 201 insertions(+), 224 deletions(-) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/algorand.ts (57%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/bitcoin.ts (62%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/cardano.ts (69%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/cosmos.ts (67%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/evm.ts (68%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/near.ts (60%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/polkadot.ts (57%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/solana.ts (64%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/stellar.ts (56%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/tron.ts (56%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/families/xrp.ts (56%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/models/Delegate.ts (67%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/models/Swap.ts (71%) rename {apps/ledger-live-desktop/tests => libs/ledger-live-common/src/e2e}/models/Transaction.ts (71%) diff --git a/apps/ledger-live-desktop/tests/page/drawer/delegate.drawer.ts b/apps/ledger-live-desktop/tests/page/drawer/delegate.drawer.ts index 3312d8d8497c..4e27f80ba9c9 100644 --- a/apps/ledger-live-desktop/tests/page/drawer/delegate.drawer.ts +++ b/apps/ledger-live-desktop/tests/page/drawer/delegate.drawer.ts @@ -1,9 +1,9 @@ import { step } from "tests/misc/reporters/step"; import { Drawer } from "tests/component/drawer.component"; import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency"; -import { Delegate } from "tests/models/Delegate"; +import { Delegate } from "@ledgerhq/live-common/e2e/models/Delegate"; import { expect } from "@playwright/test"; -import { Transaction } from "tests/models/Transaction"; +import { Transaction } from "@ledgerhq/live-common/e2e/models/Transaction"; export class DelegateDrawer extends Drawer { private provider = (provider: string) => diff --git a/apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts b/apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts index 144a013f7af2..584aa255fced 100644 --- a/apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts +++ b/apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts @@ -1,7 +1,7 @@ import { step } from "tests/misc/reporters/step"; import { Drawer } from "tests/component/drawer.component"; import { expect } from "@playwright/test"; -import { NFTTransaction, Transaction } from "tests/models/Transaction"; +import { NFTTransaction, Transaction } from "@ledgerhq/live-common/e2e/models/Transaction"; export class SendDrawer extends Drawer { private addressValue = (address: string) => 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 d66ba9bf679c..f61454bfef06 100644 --- a/apps/ledger-live-desktop/tests/page/modal/send.modal.ts +++ b/apps/ledger-live-desktop/tests/page/modal/send.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 { NFTTransaction, Transaction } from "../../models/Transaction"; +import { NFTTransaction, Transaction } from "@ledgerhq/live-common/e2e/models/Transaction"; export class SendModal extends Modal { private drowdownAccount = this.page.locator('[data-testid="modal-content"] svg').nth(1); diff --git a/apps/ledger-live-desktop/tests/page/speculos.page.ts b/apps/ledger-live-desktop/tests/page/speculos.page.ts index 107086d9401d..6a7d237e61ed 100644 --- a/apps/ledger-live-desktop/tests/page/speculos.page.ts +++ b/apps/ledger-live-desktop/tests/page/speculos.page.ts @@ -1,31 +1,19 @@ import { AppPage } from "tests/page/abstractClasses"; import { step } from "tests/misc/reporters/step"; import { - pressBoth, - pressUntilTextFound, - containsSubstringInEvent, activateLedgerSync, expectValidAddressDevice, + signSendTransaction, + signSendNFTTransaction, + signDelegationTransaction, + verifyAmountsAndAcceptSwap, + verifyAmountsAndRejectSwap, } from "@ledgerhq/live-common/e2e/speculos"; import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; -import { expect } from "@playwright/test"; -import { NFTTransaction, Transaction } from "tests/models/Transaction"; -import { Delegate } from "tests/models/Delegate"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; -import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency"; -import { Swap } from "tests/models/Swap"; -import { extractNumberFromString } from "tests/utils/textParserUtils"; -import { sendBTCBasedCoin } from "tests/families/bitcoin"; -import { sendEVM, sendEvmNFT } from "tests/families/evm"; -import { sendPolkadot } from "tests/families/polkadot"; -import { sendAlgorand } from "tests/families/algorand"; -import { sendTron } from "tests/families/tron"; -import { sendStellar } from "tests/families/stellar"; -import { sendCardano } from "tests/families/cardano"; -import { sendXRP } from "tests/families/xrp"; -import { delegateNear } from "tests/families/near"; -import { delegateCosmos, sendCosmos } from "tests/families/cosmos"; -import { delegateSolana, sendSolana } from "tests/families/solana"; +import { NFTTransaction, Transaction } from "@ledgerhq/live-common/e2e/models/Transaction"; +import { Delegate } from "@ledgerhq/live-common/e2e/models/Delegate"; + +import { Swap } from "@ledgerhq/live-common/e2e/models/Swap"; export class SpeculosPage extends AppPage { @step("Verify receive address correctness on device") async expectValidAddressDevice(account: Account, addressDisplayed: string) { @@ -39,113 +27,26 @@ export class SpeculosPage extends AppPage { @step("Sign Send NFT Transaction") async signSendNFTTransaction(tx: NFTTransaction) { - const currencyName = tx.accountToDebit.currency; - switch (currencyName) { - case Currency.ETH: - await sendEvmNFT(tx); - break; - default: - throw new Error(`Unsupported currency: ${currencyName}`); - } + await signSendNFTTransaction(tx); } @step("Sign Send Transaction") async signSendTransaction(tx: Transaction) { - const currencyName = tx.accountToDebit.currency; - switch (currencyName) { - case Currency.sepETH: - case Currency.POL: - await sendEVM(tx); - break; - case Currency.DOGE: - case Currency.BCH: - await sendBTCBasedCoin(tx); - break; - case Currency.DOT: - await sendPolkadot(tx); - break; - case Currency.ALGO: - await sendAlgorand(tx); - break; - case Currency.SOL: - await sendSolana(tx); - break; - case Currency.TRX: - await sendTron(tx); - break; - case Currency.XLM: - await sendStellar(tx); - break; - case Currency.ATOM: - await sendCosmos(tx); - break; - case Currency.ADA: - await sendCardano(tx); - break; - case Currency.XRP: - await sendXRP(tx); - break; - default: - throw new Error(`Unsupported currency: ${currencyName}`); - } + await signSendTransaction(tx); } @step("Sign Delegation Transaction") async signDelegationTransaction(delegatingAccount: Delegate) { - const currencyName = delegatingAccount.account.currency.name; - switch (currencyName) { - case Account.SOL_1.currency.name: - await delegateSolana(); - break; - case Account.NEAR_1.currency.name: - await delegateNear(delegatingAccount); - break; - case Account.ATOM_1.currency.name: - await delegateCosmos(delegatingAccount); - break; - default: - throw new Error(`Unsupported currency: ${currencyName}`); - } + await signDelegationTransaction(delegatingAccount); } @step("Verify amounts and accept swap") async verifyAmountsAndAcceptSwap(swap: Swap) { - const events = await pressUntilTextFound(DeviceLabels.ACCEPT); - await this.verifySwapData(swap, events); - await pressBoth(); + await verifyAmountsAndAcceptSwap(swap); } @step("Verify amounts and reject swap") async verifyAmountsAndRejectSwap(swap: Swap) { - const events = await pressUntilTextFound(DeviceLabels.REJECT); - await this.verifySwapData(swap, events); - await pressBoth(); - } - - async verifySwapData(swap: Swap, events: string[]) { - const sendAmountScreen = containsSubstringInEvent(swap.amount, events); - expect(sendAmountScreen).toBeTruthy(); - this.verifySwapGetAmountScreen(swap, events); - this.verifySwapFeesAmountScreen(swap, events); - } - - verifySwapGetAmountScreen(swap: Swap, events: string[]) { - const parsedAmountToReceive = extractNumberFromString(swap.amountToReceive); - swap.amountToReceive = - parsedAmountToReceive.length < 19 - ? parsedAmountToReceive - : parsedAmountToReceive.substring(0, 18); - - const receivedGetAmount = containsSubstringInEvent(`${swap.amountToReceive}`, events); - expect(receivedGetAmount).toBeTruthy(); - } - - verifySwapFeesAmountScreen(swap: Swap, events: string[]) { - const parsedFeesAmount = extractNumberFromString(swap.feesAmount); - swap.feesAmount = - parsedFeesAmount.length < 19 ? parsedFeesAmount : parsedFeesAmount.substring(0, 18); - - const receivedFeesAmount = containsSubstringInEvent(swap.feesAmount, events); - expect(receivedFeesAmount).toBeTruthy(); + await verifyAmountsAndRejectSwap(swap); } } diff --git a/apps/ledger-live-desktop/tests/specs/speculos/delegate.spec.ts b/apps/ledger-live-desktop/tests/specs/speculos/delegate.spec.ts index eceb91be039a..49aa1e12a1c3 100644 --- a/apps/ledger-live-desktop/tests/specs/speculos/delegate.spec.ts +++ b/apps/ledger-live-desktop/tests/specs/speculos/delegate.spec.ts @@ -1,6 +1,6 @@ import { test } from "../../fixtures/common"; import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; -import { Delegate } from "../../models/Delegate"; +import { Delegate } from "@ledgerhq/live-common/e2e/models/Delegate"; import { addTmsLink, addBugLink } from "tests/utils/allureUtils"; import { getDescription } from "../../utils/customJsonReporter"; import { CLI } from "tests/utils/cliUtils"; diff --git a/apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts b/apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts index 066517483219..c92f2b46e1d1 100644 --- a/apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts +++ b/apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts @@ -1,5 +1,5 @@ import { test } from "../../fixtures/common"; -import { NFTTransaction } from "../../models/Transaction"; +import { NFTTransaction } from "@ledgerhq/live-common/e2e/models/Transaction"; import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; import { Nft } from "@ledgerhq/live-common/e2e/enum/Nft"; import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee"; 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 7f85819bf99b..5901aa174c4e 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 @@ -2,7 +2,7 @@ import { test } from "../../fixtures/common"; import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee"; import { OperationType } from "@ledgerhq/live-common/e2e/enum/OperationType"; -import { Transaction } from "../../models/Transaction"; +import { Transaction } from "@ledgerhq/live-common/e2e/models/Transaction"; import { addTmsLink, addBugLink } from "tests/utils/allureUtils"; import { getDescription } from "../../utils/customJsonReporter"; import { CLI } from "tests/utils/cliUtils"; diff --git a/apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts b/apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts index 4db95b8fa03b..b10c17c715be 100644 --- a/apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts +++ b/apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts @@ -3,7 +3,7 @@ import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; import { AppInfos } from "@ledgerhq/live-common/e2e/enum/AppInfos"; import { setExchangeDependencies } from "@ledgerhq/live-common/e2e/speculos"; import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee"; -import { Swap } from "tests/models/Swap"; +import { Swap } from "@ledgerhq/live-common/e2e/models/Swap"; import { Provider, Rate } from "@ledgerhq/live-common/e2e/enum/Swap"; import { addTmsLink } from "tests/utils/allureUtils"; import { getDescription } from "tests/utils/customJsonReporter"; diff --git a/apps/ledger-live-desktop/tests/families/algorand.ts b/libs/ledger-live-common/src/e2e/families/algorand.ts similarity index 57% rename from apps/ledger-live-desktop/tests/families/algorand.ts rename to libs/ledger-live-common/src/e2e/families/algorand.ts index 69097bfbb50d..5bf84eee4558 100644 --- a/apps/ledger-live-desktop/tests/families/algorand.ts +++ b/libs/ledger-live-common/src/e2e/families/algorand.ts @@ -1,11 +1,7 @@ -import { expect } from "@playwright/test"; -import { Transaction } from "tests/models/Transaction"; -import { - pressBoth, - pressUntilTextFound, - containsSubstringInEvent, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { Transaction } from "../models/Transaction"; +import { pressBoth, pressUntilTextFound, containsSubstringInEvent } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function sendAlgorand(tx: Transaction) { const events = await pressUntilTextFound(DeviceLabels.CAPS_APPROVE); diff --git a/apps/ledger-live-desktop/tests/families/bitcoin.ts b/libs/ledger-live-common/src/e2e/families/bitcoin.ts similarity index 62% rename from apps/ledger-live-desktop/tests/families/bitcoin.ts rename to libs/ledger-live-common/src/e2e/families/bitcoin.ts index bacff2ab6955..2b7cadd2c1b4 100644 --- a/apps/ledger-live-desktop/tests/families/bitcoin.ts +++ b/libs/ledger-live-common/src/e2e/families/bitcoin.ts @@ -1,12 +1,7 @@ -import { expect } from "@playwright/test"; -import { Transaction } from "tests/models/Transaction"; -import { - pressBoth, - pressUntilTextFound, - waitFor, - containsSubstringInEvent, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { Transaction } from "../models/Transaction"; +import { pressBoth, pressUntilTextFound, waitFor, containsSubstringInEvent } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function sendBTCBasedCoin(tx: Transaction) { const events = await pressUntilTextFound(DeviceLabels.ACCEPT); diff --git a/apps/ledger-live-desktop/tests/families/cardano.ts b/libs/ledger-live-common/src/e2e/families/cardano.ts similarity index 69% rename from apps/ledger-live-desktop/tests/families/cardano.ts rename to libs/ledger-live-common/src/e2e/families/cardano.ts index 3487f653c343..7863145ff352 100644 --- a/apps/ledger-live-desktop/tests/families/cardano.ts +++ b/libs/ledger-live-common/src/e2e/families/cardano.ts @@ -1,12 +1,7 @@ -import { expect } from "@playwright/test"; -import { Transaction } from "tests/models/Transaction"; -import { - pressBoth, - pressUntilTextFound, - containsSubstringInEvent, - waitFor, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { Transaction } from "../models/Transaction"; +import { pressBoth, pressUntilTextFound, containsSubstringInEvent, waitFor } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function sendCardano(tx: Transaction) { await waitFor(DeviceLabels.NEW_ORDINARY_TRANSACTION); diff --git a/apps/ledger-live-desktop/tests/families/cosmos.ts b/libs/ledger-live-common/src/e2e/families/cosmos.ts similarity index 67% rename from apps/ledger-live-desktop/tests/families/cosmos.ts rename to libs/ledger-live-common/src/e2e/families/cosmos.ts index f7a97ccb64d5..9354e77130c2 100644 --- a/apps/ledger-live-desktop/tests/families/cosmos.ts +++ b/libs/ledger-live-common/src/e2e/families/cosmos.ts @@ -1,13 +1,8 @@ -import { expect } from "@playwright/test"; -import { Delegate } from "tests/models/Delegate"; -import { Transaction } from "tests/models/Transaction"; -import { - pressBoth, - pressUntilTextFound, - waitFor, - containsSubstringInEvent, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { Delegate } from "../models/Delegate"; +import { Transaction } from "../models/Transaction"; +import { pressBoth, pressUntilTextFound, waitFor, containsSubstringInEvent } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function delegateCosmos(delegatingAccount: Delegate) { await waitFor(DeviceLabels.PLEASE_REVIEW); diff --git a/apps/ledger-live-desktop/tests/families/evm.ts b/libs/ledger-live-common/src/e2e/families/evm.ts similarity index 68% rename from apps/ledger-live-desktop/tests/families/evm.ts rename to libs/ledger-live-common/src/e2e/families/evm.ts index 2dca0d54492f..6d42c2406438 100644 --- a/apps/ledger-live-desktop/tests/families/evm.ts +++ b/libs/ledger-live-common/src/e2e/families/evm.ts @@ -1,12 +1,7 @@ -import { expect } from "@playwright/test"; -import { NFTTransaction, Transaction } from "tests/models/Transaction"; -import { - pressBoth, - pressUntilTextFound, - containsSubstringInEvent, - waitFor, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { NFTTransaction, Transaction } from "../models/Transaction"; +import { pressBoth, pressUntilTextFound, containsSubstringInEvent, waitFor } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function sendEVM(tx: Transaction) { const events = await pressUntilTextFound(DeviceLabels.ACCEPT); diff --git a/apps/ledger-live-desktop/tests/families/near.ts b/libs/ledger-live-common/src/e2e/families/near.ts similarity index 60% rename from apps/ledger-live-desktop/tests/families/near.ts rename to libs/ledger-live-common/src/e2e/families/near.ts index c01adab9f6c5..c0cc3cbc2609 100644 --- a/apps/ledger-live-desktop/tests/families/near.ts +++ b/libs/ledger-live-common/src/e2e/families/near.ts @@ -1,12 +1,7 @@ -import { expect } from "@playwright/test"; -import { Delegate } from "tests/models/Delegate"; -import { - pressBoth, - pressUntilTextFound, - waitFor, - containsSubstringInEvent, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { Delegate } from "../models/Delegate"; +import { pressBoth, pressUntilTextFound, waitFor, containsSubstringInEvent } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function delegateNear(delegatingAccount: Delegate) { await waitFor(DeviceLabels.VIEW_HEADER); diff --git a/apps/ledger-live-desktop/tests/families/polkadot.ts b/libs/ledger-live-common/src/e2e/families/polkadot.ts similarity index 57% rename from apps/ledger-live-desktop/tests/families/polkadot.ts rename to libs/ledger-live-common/src/e2e/families/polkadot.ts index a12540c6842c..c9104daa49e6 100644 --- a/apps/ledger-live-desktop/tests/families/polkadot.ts +++ b/libs/ledger-live-common/src/e2e/families/polkadot.ts @@ -1,11 +1,7 @@ -import { expect } from "@playwright/test"; -import { Transaction } from "tests/models/Transaction"; -import { - pressBoth, - pressUntilTextFound, - containsSubstringInEvent, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { Transaction } from "../models/Transaction"; +import { pressBoth, pressUntilTextFound, containsSubstringInEvent } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function sendPolkadot(tx: Transaction) { const events = await pressUntilTextFound(DeviceLabels.CAPS_APPROVE); diff --git a/apps/ledger-live-desktop/tests/families/solana.ts b/libs/ledger-live-common/src/e2e/families/solana.ts similarity index 64% rename from apps/ledger-live-desktop/tests/families/solana.ts rename to libs/ledger-live-common/src/e2e/families/solana.ts index 05840ed319cf..352a3c577b59 100644 --- a/apps/ledger-live-desktop/tests/families/solana.ts +++ b/libs/ledger-live-common/src/e2e/families/solana.ts @@ -1,12 +1,7 @@ -import { expect } from "@playwright/test"; -import { - pressBoth, - pressUntilTextFound, - waitFor, - containsSubstringInEvent, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; -import { Transaction } from "tests/models/Transaction"; +import expect from "expect"; +import { pressBoth, pressUntilTextFound, waitFor, containsSubstringInEvent } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; +import { Transaction } from "../models/Transaction"; export async function delegateSolana() { await waitFor(DeviceLabels.DELEGATE_FROM); diff --git a/apps/ledger-live-desktop/tests/families/stellar.ts b/libs/ledger-live-common/src/e2e/families/stellar.ts similarity index 56% rename from apps/ledger-live-desktop/tests/families/stellar.ts rename to libs/ledger-live-common/src/e2e/families/stellar.ts index cd29898f9dc1..785d600b56f7 100644 --- a/apps/ledger-live-desktop/tests/families/stellar.ts +++ b/libs/ledger-live-common/src/e2e/families/stellar.ts @@ -1,11 +1,7 @@ -import { expect } from "@playwright/test"; -import { Transaction } from "tests/models/Transaction"; -import { - pressBoth, - pressUntilTextFound, - containsSubstringInEvent, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { Transaction } from "../models/Transaction"; +import { pressBoth, pressUntilTextFound, containsSubstringInEvent } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function sendStellar(tx: Transaction) { const events = await pressUntilTextFound(DeviceLabels.SIGN); diff --git a/apps/ledger-live-desktop/tests/families/tron.ts b/libs/ledger-live-common/src/e2e/families/tron.ts similarity index 56% rename from apps/ledger-live-desktop/tests/families/tron.ts rename to libs/ledger-live-common/src/e2e/families/tron.ts index 7727b9acbe91..5f819a2fbf0e 100644 --- a/apps/ledger-live-desktop/tests/families/tron.ts +++ b/libs/ledger-live-common/src/e2e/families/tron.ts @@ -1,11 +1,7 @@ -import { expect } from "@playwright/test"; -import { Transaction } from "tests/models/Transaction"; -import { - pressBoth, - pressUntilTextFound, - containsSubstringInEvent, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { Transaction } from "../models/Transaction"; +import { pressBoth, pressUntilTextFound, containsSubstringInEvent } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function sendTron(tx: Transaction) { const events = await pressUntilTextFound(DeviceLabels.SIGN); diff --git a/apps/ledger-live-desktop/tests/families/xrp.ts b/libs/ledger-live-common/src/e2e/families/xrp.ts similarity index 56% rename from apps/ledger-live-desktop/tests/families/xrp.ts rename to libs/ledger-live-common/src/e2e/families/xrp.ts index 2f724f0532b2..6a3123c28648 100644 --- a/apps/ledger-live-desktop/tests/families/xrp.ts +++ b/libs/ledger-live-common/src/e2e/families/xrp.ts @@ -1,11 +1,7 @@ -import { expect } from "@playwright/test"; -import { Transaction } from "tests/models/Transaction"; -import { - pressBoth, - pressUntilTextFound, - containsSubstringInEvent, -} from "@ledgerhq/live-common/e2e/speculos"; -import { DeviceLabels } from "@ledgerhq/live-common/e2e/enum/DeviceLabels"; +import expect from "expect"; +import { Transaction } from "../models/Transaction"; +import { pressBoth, pressUntilTextFound, containsSubstringInEvent } from "../speculos"; +import { DeviceLabels } from "../enum/DeviceLabels"; export async function sendXRP(tx: Transaction) { const events = await pressUntilTextFound(DeviceLabels.SIGN); diff --git a/apps/ledger-live-desktop/tests/models/Delegate.ts b/libs/ledger-live-common/src/e2e/models/Delegate.ts similarity index 67% rename from apps/ledger-live-desktop/tests/models/Delegate.ts rename to libs/ledger-live-common/src/e2e/models/Delegate.ts index 60811212792c..f4142fb9b65e 100644 --- a/apps/ledger-live-desktop/tests/models/Delegate.ts +++ b/libs/ledger-live-common/src/e2e/models/Delegate.ts @@ -1,4 +1,4 @@ -import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; +import { Account } from "../enum/Account"; export class Delegate { constructor( diff --git a/apps/ledger-live-desktop/tests/models/Swap.ts b/libs/ledger-live-common/src/e2e/models/Swap.ts similarity index 71% rename from apps/ledger-live-desktop/tests/models/Swap.ts rename to libs/ledger-live-common/src/e2e/models/Swap.ts index db010055ff56..e9c266f080de 100644 --- a/apps/ledger-live-desktop/tests/models/Swap.ts +++ b/libs/ledger-live-common/src/e2e/models/Swap.ts @@ -1,7 +1,7 @@ -import { Transaction } from "tests/models/Transaction"; -import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee"; -import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; -import { Provider, Rate } from "@ledgerhq/live-common/e2e/enum/Swap"; +import { Transaction } from "./Transaction"; +import { Fee } from "../enum/Fee"; +import { Account } from "../enum/Account"; +import { Provider, Rate } from "../enum/Swap"; export class Swap extends Transaction { provider: Provider; diff --git a/apps/ledger-live-desktop/tests/models/Transaction.ts b/libs/ledger-live-common/src/e2e/models/Transaction.ts similarity index 71% rename from apps/ledger-live-desktop/tests/models/Transaction.ts rename to libs/ledger-live-common/src/e2e/models/Transaction.ts index 2dd4f92a520b..27b17782d416 100644 --- a/apps/ledger-live-desktop/tests/models/Transaction.ts +++ b/libs/ledger-live-common/src/e2e/models/Transaction.ts @@ -1,6 +1,6 @@ -import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee"; -import { Account } from "@ledgerhq/live-common/e2e/enum/Account"; -import { Nft } from "@ledgerhq/live-common/e2e/enum/Nft"; +import { Fee } from "../enum/Fee"; +import { Account } from "../enum/Account"; +import { Nft } from "../enum/Nft"; export class Transaction { constructor( diff --git a/libs/ledger-live-common/src/e2e/speculos.ts b/libs/ledger-live-common/src/e2e/speculos.ts index 31d5bca468ed..ccbe257fa5d5 100644 --- a/libs/ledger-live-common/src/e2e/speculos.ts +++ b/libs/ledger-live-common/src/e2e/speculos.ts @@ -18,6 +18,20 @@ import { DeviceLabels } from "../e2e/enum/DeviceLabels"; import { Account } from "./enum/Account"; import { Currency } from "./enum/Currency"; import expect from "expect"; +import { sendBTCBasedCoin } from "./families/bitcoin"; +import { sendEVM, sendEvmNFT } from ".//families/evm"; +import { sendPolkadot } from "./families/polkadot"; +import { sendAlgorand } from "./families/algorand"; +import { sendTron } from "./families/tron"; +import { sendStellar } from "./families/stellar"; +import { sendCardano } from "./families/cardano"; +import { sendXRP } from "./families/xrp"; +import { delegateNear } from "./families/near"; +import { delegateCosmos, sendCosmos } from "./families/cosmos"; +import { delegateSolana, sendSolana } from "./families/solana"; +import { NFTTransaction, Transaction } from "./models/Transaction"; +import { Delegate } from "./models/Delegate"; +import { Swap } from "./models/Swap"; export type Spec = { currency?: CryptoCurrency; @@ -466,3 +480,115 @@ export async function expectValidAddressDevice(account: Account, addressDisplaye expect(isAddressCorrect).toBeTruthy(); await pressBoth(); } + +export async function signSendTransaction(tx: Transaction) { + const currencyName = tx.accountToDebit.currency; + switch (currencyName) { + case Currency.sepETH: + case Currency.POL: + await sendEVM(tx); + break; + case Currency.DOGE: + case Currency.BCH: + await sendBTCBasedCoin(tx); + break; + case Currency.DOT: + await sendPolkadot(tx); + break; + case Currency.ALGO: + await sendAlgorand(tx); + break; + case Currency.SOL: + await sendSolana(tx); + break; + case Currency.TRX: + await sendTron(tx); + break; + case Currency.XLM: + await sendStellar(tx); + break; + case Currency.ATOM: + await sendCosmos(tx); + break; + case Currency.ADA: + await sendCardano(tx); + break; + case Currency.XRP: + await sendXRP(tx); + break; + default: + throw new Error(`Unsupported currency: ${currencyName}`); + } +} + +export async function signSendNFTTransaction(tx: NFTTransaction) { + const currencyName = tx.accountToDebit.currency; + switch (currencyName) { + case Currency.ETH: + await sendEvmNFT(tx); + break; + default: + throw new Error(`Unsupported currency: ${currencyName}`); + } +} + +export async function signDelegationTransaction(delegatingAccount: Delegate) { + const currencyName = delegatingAccount.account.currency.name; + switch (currencyName) { + case Account.SOL_1.currency.name: + await delegateSolana(); + break; + case Account.NEAR_1.currency.name: + await delegateNear(delegatingAccount); + break; + case Account.ATOM_1.currency.name: + await delegateCosmos(delegatingAccount); + break; + default: + throw new Error(`Unsupported currency: ${currencyName}`); + } +} + +export async function verifyAmountsAndAcceptSwap(swap: Swap) { + const events = await pressUntilTextFound(DeviceLabels.ACCEPT); + await verifySwapData(swap, events); + await pressBoth(); +} + +export async function verifyAmountsAndRejectSwap(swap: Swap) { + const events = await pressUntilTextFound(DeviceLabels.REJECT); + await verifySwapData(swap, events); + await pressBoth(); +} + +async function verifySwapData(swap: Swap, events: string[]) { + const sendAmountScreen = containsSubstringInEvent(swap.amount, events); + expect(sendAmountScreen).toBeTruthy(); + verifySwapGetAmountScreen(swap, events); + verifySwapFeesAmountScreen(swap, events); +} + +function verifySwapGetAmountScreen(swap: Swap, events: string[]) { + const parsedAmountToReceive = extractNumberFromString(swap.amountToReceive); + swap.amountToReceive = + parsedAmountToReceive.length < 19 + ? parsedAmountToReceive + : parsedAmountToReceive.substring(0, 18); + + const receivedGetAmount = containsSubstringInEvent(`${swap.amountToReceive}`, events); + expect(receivedGetAmount).toBeTruthy(); +} + +function verifySwapFeesAmountScreen(swap: Swap, events: string[]) { + const parsedFeesAmount = extractNumberFromString(swap.feesAmount); + swap.feesAmount = + parsedFeesAmount.length < 19 ? parsedFeesAmount : parsedFeesAmount.substring(0, 18); + + const receivedFeesAmount = containsSubstringInEvent(swap.feesAmount, events); + expect(receivedFeesAmount).toBeTruthy(); +} + +const extractNumberFromString = (input: string | undefined): string => { + const match = input?.match(/[\d.]+/); + return match ? match[0] : ""; +};