|
1 | 1 | import type { TypedTransaction } from '@ethereumjs/tx'; |
| 2 | +import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller'; |
2 | 3 | import type { |
3 | 4 | ApprovalControllerActions, |
4 | 5 | ApprovalControllerEvents, |
@@ -61,7 +62,8 @@ import * as etherscanUtils from './utils/etherscan'; |
61 | 62 | type UnrestrictedControllerMessenger = ControllerMessenger< |
62 | 63 | | NetworkControllerActions |
63 | 64 | | ApprovalControllerActions |
64 | | - | TransactionControllerActions, |
| 65 | + | TransactionControllerActions |
| 66 | + | AccountsControllerGetSelectedAccountAction, |
65 | 67 | | NetworkControllerEvents |
66 | 68 | | ApprovalControllerEvents |
67 | 69 | | TransactionControllerEvents |
@@ -188,10 +190,20 @@ const setupController = async ( |
188 | 190 | 'ApprovalController:addRequest', |
189 | 191 | 'NetworkController:getNetworkClientById', |
190 | 192 | 'NetworkController:findNetworkClientIdByChainId', |
| 193 | + 'AccountsController:getSelectedAccount', |
191 | 194 | ], |
192 | 195 | allowedEvents: ['NetworkController:stateChange'], |
193 | 196 | }); |
194 | 197 |
|
| 198 | + const mockSelectedAccountCall = jest |
| 199 | + .fn() |
| 200 | + .mockReturnValue(createMockInternalAccount({ address: '0xdeadbeef' })); |
| 201 | + |
| 202 | + unrestrictedMessenger.registerActionHandler( |
| 203 | + 'AccountsController:getSelectedAccount', |
| 204 | + mockSelectedAccountCall, |
| 205 | + ); |
| 206 | + |
195 | 207 | const options = { |
196 | 208 | blockTracker, |
197 | 209 | disableHistory: false, |
@@ -230,6 +242,7 @@ const setupController = async ( |
230 | 242 | approvalController, |
231 | 243 | networkController, |
232 | 244 | messenger, |
| 245 | + mockSelectedAccountCall, |
233 | 246 | }; |
234 | 247 | }; |
235 | 248 |
|
@@ -841,12 +854,16 @@ describe('TransactionController Integration', () => { |
841 | 854 | ], |
842 | 855 | }); |
843 | 856 |
|
844 | | - const { approvalController, networkController, transactionController } = |
845 | | - await setupController({ |
846 | | - isMultichainEnabled: true, |
847 | | - getPermittedAccounts: async () => [ACCOUNT_MOCK], |
848 | | - getSelectedAccount: () => INTERNAL_ACCOUNT_MOCK, |
849 | | - }); |
| 857 | + const { |
| 858 | + approvalController, |
| 859 | + networkController, |
| 860 | + transactionController, |
| 861 | + mockSelectedAccountCall, |
| 862 | + } = await setupController({ |
| 863 | + isMultichainEnabled: true, |
| 864 | + getPermittedAccounts: async () => [ACCOUNT_MOCK], |
| 865 | + }); |
| 866 | + mockSelectedAccountCall.mockReturnValue(INTERNAL_ACCOUNT_MOCK); |
850 | 867 | const otherNetworkClientIdOnGoerli = |
851 | 868 | await networkController.upsertNetworkConfiguration( |
852 | 869 | { |
@@ -922,12 +939,15 @@ describe('TransactionController Integration', () => { |
922 | 939 | buildEthGetTransactionReceiptRequestMock('0x2', '0x2', '0x4'), |
923 | 940 | ], |
924 | 941 | }); |
925 | | - const { approvalController, transactionController } = |
926 | | - await setupController({ |
927 | | - isMultichainEnabled: true, |
928 | | - getPermittedAccounts: async () => [ACCOUNT_MOCK], |
929 | | - getSelectedAccount: () => INTERNAL_ACCOUNT_MOCK, |
930 | | - }); |
| 942 | + const { |
| 943 | + approvalController, |
| 944 | + transactionController, |
| 945 | + mockSelectedAccountCall, |
| 946 | + } = await setupController({ |
| 947 | + isMultichainEnabled: true, |
| 948 | + getPermittedAccounts: async () => [ACCOUNT_MOCK], |
| 949 | + }); |
| 950 | + mockSelectedAccountCall.mockReturnValue(INTERNAL_ACCOUNT_MOCK); |
931 | 951 |
|
932 | 952 | const addTx1 = await transactionController.addTransaction( |
933 | 953 | { |
@@ -1187,11 +1207,14 @@ describe('TransactionController Integration', () => { |
1187 | 1207 | address: selectedAddress, |
1188 | 1208 | }); |
1189 | 1209 |
|
1190 | | - const { networkController, transactionController } = |
1191 | | - await setupController({ |
1192 | | - getSelectedAccount: () => selectedAccountMock, |
1193 | | - isMultichainEnabled: true, |
1194 | | - }); |
| 1210 | + const { |
| 1211 | + networkController, |
| 1212 | + transactionController, |
| 1213 | + mockSelectedAccountCall, |
| 1214 | + } = await setupController({ |
| 1215 | + isMultichainEnabled: true, |
| 1216 | + }); |
| 1217 | + mockSelectedAccountCall.mockReturnValue(selectedAccountMock); |
1195 | 1218 |
|
1196 | 1219 | const expectedLastFetchedBlockNumbers: Record<string, number> = {}; |
1197 | 1220 | const expectedTransactions: Partial<TransactionMeta>[] = []; |
@@ -1274,9 +1297,10 @@ describe('TransactionController Integration', () => { |
1274 | 1297 | ) |
1275 | 1298 | .reply(200, ETHERSCAN_TRANSACTION_RESPONSE_MOCK); |
1276 | 1299 |
|
1277 | | - const { transactionController } = await setupController({ |
1278 | | - getSelectedAccount: () => selectedAccountMock, |
1279 | | - }); |
| 1300 | + const { transactionController, mockSelectedAccountCall } = |
| 1301 | + await setupController({}); |
| 1302 | + |
| 1303 | + mockSelectedAccountCall.mockReturnValue(selectedAccountMock); |
1280 | 1304 |
|
1281 | 1305 | transactionController.startIncomingTransactionPolling(); |
1282 | 1306 |
|
@@ -1367,11 +1391,14 @@ describe('TransactionController Integration', () => { |
1367 | 1391 | address: selectedAddress, |
1368 | 1392 | }); |
1369 | 1393 |
|
1370 | | - const { networkController, transactionController } = |
1371 | | - await setupController({ |
1372 | | - getSelectedAccount: () => selectedAccountMock, |
1373 | | - isMultichainEnabled: true, |
1374 | | - }); |
| 1394 | + const { |
| 1395 | + networkController, |
| 1396 | + transactionController, |
| 1397 | + mockSelectedAccountCall, |
| 1398 | + } = await setupController({ |
| 1399 | + isMultichainEnabled: true, |
| 1400 | + }); |
| 1401 | + mockSelectedAccountCall.mockReturnValue(selectedAccountMock); |
1375 | 1402 |
|
1376 | 1403 | const otherGoerliClientNetworkClientId = |
1377 | 1404 | await networkController.upsertNetworkConfiguration( |
@@ -1466,10 +1493,12 @@ describe('TransactionController Integration', () => { |
1466 | 1493 | address: selectedAddress, |
1467 | 1494 | }); |
1468 | 1495 |
|
1469 | | - const { networkController, transactionController } = |
1470 | | - await setupController({ |
1471 | | - getSelectedAccount: () => selectedAccountMock, |
1472 | | - }); |
| 1496 | + const { |
| 1497 | + networkController, |
| 1498 | + transactionController, |
| 1499 | + mockSelectedAccountCall, |
| 1500 | + } = await setupController({}); |
| 1501 | + mockSelectedAccountCall.mockReturnValue(selectedAccountMock); |
1473 | 1502 |
|
1474 | 1503 | const networkClients = networkController.getNetworkClientRegistry(); |
1475 | 1504 | const networkClientIds = Object.keys(networkClients); |
@@ -1513,9 +1542,10 @@ describe('TransactionController Integration', () => { |
1513 | 1542 | address: selectedAddress, |
1514 | 1543 | }); |
1515 | 1544 |
|
1516 | | - const { transactionController } = await setupController({ |
1517 | | - getSelectedAccount: () => selectedAccountMock, |
1518 | | - }); |
| 1545 | + const { transactionController, mockSelectedAccountCall } = |
| 1546 | + await setupController({}); |
| 1547 | + |
| 1548 | + mockSelectedAccountCall.mockReturnValue(selectedAccountMock); |
1519 | 1549 |
|
1520 | 1550 | mockNetwork({ |
1521 | 1551 | networkClientConfiguration: buildInfuraNetworkClientConfiguration( |
@@ -1552,10 +1582,12 @@ describe('TransactionController Integration', () => { |
1552 | 1582 | address: selectedAddress, |
1553 | 1583 | }); |
1554 | 1584 |
|
1555 | | - const { networkController, transactionController } = |
1556 | | - await setupController({ |
1557 | | - getSelectedAccount: () => selectedAccountMock, |
1558 | | - }); |
| 1585 | + const { |
| 1586 | + networkController, |
| 1587 | + transactionController, |
| 1588 | + mockSelectedAccountCall, |
| 1589 | + } = await setupController({}); |
| 1590 | + mockSelectedAccountCall.mockReturnValue(selectedAccountMock); |
1559 | 1591 |
|
1560 | 1592 | const networkClients = networkController.getNetworkClientRegistry(); |
1561 | 1593 | const networkClientIds = Object.keys(networkClients); |
@@ -1599,11 +1631,14 @@ describe('TransactionController Integration', () => { |
1599 | 1631 | address: selectedAddress, |
1600 | 1632 | }); |
1601 | 1633 |
|
1602 | | - const { networkController, transactionController } = |
1603 | | - await setupController({ |
1604 | | - getSelectedAccount: () => selectedAccountMock, |
1605 | | - isMultichainEnabled: true, |
1606 | | - }); |
| 1634 | + const { |
| 1635 | + networkController, |
| 1636 | + transactionController, |
| 1637 | + mockSelectedAccountCall, |
| 1638 | + } = await setupController({ |
| 1639 | + isMultichainEnabled: true, |
| 1640 | + }); |
| 1641 | + mockSelectedAccountCall.mockReturnValue(selectedAccountMock); |
1607 | 1642 |
|
1608 | 1643 | const expectedLastFetchedBlockNumbers: Record<string, number> = {}; |
1609 | 1644 | const expectedTransactions: Partial<TransactionMeta>[] = []; |
@@ -1668,9 +1703,9 @@ describe('TransactionController Integration', () => { |
1668 | 1703 | address: selectedAddress, |
1669 | 1704 | }); |
1670 | 1705 |
|
1671 | | - const { transactionController } = await setupController({ |
1672 | | - getSelectedAccount: () => selectedAccountMock, |
1673 | | - }); |
| 1706 | + const { transactionController, mockSelectedAccountCall } = |
| 1707 | + await setupController({}); |
| 1708 | + mockSelectedAccountCall.mockReturnValue(selectedAccountMock); |
1674 | 1709 |
|
1675 | 1710 | mockNetwork({ |
1676 | 1711 | networkClientConfiguration: buildInfuraNetworkClientConfiguration( |
|
0 commit comments