From c902774ca04b0d945fd6a73eb970ba2d932839b3 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 8 May 2025 21:25:26 +0530 Subject: [PATCH 01/12] Remove upgrade rejection persistence --- .../preferences-controller.test.ts | 68 ------------------- .../controllers/preferences-controller.ts | 23 ------- app/scripts/lib/transaction/eip5792.test.ts | 34 ---------- app/scripts/lib/transaction/eip5792.ts | 29 ++------ app/scripts/metamask-controller.js | 11 --- app/scripts/migrations/157.test.ts | 58 ++++++++++++++++ app/scripts/migrations/157.ts | 41 +++++++++++ ...rs-after-init-opt-in-background-state.json | 3 +- .../errors-after-init-opt-in-ui-state.json | 1 - .../smart-account-update.test.tsx | 7 +- .../hooks/useSmartAccountActions.test.ts | 7 +- .../hooks/useSmartAccountActions.ts | 7 +- ui/store/actions.ts | 7 -- 13 files changed, 107 insertions(+), 189 deletions(-) create mode 100644 app/scripts/migrations/157.test.ts create mode 100644 app/scripts/migrations/157.ts diff --git a/app/scripts/controllers/preferences-controller.test.ts b/app/scripts/controllers/preferences-controller.test.ts index 6ad4ac422a44..5028b217cd2c 100644 --- a/app/scripts/controllers/preferences-controller.test.ts +++ b/app/scripts/controllers/preferences-controller.test.ts @@ -841,74 +841,6 @@ describe('preferences controller', () => { }); }); - describe('getDisabledUpgradeAccountsByChain', () => { - it('returns empty object if disabledAccountUpgradeChainsAddresses is empty', () => { - const { controller } = setupController({}); - expect(controller.getDisabledUpgradeAccountsByChain()).toStrictEqual({}); - }); - - it('returns disabledAccountUpgrades state', () => { - const mockStateObject = { - [CHAIN_IDS.MAINNET]: ['0x0'] as Hex[], - [CHAIN_IDS.GOERLI]: ['0x1'] as Hex[], - }; - const { controller } = setupController({ - state: { - disabledUpgradeAccountsByChain: mockStateObject, - }, - }); - - expect(controller.getDisabledUpgradeAccountsByChain()).toStrictEqual( - mockStateObject, - ); - }); - }); - - describe('disableAccountUpgrade', () => { - it('adds chain ID, address to disabledAccountUpgrades if empty', () => { - const { controller } = setupController({}); - - controller.disableAccountUpgrade(CHAIN_IDS.GOERLI, '0x0'); - - expect(controller.state.disabledUpgradeAccountsByChain).toStrictEqual({ - [CHAIN_IDS.GOERLI]: ['0x0'], - }); - }); - - it('adds chain ID, address to disabledAccountUpgrades if not empty', () => { - const { controller } = setupController({ - state: { - disabledUpgradeAccountsByChain: { - [CHAIN_IDS.MAINNET]: ['0x0'], - }, - }, - }); - - controller.disableAccountUpgrade(CHAIN_IDS.GOERLI, '0x1'); - - expect(controller.state.disabledUpgradeAccountsByChain).toStrictEqual({ - [CHAIN_IDS.MAINNET]: ['0x0'], - [CHAIN_IDS.GOERLI]: ['0x1'], - }); - }); - - it('does not add chain ID to disabledAccountUpgrades if duplicate', () => { - const { controller } = setupController({ - state: { - disabledUpgradeAccountsByChain: { - [CHAIN_IDS.MAINNET]: ['0x0'], - }, - }, - }); - - controller.disableAccountUpgrade(CHAIN_IDS.MAINNET, '0x0'); - - expect(controller.state.disabledUpgradeAccountsByChain).toStrictEqual({ - [CHAIN_IDS.MAINNET]: ['0x0'], - }); - }); - }); - describe('manageInstitutionalWallets', () => { it('defaults manageInstitutionalWallets to false', () => { const { controller } = setupController({}); diff --git a/app/scripts/controllers/preferences-controller.ts b/app/scripts/controllers/preferences-controller.ts index e6242cf8179c..59cdf94c8a1b 100644 --- a/app/scripts/controllers/preferences-controller.ts +++ b/app/scripts/controllers/preferences-controller.ts @@ -150,7 +150,6 @@ export type PreferencesControllerState = Omit< useExternalServices: boolean; textDirection?: string; manageInstitutionalWallets: boolean; - disabledUpgradeAccountsByChain?: Record; }; /** @@ -256,7 +255,6 @@ export const getDefaultPreferencesControllerState = [ETHERSCAN_SUPPORTED_CHAIN_IDS.GNOSIS]: true, }, manageInstitutionalWallets: false, - disabledUpgradeAccountsByChain: {}, }); /** @@ -428,7 +426,6 @@ const controllerMetadata = { isMultiAccountBalancesEnabled: { persist: true, anonymous: true }, showIncomingTransactions: { persist: true, anonymous: true }, manageInstitutionalWallets: { persist: true, anonymous: false }, - disabledUpgradeAccountsByChain: { persist: true, anonymous: false }, }; export class PreferencesController extends BaseController< @@ -964,26 +961,6 @@ export class PreferencesController extends BaseController< }); } - getDisabledUpgradeAccountsByChain(): Record { - return this.state.disabledUpgradeAccountsByChain ?? {}; - } - - disableAccountUpgrade(chainId: Hex, address: Hex): void { - this.update((state) => { - const { disabledUpgradeAccountsByChain = {} } = state; - const addressLowerCase = address.toLowerCase() as Hex; - - if ( - !disabledUpgradeAccountsByChain[chainId]?.includes(addressLowerCase) - ) { - if (!disabledUpgradeAccountsByChain[chainId]) { - disabledUpgradeAccountsByChain[chainId] = []; - } - disabledUpgradeAccountsByChain[chainId].push(addressLowerCase); - } - }); - } - ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) setSnapsAddSnapAccountModalDismissed(value: boolean): void { this.update((state) => { diff --git a/app/scripts/lib/transaction/eip5792.test.ts b/app/scripts/lib/transaction/eip5792.test.ts index 8cffe2c61763..991ddcef879c 100644 --- a/app/scripts/lib/transaction/eip5792.test.ts +++ b/app/scripts/lib/transaction/eip5792.test.ts @@ -93,10 +93,6 @@ describe('EIP-5792', () => { TransactionControllerGetStateAction['handler'] > = jest.fn(); - const getDisabledUpgradeAccountsByChainMock: jest.MockedFn< - () => Record - > = jest.fn(); - const isAtomicBatchSupportedMock: jest.MockedFn< TransactionController['isAtomicBatchSupported'] > = jest.fn(); @@ -113,7 +109,6 @@ describe('EIP-5792', () => { const sendCallsHooks = { addTransactionBatch: addTransactionBatchMock, - getDisabledUpgradeAccountsByChain: getDisabledUpgradeAccountsByChainMock, getDismissSmartAccountSuggestionEnabled: getDismissSmartAccountSuggestionEnabledMock, isAtomicBatchSupported: isAtomicBatchSupportedMock, @@ -150,7 +145,6 @@ describe('EIP-5792', () => { batchId: BATCH_ID_MOCK, }); - getDisabledUpgradeAccountsByChainMock.mockReturnValue({}); getDismissSmartAccountSuggestionEnabledMock.mockReturnValue(false); isAtomicBatchSupportedMock.mockResolvedValue([ @@ -237,10 +231,6 @@ describe('EIP-5792', () => { }); it('throws if disabled preference for chain and account', async () => { - getDisabledUpgradeAccountsByChainMock.mockReturnValue({ - [CHAIN_ID_MOCK]: [FROM_MOCK], - }); - await expect( processSendCalls( sendCallsHooks, @@ -254,10 +244,6 @@ describe('EIP-5792', () => { }); it('does not throw if disabled preference for chain and account if already upgraded', async () => { - getDisabledUpgradeAccountsByChainMock.mockReturnValue({ - [CHAIN_ID_MOCK]: [FROM_MOCK], - }); - isAtomicBatchSupportedMock.mockResolvedValueOnce([ { chainId: CHAIN_ID_MOCK, @@ -530,8 +516,6 @@ describe('EIP-5792', () => { const capabilities = await getCapabilities( { - getDisabledUpgradeAccountsByChain: - getDisabledUpgradeAccountsByChainMock, getDismissSmartAccountSuggestionEnabled: getDismissSmartAccountSuggestionEnabledMock, isAtomicBatchSupported: isAtomicBatchSupportedMock, @@ -561,8 +545,6 @@ describe('EIP-5792', () => { const capabilities = await getCapabilities( { - getDisabledUpgradeAccountsByChain: - getDisabledUpgradeAccountsByChainMock, getDismissSmartAccountSuggestionEnabled: getDismissSmartAccountSuggestionEnabledMock, isAtomicBatchSupported: isAtomicBatchSupportedMock, @@ -585,8 +567,6 @@ describe('EIP-5792', () => { const capabilities = await getCapabilities( { - getDisabledUpgradeAccountsByChain: - getDisabledUpgradeAccountsByChainMock, getDismissSmartAccountSuggestionEnabled: getDismissSmartAccountSuggestionEnabledMock, isAtomicBatchSupported: isAtomicBatchSupportedMock, @@ -612,8 +592,6 @@ describe('EIP-5792', () => { const capabilities = await getCapabilities( { - getDisabledUpgradeAccountsByChain: - getDisabledUpgradeAccountsByChainMock, getDismissSmartAccountSuggestionEnabled: getDismissSmartAccountSuggestionEnabledMock, isAtomicBatchSupported: isAtomicBatchSupportedMock, @@ -635,14 +613,8 @@ describe('EIP-5792', () => { }, ]); - getDisabledUpgradeAccountsByChainMock.mockReturnValue({ - [CHAIN_ID_MOCK]: [FROM_MOCK], - }); - const capabilities = await getCapabilities( { - getDisabledUpgradeAccountsByChain: - getDisabledUpgradeAccountsByChainMock, getDismissSmartAccountSuggestionEnabled: getDismissSmartAccountSuggestionEnabledMock, isAtomicBatchSupported: isAtomicBatchSupportedMock, @@ -664,14 +636,8 @@ describe('EIP-5792', () => { }, ]); - getDisabledUpgradeAccountsByChainMock.mockReturnValue({ - [CHAIN_ID_MOCK]: [FROM_MOCK], - }); - const capabilities = await getCapabilities( { - getDisabledUpgradeAccountsByChain: - getDisabledUpgradeAccountsByChainMock, getDismissSmartAccountSuggestionEnabled: getDismissSmartAccountSuggestionEnabledMock, isAtomicBatchSupported: isAtomicBatchSupportedMock, diff --git a/app/scripts/lib/transaction/eip5792.ts b/app/scripts/lib/transaction/eip5792.ts index 015fa210710a..e22251cab1d9 100644 --- a/app/scripts/lib/transaction/eip5792.ts +++ b/app/scripts/lib/transaction/eip5792.ts @@ -41,7 +41,6 @@ const VERSION = '2.0.0'; export async function processSendCalls( hooks: { addTransactionBatch: TransactionController['addTransactionBatch']; - getDisabledUpgradeAccountsByChain: () => Record; getDismissSmartAccountSuggestionEnabled: () => boolean; isAtomicBatchSupported: TransactionController['isAtomicBatchSupported']; validateSecurity: ( @@ -56,7 +55,6 @@ export async function processSendCalls( ): Promise { const { addTransactionBatch, - getDisabledUpgradeAccountsByChain, getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported, validateSecurity: validateSecurityHook, @@ -75,8 +73,6 @@ export async function processSendCalls( paramFrom ?? (messenger.call('AccountsController:getSelectedAccount').address as Hex); - const disabledUpgradeAccountsByChain = getDisabledUpgradeAccountsByChain(); - const dismissSmartAccountSuggestionEnabled = getDismissSmartAccountSuggestionEnabled(); @@ -91,7 +87,6 @@ export async function processSendCalls( params, from, dappChainId, - disabledUpgradeAccountsByChain, dismissSmartAccountSuggestionEnabled, chainBatchSupport, ); @@ -159,18 +154,14 @@ export function getCallsStatus( export async function getCapabilities( hooks: { - getDisabledUpgradeAccountsByChain: () => Record; getDismissSmartAccountSuggestionEnabled: () => boolean; isAtomicBatchSupported: TransactionController['isAtomicBatchSupported']; }, address: Hex, chainIds: Hex[] | undefined, ) { - const { - getDisabledUpgradeAccountsByChain, - getDismissSmartAccountSuggestionEnabled, - isAtomicBatchSupported, - } = hooks; + const { getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported } = + hooks; const addressNormalized = address.toLowerCase() as Hex; @@ -190,13 +181,7 @@ export async function getCapabilities( const { delegationAddress, isSupported, upgradeContractAddress } = chainBatchSupport; - const isUpgradeDisabled = - getDisabledUpgradeAccountsByChain()?.[chainId]?.includes( - addressNormalized, - ) || getDismissSmartAccountSuggestionEnabled(); - - const canUpgrade = - !isUpgradeDisabled && upgradeContractAddress && !delegationAddress; + const canUpgrade = upgradeContractAddress && !delegationAddress; if (!isSupported && !canUpgrade) { return acc; @@ -222,7 +207,6 @@ function validateSendCalls( sendCalls: SendCalls, from: Hex, dappChainId: Hex, - disabledUpgradeAccountsByChain: Record, dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, ) { @@ -232,7 +216,6 @@ function validateSendCalls( validateUserDisabled( from, - disabledUpgradeAccountsByChain, dappChainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, @@ -303,7 +286,6 @@ function validateCapabilities(sendCalls: SendCalls) { function validateUserDisabled( from: Hex, - disabledUpgradeAccountsByChain: Record, dappChainId: Hex, dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, @@ -314,10 +296,7 @@ function validateUserDisabled( return; } - const isDisabled = - disabledUpgradeAccountsByChain[dappChainId]?.includes(addressLowerCase); - - if (isDisabled || dismissSmartAccountSuggestionEnabled) { + if (dismissSmartAccountSuggestionEnabled) { throw new JsonRpcError( EIP5792ErrorCode.RejectedUpgrade, `EIP-7702 upgrade rejected for this chain and account - Chain ID: ${dappChainId}, Account: ${from}`, diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 7bbf9a585889..3ea3df815e6f 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -2071,10 +2071,6 @@ export default class MetamaskController extends EventEmitter { addTransactionBatch: this.txController.addTransactionBatch.bind( this.txController, ), - getDisabledUpgradeAccountsByChain: - this.preferencesController.getDisabledUpgradeAccountsByChain.bind( - this.preferencesController, - ), getDismissSmartAccountSuggestionEnabled: () => this.preferencesController.state.preferences .dismissSmartAccountSuggestionEnabled, @@ -2095,10 +2091,6 @@ export default class MetamaskController extends EventEmitter { ), getCallsStatus: getCallsStatus.bind(null, this.controllerMessenger), getCapabilities: getCapabilities.bind(null, { - getDisabledUpgradeAccountsByChain: - this.preferencesController.getDisabledUpgradeAccountsByChain.bind( - this.preferencesController, - ), getDismissSmartAccountSuggestionEnabled: () => this.preferencesController.state.preferences .dismissSmartAccountSuggestionEnabled, @@ -3679,9 +3671,6 @@ export default class MetamaskController extends EventEmitter { preferencesController, ), setTheme: preferencesController.setTheme.bind(preferencesController), - disableAccountUpgrade: preferencesController.disableAccountUpgrade.bind( - preferencesController, - ), ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) setSnapsAddSnapAccountModalDismissed: preferencesController.setSnapsAddSnapAccountModalDismissed.bind( diff --git a/app/scripts/migrations/157.test.ts b/app/scripts/migrations/157.test.ts new file mode 100644 index 000000000000..47193f9847f7 --- /dev/null +++ b/app/scripts/migrations/157.test.ts @@ -0,0 +1,58 @@ +import { migrate, version } from './157'; + +const oldVersion = 156; + +describe(`migration #${version}`, () => { + it('updates the version metadata', async () => { + const oldStorage = { + meta: { version: oldVersion }, + data: {}, + }; + const newStorage = await migrate(oldStorage); + expect(newStorage.meta).toStrictEqual({ version }); + }); + + describe(`migration #${version}`, () => { + it('removes the disabledUpgradeAccountsByChain preference', async () => { + const oldStorage = { + meta: { version: oldVersion }, + data: { + PreferencesController: { + preferences: { + disabledUpgradeAccountsByChain: {}, + }, + }, + }, + }; + const expectedData = { + PreferencesController: { + preferences: {}, + }, + }; + const newStorage = await migrate(oldStorage); + + expect(newStorage.data).toStrictEqual(expectedData); + }); + + it('does nothing to other PreferencesController state if there is not a petnamesEnabled preference', async () => { + const oldStorage = { + meta: { version: oldVersion }, + data: { + PreferencesController: { + existingPreference: true, + }, + }, + }; + + const expectedData = { + PreferencesController: { + existingPreference: true, + }, + }; + + const newStorage = await migrate(oldStorage); + + expect(newStorage.data).toStrictEqual(expectedData); + }); + }); +}); diff --git a/app/scripts/migrations/157.ts b/app/scripts/migrations/157.ts new file mode 100644 index 000000000000..4226e1d3e4c3 --- /dev/null +++ b/app/scripts/migrations/157.ts @@ -0,0 +1,41 @@ +import { cloneDeep } from 'lodash'; + +type VersionedData = { + meta: { version: number }; + data: Record; +}; + +export const version = 157; + +/** + * This migration deletes the preference `disabledUpgradeAccountsByChain` if the user has + * existing data. + * + * @param originalVersionedData - Versioned MetaMask extension state, exactly + * what we persist to dist. + * @param originalVersionedData.meta - State metadata. + * @param originalVersionedData.meta.version - The current state version. + * @param originalVersionedData.data - The persisted MetaMask state, keyed by + * controller. + * @returns Updated versioned MetaMask extension state. + */ +export async function migrate( + originalVersionedData: VersionedData, +): Promise { + const versionedData = cloneDeep(originalVersionedData); + versionedData.meta.version = version; + transformState(versionedData.data); + return versionedData; +} + +function transformState(state: Record) { + const preferencesControllerState = state?.PreferencesController as + | Record + | undefined; + + const preferences = preferencesControllerState?.preferences as + | Record + | undefined; + + delete preferences?.disabledUpgradeAccountsByChain; +} diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json index 8b39fbede6c5..a520e915aa9f 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json @@ -266,8 +266,7 @@ "useExternalServices": "boolean", "isMultiAccountBalancesEnabled": "boolean", "showIncomingTransactions": "object", - "manageInstitutionalWallets": "boolean", - "disabledUpgradeAccountsByChain": "object" + "manageInstitutionalWallets": "boolean" }, "RemoteFeatureFlagController": { "remoteFeatureFlags": { diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json index 30bcb85eb9a9..1f6a9b5d7ad9 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json @@ -214,7 +214,6 @@ "isMultiAccountBalancesEnabled": "boolean", "showIncomingTransactions": "object", "manageInstitutionalWallets": "boolean", - "disabledUpgradeAccountsByChain": "object", "metaMetricsId": "0x86bacb9b2bf9a7e8d2b147eadb95ac9aaa26842327cd24afc8bd4b3c1d136420", "marketingCampaignCookieId": null, "eventsBeforeMetricsOptIn": "object", diff --git a/ui/pages/confirmations/components/confirm/splash/smart-account-update/smart-account-update.test.tsx b/ui/pages/confirmations/components/confirm/splash/smart-account-update/smart-account-update.test.tsx index cab40abb0fe4..95489f88174f 100644 --- a/ui/pages/confirmations/components/confirm/splash/smart-account-update/smart-account-update.test.tsx +++ b/ui/pages/confirmations/components/confirm/splash/smart-account-update/smart-account-update.test.tsx @@ -7,14 +7,10 @@ import { getMockConfirmStateForTransaction } from '../../../../../../../test/dat import { renderWithConfirmContextProvider } from '../../../../../../../test/lib/confirmations/render-helpers'; import { upgradeAccountConfirmation } from '../../../../../../../test/data/confirmations/batch-transaction'; import { Confirmation } from '../../../../types/confirm'; -import { - disableAccountUpgrade, - rejectPendingApproval, -} from '../../../../../../store/actions'; +import { rejectPendingApproval } from '../../../../../../store/actions'; import { SmartAccountUpdate } from './smart-account-update'; jest.mock('../../../../../../store/actions', () => ({ - disableAccountUpgrade: jest.fn(), setAccountDetailsAddress: jest.fn(), rejectPendingApproval: jest.fn().mockReturnValue({}), })); @@ -81,7 +77,6 @@ describe('Splash', () => { name: /Don’t use smart account/iu, }), ); - expect(disableAccountUpgrade).toHaveBeenCalledTimes(1); await flushPromises(); expect(rejectPendingApproval).toHaveBeenCalledTimes(1); }); diff --git a/ui/pages/confirmations/hooks/useSmartAccountActions.test.ts b/ui/pages/confirmations/hooks/useSmartAccountActions.test.ts index 32039bd00af4..a5eccbd1519d 100644 --- a/ui/pages/confirmations/hooks/useSmartAccountActions.test.ts +++ b/ui/pages/confirmations/hooks/useSmartAccountActions.test.ts @@ -1,8 +1,5 @@ import { getMockConfirmStateForTransaction } from '../../../../test/data/confirmations/helper'; -import { - disableAccountUpgrade, - rejectPendingApproval, -} from '../../../store/actions'; +import { rejectPendingApproval } from '../../../store/actions'; import { renderHookWithConfirmContextProvider } from '../../../../test/lib/confirmations/render-helpers'; import { flushPromises } from '../../../../test/lib/timer-helpers'; import { upgradeAccountConfirmation } from '../../../../test/data/confirmations/batch-transaction'; @@ -10,7 +7,6 @@ import { Confirmation } from '../types/confirm'; import { useSmartAccountActions } from './useSmartAccountActions'; jest.mock('../../../store/actions', () => ({ - disableAccountUpgrade: jest.fn(), rejectPendingApproval: jest.fn().mockReturnValue({}), setAccountDetailsAddress: jest.fn(), })); @@ -37,7 +33,6 @@ describe('useSmartAccountActions', () => { state, ); result.current.handleRejectUpgrade(); - expect(disableAccountUpgrade).toHaveBeenCalledTimes(1); await flushPromises(); expect(rejectPendingApproval).toHaveBeenCalledTimes(1); expect(mockDispatch).toHaveBeenCalledTimes(2); diff --git a/ui/pages/confirmations/hooks/useSmartAccountActions.ts b/ui/pages/confirmations/hooks/useSmartAccountActions.ts index 8920112fd76f..34a6b18f6dd8 100644 --- a/ui/pages/confirmations/hooks/useSmartAccountActions.ts +++ b/ui/pages/confirmations/hooks/useSmartAccountActions.ts @@ -3,10 +3,7 @@ import { JsonRpcError, serializeError } from '@metamask/rpc-errors'; import { useCallback } from 'react'; import { useDispatch } from 'react-redux'; -import { - disableAccountUpgrade, - rejectPendingApproval, -} from '../../../store/actions'; +import { rejectPendingApproval } from '../../../store/actions'; import { useConfirmContext } from '../context/confirm'; import { EIP5792ErrorCode } from '../../../../shared/constants/transaction'; @@ -28,8 +25,6 @@ export function useSmartAccountActions() { const serializedError = serializeError(error); - await disableAccountUpgrade(chainId as string, from); - dispatch(rejectPendingApproval(confirmationId, serializedError)); }, [dispatch, confirmationId, chainId, from]); diff --git a/ui/store/actions.ts b/ui/store/actions.ts index 5bff5d7dd7a8..4bf48139988f 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -6189,13 +6189,6 @@ export async function createSnapAccount( } ///: END:ONLY_INCLUDE_IF -export async function disableAccountUpgrade(chainId: string, address: string) { - return await submitRequestToBackground('disableAccountUpgrade', [ - chainId, - address, - ]); -} - export async function getCode(address: Hex, networkClientId: string) { return await submitRequestToBackground('getCode', [ address, From 2f573183cb033436aaad50f967b909655d5451f2 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 8 May 2025 21:49:25 +0530 Subject: [PATCH 02/12] update --- app/scripts/controllers/preferences-controller.test.ts | 1 - app/scripts/controllers/preferences-controller.ts | 2 +- app/scripts/lib/transaction/eip5792.test.ts | 2 +- app/scripts/lib/transaction/eip5792.ts | 8 ++++---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/scripts/controllers/preferences-controller.test.ts b/app/scripts/controllers/preferences-controller.test.ts index 5028b217cd2c..f14b3822751e 100644 --- a/app/scripts/controllers/preferences-controller.test.ts +++ b/app/scripts/controllers/preferences-controller.test.ts @@ -3,7 +3,6 @@ */ import { Messenger } from '@metamask/base-controller'; import { AccountsController } from '@metamask/accounts-controller'; -import { Hex } from '@metamask/utils'; import { KeyringControllerStateChangeEvent } from '@metamask/keyring-controller'; import type { MultichainNetworkControllerNetworkDidChangeEvent } from '@metamask/multichain-network-controller'; import { SnapControllerStateChangeEvent } from '@metamask/snaps-controllers'; diff --git a/app/scripts/controllers/preferences-controller.ts b/app/scripts/controllers/preferences-controller.ts index 59cdf94c8a1b..eac56b0fa26f 100644 --- a/app/scripts/controllers/preferences-controller.ts +++ b/app/scripts/controllers/preferences-controller.ts @@ -6,7 +6,7 @@ import { AccountsControllerSetSelectedAccountAction, AccountsControllerState, } from '@metamask/accounts-controller'; -import { Hex, Json } from '@metamask/utils'; +import { Json } from '@metamask/utils'; import { BaseController, ControllerGetStateAction, diff --git a/app/scripts/lib/transaction/eip5792.test.ts b/app/scripts/lib/transaction/eip5792.test.ts index 991ddcef879c..499efa2d4d82 100644 --- a/app/scripts/lib/transaction/eip5792.test.ts +++ b/app/scripts/lib/transaction/eip5792.test.ts @@ -14,7 +14,7 @@ import { SendCalls, SendCallsParams, } from '@metamask/eth-json-rpc-middleware'; -import { Hex, JsonRpcRequest } from '@metamask/utils'; +import { JsonRpcRequest } from '@metamask/utils'; import { Messenger } from '@metamask/base-controller'; import { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller'; import { InternalAccount } from '@metamask/keyring-internal-api'; diff --git a/app/scripts/lib/transaction/eip5792.ts b/app/scripts/lib/transaction/eip5792.ts index e22251cab1d9..38f0d758f86a 100644 --- a/app/scripts/lib/transaction/eip5792.ts +++ b/app/scripts/lib/transaction/eip5792.ts @@ -160,8 +160,10 @@ export async function getCapabilities( address: Hex, chainIds: Hex[] | undefined, ) { - const { getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported } = - hooks; + const { + getDismissSmartAccountSuggestionEnabled, + isAtomicBatchSupported, + } = hooks; const addressNormalized = address.toLowerCase() as Hex; @@ -290,8 +292,6 @@ function validateUserDisabled( dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, ) { - const addressLowerCase = from.toLowerCase() as Hex; - if (chainBatchSupport?.delegationAddress) { return; } From f5843e4ca808187db2ef49de6b6f5856cb8d698d Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 8 May 2025 21:49:32 +0530 Subject: [PATCH 03/12] update --- app/scripts/lib/transaction/eip5792.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/scripts/lib/transaction/eip5792.ts b/app/scripts/lib/transaction/eip5792.ts index 38f0d758f86a..f40904b94f5c 100644 --- a/app/scripts/lib/transaction/eip5792.ts +++ b/app/scripts/lib/transaction/eip5792.ts @@ -160,10 +160,8 @@ export async function getCapabilities( address: Hex, chainIds: Hex[] | undefined, ) { - const { - getDismissSmartAccountSuggestionEnabled, - isAtomicBatchSupported, - } = hooks; + const { getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported } = + hooks; const addressNormalized = address.toLowerCase() as Hex; From cad94738d9c5ba6fcc626e271182dcc4bb44c257 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 8 May 2025 21:52:00 +0530 Subject: [PATCH 04/12] update --- app/scripts/lib/transaction/eip5792.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/app/scripts/lib/transaction/eip5792.ts b/app/scripts/lib/transaction/eip5792.ts index f40904b94f5c..7ad5da6d7bd4 100644 --- a/app/scripts/lib/transaction/eip5792.ts +++ b/app/scripts/lib/transaction/eip5792.ts @@ -85,7 +85,6 @@ export async function processSendCalls( validateSendCalls( params, - from, dappChainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, @@ -205,7 +204,6 @@ export async function getCapabilities( function validateSendCalls( sendCalls: SendCalls, - from: Hex, dappChainId: Hex, dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, @@ -214,12 +212,7 @@ function validateSendCalls( validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport); validateCapabilities(sendCalls); - validateUserDisabled( - from, - dappChainId, - dismissSmartAccountSuggestionEnabled, - chainBatchSupport, - ); + validateUserDisabled(dismissSmartAccountSuggestionEnabled, chainBatchSupport); } function validateSendCallsVersion(sendCalls: SendCalls) { @@ -285,8 +278,6 @@ function validateCapabilities(sendCalls: SendCalls) { } function validateUserDisabled( - from: Hex, - dappChainId: Hex, dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, ) { @@ -297,7 +288,7 @@ function validateUserDisabled( if (dismissSmartAccountSuggestionEnabled) { throw new JsonRpcError( EIP5792ErrorCode.RejectedUpgrade, - `EIP-7702 upgrade rejected for this chain and account - Chain ID: ${dappChainId}, Account: ${from}`, + 'EIP-7702 upgrade disabled by the user', ); } } From d6644881c7e2555061d8a7cfc6c3c7d13c398a87 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Fri, 9 May 2025 12:26:40 +0530 Subject: [PATCH 05/12] update --- app/scripts/lib/transaction/eip5792.ts | 7 ++++--- app/scripts/migrations/index.js | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/transaction/eip5792.ts b/app/scripts/lib/transaction/eip5792.ts index 7ad5da6d7bd4..63df163204b4 100644 --- a/app/scripts/lib/transaction/eip5792.ts +++ b/app/scripts/lib/transaction/eip5792.ts @@ -162,8 +162,6 @@ export async function getCapabilities( const { getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported } = hooks; - const addressNormalized = address.toLowerCase() as Hex; - const chainIdsNormalized = chainIds?.map( (chainId) => chainId.toLowerCase() as Hex, ); @@ -180,7 +178,10 @@ export async function getCapabilities( const { delegationAddress, isSupported, upgradeContractAddress } = chainBatchSupport; - const canUpgrade = upgradeContractAddress && !delegationAddress; + const canUpgrade = + !getDismissSmartAccountSuggestionEnabled() && + upgradeContractAddress && + !delegationAddress; if (!isSupported && !canUpgrade) { return acc; diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index f08ed5ea68b4..87fb0b55ea91 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -184,6 +184,7 @@ const migrations = [ require('./154'), require('./155'), require('./156'), + require('./157'), ]; export default migrations; From 2d3821fa854276f0906140ecca8e466bed8b79d2 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Fri, 9 May 2025 15:07:20 +0530 Subject: [PATCH 06/12] update --- app/scripts/lib/transaction/eip5792.test.ts | 59 +-------------------- app/scripts/lib/transaction/eip5792.ts | 22 ++++++-- 2 files changed, 18 insertions(+), 63 deletions(-) diff --git a/app/scripts/lib/transaction/eip5792.test.ts b/app/scripts/lib/transaction/eip5792.test.ts index 499efa2d4d82..b2ebb7932d2e 100644 --- a/app/scripts/lib/transaction/eip5792.test.ts +++ b/app/scripts/lib/transaction/eip5792.test.ts @@ -230,38 +230,6 @@ describe('EIP-5792', () => { ); }); - it('throws if disabled preference for chain and account', async () => { - await expect( - processSendCalls( - sendCallsHooks, - messenger, - SEND_CALLS_MOCK, - REQUEST_MOCK, - ), - ).rejects.toThrow( - `EIP-7702 upgrade rejected for this chain and account - Chain ID: ${CHAIN_ID_MOCK}, Account: ${SEND_CALLS_MOCK.from}`, - ); - }); - - it('does not throw if disabled preference for chain and account if already upgraded', async () => { - isAtomicBatchSupportedMock.mockResolvedValueOnce([ - { - chainId: CHAIN_ID_MOCK, - delegationAddress: DELEGATION_ADDRESS_MOCK, - isSupported: true, - }, - ]); - - expect( - await processSendCalls( - sendCallsHooks, - messenger, - SEND_CALLS_MOCK, - REQUEST_MOCK, - ), - ).toBeDefined(); - }); - it('throws if user enabled preference to dismiss option to upgrade account', async () => { getDismissSmartAccountSuggestionEnabledMock.mockReturnValue(true); @@ -272,9 +240,7 @@ describe('EIP-5792', () => { SEND_CALLS_MOCK, REQUEST_MOCK, ), - ).rejects.toThrow( - `EIP-7702 upgrade rejected for this chain and account - Chain ID: ${CHAIN_ID_MOCK}, Account: ${SEND_CALLS_MOCK.from}`, - ); + ).rejects.toThrow('EIP-7702 upgrade disabled by the user'); }); it('does not throw if user enabled preference to dismiss option to upgrade account if already upgraded', async () => { @@ -603,29 +569,6 @@ describe('EIP-5792', () => { expect(capabilities).toStrictEqual({}); }); - it('does not include atomic capability if upgrade disabled for chain and account', async () => { - isAtomicBatchSupportedMock.mockResolvedValueOnce([ - { - chainId: CHAIN_ID_MOCK, - delegationAddress: undefined, - isSupported: false, - upgradeContractAddress: DELEGATION_ADDRESS_MOCK, - }, - ]); - - const capabilities = await getCapabilities( - { - getDismissSmartAccountSuggestionEnabled: - getDismissSmartAccountSuggestionEnabledMock, - isAtomicBatchSupported: isAtomicBatchSupportedMock, - }, - FROM_MOCK, - [CHAIN_ID_MOCK], - ); - - expect(capabilities).toStrictEqual({}); - }); - it('does not include atomic capability if no upgrade contract address', async () => { isAtomicBatchSupportedMock.mockResolvedValueOnce([ { diff --git a/app/scripts/lib/transaction/eip5792.ts b/app/scripts/lib/transaction/eip5792.ts index 63df163204b4..a7c6a174b58e 100644 --- a/app/scripts/lib/transaction/eip5792.ts +++ b/app/scripts/lib/transaction/eip5792.ts @@ -85,6 +85,7 @@ export async function processSendCalls( validateSendCalls( params, + from, dappChainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, @@ -162,6 +163,8 @@ export async function getCapabilities( const { getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported } = hooks; + const addressNormalized = address.toLowerCase() as Hex; + const chainIdsNormalized = chainIds?.map( (chainId) => chainId.toLowerCase() as Hex, ); @@ -178,10 +181,10 @@ export async function getCapabilities( const { delegationAddress, isSupported, upgradeContractAddress } = chainBatchSupport; + const isUpgradeDisabled = getDismissSmartAccountSuggestionEnabled(); + const canUpgrade = - !getDismissSmartAccountSuggestionEnabled() && - upgradeContractAddress && - !delegationAddress; + !isUpgradeDisabled && upgradeContractAddress && !delegationAddress; if (!isSupported && !canUpgrade) { return acc; @@ -205,6 +208,7 @@ export async function getCapabilities( function validateSendCalls( sendCalls: SendCalls, + from: Hex, dappChainId: Hex, dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, @@ -212,8 +216,12 @@ function validateSendCalls( validateSendCallsVersion(sendCalls); validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport); validateCapabilities(sendCalls); - - validateUserDisabled(dismissSmartAccountSuggestionEnabled, chainBatchSupport); + validateUserDisabled( + from, + dappChainId, + dismissSmartAccountSuggestionEnabled, + chainBatchSupport, + ); } function validateSendCallsVersion(sendCalls: SendCalls) { @@ -279,9 +287,13 @@ function validateCapabilities(sendCalls: SendCalls) { } function validateUserDisabled( + from: Hex, + dappChainId: Hex, dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, ) { + const addressLowerCase = from.toLowerCase() as Hex; + if (chainBatchSupport?.delegationAddress) { return; } From 0458ff4aae14d0fa8c465ed8c9c1bbb6b2ef0386 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Fri, 9 May 2025 16:42:28 +0530 Subject: [PATCH 07/12] update --- app/scripts/lib/transaction/eip5792.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/scripts/lib/transaction/eip5792.ts b/app/scripts/lib/transaction/eip5792.ts index a7c6a174b58e..76b9bd2c4223 100644 --- a/app/scripts/lib/transaction/eip5792.ts +++ b/app/scripts/lib/transaction/eip5792.ts @@ -163,8 +163,6 @@ export async function getCapabilities( const { getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported } = hooks; - const addressNormalized = address.toLowerCase() as Hex; - const chainIdsNormalized = chainIds?.map( (chainId) => chainId.toLowerCase() as Hex, ); @@ -218,7 +216,6 @@ function validateSendCalls( validateCapabilities(sendCalls); validateUserDisabled( from, - dappChainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, ); @@ -288,12 +285,9 @@ function validateCapabilities(sendCalls: SendCalls) { function validateUserDisabled( from: Hex, - dappChainId: Hex, dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, ) { - const addressLowerCase = from.toLowerCase() as Hex; - if (chainBatchSupport?.delegationAddress) { return; } From b1a3647c9a7c957ae7872ca2be8650c04fe7045f Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Fri, 9 May 2025 17:04:00 +0530 Subject: [PATCH 08/12] update --- app/scripts/lib/transaction/eip5792.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/scripts/lib/transaction/eip5792.ts b/app/scripts/lib/transaction/eip5792.ts index 76b9bd2c4223..dbc609a3a210 100644 --- a/app/scripts/lib/transaction/eip5792.ts +++ b/app/scripts/lib/transaction/eip5792.ts @@ -85,7 +85,6 @@ export async function processSendCalls( validateSendCalls( params, - from, dappChainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, @@ -206,7 +205,6 @@ export async function getCapabilities( function validateSendCalls( sendCalls: SendCalls, - from: Hex, dappChainId: Hex, dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, @@ -214,11 +212,7 @@ function validateSendCalls( validateSendCallsVersion(sendCalls); validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport); validateCapabilities(sendCalls); - validateUserDisabled( - from, - dismissSmartAccountSuggestionEnabled, - chainBatchSupport, - ); + validateUserDisabled(dismissSmartAccountSuggestionEnabled, chainBatchSupport); } function validateSendCallsVersion(sendCalls: SendCalls) { @@ -284,7 +278,6 @@ function validateCapabilities(sendCalls: SendCalls) { } function validateUserDisabled( - from: Hex, dismissSmartAccountSuggestionEnabled: boolean, chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined, ) { From 5cd15af84a57a39891ca3190b8f82c89f415c3c2 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Fri, 9 May 2025 20:29:42 +0530 Subject: [PATCH 09/12] update --- app/scripts/migrations/157.test.ts | 1 + app/scripts/migrations/157.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/app/scripts/migrations/157.test.ts b/app/scripts/migrations/157.test.ts index 47193f9847f7..2c616d9e3876 100644 --- a/app/scripts/migrations/157.test.ts +++ b/app/scripts/migrations/157.test.ts @@ -20,6 +20,7 @@ describe(`migration #${version}`, () => { PreferencesController: { preferences: { disabledUpgradeAccountsByChain: {}, + accountUpgradeDisabledChains: {}, }, }, }, diff --git a/app/scripts/migrations/157.ts b/app/scripts/migrations/157.ts index 4226e1d3e4c3..529b30402dab 100644 --- a/app/scripts/migrations/157.ts +++ b/app/scripts/migrations/157.ts @@ -38,4 +38,5 @@ function transformState(state: Record) { | undefined; delete preferences?.disabledUpgradeAccountsByChain; + delete preferences?.accountUpgradeDisabledChains; } From 9538c5ba0b4f7b5d427ce519fdc7e69fad8305a1 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 13 May 2025 10:57:56 +0530 Subject: [PATCH 10/12] update --- app/scripts/migrations/{157.test.ts => 158.test.ts} | 4 ++-- app/scripts/migrations/{157.ts => 158.ts} | 2 +- app/scripts/migrations/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename app/scripts/migrations/{157.test.ts => 158.test.ts} (95%) rename app/scripts/migrations/{157.ts => 158.ts} (97%) diff --git a/app/scripts/migrations/157.test.ts b/app/scripts/migrations/158.test.ts similarity index 95% rename from app/scripts/migrations/157.test.ts rename to app/scripts/migrations/158.test.ts index 2c616d9e3876..6973d2fadd04 100644 --- a/app/scripts/migrations/157.test.ts +++ b/app/scripts/migrations/158.test.ts @@ -1,6 +1,6 @@ -import { migrate, version } from './157'; +import { migrate, version } from './158'; -const oldVersion = 156; +const oldVersion = 157; describe(`migration #${version}`, () => { it('updates the version metadata', async () => { diff --git a/app/scripts/migrations/157.ts b/app/scripts/migrations/158.ts similarity index 97% rename from app/scripts/migrations/157.ts rename to app/scripts/migrations/158.ts index 529b30402dab..cebdcbc9ab62 100644 --- a/app/scripts/migrations/157.ts +++ b/app/scripts/migrations/158.ts @@ -5,7 +5,7 @@ type VersionedData = { data: Record; }; -export const version = 157; +export const version = 158; /** * This migration deletes the preference `disabledUpgradeAccountsByChain` if the user has diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index 87fb0b55ea91..d24b9609a8f7 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -184,7 +184,7 @@ const migrations = [ require('./154'), require('./155'), require('./156'), - require('./157'), + require('./158'), ]; export default migrations; From da803bbb4953e142f5e423a0dcbc64864c814158 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 13 May 2025 18:11:03 +0530 Subject: [PATCH 11/12] update --- app/scripts/migrations/152.2.test.ts | 57 ++++++++++++++++++++ app/scripts/migrations/{158.ts => 152.2.ts} | 2 +- app/scripts/migrations/158.test.ts | 59 --------------------- app/scripts/migrations/index.js | 2 +- 4 files changed, 59 insertions(+), 61 deletions(-) create mode 100644 app/scripts/migrations/152.2.test.ts rename app/scripts/migrations/{158.ts => 152.2.ts} (95%) delete mode 100644 app/scripts/migrations/158.test.ts diff --git a/app/scripts/migrations/152.2.test.ts b/app/scripts/migrations/152.2.test.ts new file mode 100644 index 000000000000..8ce16f85d911 --- /dev/null +++ b/app/scripts/migrations/152.2.test.ts @@ -0,0 +1,57 @@ +import { migrate, version } from './152.2'; + +const oldVersion = 152.1; + +describe(`migration #${version}`, () => { + it('updates the version metadata', async () => { + const oldStorage = { + meta: { version: oldVersion }, + data: {}, + }; + const newStorage = await migrate(oldStorage); + expect(newStorage.meta).toStrictEqual({ version }); + }); + + it('removes the disabledUpgradeAccountsByChain preference', async () => { + const oldStorage = { + meta: { version: oldVersion }, + data: { + PreferencesController: { + preferences: { + disabledUpgradeAccountsByChain: {}, + accountUpgradeDisabledChains: {}, + }, + }, + }, + }; + const expectedData = { + PreferencesController: { + preferences: {}, + }, + }; + const newStorage = await migrate(oldStorage); + + expect(newStorage.data).toStrictEqual(expectedData); + }); + + it('does nothing to other PreferencesController state if there is not a petnamesEnabled preference', async () => { + const oldStorage = { + meta: { version: oldVersion }, + data: { + PreferencesController: { + existingPreference: true, + }, + }, + }; + + const expectedData = { + PreferencesController: { + existingPreference: true, + }, + }; + + const newStorage = await migrate(oldStorage); + + expect(newStorage.data).toStrictEqual(expectedData); + }); +}); diff --git a/app/scripts/migrations/158.ts b/app/scripts/migrations/152.2.ts similarity index 95% rename from app/scripts/migrations/158.ts rename to app/scripts/migrations/152.2.ts index cebdcbc9ab62..c8cb567da110 100644 --- a/app/scripts/migrations/158.ts +++ b/app/scripts/migrations/152.2.ts @@ -8,7 +8,7 @@ type VersionedData = { export const version = 158; /** - * This migration deletes the preference `disabledUpgradeAccountsByChain` if the user has + * This migration deletes the preference `disabledUpgradeAccountsByChain`, `accountUpgradeDisabledChains` if the user has * existing data. * * @param originalVersionedData - Versioned MetaMask extension state, exactly diff --git a/app/scripts/migrations/158.test.ts b/app/scripts/migrations/158.test.ts deleted file mode 100644 index 6973d2fadd04..000000000000 --- a/app/scripts/migrations/158.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { migrate, version } from './158'; - -const oldVersion = 157; - -describe(`migration #${version}`, () => { - it('updates the version metadata', async () => { - const oldStorage = { - meta: { version: oldVersion }, - data: {}, - }; - const newStorage = await migrate(oldStorage); - expect(newStorage.meta).toStrictEqual({ version }); - }); - - describe(`migration #${version}`, () => { - it('removes the disabledUpgradeAccountsByChain preference', async () => { - const oldStorage = { - meta: { version: oldVersion }, - data: { - PreferencesController: { - preferences: { - disabledUpgradeAccountsByChain: {}, - accountUpgradeDisabledChains: {}, - }, - }, - }, - }; - const expectedData = { - PreferencesController: { - preferences: {}, - }, - }; - const newStorage = await migrate(oldStorage); - - expect(newStorage.data).toStrictEqual(expectedData); - }); - - it('does nothing to other PreferencesController state if there is not a petnamesEnabled preference', async () => { - const oldStorage = { - meta: { version: oldVersion }, - data: { - PreferencesController: { - existingPreference: true, - }, - }, - }; - - const expectedData = { - PreferencesController: { - existingPreference: true, - }, - }; - - const newStorage = await migrate(oldStorage); - - expect(newStorage.data).toStrictEqual(expectedData); - }); - }); -}); diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index 2d33865da4e1..d258bd96b58e 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -180,12 +180,12 @@ const migrations = [ require('./151'), require('./152'), require('./152.1'), + require('./152.2'), require('./153'), require('./154'), require('./155'), require('./156'), require('./157'), - require('./158'), ]; export default migrations; From 69837caeca8b307d136317e1f7c3eb9dfd0d9c2f Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 13 May 2025 18:59:04 +0530 Subject: [PATCH 12/12] update --- .../eip7702-eip5792-upgrade-account.spec.ts | 60 ------------------- 1 file changed, 60 deletions(-) diff --git a/test/e2e/tests/confirmations/transactions/eip7702-eip5792-upgrade-account.spec.ts b/test/e2e/tests/confirmations/transactions/eip7702-eip5792-upgrade-account.spec.ts index 80c6c9ccf18d..30090381ba2b 100644 --- a/test/e2e/tests/confirmations/transactions/eip7702-eip5792-upgrade-account.spec.ts +++ b/test/e2e/tests/confirmations/transactions/eip7702-eip5792-upgrade-account.spec.ts @@ -96,66 +96,6 @@ describe('Upgrade Account', function (this: Suite) { ); }); - it('an EOA account is not upgraded when rejecting a batch and upgrade transaction, and cannot trigger new send calls', async function () { - await withFixtures( - { - dapp: true, - fixtures: new FixtureBuilder() - .withPermissionControllerConnectedToTestDapp() - .build(), - localNodeOptions: [ - { - type: 'anvil', - options: { - hardfork: 'prague', - loadState: - './test/e2e/seeder/network-states/eip7702-state/withDelegatorContracts.json', - }, - }, - ], - testSpecificMock: mockEip7702FeatureFlag, - title: this.test?.fullTitle(), - }, - async ({ - driver, - localNodes, - }: { - driver: Driver; - localNodes: Anvil[]; - }) => { - await loginWithBalanceValidation(driver); - - // We check that we have an EOA account - let accountBytecode = await localNodes[0].getCode( - DEFAULT_FIXTURE_ACCOUNT, - ); - assert.strictEqual(accountBytecode, undefined); - - const testDapp = new TestDapp(driver); - await testDapp.openTestDappPage(); - await testDapp.clickSendCalls(); - - await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - const upgradeAndBatchTxConfirmation = new Eip7702AndSendCalls(driver); - - // Reject upgrade and batch tx - await upgradeAndBatchTxConfirmation.clickDontUseSmartAccountButton(); - - // We check that we continue to have an EOA account - accountBytecode = await localNodes[0].getCode(DEFAULT_FIXTURE_ACCOUNT); - assert.strictEqual(accountBytecode, undefined); - - // We check that we cannot perform new send calls as the upgrade tx was rejected - await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await testDapp.clickSendCalls(); - - await testDapp.checkEip5792SendCallsError( - 'Error: EIP-7702 upgrade rejected for this chain and account - Chain ID: 0x539, Account: 0x5cfe73b6021e818b776b421b1c4db2474086a7e1', - ); - }, - ); - }); - it('an EOA account is not upgraded when rejecting a batch transaction, but can trigger a new send call', async function () { await withFixtures( {