Skip to content

Commit d2070ab

Browse files
committed
integrating multichain controller upgrades
1 parent 4d98cea commit d2070ab

6 files changed

+231
-32
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@metamask/base-controller": "^3.2.1",
3232
"@metamask/controller-utils": "^5.0.0",
3333
"@metamask/network-controller": "^13.0.0",
34+
"@metamask/polling-controller": "^0.1.0",
3435
"bignumber.js": "^9.0.1",
3536
"fast-json-patch": "^3.1.0",
3637
"lodash": "^4.17.21"

src/SmartTransactionsController.test.ts

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ const createStateAfterPending = () => {
195195
uuid: 'uuid1',
196196
status: 'pending',
197197
cancellable: true,
198+
chainId: '0x1',
198199
statusMetadata: {
199200
cancellationFeeWei: 0,
200201
cancellationReason: 'not_cancelled',
@@ -223,6 +224,7 @@ const createStateAfterSuccess = () => {
223224
uuid: 'uuid2',
224225
status: 'success',
225226
cancellable: false,
227+
chainId: '0x1',
226228
statusMetadata: {
227229
cancellationFeeWei: 36777567771000,
228230
cancellationReason: 'not_cancelled',
@@ -269,6 +271,7 @@ describe('SmartTransactionsController', () => {
269271
provider: jest.fn(),
270272
confirmExternalTransaction: confirmExternalMock,
271273
trackMetaMetricsEvent: trackMetaMetricsEventSpy,
274+
getNetworkClientById: jest.fn(),
272275
});
273276
// eslint-disable-next-line jest/prefer-spy-on
274277
smartTransactionsController.subscribe = jest.fn();
@@ -283,7 +286,7 @@ describe('SmartTransactionsController', () => {
283286
it('initializes with default config', () => {
284287
expect(smartTransactionsController.config).toStrictEqual({
285288
interval: DEFAULT_INTERVAL,
286-
supportedChainIds: [CHAIN_IDS.ETHEREUM, CHAIN_IDS.RINKEBY],
289+
supportedChainIds: [CHAIN_IDS.ETHEREUM, CHAIN_IDS.GOERLI],
287290
chainId: CHAIN_IDS.ETHEREUM,
288291
clientId: 'default',
289292
});
@@ -300,20 +303,44 @@ describe('SmartTransactionsController', () => {
300303
approvalTxFees: undefined,
301304
tradeTxFees: undefined,
302305
},
306+
feesByChainId: {
307+
[CHAIN_IDS.ETHEREUM]: {
308+
approvalTxFees: undefined,
309+
tradeTxFees: undefined,
310+
},
311+
[CHAIN_IDS.GOERLI]: {
312+
approvalTxFees: undefined,
313+
tradeTxFees: undefined,
314+
},
315+
},
303316
liveness: true,
317+
livenessByChainId: {
318+
[CHAIN_IDS.ETHEREUM]: true,
319+
[CHAIN_IDS.GOERLI]: true,
320+
},
304321
},
305322
});
306323
});
307324

308325
describe('onNetworkChange', () => {
309326
it('is triggered', () => {
310-
networkListener({ providerConfig: { chainId: '52' } } as NetworkState);
311-
expect(smartTransactionsController.config.chainId).toBe('52');
327+
networkListener({
328+
providerConfig: { chainId: '0x32', type: 'rpc', ticker: 'CET' },
329+
selectedNetworkClientId: 'networkClientId',
330+
networkConfigurations: {},
331+
networksMetadata: {},
332+
} as NetworkState);
333+
expect(smartTransactionsController.config.chainId).toBe('0x32');
312334
});
313335

314336
it('calls poll', () => {
315337
const checkPollSpy = jest.spyOn(smartTransactionsController, 'checkPoll');
316-
networkListener({ providerConfig: { chainId: '2' } } as NetworkState);
338+
networkListener({
339+
providerConfig: { chainId: '0x32', type: 'rpc', ticker: 'CET' },
340+
selectedNetworkClientId: 'networkClientId',
341+
networkConfigurations: {},
342+
networksMetadata: {},
343+
} as NetworkState);
317344
expect(checkPollSpy).toHaveBeenCalled();
318345
});
319346
});
@@ -354,7 +381,12 @@ describe('SmartTransactionsController', () => {
354381
'updateSmartTransactions',
355382
);
356383
expect(updateSmartTransactionsSpy).not.toHaveBeenCalled();
357-
networkListener({ providerConfig: { chainId: '56' } } as NetworkState);
384+
networkListener({
385+
providerConfig: { chainId: '0x32', type: 'rpc', ticker: 'CET' },
386+
selectedNetworkClientId: 'networkClientId',
387+
networkConfigurations: {},
388+
networksMetadata: {},
389+
} as NetworkState);
358390
expect(updateSmartTransactionsSpy).not.toHaveBeenCalled();
359391
});
360392
});
@@ -489,7 +521,11 @@ describe('SmartTransactionsController', () => {
489521
nock(API_BASE_URL)
490522
.get(`/networks/${ethereumChainIdDec}/batchStatus?uuids=uuid1`)
491523
.reply(200, pendingBatchStatusApiResponse);
492-
await smartTransactionsController.fetchSmartTransactionsStatus(uuids);
524+
525+
await smartTransactionsController.fetchSmartTransactionsStatus(
526+
uuids,
527+
CHAIN_IDS.ETHEREUM,
528+
);
493529
const pendingState = createStateAfterPending()[0];
494530
const pendingTransaction = { ...pendingState, history: [pendingState] };
495531
expect(smartTransactionsController.state).toStrictEqual({
@@ -502,7 +538,21 @@ describe('SmartTransactionsController', () => {
502538
approvalTxFees: undefined,
503539
tradeTxFees: undefined,
504540
},
541+
feesByChainId: {
542+
[CHAIN_IDS.ETHEREUM]: {
543+
approvalTxFees: undefined,
544+
tradeTxFees: undefined,
545+
},
546+
[CHAIN_IDS.GOERLI]: {
547+
approvalTxFees: undefined,
548+
tradeTxFees: undefined,
549+
},
550+
},
505551
liveness: true,
552+
livenessByChainId: {
553+
[CHAIN_IDS.ETHEREUM]: true,
554+
[CHAIN_IDS.GOERLI]: true,
555+
},
506556
},
507557
});
508558
});
@@ -524,7 +574,11 @@ describe('SmartTransactionsController', () => {
524574
nock(API_BASE_URL)
525575
.get(`/networks/${ethereumChainIdDec}/batchStatus?uuids=uuid2`)
526576
.reply(200, successBatchStatusApiResponse);
527-
await smartTransactionsController.fetchSmartTransactionsStatus(uuids);
577+
578+
await smartTransactionsController.fetchSmartTransactionsStatus(
579+
uuids,
580+
CHAIN_IDS.ETHEREUM,
581+
);
528582
const successState = createStateAfterSuccess()[0];
529583
const successTransaction = { ...successState, history: [successState] };
530584
expect(smartTransactionsController.state).toStrictEqual({
@@ -541,6 +595,20 @@ describe('SmartTransactionsController', () => {
541595
tradeTxFees: undefined,
542596
},
543597
liveness: true,
598+
feesByChainId: {
599+
'0x1': {
600+
approvalTxFees: undefined,
601+
tradeTxFees: undefined,
602+
},
603+
'0x5': {
604+
approvalTxFees: undefined,
605+
tradeTxFees: undefined,
606+
},
607+
},
608+
livenessByChainId: {
609+
'0x1': true,
610+
'0x5': true,
611+
},
544612
},
545613
});
546614
});

0 commit comments

Comments
 (0)