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

test(extension): fetch token prices tests #1077

Merged
merged 10 commits into from
Apr 22, 2024
28 changes: 28 additions & 0 deletions packages/e2e-tests/src/assert/tokensPageAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type ExpectedTokenDetails = {
};

class TokensPageAssert {
ADA_PRICE_CHECK_INTERVAL = 65_000;

assertSeeTitle = async () => {
await TokensPage.title.waitForDisplayed({ timeout: 10_000 });
};
Expand Down Expand Up @@ -252,6 +254,32 @@ class TokensPageAssert {

expect(tickerDisplayed).to.equal(expectedTicker);
}

async seePriceFetchExpiredErrorMessage(shouldBeVisible: boolean) {
await TokensPage.priceFetchErrorDescription.waitForDisplayed({
reverse: !shouldBeVisible,
timeout: this.ADA_PRICE_CHECK_INTERVAL * 3
});
if (shouldBeVisible) {
const expiredErrorMessageToMatch = (await t('general.warnings.priceDataExpired')).split(':')[0];
oldGreg5 marked this conversation as resolved.
Show resolved Hide resolved
expect(await TokensPage.priceFetchErrorDescription.getText())
.to.include(expiredErrorMessageToMatch)
.to.include(new Date().getFullYear())
.to.include(new Date().getDate())
.to.include(new Date().getMinutes());
}
}

async seePriceFetchFailedErrorMessage(shouldBeVisible: boolean) {
await TokensPage.priceFetchErrorDescription.waitForDisplayed({
reverse: !shouldBeVisible,
timeout: this.ADA_PRICE_CHECK_INTERVAL * 3
});
if (shouldBeVisible)
expect(await TokensPage.priceFetchErrorDescription.getText()).to.equal(
await t('general.warnings.cannotFetchPrice')
);
}
}

export default new TokensPageAssert();
10 changes: 10 additions & 0 deletions packages/e2e-tests/src/elements/tokensPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import SectionTitle from './sectionTitle';
import { ChainablePromiseElement } from 'webdriverio';
import { ChainablePromiseArray } from 'webdriverio/build/types';
import TokensPageAssert from '../assert/tokensPageAssert';

class TokensPage {
private BALANCE_LABEL = '[data-testid="portfolio-balance-label"]';
Expand All @@ -21,6 +22,7 @@ class TokensPage {
private OPENED_EYE_ICON = '[data-testid="opened-eye-icon"]';
private VIEW_ALL_BUTTON = '[data-testid="view-all-button"]';
private TOKEN_ROW_SKELETON = '.ant-skeleton';
private PRICE_FETCH_ERROR_DESCRIPTION = '[data-testid="banner-description"]';

get sendButtonPopupMode(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.SEND_BUTTON_POPUP_MODE);
Expand Down Expand Up @@ -103,6 +105,10 @@ class TokensPage {
return $(this.TOKEN_ROW_SKELETON);
}

get priceFetchErrorDescription(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.PRICE_FETCH_ERROR_DESCRIPTION);
}

async getRows(): Promise<WebdriverIO.ElementArray> {
return $$(this.TOKENS_TABLE_ROW);
}
Expand Down Expand Up @@ -143,6 +149,10 @@ class TokensPage {
async getTokensCounterAsNumber(): Promise<number> {
return SectionTitle.getCounterAsNumber();
}

async waitForPricesToBeFetched() {
await this.totalBalanceValue.waitForDisplayed({ timeout: TokensPageAssert.ADA_PRICE_CHECK_INTERVAL });
}
}

export default new TokensPage();
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Feature: Send - Extended Browser View (Advanced Tx)

@LW-3578
Scenario: Extended-view - Transaction error screen displayed for multiple bundles on transaction submit error
Given I enable network interception to fail request: "*/tx-submit/submit" with error 400
Given I enable network interception to finish request: "*/tx-submit/submit" with error 400
And I click "Send" button on page header
And I set 2 bundles with the same assets
And I click "Review transaction" button on "Send" page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Feature: LW-484: Send & Receive - Extended Browser View (Simple Tx)

@LW-2374 @Testnet
Scenario: Extended-view - Transaction error screen displayed on transaction submit error
Given I enable network interception to fail request: "*/tx-submit/submit" with error 400
Given I enable network interception to finish request: "*/tx-submit/submit" with error 400
And I click "Send" button on page header
And I’ve entered accepted values for all fields of simple Tx
And I click "Review transaction" button on "Send" page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Feature: LW-484: Send & Receive - Popup View (Simple Tx)

@LW-2408 @Testnet
Scenario: Popup-view - Transaction error screen displayed on transaction submit error
Given I enable network interception to fail request: "*/tx-submit/submit" with error 400
Given I enable network interception to finish request: "*/tx-submit/submit" with error 400
And I click "Send" button on Tokens page in popup mode
And I’ve entered accepted values for all fields of simple Tx
And I click "Review transaction" button on "Send" page
Expand Down
48 changes: 45 additions & 3 deletions packages/e2e-tests/src/features/TokensPageExtended.feature
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Feature: LW: Tokens tab - extended view
And I see total wallet balance in USD
And balance and FIAT balance for each token are visible

@Testnet @Mainnet @LW-7121 @LW-7123
@LW-7121 @LW-7123 @Testnet @Mainnet
Scenario Outline: Extended View - Hide my balance - keep state after <action> the page
When I click closed eye icon on Tokens page
Then opened eye icon is displayed on Tokens page
Expand All @@ -124,8 +124,7 @@ Feature: LW: Tokens tab - extended view
# LW-7706
# | reopening | I reopen the page |


@Testnet @Mainnet @LW-7125
@LW-7125 @Testnet @Mainnet
Scenario: Extended view - Hide my balance - keep state after switching to popup view
When I click closed eye icon on Tokens page
Then opened eye icon is displayed on Tokens page
Expand All @@ -135,3 +134,46 @@ Feature: LW: Tokens tab - extended view
Then opened eye icon is displayed on Tokens page
And total wallet balance is masked with asterisks
And balance and FIAT balance for each token are masked with asterisks

@LW-6889 @Testnet @Mainnet
Scenario: Extended view - Token pricing - Price fetch expired error is displayed when coingecko request fails
Given ADA fiat price has been fetched
When I enable network interception to fail request: "https://coingecko.*"
And I shift back last fiat price fetch time in local storage by 500 seconds
Then "Price data expired" error is displayed
When I disable network interception
Then ADA fiat price has been fetched
And "Price data expired" error is not displayed

@LW-10283 @Testnet @Mainnet @Pending
@issue=LW-10296
Scenario: Extended view - Token pricing - Price fetch expired error is displayed when coingecko request returns 500
Given ADA fiat price has been fetched
When I enable network interception to finish request: "https://coingecko.*" with error 500
And I shift back last fiat price fetch time in local storage by 500 seconds
Then "Price data expired" error is displayed
When I disable network interception
Then ADA fiat price has been fetched
And "Price data expired" error is not displayed

@LW-6890 @Testnet @Mainnet @Pending
@issue=LW-10296
Scenario: Extended view - Token pricing - Fiat price unable to fetch error is displayed on failed request
Given ADA fiat price has been fetched
When I enable network interception to fail request: "https://coingecko.*"
And I delete fiat price timestamp from background storage
Then "Unable to fetch fiat values" error is displayed
When I disable network interception
Then ADA fiat price has been fetched
Then "Unable to fetch fiat values" error is not displayed

@LW-6681 @Testnet @Mainnet @Pending
@issue=LW-10296
Scenario: Extended view - Token pricing - Fiat price unable to fetch error is displayed when coingecko request returns 500
Given ADA fiat price has been fetched
When I enable network interception to finish request: "https://coingecko.*" with error 500
And I delete fiat price timestamp from background storage
Then "Unable to fetch fiat values" error is displayed
And I disable network interception
Then ADA fiat price has been fetched
Then "Unable to fetch fiat values" error is not displayed
47 changes: 45 additions & 2 deletions packages/e2e-tests/src/features/TokensPagePopup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Feature: LW: Tokens tab - popup view
And I see total wallet balance in USD
And balance and FIAT balance for each token are visible

@Testnet @Mainnet @LW-7122 @LW-7124
@LW-7122 @LW-7124 @Testnet @Mainnet
Scenario Outline: Popup View - Hide my balance - keep state after <action> the page
When I click closed eye icon on Tokens page
Then opened eye icon is displayed on Tokens page
Expand All @@ -94,7 +94,7 @@ Feature: LW: Tokens tab - popup view
# LW-7706
# | reopening | I reopen the page |

@Testnet @Mainnet @LW-7126
@LW-7126 @Testnet @Mainnet
Scenario: Popup View - Hide my balance - keep state after switching to extended view
When I click closed eye icon on Tokens page
Then opened eye icon is displayed on Tokens page
Expand All @@ -104,3 +104,46 @@ Feature: LW: Tokens tab - popup view
Then opened eye icon is displayed on Tokens page
And total wallet balance is masked with asterisks
And balance and FIAT balance for each token are masked with asterisks

@LW-6684 @Testnet @Mainnet
Scenario: Popup view - Token pricing - Price fetch expired error is displayed when coingecko request fails
Given ADA fiat price has been fetched
When I enable network interception to fail request: "https://coingecko.*"
And I shift back last fiat price fetch time in local storage by 500 seconds
Then "Price data expired" error is displayed
When I disable network interception
Then ADA fiat price has been fetched
And "Price data expired" error is not displayed

@LW-10307 @Testnet @Mainnet @Pending
@issue=LW-10296
Scenario: Popup view - Token pricing - Price fetch expired error is displayed when coingecko request returns 500
Given ADA fiat price has been fetched
When I enable network interception to finish request: "https://coingecko.*" with error 500
And I shift back last fiat price fetch time in local storage by 500 seconds
Then "Price data expired" error is displayed
When I disable network interception
Then ADA fiat price has been fetched
And "Price data expired" error is not displayed

@LW-6682 @Testnet @Mainnet @Pending
@issue=LW-10296
Scenario: Popup view - Token pricing - Fiat price unable to fetch error is displayed on failed request
Given ADA fiat price has been fetched
When I enable network interception to fail request: "https://coingecko.*"
And I delete fiat price timestamp from background storage
Then "Unable to fetch fiat values" error is displayed
When I disable network interception
Then ADA fiat price has been fetched
Then "Unable to fetch fiat values" error is not displayed

@LW-6683 @Testnet @Mainnet @Pending
@issue=LW-10296
Scenario: Popup view - Token pricing - Fiat price unable to fetch error is displayed when coingecko request returns 500
Given ADA fiat price has been fetched
When I enable network interception to finish request: "https://coingecko.*" with error 500
And I delete fiat price timestamp from background storage
Then "Unable to fetch fiat values" error is displayed
And I disable network interception
Then ADA fiat price has been fetched
Then "Unable to fetch fiat values" error is not displayed
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Feature: Staking Page - Switching pools - Extended Browser View - E2E

@LW-4558 @Testnet
Scenario: Extended View - Staking - Staking error screen displayed on transaction submit error
Given I enable network interception to fail request: "*/tx-submit/submit" with error 400
Given I enable network interception to finish request: "*/tx-submit/submit" with error 400
When I navigate to Staking extended page
Then I see currently staking stake pool in extended mode and choose new pool as "OtherStakePool"
When I input "OtherStakePool" to the search bar
Expand Down
36 changes: 28 additions & 8 deletions packages/e2e-tests/src/steps/commonSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import localStorageManager from '../utils/localStorageManager';
import networkManager from '../utils/networkManager';
import { Logger } from '../support/logger';
import clipboard from 'clipboardy';
import { cleanBrowserStorage } from '../utils/browserStorage';
import {
shiftBackFiatPriceFetchedTimeInBrowserStorage,
cleanBrowserStorage,
deleteFiatPriceTimestampFromBackgroundStorage
} from '../utils/browserStorage';
import BackgroundStorageAssert from '../assert/backgroundStorageAssert';
import topNavigationAssert from '../assert/topNavigationAssert';
import testContext from '../utils/testContext';
Expand Down Expand Up @@ -201,13 +205,6 @@ When(/^I am in the offline network mode: (true|false)$/, async (offline: 'true'
await networkManager.changeNetworkCapabilitiesOfBrowser(offline === 'true');
});

When(
/^I enable network interception to fail request: "([^"]*)" with error (\d*)$/,
async (urlPattern: string, errorCode: number) => {
await networkManager.failResponse(urlPattern, errorCode);
}
);

When(/^I click outside the drawer$/, async () => {
await new CommonDrawerElements().areaOutsideDrawer.click();
});
Expand Down Expand Up @@ -364,3 +361,26 @@ When(/^I scroll (down|up) (\d*) pixels$/, async (direction: 'down' | 'up', pixel
Given(/^I confirm multi-address discovery modal$/, async () => {
await settingsExtendedPageObject.multiAddressModalConfirm();
});

When(/^I enable network interception to fail request: "([^"]*)"$/, async (urlPattern: string) => {
await networkManager.failRequest(urlPattern);
});

When(
/^I enable network interception to finish request: "([^"]*)" with error (\d*)$/,
async (urlPattern: string, errorCode: number) => {
await networkManager.finishWithResponseCode(urlPattern, errorCode);
}
);

Given(/^I shift back last fiat price fetch time in local storage by (\d+) seconds$/, async (seconds: number) => {
await shiftBackFiatPriceFetchedTimeInBrowserStorage(seconds);
});

Then(/^I disable network interception$/, async () => {
await networkManager.closeOpenedCdpSessions();
});

Given(/^I delete fiat price timestamp from background storage$/, async () => {
await deleteFiatPriceTimestampFromBackgroundStorage();
});
16 changes: 15 additions & 1 deletion packages/e2e-tests/src/steps/tokensPageSteps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { When, Then } from '@cucumber/cucumber';
import { Then, When } from '@cucumber/cucumber';
import tokensPageAssert from '../assert/tokensPageAssert';
import tokensPageObject from '../pageobject/tokensPageObject';
import tokenDetailsAssert from '../assert/tokenDetailsAssert';
Expand All @@ -9,6 +9,7 @@ import { switchToLastWindow } from '../utils/window';
import extensionUtils from '../utils/utils';
import TokensPage from '../elements/tokensPage';
import type { NetworkType } from '../types/network';
import { Given } from '@wdio/cucumber-framework';

When(/^I see Tokens counter with total number of tokens displayed$/, async () => {
await tokensPageAssert.assertSeeTitleWithCounter();
Expand Down Expand Up @@ -217,3 +218,16 @@ Then(/^I see total wallet balance in ADA is "([^"]*)"$/, async (balanceInAda: nu
Then(/^I see tMin token with the ADA balance of "([^"]*)"$/, async (balanceInAda: number) => {
await tokensPageAssert.assertTMinBalance(balanceInAda);
});

Then(
oldGreg5 marked this conversation as resolved.
Show resolved Hide resolved
/^"(Price data expired|Unable to fetch fiat values)" error (is|is not) displayed$/,
async (errorType: 'Price data expired' | 'Unable to fetch fiat values', shouldBeDisplayed: 'is' | 'is not') => {
errorType === 'Price data expired'
? await tokensPageAssert.seePriceFetchExpiredErrorMessage(shouldBeDisplayed === 'is')
: await tokensPageAssert.seePriceFetchFailedErrorMessage(shouldBeDisplayed === 'is');
}
);

Given(/^ADA fiat price has been fetched$/, async () => {
await TokensPage.waitForPricesToBeFetched();
});
26 changes: 26 additions & 0 deletions packages/e2e-tests/src/utils/browserStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,29 @@ export const clearBackgroundStorageKey: any = async (): Promise<void> => {
Logger.warn(`Clearing background storage key failed: ${error}`);
}
};

export const shiftBackFiatPriceFetchedTimeInBrowserStorage = async (seconds: number): Promise<void> => {
const backgroundStorage = await getBackgroundStorage();
backgroundStorage.fiatPrices.timestamp -= seconds * 1000;
try {
await browser.execute(
`await chrome.storage.local.set({ BACKGROUND_STORAGE: ${JSON.stringify(backgroundStorage)}})`,
[]
);
} catch (error) {
throw new Error(`Setting browser storage failed: ${error}`);
}
};

export const deleteFiatPriceTimestampFromBackgroundStorage = async (): Promise<void> => {
const backgroundStorage = await getBackgroundStorage();
delete backgroundStorage.fiatPrices.timestamp;
try {
await browser.execute(
`await chrome.storage.local.set({ BACKGROUND_STORAGE: ${JSON.stringify(backgroundStorage)}})`,
[]
);
} catch (error) {
throw new Error(`Setting browser storage failed: ${error}`);
}
};
Loading