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-353][Playwright][Speculos] Improve CLI calls #8636

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
35 changes: 6 additions & 29 deletions apps/ledger-live-desktop/tests/fixtures/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ import { captureArtifacts } from "tests/utils/allureUtils";
import { randomUUID } from "crypto";
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";
import { activateLedgerSync } from "@ledgerhq/live-common/e2e/speculos";

type Command<T extends (...args: any) => Observable<any> | Promise<any> | string> = {
command: T;
args: Parameters<T>[0]; // Infer the first argument type
output?: (output: any) => void;
};

type TestFixtures = {
lang: string;
Expand All @@ -38,7 +30,7 @@ type TestFixtures = {
featureFlags: OptionalFeatureMap;
simulateCamera: string;
app: Application;
cliCommands: Command<(typeof commandCLI)[keyof typeof commandCLI]>[];
cliCommands?: ((appjsonPath: string) => Observable<unknown> | Promise<unknown> | string)[];
};

const IS_NOT_MOCK = process.env.MOCK == "0";
Expand Down Expand Up @@ -121,31 +113,16 @@ export const test = base.extend<TestFixtures>({
setEnv("SPECULOS_API_PORT", device?.ports.apiPort?.toString());
setEnv("MOCK", "");

if (cliCommands) {
if (cliCommands?.length) {
registerSpeculosTransport(device?.ports.apiPort);
for (const command of cliCommands) {
if (command.args && "appjson" in command.args) {
command.args.appjson = `${userdataDestinationPath}/app.json`;
}

const resultPromise = handleResult(command.command(command.args as any));

if (command.args && "getKeyRingTree" in command.args) {
await activateLedgerSync();
}

const result = await resultPromise;
command?.output?.(result);
for (const cmd of cliCommands) {
const promise = await cmd(`${userdataDestinationPath}/app.json`);
const result =
promise instanceof Observable ? await lastValueFrom(promise) : await promise;
console.log("CLI result: ", result);
}
}
}
async function handleResult(result: Promise<any> | Observable<any> | string): Promise<any> {
if (result instanceof Observable) {
return lastValueFrom(result); // Converts Observable to Promise
}
return result; // Return Promise directly
}

// default environment variables
env = Object.assign(
Expand Down
29 changes: 13 additions & 16 deletions apps/ledger-live-desktop/tests/specs/speculos/delegate.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 { Delegate } from "../../models/Delegate";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
import { commandCLI } from "tests/utils/cliUtils";
import { CLI } from "tests/utils/cliUtils";
import { isRunningInScheduledWorkflow } from "tests/utils/githubUtils";
import { Currency } from "@ledgerhq/live-common/e2e/enum/Currency";

Expand Down Expand Up @@ -60,14 +60,13 @@ test.describe("Delegate flows", () => {
userdata: "skip-onboarding",
speculosApp: account.delegate.account.currency.speculosApp,
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: account.delegate.account.currency.ticker,
index: account.delegate.account.index,
add: true,
appjson: "",
},
appjson: appjsonPath,
});
},
],
});
Expand Down Expand Up @@ -120,14 +119,13 @@ test.describe("Delegate flows", () => {
userdata: "skip-onboarding",
speculosApp: validator.delegate.account.currency.speculosApp,
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: validator.delegate.account.currency.ticker,
index: validator.delegate.account.index,
add: true,
appjson: "",
},
appjson: appjsonPath,
});
},
],
});
Expand Down Expand Up @@ -176,14 +174,13 @@ test.describe("Delegate flows", () => {
userdata: "skip-onboarding",
speculosApp: delegateAccount.account.currency.speculosApp,
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: delegateAccount.account.currency.ticker,
index: delegateAccount.account.index,
add: true,
appjson: "",
},
appjson: appjsonPath,
});
},
],
});
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 { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
import { commandCLI } from "tests/utils/cliUtils";
import { CLI } from "tests/utils/cliUtils";

const accounts = [
{ account: Account.BTC_NATIVE_SEGWIT_1, xrayTicket: "B2CQA-2548" },
Expand All @@ -24,14 +24,13 @@ for (const account of accounts) {
test.use({
userdata: "skip-onboarding",
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: account.account.currency.currencyId,
index: account.account.index,
appjson: "",
add: true,
},
appjson: appjsonPath,
});
},
],
speculosApp: account.account.currency.speculosApp,
Expand Down
74 changes: 42 additions & 32 deletions apps/ledger-live-desktop/tests/specs/speculos/ledgerSync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,65 @@ import { test } from "../../fixtures/common";
import { AppInfos } from "@ledgerhq/live-common/e2e/enum/AppInfos";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
import { commandCLI } from "tests/utils/cliUtils";
import { CLI } from "tests/utils/cliUtils";
import { activateLedgerSync } from "@ledgerhq/live-common/e2e/speculos";

const app: AppInfos = AppInfos.LS;

test.describe(`[${app.name}] Sync Accounts`, () => {
const ledgerKeyRingProtocolArgs = {
getKeyRingTree: true,
pubKey: undefined,
privateKey: undefined,
pubKey: "",
privateKey: "",
};
const ledgerSyncPushDataArgs = {
pubKey: undefined,
privateKey: undefined,
rootId: undefined,
walletSyncEncryptionKey: undefined,
applicationPath: undefined,
rootId: "",
walletSyncEncryptionKey: "",
applicationPath: "",
push: true,
data: '{"accounts":[{"id":"mock:1:dogecoin:0.790010769447963:","currencyId":"dogecoin","index":1,"seedIdentifier":"mock","derivationMode":"","freshAddress":"1uVnrWAzycYqKUXSuNXt3XSjJ8"},{"id":"mock:1:bitcoin_gold:0.8027791663782486:","currencyId":"bitcoin_gold","index":1,"seedIdentifier":"mock","derivationMode":"","freshAddress":"1Y5T8JQqBKUS7cXbxUYCR4wg3YSbV9R"}],"accountNames":{"mock:1:dogecoin:0.790010769447963:":"Renamed Dogecoin 2","mock:1:bitcoin_gold:0.8027791663782486:":"Bitcoin Gold 2"}}',
};

async function initializeLedgerKeyRingProtocol() {
return CLI.ledgerKeyRingProtocol({ initMemberCredentials: true }).then(output => {
if (output && typeof output !== "string" && "pubkey" in output) {
ledgerKeyRingProtocolArgs.pubKey = output.pubkey;
ledgerKeyRingProtocolArgs.privateKey = output.privatekey;
}
return output;
});
}

async function initializeLedgerSync() {
const output = CLI.ledgerKeyRingProtocol({
getKeyRingTree: true,
...ledgerKeyRingProtocolArgs,
}).then(out => {
if (out && typeof out !== "string" && "rootId" in out) {
ledgerSyncPushDataArgs.rootId = out.rootId;
ledgerSyncPushDataArgs.walletSyncEncryptionKey = out.walletSyncEncryptionKey;
ledgerSyncPushDataArgs.applicationPath = out.applicationPath;
}
return out;
});
await activateLedgerSync();
return output;
}

test.use({
userdata: "skip-onboarding",
speculosApp: app,
cliCommands: [
{
command: commandCLI.ledgerKeyRingProtocol,
args: {
initMemberCredentials: true,
},
output: output => {
ledgerKeyRingProtocolArgs.pubKey = output.pubkey;
ledgerKeyRingProtocolArgs.privateKey = output.privatekey;

ledgerSyncPushDataArgs.pubKey = output.pubkey;
ledgerSyncPushDataArgs.privateKey = output.privatekey;
},
async () => {
return initializeLedgerKeyRingProtocol();
},
{
command: commandCLI.ledgerKeyRingProtocol,
args: ledgerKeyRingProtocolArgs,
output: output => {
ledgerSyncPushDataArgs.rootId = output.rootId;
ledgerSyncPushDataArgs.walletSyncEncryptionKey = output.walletSyncEncryptionKey;
ledgerSyncPushDataArgs.applicationPath = output.applicationPath;
},
async () => {
return initializeLedgerSync();
},
{
command: commandCLI.ledgerSync,
args: ledgerSyncPushDataArgs,
async () => {
return CLI.ledgerSync({
...ledgerKeyRingProtocolArgs,
...ledgerSyncPushDataArgs,
});
},
],
});
Expand Down
38 changes: 17 additions & 21 deletions apps/ledger-live-desktop/tests/specs/speculos/nft.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Nft } from "@ledgerhq/live-common/e2e/enum/Nft";
import { Fee } from "@ledgerhq/live-common/e2e/enum/Fee";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
import { commandCLI } from "tests/utils/cliUtils";
import { CLI } from "tests/utils/cliUtils";
import invariant from "invariant";

test.describe("send NFT to ENS address", () => {
Expand All @@ -19,14 +19,13 @@ test.describe("send NFT to ENS address", () => {
test.use({
userdata: "skip-onboarding",
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: transaction.accountToDebit.currency.currencyId,
index: transaction.accountToDebit.index,
appjson: "",
add: true,
},
appjson: appjsonPath,
});
},
],
speculosApp: transaction.accountToDebit.currency.speculosApp,
Expand Down Expand Up @@ -67,14 +66,13 @@ test.describe("The user can see his NFT floor price", () => {
test.use({
userdata: "skip-onboarding",
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: account.currency.currencyId,
index: account.index,
appjson: "",
add: true,
},
appjson: appjsonPath,
});
},
],
speculosApp: account.currency.speculosApp,
Expand Down Expand Up @@ -116,14 +114,13 @@ for (const account of accounts) {
test.use({
userdata: "skip-onboarding",
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: account.account.currency.currencyId,
index: account.account.index,
appjson: "",
add: true,
},
appjson: appjsonPath,
});
},
],
speculosApp: account.account.currency.speculosApp,
Expand Down Expand Up @@ -152,14 +149,13 @@ for (const account of accounts) {
test.use({
userdata: "skip-onboarding",
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: account.account.currency.currencyId,
index: account.account.index,
appjson: "",
add: true,
},
appjson: appjsonPath,
});
},
],
speculosApp: account.account.currency.speculosApp,
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 { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "../../utils/customJsonReporter";
import { commandCLI } from "tests/utils/cliUtils";
import { CLI } from "tests/utils/cliUtils";

const accounts = [
{ account: Account.BTC_NATIVE_SEGWIT_1, xrayTicket: "B2CQA-2559, B2CQA-2687" },
Expand All @@ -24,14 +24,13 @@ for (const account of accounts) {
userdata: "skip-onboarding",
speculosApp: account.account.currency.speculosApp,
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: account.account.currency.currencyId,
index: account.account.index,
appjson: "",
add: true,
},
appjson: appjsonPath,
});
},
],
});
Expand Down Expand Up @@ -82,14 +81,13 @@ test.describe("Receive", () => {
userdata: "skip-onboarding",
speculosApp: account.currency.speculosApp,
cliCommands: [
{
command: commandCLI.liveData,
args: {
(appjsonPath: string) => {
return CLI.liveData({
currency: account.currency.currencyId,
index: account.index,
add: true,
appjson: "",
},
appjson: appjsonPath,
});
},
],
});
Expand Down
Loading
Loading