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

[Playwright] speculos // swap e2e tests with common currencies (BTC, USDT, ETH) #8017

Merged
merged 3 commits into from
Oct 11, 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
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Please make sure to read CONTRIBUTING.md if you have not already. Pull Requests
<!-- Pull Requests must pass the CI and be code reviewed. Set as Draft if the PR is not ready. -->

- [ ] `npx changeset` was attached.
- [ ] **Covered by automatic tests.** <!-- if not, please explain. (Feature must be tested / Bugfix must bring non-regression) -->
- [ ] **Covered by automatic tests.** <!-- if not, please explain. (Feature must be tested / Bug fix must bring non-regression) -->
- [ ] **Impact of the changes:** <!-- Please take some time to list the impact & what specific areas Quality Assurance (QA) should focus on -->
- ...

### πŸ“ Description

_Replace this text by a clear and concise description of what this pull request is about and why it is needed. Be sure to explain the problem you're addressing and the solution you're proposing._
_For libraries, you can add a code sample of how to use it._
_For bugfixes, you can explain the previous behavior and how it was fixed._
_For bug fixes, you can explain the previous behaviour and how it was fixed._
bharamboure-ledger marked this conversation as resolved.
Show resolved Hide resolved
_In case of visual features, please attach screenshots or video recordings to demonstrate the changes._

<!--
Expand Down
5 changes: 5 additions & 0 deletions apps/ledger-live-desktop/tests/enum/Account.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Currency } from "./Currency";
import { AccountType } from "tests/enum/AccountType";

export class Account {
constructor(
public readonly currency: Currency,
public readonly accountName: string,
public readonly address: string,
public readonly accountType?: AccountType,
) {}

static readonly BTC_NATIVE_SEGWIT_1 = new Account(
Expand Down Expand Up @@ -257,12 +259,14 @@ export class Account {
Currency.ETH_USDT,
"Ethereum 1",
"0xB9051f83AC6e147924377BBEebd1Aa7aB43a67F6",
AccountType.ERC20,
);

static readonly ETH_USDT_2 = new Account(
Currency.ETH_USDT,
"Ethereum 2",
"0x43047a5023D55a8658Fcb1c1Cea468311AdAA3Ad",
AccountType.ERC20,
);

static readonly ETH_LIDO = new Account(
Expand Down Expand Up @@ -299,6 +303,7 @@ export class Account {
Currency.TRX_USDT,
"Tron 1",
"TDUKFB9wj3P5f2iNvkRuaDDeWVkTdUVhs1",
AccountType.TRC20,
);

static readonly TRX_BTT = new Account(
Expand Down
4 changes: 4 additions & 0 deletions apps/ledger-live-desktop/tests/enum/AccountType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum AccountType {
ERC20 = "erc20",
TRC20 = "trc20",
}
9 changes: 7 additions & 2 deletions apps/ledger-live-desktop/tests/enum/Swap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export enum Providers {
CHANGELLY = "changelly",
export class Provider {
constructor(
public readonly name: string,
public readonly uiName: string,
) {}
static readonly CHANGELLY = new Provider("changelly", "Changelly");
static readonly ONEINCH = new Provider("oneinch", "1inch");
}

export enum Rates {
Expand Down
5 changes: 5 additions & 0 deletions apps/ledger-live-desktop/tests/models/Swap.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { Transaction } from "tests/models/Transaction";
import { Fee } from "tests/enum/Fee";
import { Account } from "../enum/Account";
import { Provider } from "../enum/Swap";

export class Swap extends Transaction {
provider: Provider;

constructor(
accountToDebit: Account,
accountToCredit: Account,
amount: string,
speed: Fee,
provider: Provider,
public amountToReceive?: string,
public feesAmount?: string,
) {
super(accountToDebit, accountToCredit, amount, speed);
this.provider = provider;
}

public setAmountToReceive(value: string) {
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 {}
44 changes: 34 additions & 10 deletions apps/ledger-live-desktop/tests/page/speculos.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,8 @@ export class SpeculosPage extends AppPage {
verifyAmount(`${swap.accountToDebit.currency.ticker} ${swap.amount}`, sendAmountScreen),
).toBeTruthy();
const getAmountScreen = await pressRightUntil(sendPattern[1]);
expect(
verifyAmount(
`${swap.accountToCredit.currency.ticker} ${extractNumberFromString(swap.amountToReceive)}`,
getAmountScreen,
),
).toBeTruthy();
const feesAmountScreen = await pressRightUntil(sendPattern[2]);
expect(
verifySwapFeesAmount(extractNumberFromString(swap.feesAmount), feesAmountScreen),
).toBeTruthy();
this.verifySwapGetAmountScreen(swap, getAmountScreen);
this.verifySwapFeesAmountScreen(swap, await pressRightUntil(sendPattern[2]));
await pressRightUntil(DeviceLabels.REJECT);
await pressBoth();
}
Expand Down Expand Up @@ -145,4 +137,36 @@ export class SpeculosPage extends AppPage {
throw new Error(`Unsupported currency: ${currencyName}`);
}
}

verifySwapGetAmountScreen(swap: Swap, getAmountScreen: string[]) {
if (swap.accountToCredit.currency.name === "Solana") {
expect(
verifyAmount(
`${extractNumberFromString(swap.amountToReceive)} ${swap.accountToCredit.currency.ticker}`,
getAmountScreen,
),
).toBeTruthy();
} else {
expect(
verifyAmount(
`${swap.accountToCredit.currency.ticker} ${extractNumberFromString(swap.amountToReceive)}`,
getAmountScreen,
),
).toBeTruthy();
}
}

verifySwapFeesAmountScreen(swap: Swap, feesAmountScreen: string[]) {
let speculosFeesAmount = "";
if (swap.feesAmount) {
//max number of chars on the screen
speculosFeesAmount =
extractNumberFromString(swap.feesAmount).length < 18
? extractNumberFromString(swap.feesAmount)
: extractNumberFromString(swap.feesAmount).substring(0, 17);
}
expect(
verifySwapFeesAmount(swap.accountToDebit.currency.name, speculosFeesAmount, feesAmountScreen),
).toBeTruthy();
}
}
28 changes: 19 additions & 9 deletions apps/ledger-live-desktop/tests/page/swap.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { waitFor } from "../utils/waitFor";
import { step } from "tests/misc/reporters/step";
import { ElectronApplication, expect } from "@playwright/test";
import { capitalizeFirstLetter } from "tests/utils/textParserUtils";
import { Account } from "tests/enum/Account";

export class SwapPage extends AppPage {
private currencyByName = (accountName: string) => this.page.getByText(accountName); // TODO: this is rubbish. Changed this
Expand Down Expand Up @@ -115,10 +116,7 @@ export class SwapPage extends AppPage {
}

@step("Select exchange quote $0 with rate $1")
async selectExchangeQuote(
providerName: "changelly" | "cic" | "oneinch" | "paraswap",
bharamboure-ledger marked this conversation as resolved.
Show resolved Hide resolved
exchangeType: "fixed" | "float",
) {
async selectExchangeQuote(providerName: string, exchangeType: "fixed" | "float") {
await this.quoteContainer(providerName, exchangeType).click();
}

Expand Down Expand Up @@ -150,13 +148,25 @@ export class SwapPage extends AppPage {
return this.detailsSwapId.innerText();
}

@step("Select account to swap from: $0")
async selectAccountToSwapFrom(accountToSwapFrom: string) {
getAccountName(account: Account) {
//erc20 accounts names are stored in account currency property
return account.accountType ? account.currency.name : account.accountName;
}

@step("Select account to swap from")
async selectAccountToSwapFrom(accountToSwapFrom: Account) {
await this.originCurrencyDropdown.click();
await this.dropdownOptions.locator(this.optionWithText(accountToSwapFrom)).click();
const accName = this.getAccountName(accountToSwapFrom);
if (accountToSwapFrom.accountType) {
await this.dropdownOptions
.locator(this.optionWithTextAndFollowingText(accountToSwapFrom.accountName, accName))
.first()
.click();
} else {
await this.dropdownOptions.locator(this.optionWithText(accName)).first().click();
}
const selectedAccountFrom = this.originCurrencyDropdown.locator(this.dropdownSelectedValue);
await expect(selectedAccountFrom).toHaveText(accountToSwapFrom);
await this.waitForPageLoadState();
await expect(selectedAccountFrom).toHaveText(accName);
}

@step("Fill in amount: $0")
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
Loading
Loading