Skip to content

Commit

Permalink
test:stablize swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
cortisiko committed Oct 1, 2024
1 parent 433776f commit 188e55a
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 39 deletions.
10 changes: 10 additions & 0 deletions e2e/pages/TokenOverview.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export default class TokenOverview {
static async scrollOnScreen() {
await TestHelpers.swipe(TOKEN_PRICE, 'up', 'fast', 0.6);
}
static async scrollToTokenAcitivity() {
// await TestHelpers.scrollTo(TOKEN_PRICE, 'up', 'fast', 0.6);
// await TestHelpers.scrollTo(TOKEN_PRICE, 'up', 'fast', 0.6);
// await TestHelpers.swipe('Chainlink Token activity', 'up', 'fast', 0.6);

await waitFor(element(by.text('ChainLink Token activity')))

Check failure on line 38 in e2e/pages/TokenOverview.js

View workflow job for this annotation

GitHub Actions / scripts (lint)

'waitFor' is not defined
.toBeVisible()
.whileElement(by.id('scroll-2'))
.scroll(50, 'down');
}

static async tapBackButton() {
await TestHelpers.waitAndTap(ImportTokenViewSelectorsIDs.BACK_BUTTON);
Expand Down
28 changes: 22 additions & 6 deletions e2e/pages/swaps/SwapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import {

import Matchers from '../../utils/Matchers';
import Gestures from '../../utils/Gestures';
import TestHelpers from '../../helpers.js';

class SwapView {
get quoteSummary() {
return Matchers.getElementByID(SwapsViewSelectors.QUOTE_SUMMARY);
}

get gasFee() {
return Matchers.getElementByID(SwapsViewSelectors.GAS_FEE);
}

get fetchingQuotes() {
return Matchers.getElementByText(SwapViewSelectorsTexts.FETCHING_QUOTES);
}
Expand All @@ -34,12 +33,27 @@ class SwapView {
return title;
}

async scrollToBottomOfView(tokenName) {
const token = Matchers.getElementByText(tokenName);
await Gestures.swipe(token, 'up', 'fast', 0.8);
}
// Function to check if the button is enabled
async isButtonEnabled(element) {
const attributes = await element.getAttributes();
return attributes.enabled === true; // Check if enabled is true
}

async swipeToSwap() {
const percentage = device.getPlatform() === 'ios' ? 0.72 : 0.95;
const swapsSliderElement = await this.swipeToSwapButton;
const delay = 500; // Delay in milliseconds

// Wait until the button is enabled before performing swipe actions
while (!(await this.isButtonEnabled(swapsSliderElement))) {
await TestHelpers.delay(delay); // Wait for the specified delay
}

// Swipe could happen at the same time when gas fees are falshing
// and that's when the swipe button becomes disabled
// that's the need to retry
// Once enabled, perform the swipe actions
await Gestures.swipe(this.swipeToSwapButton, 'right', 'fast', percentage);
await Gestures.swipe(this.swipeToSwapButton, 'right', 'fast', percentage);
}
Expand All @@ -50,9 +64,11 @@ class SwapView {
);
}

async tapIUnderstandPriceWarning() {
async tapIUnderstandPriceWarning(tokenName) {
try {
await Gestures.waitAndTap(this.iUnderstandLabel, 5000);
await TestHelpers.delay(1000); // Wait for the specified delay
await this.scrollToBottomOfView(tokenName);
} catch (e) {
// eslint-disable-next-line no-console
console.log(`Price warning not displayed: ${e}`);
Expand Down
3 changes: 2 additions & 1 deletion e2e/resources/blacklistURLs.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
".*phishing-detection.cx.metamask.io/.*",
".*eth.llamarpc.com/.*",
".*token-api.metaswap.codefi.network/.*",
".*gas.api.cx.metamask.io/networks/*"
".*gas.api.cx.metamask.io/networks/*",
".*rpc.vnet.tenderly.co/.*"
]
}
2 changes: 1 addition & 1 deletion e2e/resources/networks.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const CustomNetworks = {
providerConfig: {
type: 'rpc',
chainId: '0x1',
rpcUrl: `https://rpc.tenderly.co/fork/bbfe5a2e-2426-4512-a5f8-46ce85fe9ad6`,
rpcUrl: `https://virtual.mainnet.rpc.tenderly.co/d9221841-84aa-4e7f-a481-43eb0ae1f997`,
nickname: 'Tenderly',
ticker: 'ETH',
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/specs/quarantine/swap-token-chart.failing.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe(Regression('Swap from Token view'), () => {
await Assertions.checkIfVisible(SwapView.fetchingQuotes);
await Assertions.checkIfVisible(SwapView.quoteSummary);
await Assertions.checkIfVisible(SwapView.gasFee);
await SwapView.tapIUnderstandPriceWarning();
await SwapView.tapIUnderstandPriceWarning(sourceTokenSymbol);
await SwapView.swipeToSwap();
try {
await Assertions.checkIfVisible(
Expand Down
2 changes: 1 addition & 1 deletion e2e/specs/swaps/swap-action-regression.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe(Regression('Multiple Swaps from Actions'), () => {
await Assertions.checkIfVisible(SwapView.fetchingQuotes);
await Assertions.checkIfVisible(SwapView.quoteSummary);
await Assertions.checkIfVisible(SwapView.gasFee);
await SwapView.tapIUnderstandPriceWarning();
await SwapView.tapIUnderstandPriceWarning(sourceTokenSymbol);
await SwapView.swipeToSwap();
try {
await Assertions.checkIfVisible(
Expand Down
6 changes: 3 additions & 3 deletions e2e/specs/swaps/swap-action-smoke.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ describe(SmokeSwaps('Swap from Actions'), () => {

it.each`
quantity | sourceTokenSymbol | destTokenSymbol
${'.05'} | ${'ETH'} | ${'USDT'}
${'100'} | ${'USDT'} | ${'ETH'}
${'2'} | ${'ETH'} | ${'USDT'}
${'1'} | ${'USDT'} | ${'ETH'}
`(
"should Swap $quantity '$sourceTokenSymbol' to '$destTokenSymbol'",
async ({ quantity, sourceTokenSymbol, destTokenSymbol }) => {
Expand Down Expand Up @@ -91,7 +91,7 @@ describe(SmokeSwaps('Swap from Actions'), () => {
await Assertions.checkIfVisible(SwapView.fetchingQuotes);
await Assertions.checkIfVisible(SwapView.quoteSummary);
await Assertions.checkIfVisible(SwapView.gasFee);
await SwapView.tapIUnderstandPriceWarning();
await SwapView.tapIUnderstandPriceWarning(sourceTokenSymbol);
await SwapView.swipeToSwap();
try {
await Assertions.checkIfVisible(
Expand Down
56 changes: 30 additions & 26 deletions e2e/specs/wallet/send-ERC-token.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,50 @@
import { SmokeCore } from '../../tags';
import TestHelpers from '../../helpers';
import WalletView from '../../pages/wallet/WalletView';
import NetworkEducationModal from '../../pages/modals/NetworkEducationModal';
import AmountView from '../../pages/Send/AmountView';
import SendView from '../../pages/Send/SendView';
import { importWalletWithRecoveryPhrase } from '../../viewHelper';
import TransactionConfirmationView from '../../pages/Send/TransactionConfirmView';
import NetworkListModal from '../../pages/modals/NetworkListModal';
import { loginToApp } from '../../viewHelper';
import TokenOverview from '../../pages/TokenOverview';
import ConfirmAddAssetView from '../../pages/wallet/ImportTokenFlow/ConfirmAddAsset';
import ImportTokensView from '../../pages/wallet/ImportTokenFlow/ImportTokensView';
import Assertions from '../../utils/Assertions';
import { CustomNetworks } from '../../resources/networks.e2e';
import FixtureBuilder from '../../fixtures/fixture-builder';
import {
loadFixture,
startFixtureServer,
stopFixtureServer,
} from '../../fixtures/fixture-helper';
import FixtureServer from '../../fixtures/fixture-server';
import { getFixturesServerPort } from '../../fixtures/utils';

const TOKEN_ADDRESS = '0x779877A7B0D9E8603169DdbD7836e478b4624789';
const TOKEN_ADDRESS = '0x514910771AF9Ca656af840dff83E8264EcF986CA';
const SEND_ADDRESS = '0xebe6CcB6B55e1d094d9c58980Bc10Fed69932cAb';

const fixtureServer = new FixtureServer();

describe(SmokeCore('Send ERC Token'), () => {
beforeAll(async () => {
jest.setTimeout(150000);
await device.launchApp();
await TestHelpers.reverseServerPort();
const fixture = new FixtureBuilder()
.withNetworkController(CustomNetworks.Tenderly)
.build();
await startFixtureServer(fixtureServer);
await loadFixture(fixtureServer, { fixture });
await device.launchApp({
permissions: { notifications: 'YES' },
launchArgs: { fixtureServerPort: `${getFixturesServerPort()}` },
});
await loginToApp();
});

it('should import wallet and go to the wallet view', async () => {
await importWalletWithRecoveryPhrase();
afterAll(async () => {
await stopFixtureServer(fixtureServer);
});

it('should add Sepolia testnet to my networks list', async () => {
await WalletView.tapNetworksButtonOnNavBar();
await TestHelpers.delay(2000);
await NetworkListModal.tapTestNetworkSwitch();
await Assertions.checkIfToggleIsOn(NetworkListModal.testNetToggle);
await NetworkListModal.changeNetworkTo(
CustomNetworks.Sepolia.providerConfig.nickname,
);
});

it('should dismiss network education modal', async () => {
await Assertions.checkIfVisible(NetworkEducationModal.container);
await NetworkEducationModal.tapGotItButton();
await Assertions.checkIfNotVisible(NetworkEducationModal.container);
beforeEach(async () => {
jest.setTimeout(150000);
});

it('should Import custom token', async () => {
Expand All @@ -59,17 +64,16 @@ describe(SmokeCore('Send ERC Token'), () => {
it('should send token to address via asset overview screen', async () => {
await WalletView.tapOnToken('ChainLink Token');
await TestHelpers.delay(3500);
await TokenOverview.scrollOnScreen();
await TokenOverview.scrollToTokenAcitivity();
await TestHelpers.delay(3500);
await TokenOverview.tapSendButton();
await SendView.inputAddress(SEND_ADDRESS);
await TestHelpers.delay(1000);
await SendView.tapNextButton();
await AmountView.typeInTransactionAmount('0.000001');
await AmountView.typeInTransactionAmount('0.001');
await TestHelpers.delay(5000);
await AmountView.tapNextButton();
await Assertions.checkIfTextIsDisplayed('< 0.00001 LINK');
await Assertions.checkIfTextIsDisplayed('< 0.001 LINK');
await TransactionConfirmationView.tapConfirmButton();
// await Assertions.checkIfTextIsDisplayed('Transaction submitted'); removing this assertion for now
});
});

0 comments on commit 188e55a

Please sign in to comment.