Skip to content

Commit

Permalink
adapt to eip-1193 provider changes (#384)
Browse files Browse the repository at this point in the history
* adapt to eip-1193 provider changes: sendAsync deprecated, use request instead.

* replace mockProvider with getFakeProvider from test-helpers
  • Loading branch information
kanthesha authored Jul 19, 2024
1 parent a2df165 commit da59b11
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@ethersproject/bytes": "^5.7.0",
"@metamask/base-controller": "^6.0.0",
"@metamask/controller-utils": "^11.0.0",
"@metamask/eth-json-rpc-provider": "^4.1.0",
"@metamask/eth-query": "^4.0.0",
"@metamask/network-controller": "^19.0.0",
"@metamask/polling-controller": "^8.0.0",
Expand All @@ -47,6 +48,7 @@
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@metamask/json-rpc-engine": "^9.0.0",
"@types/jest": "^26.0.24",
"@types/lodash": "^4.14.194",
"@types/node": "^18.19.17",
Expand Down
10 changes: 3 additions & 7 deletions src/SmartTransactionsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { API_BASE_URL } from './constants';
import SmartTransactionsController, {
DEFAULT_INTERVAL,
} from './SmartTransactionsController';
import { advanceTime, flushPromises } from './test-helpers';
import { advanceTime, flushPromises, getFakeProvider } from './test-helpers';
import type { SmartTransaction, UnsignedTransaction, Hex } from './types';
import { SmartTransactionStatuses } from './types';
import * as utils from './utils';
Expand Down Expand Up @@ -342,13 +342,9 @@ const defaultState = {
},
};

const mockProvider = {
sendAsync: jest.fn(),
};

const mockProviderConfig = {
chainId: ChainId.mainnet,
provider: mockProvider,
provider: getFakeProvider(),
type: NetworkType.mainnet,
ticker: 'ticker',
};
Expand Down Expand Up @@ -391,7 +387,7 @@ describe('SmartTransactionsController', () => {
releaseLock: jest.fn(),
};
}),
provider: { sendAsync: jest.fn() },
provider: getFakeProvider(),
confirmExternalTransaction: jest.fn(),
getTransactions: jest.fn(),
trackMetaMetricsEvent: trackMetaMetricsEventSpy,
Expand Down
4 changes: 2 additions & 2 deletions src/SmartTransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { hexlify } from '@ethersproject/bytes';
import type { BaseConfig, BaseState } from '@metamask/base-controller';
import { query, safelyExecute, ChainId } from '@metamask/controller-utils';
import type { Provider } from '@metamask/eth-query';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
import EthQuery from '@metamask/eth-query';
import type {
NetworkClientId,
Expand Down Expand Up @@ -133,7 +133,7 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
listener: (networkState: NetworkState) => void,
) => void;
getNonceLock: any;
provider: Provider;
provider: SafeEventEmitterProvider;
confirmExternalTransaction: any;
getTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];
trackMetaMetricsEvent: any;
Expand Down
3 changes: 2 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import DefaultExport from '.';
import SmartTransactionsController from './SmartTransactionsController';
import { getFakeProvider } from './test-helpers';

describe('default export', () => {
it('exports SmartTransactionsController', () => {
jest.useFakeTimers();
const controller = new DefaultExport({
onNetworkStateChange: jest.fn(),
getNonceLock: null,
provider: { sendAsync: jest.fn() },
provider: getFakeProvider(),
confirmExternalTransaction: jest.fn(),
getTransactions: jest.fn(),
trackMetaMetricsEvent: jest.fn(),
Expand Down
7 changes: 7 additions & 0 deletions src/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { providerFromEngine } from '@metamask/eth-json-rpc-provider';
import { JsonRpcEngine } from '@metamask/json-rpc-engine';

/**
* Resolve all pending promises.
* This method is used for async tests that use fake timers.
Expand Down Expand Up @@ -35,3 +38,7 @@ export async function advanceTime({
duration -= stepSize;
} while (duration > 0);
}

export function getFakeProvider() {
return providerFromEngine(new JsonRpcEngine());
}
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,19 @@ __metadata:
languageName: node
linkType: hard

"@metamask/eth-json-rpc-provider@npm:^4.1.0":
version: 4.1.0
resolution: "@metamask/eth-json-rpc-provider@npm:4.1.0"
dependencies:
"@metamask/json-rpc-engine": ^9.0.0
"@metamask/rpc-errors": ^6.2.1
"@metamask/safe-event-emitter": ^3.0.0
"@metamask/utils": ^8.3.0
uuid: ^8.3.2
checksum: c9669c93df073423d36ff941b512247b569e7f7c56cc6110565bc8dc6590ad691a78d6d17eea6243721c1c464f0f008ea1326fc7373f90fb705fba5fb85d804d
languageName: node
linkType: hard

"@metamask/eth-query@npm:^4.0.0":
version: 4.0.0
resolution: "@metamask/eth-query@npm:4.0.0"
Expand Down Expand Up @@ -2071,7 +2084,9 @@ __metadata:
"@metamask/eslint-config-jest": ^12.1.0
"@metamask/eslint-config-nodejs": ^12.1.0
"@metamask/eslint-config-typescript": ^12.1.0
"@metamask/eth-json-rpc-provider": ^4.1.0
"@metamask/eth-query": ^4.0.0
"@metamask/json-rpc-engine": ^9.0.0
"@metamask/network-controller": ^19.0.0
"@metamask/polling-controller": ^8.0.0
"@metamask/transaction-controller": ^34.0.0
Expand Down

0 comments on commit da59b11

Please sign in to comment.