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

B2CQA-2136 : Switching From and To currencies and perform a swap test #8715

Closed
wants to merge 1 commit into from
Closed
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
B2CQA-2136 : Switching From and To currencies and perform a swap test
  • Loading branch information
stual-ledger committed Dec 17, 2024
commit 9992fc03a4afbf0c83dbba03ac52532291046bfd
87 changes: 87 additions & 0 deletions apps/ledger-live-desktop/tests/specs/speculos/swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,71 @@ for (const { swap, xrayTicket } of rejectedSwaps) {
});
}

const switchFromToSwaps = [
{
swap: new Swap(
Account.ETH_1,
Account.BTC_NATIVE_SEGWIT_1,
"0.02",
Fee.MEDIUM,
Provider.CHANGELLY,
Rate.FLOAT,
),
xrayTicket: "B2CQA-2136",
},
];

for (const { swap, xrayTicket } of switchFromToSwaps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need "for" loop here since you have only one element in switchFromToSwaps

test.describe("Swap - Switch From and To (without tx broadcast)", () => {
test.beforeAll(async () => {
process.env.SWAP_DISABLE_APPS_INSTALL = "true";
process.env.SWAP_API_BASE = "https://swap-stg.ledger-test.com/v5";
process.env.DISABLE_TRANSACTION_BROADCAST = "1";
});

const accPair: string[] = [swap.accountToDebit, swap.accountToCredit].map(acc =>
acc.currency.speculosApp.name.replace(/ /g, "_"),
);

test.beforeEach(async () => {
setExchangeDependencies(
accPair.map(appName => ({
name: appName,
})),
);
});

test.afterAll(async () => {
delete process.env.SWAP_DISABLE_APPS_INSTALL;
delete process.env.SWAP_API_BASE;
delete process.env.DISABLE_TRANSACTION_BROADCAST;
});

test.use({
userdata: "speculos-tests-app",
speculosApp: app,
});

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, "TMS").split(", "));
await switchFromToCurrencySwap(app, electronApp, swap);
await app.swap.selectQuote(electronApp, swap.provider.name, swap.rate);
await performSwapUntilDeviceVerificationStep(app, electronApp, swap);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand this test suppose to check that user is able to inverse "from" and "to" therefore I don't see the reason of doing full e2e swap scenario here

await app.speculos.verifyAmountsAndAcceptSwap(swap);
await app.swapDrawer.verifyExchangeCompletedTextContent(swap.accountToCredit.currency.name);
},
);
});
}

const tooLowAmountForQuoteSwaps = [
{
swap: new Swap(
Expand Down Expand Up @@ -436,6 +501,28 @@ async function performSwapUntilQuoteSelectionStep(
await app.swap.fillInOriginCurrencyAmount(electronApp, swap.amount);
}

async function switchFromToCurrencySwap(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function should be about switching currencies in a swap but it does ton of other stuff (looks like a duplicate of performSwapUntilQuoteSelectionStep but with reverseSwapPair() as additional step)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, this method is used only once, so I don't see a utility of having separate method for this code

app: Application,
electronApp: ElectronApplication,
swap: Swap,
) {
//todo: remove 2 following lines after LIVE-14410
await app.layout.goToAccounts();
await app.accounts.navigateToAccountByName(swap.accountToDebit.accountName);
await app.layout.waitForPageDomContentLoadedState();

await app.layout.waitForAccountsSyncToBeDone();
await app.swap.waitForPageNetworkIdleState();
await app.layout.goToSwap();
await app.swap.waitForPageNetworkIdleState();
await app.swap.selectAssetFrom(electronApp, swap.accountToDebit);
await app.swapDrawer.selectAccountByName(swap.accountToDebit);
await app.swap.selectAssetTo(electronApp, swap.accountToCredit.currency.name);
await app.swapDrawer.selectAccountByName(swap.accountToCredit);
await app.swap.reverseSwapPair();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function doesn't seem to verify that currencies have been inverted

await app.swap.fillInOriginCurrencyAmount(electronApp, swap.amount);
}

async function performSwapUntilDeviceVerificationStep(
app: Application,
electronApp: ElectronApplication,
Expand Down
Loading