Skip to content

Commit eab3b8d

Browse files
committed
test(e2e): llm addfunction to get address from speculos
1 parent 240e0af commit eab3b8d

File tree

11 files changed

+76
-56
lines changed

11 files changed

+76
-56
lines changed

e2e/mobile/models/send.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ export async function verifyAppValidationSendInfo(transaction: TransactionType,
3131
}
3232

3333
if (currenciesForValidationRecipient.includes(currency)) {
34+
if (!addressRecipient) {
35+
throw new Error("Recipient address is not set");
36+
}
3437
await app.deviceValidation.expectAddress(addressRecipient);
3538
}
3639

3740
if (currenciesForValidationSender.includes(currency)) {
41+
if (!addressSender) {
42+
throw new Error("Sender address is not set");
43+
}
3844
await app.deviceValidation.expectAddress(addressSender);
3945
}
4046

e2e/mobile/models/stake.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ export async function verifyStakeOperationDetailsInfo(
8080
await app.operationDetails.checkRecipientAsProvider(provider);
8181
}
8282
if (currenciesForSender.includes(currency)) {
83-
await app.operationDetails.checkSender(delegation.account.address);
83+
const address = delegation.account.address;
84+
if (address) {
85+
await app.operationDetails.checkSender(address);
86+
} else {
87+
throw new Error("Account address is undefined");
88+
}
8489
}
8590
if (fees) {
8691
await app.operationDetails.checkFees(fees);

e2e/mobile/page/trade/operationDetails.page.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getAccountAddress, Account } from "@ledgerhq/live-common/lib/e2e/enum/Account";
1+
import { Account } from "@ledgerhq/live-common/lib/e2e/enum/Account";
22

33
export default class OperationDetailsPage {
44
titleId = "operationDetails-title";
@@ -37,13 +37,12 @@ export default class OperationDetailsPage {
3737
await scrollToId(this.recipientId, this.operationDetailsScrollViewId);
3838
const recipientElement = getElementById(this.recipientId);
3939

40-
let expected: string;
41-
if (await IsIdVisible(this.operationDetailsConfirmed)) {
42-
expected = getAccountAddress(recipient);
40+
const expected = recipient.address;
41+
if (expected) {
42+
await detoxExpect(recipientElement).toHaveText(expected);
4343
} else {
44-
expected = recipient.address;
44+
throw new Error("Recipient address is undefined");
4545
}
46-
await detoxExpect(recipientElement).toHaveText(expected);
4746
}
4847

4948
@Step("Check recipient as provider")

e2e/mobile/page/trade/receive.page.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ export default class ReceivePage {
108108
}
109109

110110
@Step("Verify address")
111-
async verifyAddress(address: string | undefined): Promise<void> {
112-
if (!address) {
113-
throw new Error("Address is not set");
114-
}
111+
async verifyAddress(address: string): Promise<void> {
115112
await detoxExpect(getElementById(this.accountAddress)).toHaveText(address);
116113
}
117114

e2e/mobile/specs/deposit/deposit.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ const liveDataWithAddressCommand = (account: Account) => async (userdataPath?: s
1717
add: true,
1818
appjson: userdataPath,
1919
});
20-
21-
const { address } = await CLI.getAddress({
22-
currency: account.currency.speculosApp.name,
23-
path: account.accountPath,
24-
derivationMode: account.derivationMode,
25-
});
26-
27-
account.address = address;
28-
29-
return address;
3020
};
3121

3222
setEnv("DISABLE_TRANSACTION_BROADCAST", true);
@@ -66,11 +56,13 @@ export async function runCreateNewAccountAndDepositTest(
6656
await app.receive.continueCreateAccount();
6757
await app.receive.selectDontVerifyAddress();
6858
await app.receive.selectReconfirmDontVerify();
59+
const address = await CLI.getAddressForAccount(newAccount);
60+
6961
await app.receive.expectReceivePageIsDisplayed(
7062
newAccount.currency.ticker,
7163
newAccount.accountName,
7264
);
73-
await app.receive.verifyAddress(newAccount.address);
65+
await app.receive.verifyAddress(address);
7466
});
7567
});
7668
}
@@ -162,7 +154,8 @@ export async function runDepositInExistingAccountTest(
162154
await app.receive.selectDontVerifyAddress();
163155
await app.receive.selectReconfirmDontVerify();
164156
await app.receive.expectReceivePageIsDisplayed(account.currency.ticker, account.accountName);
165-
await app.receive.verifyAddress(account.address);
157+
const address = await CLI.getAddressForAccount(account);
158+
await app.receive.verifyAddress(address);
166159
});
167160
});
168161
}

e2e/mobile/specs/earn/earn.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ export async function runStartETHStakingFromEarnDashboardTest(
8787
await beforeAllFunction({
8888
userdata: "skip-onboarding",
8989
speculosApp: account.currency.speculosApp,
90-
cliCommands: [liveDataCommand(account.currency.speculosApp, account.index)],
90+
cliCommands: [
91+
liveDataCommand(account.currency.speculosApp, account.index),
92+
async () => {
93+
account.address = await CLI.getAddressForAccount(account);
94+
},
95+
],
9196
});
9297
});
9398

e2e/mobile/specs/send/send.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@ const beforeAllFunction = async (transaction: TransactionType) => {
2626
add: true,
2727
appjson: userdataPath,
2828
});
29-
30-
const { address } = await CLI.getAddress({
31-
currency: transaction.accountToCredit.currency.speculosApp.name,
32-
path: transaction.accountToCredit.accountPath,
33-
derivationMode: transaction.accountToCredit.derivationMode,
34-
});
35-
36-
transaction.accountToCredit.address = address;
37-
transaction.recipientAddress = address;
38-
39-
return address;
29+
transaction.accountToDebit.address = await CLI.getAddressForAccount(
30+
transaction.accountToDebit,
31+
);
32+
33+
transaction.accountToCredit.address = await CLI.getAddressForAccount(
34+
transaction.accountToCredit,
35+
);
36+
transaction.recipientAddress = transaction.accountToCredit.address;
4037
},
4138
],
4239
});
@@ -66,14 +63,9 @@ const beforeAllInvalidAddressFunction = async (
6663
transaction.accountToCredit.accountName !== Account.EMPTY.accountName &&
6764
transaction.accountToCredit.accountName !== Account.BTC_NATIVE_SEGWIT_1.accountName
6865
) {
69-
const { address } = await CLI.getAddress({
70-
currency: transaction.accountToCredit.currency.id,
71-
path: transaction.accountToCredit.accountPath,
72-
derivationMode: transaction.accountToCredit.derivationMode,
73-
});
74-
75-
transaction.accountToCredit.address = address;
76-
return address;
66+
transaction.accountToCredit.address = await CLI.getAddressForAccount(
67+
transaction.accountToCredit,
68+
);
7769
}
7870

7971
if (overrideRecipient !== undefined) {

e2e/mobile/specs/subAccount/subAccount.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,16 @@ const beforeAllFunction = async (transaction: TransactionType, setAccountToCredi
4747
add: true,
4848
});
4949

50-
const parentAccount = transaction.accountToCredit.parentAccount;
51-
invariant(parentAccount, "Parent account is required");
50+
const parentAccountToCredit = transaction.accountToCredit.parentAccount;
51+
invariant(parentAccountToCredit, "Parent account to credit is required");
52+
const parentAccountToDebit = transaction.accountToDebit.parentAccount;
53+
invariant(parentAccountToDebit, "Parent account to debit is required");
5254

53-
const { address } = await CLI.getAddress({
54-
currency: parentAccount.currency.id,
55-
path: parentAccount.accountPath,
56-
derivationMode: parentAccount.derivationMode,
57-
});
58-
59-
transaction.accountToCredit.address = address;
55+
transaction.accountToCredit.address = await CLI.getAddressForAccount(
56+
transaction.accountToCredit,
57+
);
6058

61-
return address;
59+
parentAccountToDebit.address = await CLI.getAddressForAccount(parentAccountToDebit);
6260
},
6361
]
6462
: []),

e2e/mobile/utils/cliUtils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
SpeculosHttpTransportOpts,
1616
} from "@ledgerhq/live-dmk-speculos";
1717
import { isRemoteIos } from "../helpers/commonHelpers";
18+
import { Account } from "@ledgerhq/live-common/e2e/enum/Account";
1819

1920
export type LiveDataOpts = {
2021
currency: string;
@@ -263,4 +264,13 @@ export const CLI = {
263264
return JSON.parse(lastLine);
264265
});
265266
},
267+
getAddressForAccount: async (account: Account) => {
268+
const addressInfo = await CLI.getAddress({
269+
currency: account.currency.speculosApp.name,
270+
path: account.accountPath,
271+
derivationMode: account.derivationMode,
272+
});
273+
account.address = addressInfo.address;
274+
return addressInfo.address;
275+
},
266276
};

libs/ledger-live-common/src/e2e/enum/Account.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import { Addresses } from "./Addresses";
12
import { Currency } from "./Currency";
23
import { TokenType } from "./TokenType";
34

45
export class Account {
5-
public address?: string;
6-
76
constructor(
87
public readonly currency: Currency,
98
public readonly accountName: string,
@@ -13,6 +12,7 @@ export class Account {
1312
public readonly ensName?: string,
1413
public readonly derivationMode?: string,
1514
public readonly parentAccount?: Account,
15+
public address?: string,
1616
) {}
1717

1818
static readonly ADA_1 = new Account(Currency.ADA, "Cardano 1", 0, "1852'/1815'/0'/0/3");
@@ -234,8 +234,19 @@ export class TokenAccount extends Account {
234234
parentAccount: Account,
235235
ensName?: string,
236236
derivationMode?: string,
237+
address?: string,
237238
) {
238-
super(currency, accountName, index, path, tokenType, ensName, derivationMode, parentAccount);
239+
super(
240+
currency,
241+
accountName,
242+
index,
243+
path,
244+
tokenType,
245+
ensName,
246+
derivationMode,
247+
parentAccount,
248+
address,
249+
);
239250
}
240251

241252
static readonly ETH_LIDO = new TokenAccount(
@@ -281,6 +292,9 @@ export class TokenAccount extends Account {
281292
Account.SOL_1.accountPath,
282293
TokenType.SPL,
283294
Account.SOL_1,
295+
undefined,
296+
undefined,
297+
Addresses.SOL_GIGA_1_ATA_ADDRESS,
284298
);
285299
static readonly SOL_GIGA_2 = new TokenAccount(
286300
Currency.SOL_GIGA,

0 commit comments

Comments
 (0)