Skip to content

Commit

Permalink
Merge pull request #3912 from LedgerHQ/support/llm-detox-wallet-api-t…
Browse files Browse the repository at this point in the history
…est-framework

Test: [LLM] Detox Framework and test for wallet api/live app
  • Loading branch information
ggilchrist-ledger authored Jul 12, 2023
2 parents db2839e + 26d7af9 commit fd35196
Show file tree
Hide file tree
Showing 62 changed files with 1,517 additions and 2,178 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test-mobile-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ jobs:
key: ${{ runner.os }}-pods-${{ hashFiles('apps/ledger-live-mobile/ios/Podfile.lock') }}
- name: install dependencies
run: |
pnpm i --filter="live-mobile..." --filter="ledger-live" --no-frozen-lockfile --unsafe-perm
pnpm i --filter="live-mobile..." --filter="ledger-live" --filter="dummy-*" --no-frozen-lockfile --unsafe-perm
- name: Build dependencies
run: |
pnpm build:llm:deps
- name: Build Dummy Live SDK and Dummy Wallet API apps for testing
run: |
pnpm test-utils dummy-apps:build
shell: bash
- name: Create iOS simulator
id: simulator
run: |
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"build": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false STAGING=1 node ./tools/dist --nosign -v",
"build:js": "cross-env NODE_ENV=production node ./tools/main.js build",
"build:testing": "cross-env NODE_ENV=production TESTING=1 node ./tools/main.js build",
"build:dummy-apps": "pnpm --filter='dummy-wallet-app' --filter='dummy-live-app' build",
"lint": "eslint src static tools tests --ext .js,.jsx,.json,.ts,.tsx --cache",
"lint:fix": "eslint src tools static tests --ext .js,.jsx,.json,.ts,.tsx --fix",
"prettier": "prettier --write \"{src,tools,tests}/**/*.{js,jsx,json,ts,tsx}\"",
Expand Down Expand Up @@ -152,6 +151,7 @@
"@babel/preset-typescript": "^7.15.0",
"@electron/notarize": "^2.0.0",
"@ledgerhq/react-devtools": "workspace:^",
"@ledgerhq/test-utils": "workspace:^",
"@octokit/rest": "^18.12.0",
"@playwright/test": "^1.34.3",
"@sentry/cli": "^2.13.0",
Expand Down
10 changes: 5 additions & 5 deletions apps/ledger-live-desktop/tests/specs/services/buy.smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import test from "../../fixtures/common";
import { expect } from "@playwright/test";
import * as server from "../../utils/serve-dummy-app";
import { Layout } from "../../models/Layout";
import { DiscoverPage } from "../../models/DiscoverPage";
import { PortfolioPage } from "../../models/PortfolioPage";
Expand All @@ -9,6 +8,7 @@ import { AccountsPage } from "../../models/AccountsPage";
import { AccountPage } from "../../models/AccountPage";
import { SettingsPage } from "../../models/SettingsPage";
import { MarketPage } from "../../models/MarketPage";
import { getLiveAppManifest, startDummyServer, stopDummyServer } from "@ledgerhq/test-utils";

test.use({
userdata: "1AccountBTC1AccountETH",
Expand All @@ -26,14 +26,14 @@ let continueTest = false;
test.beforeAll(async ({ request }) => {
// Check that dummy app in tests/utils/dummy-ptx-app has been started successfully
try {
const port = await server.start("dummy-ptx-app/public");
const port = await startDummyServer("dummy-ptx-app/public");
const url = `http://localhost:${port}`;
const response = await request.get(url);
if (response.ok() && port) {
continueTest = true;
console.info(`========> Dummy test app successfully running on port ${port}! <=========`);
process.env.MOCK_REMOTE_LIVE_MANIFEST = JSON.stringify(
server.liveAppManifest({
getLiveAppManifest({
id: "multibuy",
url,
name: "Dummy Buy / Sell App",
Expand Down Expand Up @@ -64,8 +64,8 @@ test.beforeAll(async ({ request }) => {
}
});

test.afterAll(() => {
server.stop();
test.afterAll(async () => {
await stopDummyServer();
console.info(`========> Dummy test app stopped <=========`);
delete process.env.MOCK_REMOTE_LIVE_MANIFEST;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Layout } from "../../models/Layout";
import { Drawer } from "../../models/Drawer";
import { Modal } from "../../models/Modal";
import { DeviceAction } from "../../models/DeviceAction";
import * as server from "../../utils/serve-dummy-app";
import { startDummyServer, getLiveAppManifest, stopDummyServer } from "@ledgerhq/test-utils";

test.use({ userdata: "1AccountBTC1AccountETH" });

Expand All @@ -14,14 +14,14 @@ let continueTest = false;
test.beforeAll(async ({ request }) => {
// Check that dummy app in tests/utils/dummy-app-build has been started successfully
try {
const port = await server.start("dummy-live-app/build");
const port = await startDummyServer("dummy-live-app/build");
const url = `http://localhost:${port}`;
const response = await request.get(url);
if (response.ok()) {
continueTest = true;
console.info(`========> Dummy test app successfully running on port ${port}! <=========`);
process.env.MOCK_REMOTE_LIVE_MANIFEST = JSON.stringify(
server.liveAppManifest({
getLiveAppManifest({
id: "dummy-live-app",
url,
permissions: [{ method: "*" }],
Expand All @@ -44,8 +44,8 @@ test.beforeAll(async ({ request }) => {
}
});

test.afterAll(() => {
server.stop();
test.afterAll(async () => {
await stopDummyServer();
console.info(`========> Dummy test app stopped <=========`);
delete process.env.MOCK_REMOTE_LIVE_MANIFEST;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Layout } from "../../models/Layout";
import { Drawer } from "../../models/Drawer";
import { Modal } from "../../models/Modal";
import { DeviceAction } from "../../models/DeviceAction";
import * as server from "../../utils/serve-dummy-app";
import { startDummyServer, getLiveAppManifest, stopDummyServer } from "@ledgerhq/test-utils";
import { randomUUID } from "crypto";

test.use({ userdata: "1AccountBTC1AccountETH" });
Expand All @@ -15,7 +15,7 @@ let continueTest = false;
test.beforeAll(async ({ request }) => {
// Check that dummy app in tests/utils/dummy-app-build has been started successfully
try {
const port = await server.start("dummy-wallet-app/build");
const port = await startDummyServer("dummy-wallet-app/build");
const url = `http://localhost:${port}`;
const response = await request.get(url);
if (response.ok()) {
Expand All @@ -24,7 +24,7 @@ test.beforeAll(async ({ request }) => {
`========> Dummy Wallet API app successfully running on port ${port}! <=========`,
);
process.env.MOCK_REMOTE_LIVE_MANIFEST = JSON.stringify(
server.liveAppManifest({
getLiveAppManifest({
id: "dummy-live-app",
url,
name: "Dummy Wallet API Live App",
Expand All @@ -48,8 +48,8 @@ test.beforeAll(async ({ request }) => {
}
});

test.afterAll(() => {
server.stop();
test.afterAll(async () => {
await stopDummyServer();
console.info(`========> Dummy Wallet API app stopped <=========`);
delete process.env.MOCK_REMOTE_LIVE_MANIFEST;
});
Expand All @@ -70,7 +70,7 @@ test("Wallet API methods", async ({ page }) => {
await drawer.waitForDrawerToDisappear();

const id = randomUUID();
const resPromise = discoverPage.send({
const response = discoverPage.send({
jsonrpc: "2.0",
id,
method: "account.request",
Expand All @@ -82,9 +82,7 @@ test("Wallet API methods", async ({ page }) => {
await drawer.selectCurrency("bitcoin");
await drawer.selectAccount("bitcoin");

const res = await resPromise;

expect(res).toStrictEqual({
await expect(response).resolves.toMatchObject({
jsonrpc: "2.0",
id,
result: {
Expand All @@ -94,7 +92,7 @@ test("Wallet API methods", async ({ page }) => {
balance: "35688397",
blockHeight: 194870,
currency: "bitcoin",
lastSyncDate: "2020-03-14T13:34:42.000Z",
// lastSyncDate: "2020-03-14T13:34:42.000Z", TODO: make sure the sync date doesn't change
name: "Bitcoin 1 (legacy)",
spendableBalance: "35688397",
},
Expand All @@ -104,7 +102,7 @@ test("Wallet API methods", async ({ page }) => {

await test.step("account.receive", async () => {
const id = randomUUID();
const resPromise = discoverPage.send({
const response = discoverPage.send({
jsonrpc: "2.0",
id,
method: "account.receive",
Expand All @@ -116,9 +114,7 @@ test("Wallet API methods", async ({ page }) => {
await deviceAction.openApp();
await modal.waitForModalToDisappear();

const res = await resPromise;

expect(res).toStrictEqual({
await expect(response).resolves.toStrictEqual({
jsonrpc: "2.0",
id,
result: {
Expand Down
20 changes: 0 additions & 20 deletions apps/ledger-live-desktop/tests/utils/dummy-wallet-app/README.md

This file was deleted.

This file was deleted.

79 changes: 0 additions & 79 deletions apps/ledger-live-desktop/tests/utils/dummy-wallet-app/src/App.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion apps/ledger-live-mobile/.env.mock
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ BRAZE_IOS_API_KEY="e0a7dfaf-fc30-48f6-b998-01dbebbb73a4"
BRAZE_CUSTOM_ENDPOINT="sdk.fra-02.braze.eu"
FEATURE_FLAGS={"syncOnboarding":{"enabled":false},"llmNewDeviceSelection":{"enabled":false},"protectServicesMobile":{"enabled":false},"brazePushNotifications":{"enabled":false}}
# Fix random iOS app crash https://github.com/wix/Detox/pull/3135
SIMCTL_CHILD_NSZombieEnabled=YES
SIMCTL_CHILD_NSZombieEnabled=YES
MOCK_REMOTE_LIVE_MANIFEST=[{"name":"Dummy Wallet API Live App","homepageUrl":"https://developers.ledger.com/","icon":"","platforms":["ios","android","desktop"],"apiVersion":"2.0.0","manifestVersion":"1","branch":"stable","categories":["tools"],"currencies":"*","content":{"shortDescription":{"en":"App to test the Wallet API"},"description":{"en":"App to test the Wallet API with Playwright"}},"permissions":["account.list","account.receive","account.request","currency.list","device.close","device.exchange","device.transport","message.sign","transaction.sign","transaction.signAndBroadcast","storage.set","storage.get","bitcoin.getXPub","wallet.capabilities","wallet.userId","wallet.info"],"domains":["http://*"],"visibility":"complete","id":"dummy-live-app","url":"http://localhost:52619"}]
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>
12 changes: 4 additions & 8 deletions apps/ledger-live-mobile/detox.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,24 @@ module.exports = {
"ios.debug": {
type: "ios.app",
build: `export ENVFILE=.env.mock && xcodebuild ARCHS=${iosArch} ONLY_ACTIVE_ARCH=no -workspace ios/ledgerlivemobile.xcworkspace -scheme ledgerlivemobile -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build`,
binaryPath:
"ios/build/Build/Products/Debug-iphonesimulator/ledgerlivemobile.app",
binaryPath: "ios/build/Build/Products/Debug-iphonesimulator/ledgerlivemobile.app",
},
"ios.staging": {
type: "ios.app",
build: `export ENVFILE=.env.mock && xcodebuild ARCHS=${iosArch} ONLY_ACTIVE_ARCH=no -workspace ios/ledgerlivemobile.xcworkspace -scheme ledgerlivemobile -configuration Staging -sdk iphonesimulator -derivedDataPath ios/build`,
binaryPath:
"ios/build/Build/Products/Staging-iphonesimulator/ledgerlivemobile.app",
binaryPath: "ios/build/Build/Products/Staging-iphonesimulator/ledgerlivemobile.app",
},
"ios.release": {
type: "ios.app",
build: `export ENVFILE=.env.mock && xcodebuild ARCHS=${iosArch} ONLY_ACTIVE_ARCH=no -workspace ios/ledgerlivemobile.xcworkspace -scheme ledgerlivemobile -configuration Release -sdk iphonesimulator -derivedDataPath ios/build`,
binaryPath:
"ios/build/Build/Products/Release-iphonesimulator/ledgerlivemobile.app",
binaryPath: "ios/build/Build/Products/Release-iphonesimulator/ledgerlivemobile.app",
},
"android.debug": {
type: "android.apk",
build:
"cd android && ENVFILE=.env.mock ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
binaryPath: `android/app/build/outputs/apk/debug/app-${androidArch}-debug.apk`,
testBinaryPath:
"android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
testBinaryPath: "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
},
"android.release": {
type: "android.apk",
Expand Down
Loading

1 comment on commit fd35196

@vercel
Copy link

@vercel vercel bot commented on fd35196 Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.