Skip to content

Commit

Permalink
feat(e2e): Adds new buy Ethereum test (#16785)
Browse files Browse the repository at this point in the history
minor refactoring, default watch response is approved now
  • Loading branch information
Vere-Grey authored Feb 3, 2025
1 parent 97621a3 commit 683cc27
Show file tree
Hide file tree
Showing 11 changed files with 624 additions and 13 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"trade": {
"receiveAddress": "0x3f2329C9ADFbcCd9A84f52c906E936A42dA18CB8",
"paymentId": "a77943b27141cfc423ad5dd6df7f2865",
"status": "SUBMITTED",
"originalPaymentId": "c3025b52-8836-49f2-a7c9-07a2560d6034",
"partnerData": "https://trezor.banxa.com?expires=1738581904&id=f32568ce-fd75-44ed-a417-9e7e7d2f2a8c&oid=a77943b27141cfc423ad5dd6df7f2865&signature=14165f0d8e2d24af98efea79efddb9df4e808ac8baec1d5f0487d674e7b6f161",
"exchange": "banxa",
"fiatCurrency": "CZK",
"receiveCurrency": "ethereum",
"rate": 66290.62583937685,
"wantCrypto": false,
"exp": "OnGBiPZ211B633dTxSLnUA==",
"country": "CZ",
"paymentMethodName": "Credit Card",
"fiatStringAmount": "1234.00",
"receiveStringAmount": "0.01861500",
"minFiat": 600,
"maxFiat": 50000,
"minCrypto": 0.00946059,
"maxCrypto": 0.7883824,
"paymentMethod": "creditCard",
"quoteId": "6bb961d0-b927-46b0-97e9-338b6d6c95c6",
"orderId": "dd0d10bc-136a-41f0-8fff-9a760cd341fd",
"partnerData2": "6098"
},
"tradeForm": {
"form": {
"formMethod": "GET",
"formAction": "https://trezor.banxa.com?expires=1738581904&id=f32568ce-fd75-44ed-a417-9e7e7d2f2a8c&oid=a77943b27141cfc423ad5dd6df7f2865&signature=14165f0d8e2d24af98efea79efddb9df4e808ac8baec1d5f0487d674e7b6f161",
"fields": {}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"status": "SUBMITTED"
"status": "SUCCESS"
}
8 changes: 6 additions & 2 deletions packages/suite-desktop-core/e2e/fixtures/invity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { cloneDeep } from 'lodash';
import { NetworkSymbol } from '@suite-common/wallet-config';

import buyList from './buy/list.json';
import buyQuotesBTC from './buy/quotes-bitcoin.json';
import buyQuotesEthereum from './buy/quotes-ethereum.json';
import buyQuotesSolana from './buy/quotes-solana.json';
import buyQuotesBTC from './buy/quotes.json';
import buyTradeBTC from './buy/trade-bitcoin.json';
import buyTradeEthereum from './buy/trade-ethereum.json';
import buyTradeSolana from './buy/trade-solana.json';
import buyTradeBTC from './buy/trade.json';
import buyWatch from './buy/watch.json';
import exchangeCoins from './exchange/coins.json';
import exchangeList from './exchange/list.json';
Expand Down Expand Up @@ -69,8 +71,10 @@ export {
info,
buyList,
buyQuotesBTC,
buyQuotesEthereum,
buyQuotesSolana,
buyTradeBTC,
buyTradeEthereum,
buyTradeSolana,
buyWatch,
sellList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class MarketActions {
readonly buyTermsConfirmButton: Locator;
readonly confirmOnTrezorButton: Locator;
readonly confirmationSection: Locator;
readonly confirmationAccountDropdown: Locator;
readonly confirmationCryptoAmount: Locator;
readonly confirmationFiatAmount: Locator;
readonly confirmationProvider: Locator;
Expand Down Expand Up @@ -153,6 +154,9 @@ export class MarketActions {
'@trading/offer/confirm-on-trezor-button',
);
this.confirmationSection = this.page.getByTestId('@trading/selected-offer');
this.confirmationAccountDropdown = this.page.getByTestId(
'@trading/verify-options/account/input',
);
this.confirmationCryptoAmount = this.page.getByTestId('@trading/form/info/crypto-amount');
this.confirmationFiatAmount = this.page.getByTestId('@trading/form/info/fiat-amount');
this.confirmationProvider = this.page.getByTestId('@trading/form/info/provider');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ test.describe('Trading - Buy BTC', { tag: ['@group=other', '@webOnly'] }, () =>

const watchRequestPromise = page.waitForRequest(invityEndpoint.buyWatch);
await page.clock.install();

await test.step('Confirm the trade and get redirected to transaction detail', async () => {
await marketPage.changeTransactionWatchResponseTo('SUBMITTED');
await marketPage.finishMockedTrade();
await expect(watchRequestPromise).toHavePayload(expectedWatchRequestPayload, {
omit: ['partnerData'],
Expand Down
93 changes: 90 additions & 3 deletions packages/suite-desktop-core/e2e/tests/trading/buy-ethereum.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,92 @@
import { test } from '../../support/fixtures';
import { localizeNumber } from '@suite-common/wallet-utils';
import { capitalizeFirstLetter } from '@trezor/utils';

test.describe('Trading - Buy Solana', { tag: ['@group=other', '@webOnly'] }, () => {
test.skip('Buy Ethereum that is not discovered on wallet yet', () => {});
import { buyQuotesEthereum, buyTradeEthereum, invityEndpoint } from '../../fixtures/invity';
import { formatAddress } from '../../support/common';
import { expect, test } from '../../support/fixtures';

// Expected values based on our mocked responses
const fiatAmount = buyQuotesEthereum[3].fiatStringAmount;
const provider = capitalizeFirstLetter(buyQuotesEthereum[3].exchange);
const formattedCryptoAmount = `${localizeNumber(buyQuotesEthereum[3].receiveStringAmount)} ETH`;
const formattedFiatAmount = `CZK ${localizeNumber(fiatAmount, 'en', 2)}`;
const { receiveAddress, paymentMethodName } = buyTradeEthereum.trade;

test.describe('Trading - Buy Ethereum', { tag: ['@group=other', '@webOnly'] }, () => {
test.beforeEach(async ({ page, marketPage, onboardingPage, dashboardPage }) => {
await marketPage.mockInvity();
await marketPage.mockInvityTrade(buyTradeEthereum, 'eth');
await page.route(invityEndpoint.buyQuotes, async route => {
await route.fulfill({ json: buyQuotesEthereum });
});
await onboardingPage.completeOnboarding();
await dashboardPage.discoveryShouldFinish();
});

test('Buy Ethereum that is not discovered on wallet yet', async ({
page,
dashboardPage,
settingsPage,
devicePrompt,
walletPage,
marketPage,
trezorUserEnvLink,
}) => {
await test.step('Request to buy Ethereum', async () => {
await walletPage.tradingBuyButton.click();
await marketPage.selectAccount('Ethereum', 'eth');
await marketPage.setYouPayFiatAmount(fiatAmount);
await expect(marketPage.bestOfferAmount).toHaveText(formattedCryptoAmount);
await expect(marketPage.quoteProvider).toHaveText(provider);
await marketPage.buyBestOfferButton.click();
});

await test.step('Create Ethereum account in trade confirmation dialog', async () => {
await marketPage.buyTermsConfirmButton.click();
await expect(marketPage.confirmationAccountDropdown).toHaveText(
'Select ETHEREUM receive account',
);
await expect(marketPage.confirmationAddress).toHaveText('');
await expect(page.getByText('Receive address is required')).toBeVisible();

await marketPage.confirmationAccountDropdown.click();
await page.getByRole('option', { name: 'Create a new Ethereum account' }).click();
await expect(settingsPage.coins.networkButton('eth')).toBeEnabledCoin();
await page.getByRole('button', { name: 'Find my Ethereum accounts' }).click();
await dashboardPage.discoveryShouldFinish();
await expect(marketPage.confirmationAccountDropdown).toHaveText(
'Ethereum #1Balance: 0 ETH',
);

await expect(marketPage.confirmationAddress).toHaveValue(receiveAddress);
});

await test.step('Confirm Trade', async () => {
await marketPage.confirmOnTrezorButton.click();
await expect(devicePrompt.outputValueOf('address')).toHaveText(
formatAddress(receiveAddress),
);
await devicePrompt.confirmOnDevicePromptIsShown();
await trezorUserEnvLink.pressYes();
await devicePrompt.confirmOnDevicePromptIsHidden();

await expect(marketPage.confirmationCryptoAmount).toHaveText(formattedCryptoAmount);
await expect(marketPage.confirmationFiatAmount).toHaveText(formattedFiatAmount);
await expect(marketPage.confirmationProvider).toHaveText(
capitalizeFirstLetter(provider),
);
await expect(marketPage.confirmationPaymentMethod).toHaveText(paymentMethodName);
//TODO: #16766 Uncomment once the issue with the trade confirmation dialog is fixed
// await marketPage.confirmTradeButton.click();
// });

// await test.step('Verify transaction detail', async () => {
// await expect(marketPage.transactionDetailStatus).toHaveText('Approved', {
// timeout: 15_000,
// });
// await expect(marketPage.confirmationFiatAmount).toHaveText(formattedFiatAmount);
// await expect(marketPage.confirmationCryptoAmount).toHaveText(formattedCryptoAmount);
// await expect(marketPage.confirmationProvider).toHaveText(provider);
});
});
});
11 changes: 4 additions & 7 deletions packages/suite-desktop-core/e2e/tests/trading/buy-solana.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@ const formattedFiatAmount = `CZK ${fiatAmount}`;
const { receiveAddress, paymentMethodName } = buyTradeSolana.trade;

test.describe('Trading - Buy Solana', { tag: ['@group=other', '@webOnly'] }, () => {
test.beforeEach(async ({ marketPage, onboardingPage, dashboardPage }) => {
test.beforeEach(async ({ page, marketPage, onboardingPage, dashboardPage }) => {
await marketPage.mockInvity();
await marketPage.mockInvityTrade(buyTradeSolana, 'sol');
await page.route(invityEndpoint.buyQuotes, async route => {
await route.fulfill({ json: buyQuotesSolana });
});
await onboardingPage.completeOnboarding();
await dashboardPage.discoveryShouldFinish();
});

test('Buy specific crypto amount of Solana token', async ({
page,
settingsPage,
dashboardPage,
walletPage,
marketPage,
}) => {
await page.route(invityEndpoint.buyQuotes, async route => {
await route.fulfill({ json: buyQuotesSolana });
});

await test.step('Enable Solana and open its trading', async () => {
await settingsPage.navigateTo('coins');
await settingsPage.coins.enableNetwork('sol');
Expand All @@ -57,7 +55,6 @@ test.describe('Trading - Buy Solana', { tag: ['@group=other', '@webOnly'] }, ()
capitalizeFirstLetter(provider),
);
await expect(marketPage.confirmationPaymentMethod).toHaveText(paymentMethodName);
await marketPage.changeTransactionWatchResponseTo('SUCCESS');
await marketPage.confirmTradeButton.click();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const TradingVerify = ({ tradingVerifyAccount, cryptoId }: TradingVerifyP
)}
{selectedAccountOption?.account?.networkType !== 'bitcoin' && (
<Input
data-testid="@trading/form/verify/address"
readOnly={selectedAccountOption?.type !== 'NON_SUITE'}
inputState={form.formState.errors.address ? 'error' : undefined}
labelLeft={
Expand Down

0 comments on commit 683cc27

Please sign in to comment.