Skip to content

Commit

Permalink
Merge pull request #8741 from LedgerHQ/support/qaa-399_speculos_commo…
Browse files Browse the repository at this point in the history
…n_code

[QAA-399][Speculos] Move LLM/LLD Speculos common code
  • Loading branch information
abdurrahman-ledger authored Dec 23, 2024
2 parents 370612f + 7dcb420 commit 0db73a8
Show file tree
Hide file tree
Showing 23 changed files with 201 additions and 224 deletions.
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/tests/page/drawer/delegate.drawer.ts
Original file line number Diff line number Diff line change
@@ -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) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/page/drawer/send.drawer.ts
Original file line number Diff line number Diff line change
@@ -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) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/page/modal/send.modal.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
127 changes: 14 additions & 113 deletions apps/ledger-live-desktop/tests/page/speculos.page.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Loading

0 comments on commit 0db73a8

Please sign in to comment.