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 6a56116
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 38 deletions.
1 change: 1 addition & 0 deletions apps/ledger-live-desktop/tests/enum/Swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class Provider {
) {}
static readonly CHANGELLY = new Provider("changelly", "Changelly");
static readonly ONEINCH = new Provider("oneinch", "1inch");
static readonly PARASWAP = new Provider("paraswap", "Paraswap");
}

export enum Rates {
Expand Down
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 {}
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
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const config: PlaywrightTestConfig = {
outputDir: "./artifacts/test-results",
snapshotPathTemplate:
"{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-platform}{ext}",
timeout: process.env.CI ? 190000 : 600000,
timeout: process.env.CI ? 400000 : 1200000,
expect: {
timeout: 41000,
toHaveScreenshot: {
Expand Down
70 changes: 44 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.PARASWAP),
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,35 @@ 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(", "));
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 6a56116

Please sign in to comment.