Skip to content

chore: de-deuplicates the erc20 revoke allowance tests #29658

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

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import FixtureBuilder from '../../../fixture-builder';
import {
defaultGanacheOptions,
defaultGanacheOptionsForType2Transactions,
largeDelayMs,
veryLargeDelayMs,
WINDOW_TITLES,
withFixtures,
} from '../../../helpers';
Expand All @@ -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 () {
Expand Down Expand Up @@ -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' });
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
67 changes: 65 additions & 2 deletions test/e2e/tests/confirmations/transactions/shared.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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^§³',
},
],
},
}));
}
Loading