From c825cc3761d4f98ee52806c49e2e876bc1d66575 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Wed, 21 Feb 2024 10:14:11 +0000 Subject: [PATCH 1/7] wip --- src/SmartTransactionsController.ts | 52 ++++++++++++++++++------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/SmartTransactionsController.ts b/src/SmartTransactionsController.ts index 6e2360d1..d0d9f0d7 100644 --- a/src/SmartTransactionsController.ts +++ b/src/SmartTransactionsController.ts @@ -1,13 +1,13 @@ // eslint-disable-next-line import/no-nodejs-modules import { hexlify } from '@ethersproject/bytes'; import type { BaseConfig, BaseState } from '@metamask/base-controller'; -import { safelyExecute, query } from '@metamask/controller-utils'; +import { query, safelyExecute } from '@metamask/controller-utils'; import type { Provider } from '@metamask/eth-query'; import EthQuery from '@metamask/eth-query'; import type { - NetworkState, - NetworkController, NetworkClientId, + NetworkController, + NetworkState } from '@metamask/network-controller'; import { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller'; import { BigNumber } from 'bignumber.js'; @@ -21,27 +21,27 @@ import { MetaMetricsEventName, } from './constants'; import type { - SmartTransaction, - SignedTransaction, - SignedCanceledTransaction, - UnsignedTransaction, - SmartTransactionsStatus, Fees, - IndividualTxFees, Hex, + IndividualTxFees, + SignedCanceledTransaction, + SignedTransaction, + SmartTransaction, + SmartTransactionsStatus, + UnsignedTransaction, } from './types'; import { APIType, SmartTransactionStatuses } from './types'; import { - getAPIRequestURL, - isSmartTransactionPending, calculateStatus, - snapshotFromTxMeta, - replayHistory, generateHistoryEntry, + getAPIRequestURL, getStxProcessingTime, handleFetch, - isSmartTransactionCancellable, incrementNonceInHex, + isSmartTransactionCancellable, + isSmartTransactionPending, + replayHistory, + snapshotFromTxMeta, } from './utils'; const SECOND = 1000; @@ -84,7 +84,11 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo private readonly getNonceLock: any; - private ethQuery: EthQuery; + private ethQuery!: EthQuery; + + private onNetworkStateChange: ( + listener: (networkState: NetworkState) => void, + ) => void; public confirmExternalTransaction: any; @@ -168,23 +172,29 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo this.initialize(); this.setIntervalLength(this.config.interval); this.getNonceLock = getNonceLock; - this.ethQuery = new EthQuery(provider); + this.confirmExternalTransaction = confirmExternalTransaction; this.trackMetaMetricsEvent = trackMetaMetricsEvent; this.getNetworkClientById = getNetworkClientById; this.initializeSmartTransactionsForChainId(); - onNetworkStateChange(({ providerConfig: newProvider }) => { + this.onNetworkStateChange = onNetworkStateChange; + + this.subscribe((currentState: any) => this.checkPoll(currentState)); + this.eventEmitter = new EventEmitter(); + } + + delayedInit(passedProvider: Provider) { + this.ethQuery = new EthQuery(passedProvider); + + this.onNetworkStateChange(({ providerConfig: newProvider }) => { const { chainId } = newProvider; this.configure({ chainId }); this.initializeSmartTransactionsForChainId(); this.checkPoll(this.state); - this.ethQuery = new EthQuery(provider); + this.ethQuery = new EthQuery(passedProvider); }); - - this.subscribe((currentState: any) => this.checkPoll(currentState)); - this.eventEmitter = new EventEmitter(); } async _executePoll(networkClientId: string): Promise { From 5f667aa83b3862ce54d401f578d726bab5f01fd7 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Wed, 21 Feb 2024 17:34:41 +0000 Subject: [PATCH 2/7] lint fix --- src/SmartTransactionsController.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/SmartTransactionsController.ts b/src/SmartTransactionsController.ts index d0d9f0d7..88a81814 100644 --- a/src/SmartTransactionsController.ts +++ b/src/SmartTransactionsController.ts @@ -116,7 +116,6 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo { onNetworkStateChange, getNonceLock, - provider, confirmExternalTransaction, trackMetaMetricsEvent, getNetworkClientById, @@ -125,7 +124,6 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo listener: (networkState: NetworkState) => void, ) => void; getNonceLock: any; - provider: Provider; confirmExternalTransaction: any; trackMetaMetricsEvent: any; getNetworkClientById: NetworkController['getNetworkClientById']; @@ -172,7 +170,7 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo this.initialize(); this.setIntervalLength(this.config.interval); this.getNonceLock = getNonceLock; - + this.confirmExternalTransaction = confirmExternalTransaction; this.trackMetaMetricsEvent = trackMetaMetricsEvent; this.getNetworkClientById = getNetworkClientById; From 96112c34a6c154e6c03f0709c7894034d84b8834 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Thu, 22 Feb 2024 11:01:02 +0000 Subject: [PATCH 3/7] fix unit tests --- src/SmartTransactionsController.test.ts | 24 +++++++++++++++++++----- src/index.test.ts | 1 - yarn.lock | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/SmartTransactionsController.test.ts b/src/SmartTransactionsController.test.ts index 998fff44..544030c5 100644 --- a/src/SmartTransactionsController.test.ts +++ b/src/SmartTransactionsController.test.ts @@ -1,19 +1,20 @@ import { convertHexToDecimal } from '@metamask/controller-utils'; +import { providerFromEngine } from '@metamask/eth-json-rpc-provider'; +import { JsonRpcEngine } from '@metamask/json-rpc-engine'; import type { NetworkState } from '@metamask/network-controller'; import nock from 'nock'; import * as sinon from 'sinon'; - // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore -import { API_BASE_URL, CHAIN_IDS } from './constants'; +import packageJson from '../package.json'; import SmartTransactionsController, { DEFAULT_INTERVAL, } from './SmartTransactionsController'; -import { flushPromises, advanceTime } from './test-helpers'; +import { API_BASE_URL, CHAIN_IDS } from './constants'; +import { advanceTime, flushPromises } from './test-helpers'; import type { SmartTransaction, UnsignedTransaction } from './types'; import { SmartTransactionStatuses } from './types'; import * as utils from './utils'; -import packageJson from '../package.json'; jest.mock('@ethersproject/bytes', () => ({ ...jest.requireActual('@ethersproject/bytes'), @@ -322,7 +323,6 @@ describe('SmartTransactionsController', () => { releaseLock: jest.fn(), }; }), - provider: { sendAsync: jest.fn() }, confirmExternalTransaction: jest.fn(), trackMetaMetricsEvent: trackMetaMetricsEventSpy, getNetworkClientById: jest.fn().mockImplementation((networkClientId) => { @@ -346,6 +346,10 @@ describe('SmartTransactionsController', () => { }); // eslint-disable-next-line jest/prefer-spy-on smartTransactionsController.subscribe = jest.fn(); + + const engine = new JsonRpcEngine(); + const testProvider = providerFromEngine(engine); + smartTransactionsController.delayedInit(testProvider); }); afterEach(async () => { @@ -744,6 +748,10 @@ describe('SmartTransactionsController', () => { }); it('fetches liveness and sets in feesByChainId state for the Smart Transactions API for the chainId of the networkClientId passed in', async () => { + const originalConsoleLogFn = global.console.log; + const consoleLogMockFn = jest.fn(); + global.console.log = consoleLogMockFn; + nock(API_BASE_URL) .get(`/networks/${goerliChainIdDec}/health`) .replyWithError('random error'); @@ -767,6 +775,12 @@ describe('SmartTransactionsController', () => { [CHAIN_IDS.ETHEREUM]: true, [CHAIN_IDS.GOERLI]: false, }); + + expect(consoleLogMockFn).toHaveBeenCalledWith( + '"fetchLiveness" API call failed', + ); + + global.console.log = originalConsoleLogFn; }); }); diff --git a/src/index.test.ts b/src/index.test.ts index f99e22bb..17fdd4fb 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -7,7 +7,6 @@ describe('default export', () => { const controller = new DefaultExport({ onNetworkStateChange: jest.fn(), getNonceLock: null, - provider: { sendAsync: jest.fn() }, confirmExternalTransaction: jest.fn(), trackMetaMetricsEvent: jest.fn(), getNetworkClientById: jest.fn(), diff --git a/yarn.lock b/yarn.lock index dd6f43fe..cbbef66f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1109,6 +1109,7 @@ __metadata: "@metamask/eslint-config-nodejs": ^12.1.0 "@metamask/eslint-config-typescript": ^12.1.0 "@metamask/eth-query": ^4.0.0 + "@metamask/json-rpc-engine": ^7.3.2 "@metamask/network-controller": ^17.2.0 "@metamask/polling-controller": ^5.0.0 "@types/jest": ^26.0.24 From e052bd75bdead59e0f841ae86af3ba66700703f0 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Tue, 27 Feb 2024 15:43:22 +0000 Subject: [PATCH 4/7] Pass the nonce lock at the initialization step --- src/SmartTransactionsController.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/SmartTransactionsController.ts b/src/SmartTransactionsController.ts index 88a81814..6f4b2cec 100644 --- a/src/SmartTransactionsController.ts +++ b/src/SmartTransactionsController.ts @@ -115,7 +115,6 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo constructor( { onNetworkStateChange, - getNonceLock, confirmExternalTransaction, trackMetaMetricsEvent, getNetworkClientById, @@ -123,7 +122,6 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo onNetworkStateChange: ( listener: (networkState: NetworkState) => void, ) => void; - getNonceLock: any; confirmExternalTransaction: any; trackMetaMetricsEvent: any; getNetworkClientById: NetworkController['getNetworkClientById']; @@ -169,7 +167,6 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo this.initialize(); this.setIntervalLength(this.config.interval); - this.getNonceLock = getNonceLock; this.confirmExternalTransaction = confirmExternalTransaction; this.trackMetaMetricsEvent = trackMetaMetricsEvent; @@ -183,8 +180,10 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo this.eventEmitter = new EventEmitter(); } - delayedInit(passedProvider: Provider) { + delayedInit(passedProvider: Provider, getNonceLock: any) { this.ethQuery = new EthQuery(passedProvider); + + this.getNonceLock = getNonceLock; this.onNetworkStateChange(({ providerConfig: newProvider }) => { const { chainId } = newProvider; From 711956c6e69c1c43d811ff85f5a28b67503d323a Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Thu, 7 Mar 2024 19:38:17 +0000 Subject: [PATCH 5/7] remove delayedInit function --- src/SmartTransactionsController.ts | 53 ++++++++++++++++-------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/SmartTransactionsController.ts b/src/SmartTransactionsController.ts index 6f4b2cec..c0dce13d 100644 --- a/src/SmartTransactionsController.ts +++ b/src/SmartTransactionsController.ts @@ -46,6 +46,7 @@ import { const SECOND = 1000; export const DEFAULT_INTERVAL = SECOND * 5; +const ETH_QUERY_ERROR_MSG = "`ethQuery` is not defined on SmartTransactionsController" export type SmartTransactionsControllerConfig = BaseConfig & { interval: number; @@ -84,11 +85,7 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo private readonly getNonceLock: any; - private ethQuery!: EthQuery; - - private onNetworkStateChange: ( - listener: (networkState: NetworkState) => void, - ) => void; + private ethQuery: EthQuery | undefined; public confirmExternalTransaction: any; @@ -115,6 +112,8 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo constructor( { onNetworkStateChange, + getNonceLock, + provider, confirmExternalTransaction, trackMetaMetricsEvent, getNetworkClientById, @@ -122,6 +121,8 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo onNetworkStateChange: ( listener: (networkState: NetworkState) => void, ) => void; + getNonceLock: any; + provider: Provider; confirmExternalTransaction: any; trackMetaMetricsEvent: any; getNetworkClientById: NetworkController['getNetworkClientById']; @@ -167,31 +168,24 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo this.initialize(); this.setIntervalLength(this.config.interval); - + this.getNonceLock = getNonceLock; + this.ethQuery = undefined; this.confirmExternalTransaction = confirmExternalTransaction; this.trackMetaMetricsEvent = trackMetaMetricsEvent; this.getNetworkClientById = getNetworkClientById; this.initializeSmartTransactionsForChainId(); - this.onNetworkStateChange = onNetworkStateChange; - - this.subscribe((currentState: any) => this.checkPoll(currentState)); - this.eventEmitter = new EventEmitter(); - } - - delayedInit(passedProvider: Provider, getNonceLock: any) { - this.ethQuery = new EthQuery(passedProvider); - - this.getNonceLock = getNonceLock; - - this.onNetworkStateChange(({ providerConfig: newProvider }) => { + onNetworkStateChange(({ providerConfig: newProvider }) => { const { chainId } = newProvider; this.configure({ chainId }); this.initializeSmartTransactionsForChainId(); this.checkPoll(this.state); - this.ethQuery = new EthQuery(passedProvider); + this.ethQuery = new EthQuery(provider); }); + + this.subscribe((currentState: any) => this.checkPoll(currentState)); + this.eventEmitter = new EventEmitter(); } async _executePoll(networkClientId: string): Promise { @@ -340,7 +334,7 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo ethQuery = this.ethQuery, }: { chainId: Hex; - ethQuery: EthQuery; + ethQuery: EthQuery | undefined; }, ): void { const { smartTransactionsState } = this.state; @@ -352,6 +346,9 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo const isNewSmartTransaction = this.isNewSmartTransaction( smartTransaction.uuid, ); + if (this.ethQuery === undefined) { + throw new Error(ETH_QUERY_ERROR_MSG) + } this.trackStxStatusChange( smartTransaction, @@ -452,12 +449,15 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo ethQuery = this.ethQuery, }: { chainId: Hex; - ethQuery: EthQuery; + ethQuery: EthQuery | undefined; }, ) { if (smartTransaction.skipConfirm) { return; } + if (ethQuery === undefined) { + throw new Error(ETH_QUERY_ERROR_MSG) + } const txHash = smartTransaction.statusMetadata?.minedHash; try { const transactionReceipt: { @@ -751,9 +751,14 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo }: { networkClientId?: NetworkClientId; } = {}): EthQuery { - return networkClientId - ? new EthQuery(this.getNetworkClientById(networkClientId).provider) - : this.ethQuery; + if (networkClientId) { + return new EthQuery(this.getNetworkClientById(networkClientId).provider) + } else { + if (this.ethQuery === undefined) { + throw new Error(ETH_QUERY_ERROR_MSG) + } + return this.ethQuery + } } // TODO: This should return if the cancellation was on chain or not (for nonce management) From 31711e86359198004bc35b7062d06c3915fbb816 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Fri, 8 Mar 2024 13:49:45 +0000 Subject: [PATCH 6/7] fix tests --- src/SmartTransactionsController.test.ts | 47 +++++++++++++++++++++---- src/SmartTransactionsController.ts | 23 ++++++------ src/index.test.ts | 1 + yarn.lock | 1 - 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/src/SmartTransactionsController.test.ts b/src/SmartTransactionsController.test.ts index 544030c5..db9bbdf9 100644 --- a/src/SmartTransactionsController.test.ts +++ b/src/SmartTransactionsController.test.ts @@ -1,7 +1,6 @@ -import { convertHexToDecimal } from '@metamask/controller-utils'; -import { providerFromEngine } from '@metamask/eth-json-rpc-provider'; -import { JsonRpcEngine } from '@metamask/json-rpc-engine'; +import { NetworkType, convertHexToDecimal } from '@metamask/controller-utils'; import type { NetworkState } from '@metamask/network-controller'; +import { NetworkStatus } from '@metamask/network-controller'; import nock from 'nock'; import * as sinon from 'sinon'; // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -309,12 +308,47 @@ const defaultState = { }, }; +const mockProvider = { + sendAsync: jest.fn(), +}; + +const mockProviderConfig = { + chainId: '0x1' as `0x${string}`, + provider: mockProvider, + type: NetworkType.mainnet, + ticker: 'ticker', +}; + +const mockNetworkState = { + providerConfig: mockProviderConfig, + selectedNetworkClientId: 'id', + networkConfigurations: { + id: { + id: 'id', + rpcUrl: 'string', + chainId: '0x1' as `0x${string}`, + ticker: 'string', + }, + }, + networksMetadata: { + id: { + EIPS: { + 1155: true, + }, + status: NetworkStatus.Available, + }, + }, +}; + describe('SmartTransactionsController', () => { let smartTransactionsController: SmartTransactionsController; let networkListener: (networkState: NetworkState) => void; + beforeEach(() => { smartTransactionsController = new SmartTransactionsController({ - onNetworkStateChange: (listener) => { + onNetworkStateChange: ( + listener: (networkState: NetworkState) => void, + ) => { networkListener = listener; }, getNonceLock: jest.fn(() => { @@ -323,6 +357,7 @@ describe('SmartTransactionsController', () => { releaseLock: jest.fn(), }; }), + provider: { sendAsync: jest.fn() }, confirmExternalTransaction: jest.fn(), trackMetaMetricsEvent: trackMetaMetricsEventSpy, getNetworkClientById: jest.fn().mockImplementation((networkClientId) => { @@ -347,9 +382,7 @@ describe('SmartTransactionsController', () => { // eslint-disable-next-line jest/prefer-spy-on smartTransactionsController.subscribe = jest.fn(); - const engine = new JsonRpcEngine(); - const testProvider = providerFromEngine(engine); - smartTransactionsController.delayedInit(testProvider); + networkListener(mockNetworkState); }); afterEach(async () => { diff --git a/src/SmartTransactionsController.ts b/src/SmartTransactionsController.ts index c0dce13d..7fc3a6b5 100644 --- a/src/SmartTransactionsController.ts +++ b/src/SmartTransactionsController.ts @@ -11,8 +11,8 @@ import type { } from '@metamask/network-controller'; import { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller'; import { BigNumber } from 'bignumber.js'; +import EventEmitter from 'events'; // eslint-disable-next-line import/no-nodejs-modules -import { EventEmitter } from 'events'; import cloneDeep from 'lodash/cloneDeep'; import { @@ -46,7 +46,8 @@ import { const SECOND = 1000; export const DEFAULT_INTERVAL = SECOND * 5; -const ETH_QUERY_ERROR_MSG = "`ethQuery` is not defined on SmartTransactionsController" +const ETH_QUERY_ERROR_MSG = + '`ethQuery` is not defined on SmartTransactionsController'; export type SmartTransactionsControllerConfig = BaseConfig & { interval: number; @@ -347,7 +348,7 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo smartTransaction.uuid, ); if (this.ethQuery === undefined) { - throw new Error(ETH_QUERY_ERROR_MSG) + throw new Error(ETH_QUERY_ERROR_MSG); } this.trackStxStatusChange( @@ -455,8 +456,9 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo if (smartTransaction.skipConfirm) { return; } + if (ethQuery === undefined) { - throw new Error(ETH_QUERY_ERROR_MSG) + throw new Error(ETH_QUERY_ERROR_MSG); } const txHash = smartTransaction.statusMetadata?.minedHash; try { @@ -752,13 +754,14 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo networkClientId?: NetworkClientId; } = {}): EthQuery { if (networkClientId) { - return new EthQuery(this.getNetworkClientById(networkClientId).provider) - } else { - if (this.ethQuery === undefined) { - throw new Error(ETH_QUERY_ERROR_MSG) - } - return this.ethQuery + return new EthQuery(this.getNetworkClientById(networkClientId).provider); } + + if (this.ethQuery === undefined) { + throw new Error(ETH_QUERY_ERROR_MSG); + } + + return this.ethQuery; } // TODO: This should return if the cancellation was on chain or not (for nonce management) diff --git a/src/index.test.ts b/src/index.test.ts index 17fdd4fb..f99e22bb 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -7,6 +7,7 @@ describe('default export', () => { const controller = new DefaultExport({ onNetworkStateChange: jest.fn(), getNonceLock: null, + provider: { sendAsync: jest.fn() }, confirmExternalTransaction: jest.fn(), trackMetaMetricsEvent: jest.fn(), getNetworkClientById: jest.fn(), diff --git a/yarn.lock b/yarn.lock index cbbef66f..dd6f43fe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1109,7 +1109,6 @@ __metadata: "@metamask/eslint-config-nodejs": ^12.1.0 "@metamask/eslint-config-typescript": ^12.1.0 "@metamask/eth-query": ^4.0.0 - "@metamask/json-rpc-engine": ^7.3.2 "@metamask/network-controller": ^17.2.0 "@metamask/polling-controller": ^5.0.0 "@types/jest": ^26.0.24 From f5032538f64aa8597de95a4b4d679ec298b65af8 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Fri, 8 Mar 2024 14:07:36 +0000 Subject: [PATCH 7/7] clean up --- src/SmartTransactionsController.test.ts | 15 +++------------ src/SmartTransactionsController.ts | 4 ++-- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/SmartTransactionsController.test.ts b/src/SmartTransactionsController.test.ts index db9bbdf9..67f19604 100644 --- a/src/SmartTransactionsController.test.ts +++ b/src/SmartTransactionsController.test.ts @@ -3,17 +3,18 @@ import type { NetworkState } from '@metamask/network-controller'; import { NetworkStatus } from '@metamask/network-controller'; import nock from 'nock'; import * as sinon from 'sinon'; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore -import packageJson from '../package.json'; +import { API_BASE_URL, CHAIN_IDS } from './constants'; import SmartTransactionsController, { DEFAULT_INTERVAL, } from './SmartTransactionsController'; -import { API_BASE_URL, CHAIN_IDS } from './constants'; import { advanceTime, flushPromises } from './test-helpers'; import type { SmartTransaction, UnsignedTransaction } from './types'; import { SmartTransactionStatuses } from './types'; import * as utils from './utils'; +import packageJson from '../package.json'; jest.mock('@ethersproject/bytes', () => ({ ...jest.requireActual('@ethersproject/bytes'), @@ -781,10 +782,6 @@ describe('SmartTransactionsController', () => { }); it('fetches liveness and sets in feesByChainId state for the Smart Transactions API for the chainId of the networkClientId passed in', async () => { - const originalConsoleLogFn = global.console.log; - const consoleLogMockFn = jest.fn(); - global.console.log = consoleLogMockFn; - nock(API_BASE_URL) .get(`/networks/${goerliChainIdDec}/health`) .replyWithError('random error'); @@ -808,12 +805,6 @@ describe('SmartTransactionsController', () => { [CHAIN_IDS.ETHEREUM]: true, [CHAIN_IDS.GOERLI]: false, }); - - expect(consoleLogMockFn).toHaveBeenCalledWith( - '"fetchLiveness" API call failed', - ); - - global.console.log = originalConsoleLogFn; }); }); diff --git a/src/SmartTransactionsController.ts b/src/SmartTransactionsController.ts index 7fc3a6b5..5cfa3248 100644 --- a/src/SmartTransactionsController.ts +++ b/src/SmartTransactionsController.ts @@ -7,12 +7,12 @@ import EthQuery from '@metamask/eth-query'; import type { NetworkClientId, NetworkController, - NetworkState + NetworkState, } from '@metamask/network-controller'; import { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller'; import { BigNumber } from 'bignumber.js'; -import EventEmitter from 'events'; // eslint-disable-next-line import/no-nodejs-modules +import EventEmitter from 'events'; import cloneDeep from 'lodash/cloneDeep'; import {