Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
bharamboure-ledger committed Oct 8, 2024
1 parent 230184a commit ecacee7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 40 deletions.
4 changes: 4 additions & 0 deletions apps/ledger-live-desktop/tests/page/abstractClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export abstract class Component extends PageHolder {
async waitForPageLoadState() {
return await this.page.waitForLoadState("load");
}

async waitForPageNetworkidleState() {
return await this.page.waitForLoadState("networkidle");
}
}

export abstract class AppPage extends Component {}
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/tests/page/speculos.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ export class SpeculosPage extends AppPage {
if (swap.feesAmount) {
//max number of chars on the screen
speculosFeesAmount =
extractNumberFromString(swap.feesAmount).length < 19
extractNumberFromString(swap.feesAmount).length < 18
? extractNumberFromString(swap.feesAmount)
: extractNumberFromString(swap.feesAmount).substring(0, 18);
: extractNumberFromString(swap.feesAmount).substring(0, 17);
}
expect(
verifySwapFeesAmount(swap.accountToDebit.currency.name, speculosFeesAmount, feesAmountScreen),
Expand Down
10 changes: 0 additions & 10 deletions apps/ledger-live-desktop/tests/page/swap.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,8 @@ export class SwapPage extends AppPage {
return account.accountType ? account.currency.name : account.accountName;
}

async waitForAccountsBalance(accountAddress: string, timeout = 10000) {
const regex = new RegExp(`/blockchain/v\\d+/.+/${accountAddress}$`);
const fetchTxByAddressResponse = this.page.waitForResponse(response => {
return regex.test(response.url()) && response.status() === 200;
});
const timeoutPromise = new Promise(resolve => setTimeout(resolve, timeout, null));
return Promise.race([fetchTxByAddressResponse, timeoutPromise]);
}

@step("Select account to swap from")
async selectAccountToSwapFrom(accountToSwapFrom: Account) {
await this.waitForAccountsBalance(accountToSwapFrom.address);
await this.originCurrencyDropdown.click();
const accName = this.getAccountName(accountToSwapFrom);
if (accountToSwapFrom.accountType) {
Expand Down
3 changes: 2 additions & 1 deletion apps/ledger-live-desktop/tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ const config: PlaywrightTestConfig = {
name: "speculos_tests",
testDir: "specs/speculos/",
retries: process.env.CI ? 2 : 0,
timeout: process.env.CI ? 400000 : 1200000,
},
{
name: "mocked_tests",
testDir: "specs/",
testIgnore: ["**/speculos/**", "specs/recorder.spec.ts"],
timeout: process.env.CI ? 190000 : 600000,
},
],
outputDir: "./artifacts/test-results",
snapshotPathTemplate:
"{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-platform}{ext}",
timeout: process.env.CI ? 190000 : 600000,
expect: {
timeout: 41000,
toHaveScreenshot: {
Expand Down
71 changes: 45 additions & 26 deletions apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { setExchangeDependencies } from "@ledgerhq/live-common/e2e/speculos";
import { Fee } from "tests/enum/Fee";
import { Swap } from "tests/models/Swap";
import { Provider, Rates } from "tests/enum/Swap";
import { addTmsLink } from "tests/utils/allureUtils";
import { getDescription } from "tests/utils/customJsonReporter";

const swaps = [
{
Expand All @@ -15,6 +17,7 @@ const swaps = [
Fee.MEDIUM,
Provider.CHANGELLY,
),
xrayTicket: "B2CQA-2750",
},
{
swap: new Swap(
Expand All @@ -24,15 +27,19 @@ const swaps = [
Fee.MEDIUM,
Provider.CHANGELLY,
),
xrayTicket: "B2CQA-2744",
},
{
swap: new Swap(Account.ETH_USDT_1, Account.ETH_1, "35", Fee.MEDIUM, Provider.CHANGELLY),
swap: new Swap(Account.ETH_USDT_1, Account.ETH_1, "40", Fee.MEDIUM, Provider.CHANGELLY),
xrayTicket: "B2CQA-2752",
},
{
swap: new Swap(Account.ETH_1, Account.SOL_1, "0.018", Fee.MEDIUM, Provider.CHANGELLY),
xrayTicket: "B2CQA-2748",
},
{
swap: new Swap(Account.ETH_1, Account.ETH_USDT_1, "0.02", Fee.MEDIUM, Provider.CHANGELLY),
xrayTicket: "B2CQA-2749",
},
{
swap: new Swap(
Expand All @@ -42,6 +49,7 @@ const swaps = [
Fee.MEDIUM,
Provider.CHANGELLY,
),
xrayTicket: "B2CQA-2747",
},
{
swap: new Swap(
Expand All @@ -51,24 +59,27 @@ const swaps = [
Fee.MEDIUM,
Provider.CHANGELLY,
),
xrayTicket: "B2CQA-2746",
},
{
swap: new Swap(
Account.ETH_USDT_1,
Account.BTC_NATIVE_SEGWIT_1,
"35",
"40",
Fee.MEDIUM,
Provider.CHANGELLY,
),
xrayTicket: "B2CQA-2753",
},
{
swap: new Swap(Account.ETH_USDT_1, Account.SOL_1, "40", Fee.MEDIUM, Provider.CHANGELLY),
xrayTicket: "B2CQA-2751",
},
];

const app: AppInfos = AppInfos.EXCHANGE;

for (const { swap } of swaps) {
for (const { swap, xrayTicket } of swaps) {
test.describe("Swap", () => {
test.beforeAll(async () => {
process.env.SWAP_DISABLE_APPS_INSTALL = "true";
Expand Down Expand Up @@ -97,28 +108,36 @@ for (const { swap } of swaps) {
speculosApp: app,
});

test(`Swap ${swap.accountToDebit.currency.name} to ${swap.accountToCredit.currency.name}`, async ({
app,
electronApp,
}) => {
const rate = Rates.FLOAT;
await app.layout.goToSwap();
await app.swap.selectAccountToSwapFrom(swap.accountToDebit);
await app.swap.selectCurrencyToSwapTo(swap.accountToCredit.currency.name);
await app.swap.fillInOriginAmount(swap.amount);
await app.swap.selectExchangeQuote(swap.provider.name, rate);
await app.swap.clickExchangeButton(electronApp, swap.provider.uiName);
const amountTo = await app.swapDrawer.getAmountToReceive();
const fees = await app.swapDrawer.getFees();
swap.setAmountToReceive(amountTo);
swap.setFeesAmount(fees);
await app.swapDrawer.verifyAmountToReceive(amountTo);
await app.swapDrawer.verifyAmountSent(swap.amount, swap.accountToDebit.currency.ticker);
await app.swapDrawer.verifySourceAccount(swap.accountToDebit.currency.name);
await app.swapDrawer.verifyTargetCurrency(swap.accountToCredit.currency.name);
await app.swapDrawer.verifyProvider(swap.provider.name);
await app.speculos.verifyAmountsAndRejectSwap(swap);
await app.swapDrawer.verifyExchangeErrorTextContent("Operation denied on device");
});
test(
`Swap ${swap.accountToDebit.currency.name} to ${swap.accountToCredit.currency.name}`,
{
annotation: {
type: "TMS",
description: xrayTicket,
},
},
async ({ app, electronApp }) => {
await addTmsLink(getDescription(test.info().annotations).split(", "));
const rate = Rates.FLOAT;
await app.layout.goToSwap();
await app.swap.waitForPageNetworkidleState();
await app.swap.selectAccountToSwapFrom(swap.accountToDebit);
await app.swap.selectCurrencyToSwapTo(swap.accountToCredit.currency.name);
await app.swap.fillInOriginAmount(swap.amount);
await app.swap.selectExchangeQuote(swap.provider.name, rate);
await app.swap.clickExchangeButton(electronApp, swap.provider.uiName);
const amountTo = await app.swapDrawer.getAmountToReceive();
const fees = await app.swapDrawer.getFees();
swap.setAmountToReceive(amountTo);
swap.setFeesAmount(fees);
await app.swapDrawer.verifyAmountToReceive(amountTo);
await app.swapDrawer.verifyAmountSent(swap.amount, swap.accountToDebit.currency.ticker);
await app.swapDrawer.verifySourceAccount(swap.accountToDebit.currency.name);
await app.swapDrawer.verifyTargetCurrency(swap.accountToCredit.currency.name);
await app.swapDrawer.verifyProvider(swap.provider.name);
await app.speculos.verifyAmountsAndRejectSwap(swap);
await app.swapDrawer.verifyExchangeErrorTextContent("Operation denied on device");
},
);
});
}
1 change: 0 additions & 1 deletion libs/speculos-transport/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ export async function createSpeculosDevice(
"40000",
]),
];
console.log("speculos", `${speculosID}: spawning = ${params.join(" ")}`);

log("speculos", `${speculosID}: spawning = ${params.join(" ")}`);

Expand Down

0 comments on commit ecacee7

Please sign in to comment.