diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index 7d675788f5b..acdbd92af2f 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -748,7 +748,7 @@ async function clickSignOnRedesignedSignatureConfirmation({ if (snapSigInsights) { // there is no condition we can wait for to know the snap is ready, // so we have to add a small delay as the last alternative to avoid flakiness. - await driver.delay(regularDelayMs); + await driver.delay(largeDelayMs); } await driver.clickElement({ text: 'Confirm', tag: 'button' }); diff --git a/test/e2e/tests/confirmations/transactions/erc20-approve-redesign.spec.ts b/test/e2e/tests/confirmations/transactions/erc20-approve-redesign.spec.ts index 4e340f5ef3a..b75d71cda4c 100644 --- a/test/e2e/tests/confirmations/transactions/erc20-approve-redesign.spec.ts +++ b/test/e2e/tests/confirmations/transactions/erc20-approve-redesign.spec.ts @@ -4,6 +4,7 @@ import { tinyDelayMs, veryLargeDelayMs, WINDOW_TITLES } from '../../../helpers'; import { Driver } from '../../../webdriver/driver'; import { scrollAndConfirmAndAssertConfirm } from '../helpers'; import { + mocked4BytesApprove, openDAppWithContract, TestSuiteArguments, toggleAdvancedDetails, @@ -87,30 +88,6 @@ describe('Confirmation Redesign ERC20 Approve Component', function () { }); }); -export async function mocked4BytesApprove(mockServer: MockttpServer) { - return await mockServer - .forGet('https://www.4byte.directory/api/v1/signatures/') - .always() - .withQuery({ hex_signature: '0x095ea7b3' }) - .thenCallback(() => ({ - statusCode: 200, - json: { - count: 1, - next: null, - previous: null, - results: [ - { - id: 149, - created_at: '2016-07-09T03:58:29.617584Z', - text_signature: 'approve(address,uint256)', - hex_signature: '0x095ea7b3', - bytes_signature: '\t^§³', - }, - ], - }, - })); -} - async function mocks(server: MockttpServer) { return [await mocked4BytesApprove(server)]; } diff --git a/test/e2e/tests/confirmations/transactions/increase-token-allowance-redesign.spec.ts b/test/e2e/tests/confirmations/transactions/increase-token-allowance-redesign.spec.ts index 30c87080c3f..82b995f217e 100644 --- a/test/e2e/tests/confirmations/transactions/increase-token-allowance-redesign.spec.ts +++ b/test/e2e/tests/confirmations/transactions/increase-token-allowance-redesign.spec.ts @@ -2,8 +2,6 @@ import FixtureBuilder from '../../../fixture-builder'; import { defaultGanacheOptions, defaultGanacheOptionsForType2Transactions, - largeDelayMs, - veryLargeDelayMs, WINDOW_TITLES, withFixtures, } from '../../../helpers'; @@ -12,7 +10,12 @@ import ContractAddressRegistry from '../../../seeder/contract-address-registry'; import { SMART_CONTRACTS } from '../../../seeder/smart-contracts'; import { Driver } from '../../../webdriver/driver'; import { scrollAndConfirmAndAssertConfirm } from '../helpers'; -import { openDAppWithContract, TestSuiteArguments } from './shared'; +import { + assertChangedSpendingCap, + editSpendingCap, + openDAppWithContract, + TestSuiteArguments, +} from './shared'; describe('Confirmation Redesign ERC20 Increase Allowance', function () { describe('Submit an increase allowance transaction @no-mmi', function () { @@ -158,42 +161,3 @@ async function createERC20IncreaseAllowanceTransaction(driver: Driver) { await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); await driver.clickElement('#increaseTokenAllowance'); } - -export async function editSpendingCap(driver: Driver, newSpendingCap: string) { - await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - await driver.clickElement('[data-testid="edit-spending-cap-icon"'); - - await driver.fill( - '[data-testid="custom-spending-cap-input"]', - newSpendingCap, - ); - - await driver.delay(largeDelayMs); - - await driver.clickElement({ text: 'Save', tag: 'button' }); - - // wait for the confirmation to be updated before submitting tx - await driver.delay(veryLargeDelayMs * 2); -} - -export async function assertChangedSpendingCap( - driver: Driver, - newSpendingCap: string, -) { - await driver.switchToWindowWithTitle(WINDOW_TITLES.ExtensionInFullScreenView); - - await driver.clickElement({ text: 'Activity', tag: 'button' }); - - await driver.delay(veryLargeDelayMs); - - await driver.clickElement( - '.transaction-list__completed-transactions .activity-list-item:nth-of-type(1)', - ); - - await driver.waitForSelector({ - text: `${newSpendingCap} TST`, - tag: 'span', - }); - - await driver.waitForSelector({ text: 'Confirmed', tag: 'div' }); -} diff --git a/test/e2e/tests/confirmations/transactions/revoke-allowance-redesign.spec.ts b/test/e2e/tests/confirmations/transactions/revoke-allowance-redesign.spec.ts index ba97d9cda4c..227fdb14ec8 100644 --- a/test/e2e/tests/confirmations/transactions/revoke-allowance-redesign.spec.ts +++ b/test/e2e/tests/confirmations/transactions/revoke-allowance-redesign.spec.ts @@ -3,12 +3,13 @@ import { MockttpServer } from 'mockttp'; import { WINDOW_TITLES } from '../../../helpers'; import { Driver } from '../../../webdriver/driver'; import { scrollAndConfirmAndAssertConfirm } from '../helpers'; -import { mocked4BytesApprove } from './erc20-approve-redesign.spec'; import { assertChangedSpendingCap, editSpendingCap, -} from './increase-token-allowance-redesign.spec'; -import { openDAppWithContract, TestSuiteArguments } from './shared'; + mocked4BytesApprove, + openDAppWithContract, + TestSuiteArguments, +} from './shared'; const { defaultGanacheOptions, diff --git a/test/e2e/tests/confirmations/transactions/shared.ts b/test/e2e/tests/confirmations/transactions/shared.ts index f984417fae9..d8f79a2053b 100644 --- a/test/e2e/tests/confirmations/transactions/shared.ts +++ b/test/e2e/tests/confirmations/transactions/shared.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ -import { MockedEndpoint } from 'mockttp'; -import { veryLargeDelayMs } from '../../../helpers'; +import { MockedEndpoint, MockttpServer } from 'mockttp'; +import { largeDelayMs, veryLargeDelayMs } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import ContractAddressRegistry from '../../../seeder/contract-address-registry'; import { Driver } from '../../../webdriver/driver'; @@ -238,3 +238,66 @@ export async function assertAdvancedGasDetailsWithL2Breakdown(driver: Driver) { await driver.waitForSelector({ css: 'p', text: 'Speed' }); await driver.waitForSelector({ css: 'p', text: 'Max fee' }); } + +export async function editSpendingCap(driver: Driver, newSpendingCap: string) { + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); + await driver.clickElement('[data-testid="edit-spending-cap-icon"'); + + await driver.fill( + '[data-testid="custom-spending-cap-input"]', + newSpendingCap, + ); + + await driver.delay(largeDelayMs); + + await driver.clickElement({ text: 'Save', tag: 'button' }); + + // wait for the confirmation to be updated before submitting tx + await driver.delay(veryLargeDelayMs * 2); +} + +export async function assertChangedSpendingCap( + driver: Driver, + newSpendingCap: string, +) { + await driver.switchToWindowWithTitle(WINDOW_TITLES.ExtensionInFullScreenView); + + await driver.clickElement({ text: 'Activity', tag: 'button' }); + + await driver.delay(veryLargeDelayMs); + + await driver.clickElement( + '.transaction-list__completed-transactions .activity-list-item:nth-of-type(1)', + ); + + await driver.waitForSelector({ + text: `${newSpendingCap} TST`, + tag: 'span', + }); + + await driver.waitForSelector({ text: 'Confirmed', tag: 'div' }); +} + +export async function mocked4BytesApprove(mockServer: MockttpServer) { + return await mockServer + .forGet('https://www.4byte.directory/api/v1/signatures/') + .always() + .withQuery({ hex_signature: '0x095ea7b3' }) + .thenCallback(() => ({ + statusCode: 200, + json: { + count: 1, + next: null, + previous: null, + results: [ + { + id: 149, + created_at: '2016-07-09T03:58:29.617584Z', + text_signature: 'approve(address,uint256)', + hex_signature: '0x095ea7b3', + bytes_signature: '\t^§³', + }, + ], + }, + })); +}