Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QAA-312][DETOX] Speculos add accounts tests #8186

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions .github/workflows/test-mobile-e2e-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ permissions:
id-token: write
contents: read

env:
SPECULOS_IMAGE_TAG: ghcr.io/ledgerhq/speculos:0.9.5
COINAPPS: ${{ github.workspace }}/coin-apps

jobs:
detox-tests-ios:
name: "LLM - iOS Detox Tests"
runs-on: [m1, ARM64]
if: ${{ !inputs.speculos_tests }}
env:
NODE_OPTIONS: "--max-old-space-size=7168"
LANG: en_US.UTF-8
Expand Down Expand Up @@ -89,7 +94,7 @@ jobs:
id: detox-build
with:
path: ${{ github.workspace }}/apps/ledger-live-mobile/ios/build/Build/Products/Release-iphonesimulator
key: ${{ runner.os }}-detox-${{ hashFiles('apps/ledger-live-mobile/ios/Podfile.lock', 'apps/ledger-live-mobile/ios/ledgerlivemobile.xcodeproj/project.pbxproj', 'apps/ledger-live-mobile/detox.config.js') }}
key: ${{ runner.os }}-detox-${{ hashFiles('apps/ledger-live-mobile/ios/Podfile.lock', 'apps/ledger-live-mobile/ios/ledgerlivemobile.xcodeproj/project.pbxproj', 'apps/ledger-live-mobile/detox.config.js', 'apps/ledger-live-mobile/.env.mock') }}
accessKey: ${{ env.AWS_ACCESS_KEY_ID }}
secretKey: ${{ env.AWS_SECRET_ACCESS_KEY }}
sessionToken: ${{ env.AWS_SESSION_TOKEN}}
Expand Down Expand Up @@ -121,10 +126,21 @@ jobs:
- name: Build JS Bundle app for Detox test run
if: steps.detox-build.outputs.cache-hit == 'true'
run: pnpm mobile e2e:ci -p ios --bundle
- name: Setup Speculos image and Coin Apps
if: ${{ inputs.speculos_tests }}
uses: LedgerHQ/ledger-live/tools/actions/composites/setup-speculos_image@develop
with:
coinapps_path: ${{ env.COINAPPS }}
speculos_tag: ${{ env.SPECULOS_IMAGE_TAG }}
bot_id: ${{ secrets.GH_BOT_APP_ID }}
bot_key: ${{ secrets.GH_BOT_PRIVATE_KEY }}
- name: Test iOS app
id: detox
timeout-minutes: 75
run: pnpm mobile e2e:ci -p ios -t
run: pnpm mobile e2e:ci -p ios -t $([[ "$INPUT_SPECULOS" == "true" ]] && printf %s '--speculos')
env:
SEED: ${{ secrets.SEED_QAA_B2C }}
INPUT_SPECULOS: ${{ inputs.speculos_tests }}
- name: Delete iOS simulator
if: ${{ always() && steps.simulator.outputs.id }}
run: |
Expand Down Expand Up @@ -180,8 +196,6 @@ jobs:
AVD_CORES: 4
AVD_RAM_SIZE: 4096M
AVD_OPTIONS: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
SPECULOS_IMAGE_TAG: ghcr.io/ledgerhq/speculos:0.9.5
COINAPPS: ${{ github.workspace }}/coin-apps
outputs:
status: ${{ steps.detox.outcome }}
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from "tests/page/abstractClasses";
import { step } from "tests/misc/reporters/step";
import { Account } from "tests/enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";

export class Drawer extends Component {
readonly content = this.page.getByTestId("drawer-content");
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/fixtures/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { safeAppendFile } from "tests/utils/fileUtils";
import { launchApp } from "tests/utils/electronUtils";
import { captureArtifacts } from "tests/utils/allureUtils";
import { randomUUID } from "crypto";
import { AppInfos } from "tests/enum/AppInfos";
import { AppInfos } from "@ledgerhq/live-common/e2e/enum/AppInfos";
import { lastValueFrom, Observable } from "rxjs";
import { commandCLI } from "tests/utils/cliUtils";
import { registerSpeculosTransport } from "@ledgerhq/live-cli/src/live-common-setup";
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/models/Delegate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account } from "../enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";

export class Delegate {
constructor(
Expand Down
6 changes: 3 additions & 3 deletions apps/ledger-live-desktop/tests/models/Swap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Transaction } from "tests/models/Transaction";
import { Fee } from "tests/enum/Fee";
import { Account } from "../enum/Account";
import { Provider, Rate } from "../enum/Swap";
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";

export class Swap extends Transaction {
provider: Provider;
Expand Down
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/tests/models/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fee } from "tests/enum/Fee";
import { Account } from "../enum/Account";
import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";

export class Transaction {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/page/account.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "@playwright/test";
import { step } from "tests/misc/reporters/step";
import { AppPage } from "tests/page/abstractClasses";
import { Account } from "tests/enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";

export class AccountPage extends AppPage {
readonly settingsButton = this.page.getByTestId("account-settings-button");
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/page/accounts.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "@playwright/test";
import { step } from "tests/misc/reporters/step";
import { AppPage } from "tests/page/abstractClasses";
import { Currency } from "../enum/Currency";
import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency";

export class AccountsPage extends AppPage {
private addAccountButton = this.page.getByTestId("accounts-add-account-button");
Expand Down
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/tests/page/drawer/asset.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 { Currency } from "tests/enum/Currency";
import { Account } from "tests/enum/Account";
import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";

export class AssetDrawer extends Drawer {
private assetInput = this.page.getByTestId("select-asset-drawer-search-input");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { step } from "tests/misc/reporters/step";
import { Drawer } from "tests/component/drawer.component";
import { Currency } from "tests/enum/Currency";
import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency";
import { Delegate } from "tests/models/Delegate";
import { expect } from "@playwright/test";
import { Transaction } from "tests/models/Transaction";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "@playwright/test";
import { Modal } from "../../component/modal.component";
import { step } from "tests/misc/reporters/step";
import { Account } from "tests/enum/Account";
import { Currency } from "tests/enum/Currency";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency";

export class AddAccountModal extends Modal {
private selectAccount = this.page.locator("text=Choose a crypto asset"); // FIXME: I need an id
Expand Down
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 { Account } from "tests/enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";

export class ReceiveModal extends Modal {
private skipDeviceButton = this.page.getByTestId("receive-connect-device-skip-device-button");
Expand Down
6 changes: 3 additions & 3 deletions apps/ledger-live-desktop/tests/page/speculos.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
waitFor,
containsSubstringInEvent,
} from "@ledgerhq/live-common/e2e/speculos";
import { Account } from "../enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { expect } from "@playwright/test";
import { Transaction } from "tests/models/Transaction";
import { Delegate } from "tests/models/Delegate";
import { DeviceLabels } from "tests/enum/DeviceLabels";
import { Currency } from "tests/enum/Currency";
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";
export class SpeculosPage extends AppPage {
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/page/swap.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { waitFor } from "../utils/waitFor";
import { step } from "tests/misc/reporters/step";
import { ElectronApplication, expect } from "@playwright/test";
import { capitalizeFirstLetter } from "tests/utils/textParserUtils";
import { Account } from "tests/enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { ChooseAssetDrawer } from "tests/page/drawer/choose.asset.drawer";

export class SwapPage extends AppPage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from "../../fixtures/common";
import { Currency } from "../../enum/Currency";
import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from "../../fixtures/common";
import { Account } from "../../enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { Delegate } from "../../models/Delegate";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from "../../fixtures/common";
import { Account } from "../../enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
import { commandCLI } from "tests/utils/cliUtils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from "../../fixtures/common";
import { AppInfos } from "tests/enum/AppInfos";
import { AppInfos } from "@ledgerhq/live-common/e2e/enum/AppInfos";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from "../../fixtures/common";
import { Account } from "../../enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
import { commandCLI } from "tests/utils/cliUtils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "../../fixtures/common";
import { Account } from "../../enum/Account";
import { Fee } from "../../enum/Fee";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee";
import { Transaction } from "../../models/Transaction";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from "../../fixtures/common";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
import { Account } from "tests/enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";

test.describe("Settings", () => {
test.use({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from "../../fixtures/common";
import { Account } from "../../enum/Account";
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";

Expand Down
8 changes: 4 additions & 4 deletions apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from "../../fixtures/common";
import { Account } from "tests/enum/Account";
import { AppInfos } from "tests/enum/AppInfos";
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 "tests/enum/Fee";
import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee";
import { Swap } from "tests/models/Swap";
import { Provider, Rate } from "tests/enum/Swap";
import { Provider, Rate } from "@ledgerhq/live-common/e2e/enum/Swap";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "tests/utils/customJsonReporter";
import { Application } from "tests/page";
Expand Down
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/.env.mock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
APP_NAME="LLmock"
MOCK=1
MOCK_COUNTERVALUES=1
DETOX=1
DISABLE_YELLOW_BOX=1
GOOGLE_SERVICE_INFO_NAME="GoogleService-Info-Testing"
MOCK_SCAN_RECIPIENT=bitcoin:3HX3Q4wgYi8nKakxv7kmdCgLWJFrFgcqEt?amount=0.001
Expand Down
3 changes: 3 additions & 0 deletions apps/ledger-live-mobile/e2e/bridge/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const retryDelay = 500; // Initial retry delay in milliseconds

export function init() {
const wsPort = LaunchArguments.value()["wsPort"] || "8099";
const mock = LaunchArguments.value()["mock"];
log(`[E2E Bridge Client]: wsPort=${wsPort}, mock=${mock}`);

if (mock == "0") setEnv("MOCK", "");
if (ws) {
ws.close();
}
Expand Down
15 changes: 12 additions & 3 deletions apps/ledger-live-mobile/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { findFreePort, close as closeBridge, init as initBridge } from "./bridge
import { startSpeculos, stopSpeculos, specs } from "@ledgerhq/live-common/e2e/speculos";
import { SpeculosDevice } from "@ledgerhq/speculos-transport";
import invariant from "invariant";
import { setEnv } from "@ledgerhq/live-env";
import { getEnv, setEnv } from "@ledgerhq/live-env";
import { startProxy, closeProxy } from "./bridge/proxy";

const DEFAULT_TIMEOUT = 60000; // 60s !!
Expand Down Expand Up @@ -121,6 +121,14 @@ export async function getTextOfElement(id: string | RegExp, index = 0) {
return (!("elements" in attributes) ? attributes.text : attributes.elements[index].text) || "";
}

export async function getIdOfElement(id: RegExp, index = 0) {
const attributes = await getElementById(id, index).getAttributes();
return (
(!("elements" in attributes) ? attributes.identifier : attributes.elements[index].identifier) ||
""
);
}

/**
* Waits for a specified amount of time
* /!\ Do not use it to wait for a specific element, use waitFor instead.
Expand Down Expand Up @@ -152,6 +160,7 @@ export async function launchApp() {
wsPort: port,
detoxURLBlacklistRegex:
'\\(".*sdk.*.braze.*",".*.googleapis.com/.*",".*clients3.google.com.*"\\)',
mock: getEnv("MOCK") ? getEnv("MOCK") : "0",
},
languageAndLocale: {
language: "en-US",
Expand All @@ -171,11 +180,11 @@ export async function launchSpeculos(appName: string, proxyPort: number) {
}
const speculosPort = portCounter++;
const speculosPidOffset =
(speculosPort - BASE_PORT) * 1000 + parseInt(process.env.TEST_WORKER_INDEX || "0") * 100;
(speculosPort - BASE_PORT) * 1000 + parseInt(process.env.JEST_WORKER_ID || "0") * 100;
setEnv("SPECULOS_PID_OFFSET", speculosPidOffset);

const testName = expect.getState().testPath || "unknown";
const speculosDevice = await startSpeculos(testName, specs[appName]);
const speculosDevice = await startSpeculos(testName, specs[appName.replace(/ /g, "_")]);
invariant(speculosDevice, "[E2E Setup] Speculos not started");

const speculosApiPort = speculosDevice.ports.apiPort;
Expand Down
9 changes: 4 additions & 5 deletions apps/ledger-live-mobile/e2e/jest.globalTeardown.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const detoxGlobalTeardown = require("detox/runners/jest/globalTeardown");
import { promises as fs } from "fs";
import { getEnvs, getFlags } from "./bridge/server";
import { getEnvs, getFlags, loadConfig } from "./bridge/server";
import { formatFlagsData, formatEnvData } from "@ledgerhq/live-common/e2e/index";
import { launchApp } from "./helpers";
import { launchApp, waitForElementById } from "./helpers";
import detox from "detox/internals";
import { Application } from "./page";
import { close as closeBridge } from "./bridge/server";

const environmentFilePath = "artifacts/environment.properties";
Expand All @@ -15,8 +14,8 @@ export default async () => {
try {
await initDetox();
await launchApp();
const app = await Application.init("1AccountBTC1AccountETHReadOnlyFalse");
await app.portfolio.waitForPortfolioPageToLoad();
await loadConfig("1AccountBTC1AccountETHReadOnlyFalse", true);
await waitForElementById("settings-icon", 120000);
const flagsData = formatFlagsData(JSON.parse(await getFlags()));
const envsData = formatEnvData(JSON.parse(await getEnvs()));
await fs.appendFile(environmentFilePath, flagsData + envsData);
Expand Down
Loading
Loading