diff --git a/test/integration/confirmations/transactions/contract-interaction.test.tsx b/test/integration/confirmations/transactions/contract-interaction.test.tsx index 7d07dc31e7db..d949a7447639 100644 --- a/test/integration/confirmations/transactions/contract-interaction.test.tsx +++ b/test/integration/confirmations/transactions/contract-interaction.test.tsx @@ -1,20 +1,22 @@ -import { fireEvent, waitFor, within } from '@testing-library/react'; import { ApprovalType } from '@metamask/controller-utils'; -import nock from 'nock'; import { TransactionType } from '@metamask/transaction-controller'; -import mockMetaMaskState from '../../data/integration-init-state.json'; -import { integrationTestRender } from '../../../lib/render-helpers'; -import * as backgroundConnection from '../../../../ui/store/background-connection'; +import { fireEvent, waitFor, within } from '@testing-library/react'; +import nock from 'nock'; import { MetaMetricsEventCategory, - MetaMetricsEventName, MetaMetricsEventLocation, + MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; +import * as backgroundConnection from '../../../../ui/store/background-connection'; +import { integrationTestRender } from '../../../lib/render-helpers'; +import mockMetaMaskState from '../../data/integration-init-state.json'; import { createMockImplementation, mock4byte } from '../../helpers'; import { getMaliciousUnapprovedTransaction, getUnapprovedTransaction, } from './transactionDataHelpers'; +import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails'; +import { useApproveTokenSimulation } from '../../../../ui/pages/confirmations/components/confirm/info/approve/hooks/use-approve-token-simulation'; jest.mock('../../../../ui/store/background-connection', () => ({ ...jest.requireActual('../../../../ui/store/background-connection'), @@ -22,6 +24,23 @@ jest.mock('../../../../ui/store/background-connection', () => ({ callBackgroundMethod: jest.fn(), })); +jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({ + ...jest.requireActual( + '../../../../ui/pages/confirmations/hooks/useAssetDetails', + ), + useAssetDetails: jest.fn(), +})); + +jest.mock( + '../../../../ui/pages/confirmations/components/confirm/info/approve/hooks/use-approve-token-simulation', + () => ({ + ...jest.requireActual( + '../../../../ui/pages/confirmations/components/confirm/info/approve/hooks/use-approve-token-simulation', + ), + useApproveTokenSimulation: jest.fn(), + }), +); + const mockedBackgroundConnection = jest.mocked(backgroundConnection); const backgroundConnectionMocked = { @@ -142,11 +161,26 @@ const getMetaMaskStateWithMaliciousUnapprovedContractInteraction = ( }; describe('Contract Interaction Confirmation', () => { + let useAssetDetailsMock, useApproveTokenSimulationMock; beforeEach(() => { jest.resetAllMocks(); setupSubmitRequestToBackgroundMocks(); const MINT_NFT_HEX_SIG = '0x3b4b1381'; mock4byte(MINT_NFT_HEX_SIG); + useAssetDetailsMock = jest.fn().mockImplementation(() => ({ + decimals: 18, + userBalance: '1000000', + tokenSymbol: 'TST', + })); + (useAssetDetails as jest.Mock).mockImplementation(useAssetDetailsMock); + useApproveTokenSimulationMock = jest.fn().mockImplementation(() => ({ + spendingCap: '1000', + formattedSpendingCap: '1000', + value: '1000', + })); + (useApproveTokenSimulation as jest.Mock).mockImplementation( + useApproveTokenSimulationMock, + ); }); afterEach(() => {