Skip to content

test: fix stx opt-in opt-out fixture #33264

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
Jun 3, 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
14 changes: 4 additions & 10 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,20 +845,14 @@ class FixtureBuilder {
});
}

withPreferencesControllerSmartTransactionsOptedIn() {
Copy link
Contributor Author

@seaona seaona May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this method as the opt in status is already in the default fixture, or it is set to true by default in the onboarding case

return this.withPreferencesController({
preferences: {
smartTransactionsOptInStatus: true,
tokenNetworkFilter: {},
},
});
}

/**
* @deprecated this method should not be used, as the `smartTransactionsOptInStatus` value is overridden by the migration 135
* Use the `toggleStxSetting` flow to disable this setting effectively.
*/
withPreferencesControllerSmartTransactionsOptedOut() {
Copy link
Contributor Author

@seaona seaona May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ leaving the method with the @deprecated info, so this is not used.
I could have deleted it, but I'm afraid this can be re-introduced again, so leaving this here for a while before removing it completely.
Side: removed the tokenNetworkFilter as it's irrelevant here

return this.withPreferencesController({
preferences: {
smartTransactionsOptInStatus: false,
tokenNetworkFilter: {},
},
});
}
Expand Down
17 changes: 16 additions & 1 deletion test/e2e/json-rpc/switchEthereumChain.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { strict: assert } = require('assert');
const { Key } = require('selenium-webdriver');
const {
withFixtures,
openDapp,
Expand Down Expand Up @@ -92,7 +93,6 @@ describe('Switch Ethereum Chain for two dapps', function () {
dapp: true,
fixtures: new FixtureBuilder()
.withNetworkControllerDoubleNode()
.withPreferencesControllerSmartTransactionsOptedOut()
.build(),
dappOptions: { numberOfDapps: 2 },
localNodeOptions: [
Expand All @@ -116,6 +116,21 @@ describe('Switch Ethereum Chain for two dapps', function () {
async ({ driver }) => {
await unlockWallet(driver);

// disable smart transactions step by step
// we cannot use fixtures because migration 135 overrides the opt in value to true
await driver.clickElement(
'[data-testid="account-options-menu-button"]',
);
await driver.clickElement({ text: 'Settings', tag: 'div' });
await driver.clickElement({
text: 'Advanced',
tag: 'div',
});
const stxToggle = await driver.findElement(
'[data-testid="settings-page-stx-opt-in-toggle"]',
);
stxToggle.sendKeys(Key.ENTER);

// open two dapps
await openDapp(driver, undefined, DAPP_URL);
await openDapp(driver, undefined, DAPP_ONE_URL);
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/page-objects/flows/toggle-stx-setting.flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Driver } from '../../webdriver/driver';
import AdvancedSettings from '../pages/settings/advanced-settings';
import HeaderNavbar from '../pages/header-navbar';
import SettingsPage from '../pages/settings/settings-page';

/**
* Toggle the Smart Transactions (STX) option from the Advance settings.
*
* @param driver - The driver instance.
*/
export async function toggleStxSetting(driver: Driver) {
const headerNavbar = new HeaderNavbar(driver);
await headerNavbar.check_pageIsLoaded();
await headerNavbar.openSettingsPage();

const settingsPage = new SettingsPage(driver);
await settingsPage.check_pageIsLoaded();
await settingsPage.clickAdvancedTab();
const advancedSettingsPage = new AdvancedSettings(driver);
await advancedSettingsPage.check_pageIsLoaded();
await advancedSettingsPage.toggleSmartTransactions();
await settingsPage.closeSettingsPage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CHAIN_IDS } from '@metamask/transaction-controller';
import { Driver } from '../../../webdriver/driver';
import FixtureBuilder from '../../../fixture-builder';
import { WINDOW_TITLES, unlockWallet, withFixtures } from '../../../helpers';
import { toggleStxSetting } from '../../../page-objects/flows/toggle-stx-setting.flow';
import { createDappTransaction } from '../../../page-objects/flows/transaction';
import TransactionConfirmation from '../../../page-objects/pages/confirmations/redesign/transaction-confirmation';
import GasFeeTokenModal from '../../../page-objects/pages/confirmations/redesign/gas-fee-token-modal';
Expand All @@ -25,7 +26,6 @@ describe('Gas Fee Tokens - EIP-7702', function (this: Suite) {
dapp: true,
fixtures: new FixtureBuilder({ inputChainId: CHAIN_IDS.MAINNET })
.withPermissionControllerConnectedToTestDapp()
.withPreferencesControllerSmartTransactionsOptedOut()
.build(),
localNodeOptions: {
hardfork: 'prague',
Expand All @@ -44,6 +44,11 @@ describe('Gas Fee Tokens - EIP-7702', function (this: Suite) {
},
async ({ driver }: { driver: Driver; localNodes: Anvil }) => {
await unlockWallet(driver);

// disable smart transactions step by step
// we cannot use fixtures because migration 135 overrides the opt in value to true
await toggleStxSetting(driver);

await createDappTransaction(driver);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

Expand Down Expand Up @@ -86,7 +91,6 @@ describe('Gas Fee Tokens - EIP-7702', function (this: Suite) {
dapp: true,
fixtures: new FixtureBuilder({ inputChainId: CHAIN_IDS.MAINNET })
.withPermissionControllerConnectedToTestDapp()
.withPreferencesControllerSmartTransactionsOptedIn()
.withNetworkControllerOnMainnet()
.build(),
localNodeOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('Gas Fee Tokens - Smart Transactions', function (this: Suite) {
dapp: true,
fixtures: new FixtureBuilder({ inputChainId: CHAIN_IDS.MAINNET })
.withPermissionControllerConnectedToTestDapp()
.withPreferencesControllerSmartTransactionsOptedIn()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already true by default

.withNetworkControllerOnMainnet()
.build(),
localNodeOptions: {
Expand Down Expand Up @@ -84,7 +83,6 @@ describe('Gas Fee Tokens - Smart Transactions', function (this: Suite) {
dapp: true,
fixtures: new FixtureBuilder({ inputChainId: CHAIN_IDS.MAINNET })
.withPermissionControllerConnectedToTestDapp()
.withPreferencesControllerSmartTransactionsOptedIn()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already true by default

.withNetworkControllerOnMainnet()
.build(),
localNodeOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ async function withFixturesForSmartTransactions(
{
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withPreferencesControllerSmartTransactionsOptedIn()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already true by default

.withNetworkControllerOnMainnet()
.build(),
title,
Expand Down
Loading