@@ -11,6 +11,8 @@ import {
1111 InfuraNetworkType ,
1212 NetworkType ,
1313} from '@metamask/controller-utils' ;
14+ import type { InternalAccount } from '@metamask/keyring-api' ;
15+ import { EthAccountType , EthMethod } from '@metamask/keyring-api' ;
1416import {
1517 NetworkController ,
1618 NetworkClientType ,
@@ -25,6 +27,7 @@ import assert from 'assert';
2527import nock from 'nock' ;
2628import type { SinonFakeTimers } from 'sinon' ;
2729import { useFakeTimers } from 'sinon' ;
30+ import { v4 } from 'uuid' ;
2831
2932import { advanceTime } from '../../../tests/helpers' ;
3033import { mockNetwork } from '../../../tests/mock-network' ;
@@ -64,7 +67,46 @@ type UnrestrictedControllerMessenger = ControllerMessenger<
6467 | TransactionControllerEvents
6568> ;
6669
70+ const createMockInternalAccount = ( {
71+ id = v4 ( ) ,
72+ address = '0x2990079bcdee240329a520d2444386fc119da21a' ,
73+ name = 'Account 1' ,
74+ importTime = Date . now ( ) ,
75+ lastSelected = Date . now ( ) ,
76+ } : {
77+ id ?: string ;
78+ address ?: string ;
79+ name ?: string ;
80+ importTime ?: number ;
81+ lastSelected ?: number ;
82+ } = { } ) : InternalAccount => {
83+ return {
84+ id,
85+ address,
86+ options : { } ,
87+ methods : [
88+ EthMethod . PersonalSign ,
89+ EthMethod . Sign ,
90+ EthMethod . SignTransaction ,
91+ EthMethod . SignTypedDataV1 ,
92+ EthMethod . SignTypedDataV3 ,
93+ EthMethod . SignTypedDataV4 ,
94+ ] ,
95+ type : EthAccountType . Eoa ,
96+ metadata : {
97+ name,
98+ keyring : { type : 'HD Key Tree' } ,
99+ importTime,
100+ lastSelected,
101+ } ,
102+ } as InternalAccount ;
103+ } ;
104+
67105const ACCOUNT_MOCK = '0x6bf137f335ea1b8f193b8f6ea92561a60d23a207' ;
106+ const INTERNAL_ACCOUNT_MOCK = createMockInternalAccount ( {
107+ address : ACCOUNT_MOCK ,
108+ } ) ;
109+
68110const ACCOUNT_2_MOCK = '0x08f137f335ea1b8f193b8f6ea92561a60d23a211' ;
69111const ACCOUNT_3_MOCK = '0xe688b84b23f322a994a53dbf8e15fa82cdb71127' ;
70112const infuraProjectId = 'fake-infura-project-id' ;
@@ -167,7 +209,8 @@ const setupController = async (
167209 getNetworkClientRegistry :
168210 networkController . getNetworkClientRegistry . bind ( networkController ) ,
169211 getPermittedAccounts : async ( ) => [ ACCOUNT_MOCK ] ,
170- getSelectedAddress : ( ) => '0xdeadbeef' ,
212+ getSelectedAccount : ( ) =>
213+ createMockInternalAccount ( { address : '0xdeadbeef' } ) ,
171214 hooks : { } ,
172215 isMultichainEnabled : false ,
173216 messenger,
@@ -802,7 +845,7 @@ describe('TransactionController Integration', () => {
802845 await setupController ( {
803846 isMultichainEnabled : true ,
804847 getPermittedAccounts : async ( ) => [ ACCOUNT_MOCK ] ,
805- getSelectedAddress : ( ) => ACCOUNT_MOCK ,
848+ getSelectedAccount : ( ) => INTERNAL_ACCOUNT_MOCK ,
806849 } ) ;
807850 const otherNetworkClientIdOnGoerli =
808851 await networkController . upsertNetworkConfiguration (
@@ -883,7 +926,7 @@ describe('TransactionController Integration', () => {
883926 await setupController ( {
884927 isMultichainEnabled : true ,
885928 getPermittedAccounts : async ( ) => [ ACCOUNT_MOCK ] ,
886- getSelectedAddress : ( ) => ACCOUNT_MOCK ,
929+ getSelectedAccount : ( ) => INTERNAL_ACCOUNT_MOCK ,
887930 } ) ;
888931
889932 const addTx1 = await transactionController . addTransaction (
@@ -1140,10 +1183,13 @@ describe('TransactionController Integration', () => {
11401183 } ) ;
11411184
11421185 const selectedAddress = ETHERSCAN_TRANSACTION_BASE_MOCK . to ;
1186+ const selectedAccountMock = createMockInternalAccount ( {
1187+ address : selectedAddress ,
1188+ } ) ;
11431189
11441190 const { networkController, transactionController } =
11451191 await setupController ( {
1146- getSelectedAddress : ( ) => selectedAddress ,
1192+ getSelectedAccount : ( ) => selectedAccountMock ,
11471193 isMultichainEnabled : true ,
11481194 } ) ;
11491195
@@ -1209,6 +1255,9 @@ describe('TransactionController Integration', () => {
12091255
12101256 it ( 'should start the global incoming transaction helper when no networkClientIds provided' , async ( ) => {
12111257 const selectedAddress = ETHERSCAN_TRANSACTION_BASE_MOCK . to ;
1258+ const selectedAccountMock = createMockInternalAccount ( {
1259+ address : selectedAddress ,
1260+ } ) ;
12121261
12131262 mockNetwork ( {
12141263 networkClientConfiguration : buildInfuraNetworkClientConfiguration (
@@ -1226,7 +1275,7 @@ describe('TransactionController Integration', () => {
12261275 . reply ( 200 , ETHERSCAN_TRANSACTION_RESPONSE_MOCK ) ;
12271276
12281277 const { transactionController } = await setupController ( {
1229- getSelectedAddress : ( ) => selectedAddress ,
1278+ getSelectedAccount : ( ) => selectedAccountMock ,
12301279 } ) ;
12311280
12321281 transactionController . startIncomingTransactionPolling ( ) ;
@@ -1314,10 +1363,13 @@ describe('TransactionController Integration', () => {
13141363 } ) ;
13151364
13161365 const selectedAddress = ETHERSCAN_TRANSACTION_BASE_MOCK . to ;
1366+ const selectedAccountMock = createMockInternalAccount ( {
1367+ address : selectedAddress ,
1368+ } ) ;
13171369
13181370 const { networkController, transactionController } =
13191371 await setupController ( {
1320- getSelectedAddress : ( ) => selectedAddress ,
1372+ getSelectedAccount : ( ) => selectedAccountMock ,
13211373 isMultichainEnabled : true ,
13221374 } ) ;
13231375
@@ -1410,10 +1462,13 @@ describe('TransactionController Integration', () => {
14101462 describe ( 'stopIncomingTransactionPolling' , ( ) => {
14111463 it ( 'should not poll for new incoming transactions for the given networkClientId' , async ( ) => {
14121464 const selectedAddress = ETHERSCAN_TRANSACTION_BASE_MOCK . to ;
1465+ const selectedAccountMock = createMockInternalAccount ( {
1466+ address : selectedAddress ,
1467+ } ) ;
14131468
14141469 const { networkController, transactionController } =
14151470 await setupController ( {
1416- getSelectedAddress : ( ) => selectedAddress ,
1471+ getSelectedAccount : ( ) => selectedAccountMock ,
14171472 } ) ;
14181473
14191474 const networkClients = networkController . getNetworkClientRegistry ( ) ;
@@ -1454,9 +1509,12 @@ describe('TransactionController Integration', () => {
14541509
14551510 it ( 'should stop the global incoming transaction helper when no networkClientIds provided' , async ( ) => {
14561511 const selectedAddress = ETHERSCAN_TRANSACTION_BASE_MOCK . to ;
1512+ const selectedAccountMock = createMockInternalAccount ( {
1513+ address : selectedAddress ,
1514+ } ) ;
14571515
14581516 const { transactionController } = await setupController ( {
1459- getSelectedAddress : ( ) => selectedAddress ,
1517+ getSelectedAccount : ( ) => selectedAccountMock ,
14601518 } ) ;
14611519
14621520 mockNetwork ( {
@@ -1490,10 +1548,13 @@ describe('TransactionController Integration', () => {
14901548 describe ( 'stopAllIncomingTransactionPolling' , ( ) => {
14911549 it ( 'should not poll for incoming transactions on any network client' , async ( ) => {
14921550 const selectedAddress = ETHERSCAN_TRANSACTION_BASE_MOCK . to ;
1551+ const selectedAccountMock = createMockInternalAccount ( {
1552+ address : selectedAddress ,
1553+ } ) ;
14931554
14941555 const { networkController, transactionController } =
14951556 await setupController ( {
1496- getSelectedAddress : ( ) => selectedAddress ,
1557+ getSelectedAccount : ( ) => selectedAccountMock ,
14971558 } ) ;
14981559
14991560 const networkClients = networkController . getNetworkClientRegistry ( ) ;
@@ -1534,10 +1595,13 @@ describe('TransactionController Integration', () => {
15341595 describe ( 'updateIncomingTransactions' , ( ) => {
15351596 it ( 'should add incoming transactions to state with the correct chainId for the given networkClientId without waiting for the next block' , async ( ) => {
15361597 const selectedAddress = ETHERSCAN_TRANSACTION_BASE_MOCK . to ;
1598+ const selectedAccountMock = createMockInternalAccount ( {
1599+ address : selectedAddress ,
1600+ } ) ;
15371601
15381602 const { networkController, transactionController } =
15391603 await setupController ( {
1540- getSelectedAddress : ( ) => selectedAddress ,
1604+ getSelectedAccount : ( ) => selectedAccountMock ,
15411605 isMultichainEnabled : true ,
15421606 } ) ;
15431607
@@ -1600,9 +1664,12 @@ describe('TransactionController Integration', () => {
16001664
16011665 it ( 'should update the incoming transactions for the gloablly selected network when no networkClientIds provided' , async ( ) => {
16021666 const selectedAddress = ETHERSCAN_TRANSACTION_BASE_MOCK . to ;
1667+ const selectedAccountMock = createMockInternalAccount ( {
1668+ address : selectedAddress ,
1669+ } ) ;
16031670
16041671 const { transactionController } = await setupController ( {
1605- getSelectedAddress : ( ) => selectedAddress ,
1672+ getSelectedAccount : ( ) => selectedAccountMock ,
16061673 } ) ;
16071674
16081675 mockNetwork ( {
0 commit comments