From 4fe6141a24aa11bb6672ea31a6e33efe041ffcc1 Mon Sep 17 00:00:00 2001 From: Monte Lai Date: Thu, 27 Jun 2024 01:49:14 +0800 Subject: [PATCH 1/2] Release/166.0.0 (#4460) --- package.json | 2 +- packages/accounts-controller/CHANGELOG.md | 15 ++++++- packages/accounts-controller/package.json | 2 +- packages/assets-controllers/CHANGELOG.md | 44 ++++++++++++++++++- packages/assets-controllers/package.json | 4 +- packages/transaction-controller/CHANGELOG.md | 10 ++++- packages/transaction-controller/package.json | 4 +- .../user-operation-controller/CHANGELOG.md | 9 +++- .../user-operation-controller/package.json | 4 +- yarn.lock | 10 ++--- 10 files changed, 87 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 40e94dd553..a7ada84b7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@metamask/core-monorepo", - "version": "165.0.0", + "version": "166.0.0", "private": true, "description": "Monorepo for packages shared between MetaMask clients", "repository": { diff --git a/packages/accounts-controller/CHANGELOG.md b/packages/accounts-controller/CHANGELOG.md index 3c750b0d52..885a22e1f6 100644 --- a/packages/accounts-controller/CHANGELOG.md +++ b/packages/accounts-controller/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [17.1.0] + +### Added + +- Add `AccountsController:listMultichainAccounts` action ([#4426](https://github.com/MetaMask/core/pull/4426)) + +### Fixed + +- Refactored `getSelectedAccount` to handle case when there are no accounts to return. The logic was previously contained in `getAccountExpect` has been transferred to `getSelectedAccount`. ([#4322](https://github.com/MetaMask/core/pull/4322)) +- Updated `handleAccountRemoved` to automatically select the most recent account if the removed account was the currently selected account. ([#4322](https://github.com/MetaMask/core/pull/4322)) +- Move `@metamask/keyring-controller` to dependency ([#4425](https://github.com/MetaMask/core/pull/4425)) + ## [17.0.0] ### Changed @@ -215,7 +227,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial release ([#1637](https://github.com/MetaMask/core/pull/1637)) -[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@17.0.0...HEAD +[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@17.1.0...HEAD +[17.1.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@17.0.0...@metamask/accounts-controller@17.1.0 [17.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@16.0.0...@metamask/accounts-controller@17.0.0 [16.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@15.0.0...@metamask/accounts-controller@16.0.0 [15.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@14.0.0...@metamask/accounts-controller@15.0.0 diff --git a/packages/accounts-controller/package.json b/packages/accounts-controller/package.json index 5658a9c3e4..9fe154d750 100644 --- a/packages/accounts-controller/package.json +++ b/packages/accounts-controller/package.json @@ -1,6 +1,6 @@ { "name": "@metamask/accounts-controller", - "version": "17.0.0", + "version": "17.1.0", "description": "Manages internal accounts", "keywords": [ "MetaMask", diff --git a/packages/assets-controllers/CHANGELOG.md b/packages/assets-controllers/CHANGELOG.md index c8c8a1b216..c6bf2671c5 100644 --- a/packages/assets-controllers/CHANGELOG.md +++ b/packages/assets-controllers/CHANGELOG.md @@ -7,6 +7,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [34.0.0] + +### Added + +- Add `AccountTrackerControllerGetStateAction`, `AccountTrackerControllerActions`, `AccountTrackerControllerStateChangeEvent`, and `AccountTrackerControllerEvents` types ([#4407](https://github.com/MetaMask/core/pull/4407)) +- Add `setIntervalLength` and `getIntervalLength` methods to `AccountTrackerController` ([#4407](https://github.com/MetaMask/core/pull/4407)) + - `setIntervalLength` replaces updating the polling interval via `configure`. + +### Changed + +- **BREAKING** `TokenBalancesController` messenger must allow the action `AccountsController:getSelectedAccount` and remove `PreferencesController:getState`. ([#4219](https://github.com/MetaMask/core/pull/4219)) +- **BREAKING** `TokenDetectionController` messenger must allow the action `AccountsController:getAccount`. ([#4219](https://github.com/MetaMask/core/pull/4219)) +- **BREAKING** `TokenDetectionController` messenger must allow the event `AccountsController:selectedEvmAccountChange` and remove `AccountsController:selectedAccountChange`. ([#4219](https://github.com/MetaMask/core/pull/4219)) +- **BREAKING** `TokenRatesController` messenger must allow the action `AccountsController:getAccount`, `AccountsController:getSelectedAccount` and remove `PreferencesController:getState`. ([#4219](https://github.com/MetaMask/core/pull/4219)) +- **BREAKING** `TokenRatesController` messenger must allow the event `AccountsController:selectedEvmAccountChange` and remove `PreferencesController:stateChange`. ([#4219](https://github.com/MetaMask/core/pull/4219)) +- **BREAKING** `TokensController` messenger must allow the action `AccountsController:getAccount`, `AccountsController:getSelectedAccount`. +- **BREAKING** `TokensController` messenger must allow the event `AccountsController:selectedEvmAccountChange`. ([#4219](https://github.com/MetaMask/core/pull/4219)) +- Upgrade AccountTrackerController to BaseControllerV2 ([#4407](https://github.com/MetaMask/core/pull/4407)) +- **BREAKING:** Convert `AccountInformation` from interface to type ([#4407](https://github.com/MetaMask/core/pull/4407)) +- **BREAKING:** Rename `AccountTrackerState` to `AccountTrackerControllerState` and convert from interface to type ([#4407](https://github.com/MetaMask/core/pull/4407)) +- **BREAKING:** `AccountTrackerController` now inherits from `StaticIntervalPollingController` instead of `StaticIntervalPollingControllerV1` ([#4407](https://github.com/MetaMask/core/pull/4407)) + - The constructor now takes a single options object rather than three arguments. Some options have been removed; see later entries. +- **BREAKING:** The `AccountTrackerController` messenger must now allow the actions `PreferencesController:getState`, `NetworkController:getState`, and `NetworkController:getNetworkClientById` ([#4407](https://github.com/MetaMask/core/pull/4407)) +- **BREAKING:** The `refresh` method is no longer pre-bound to the controller ([#4407](https://github.com/MetaMask/core/pull/4407)) + - You may now need to pre-bind it e.g. `accountTrackerController.refresh.bind(accountTrackerController)`. +- Bump `@metamask/accounts-controller` to `^17.1.0` ([#4460](https://github.com/MetaMask/core/pull/4460)) + +### Removed + +- **BREAKING** `TokensController` removes `selectedAddress` constructor argument. ([#4219](https://github.com/MetaMask/core/pull/4219)) +- **BREAKING** `TokenDetectionController` removes `selectedAddress` constructor argument. ([#4219](https://github.com/MetaMask/core/pull/4219)) +- **BREAKING:** Remove `AccountTrackerConfig` type ([#4407](https://github.com/MetaMask/core/pull/4407)) + - Some of these properties have been merged into the options that the `AccountTrackerController` constructor takes. +- **BREAKING:** Remove `config` property and `configure` method from `AccountTrackerController` ([#4407](https://github.com/MetaMask/core/pull/4407)) + - The controller now takes a single options object which can be used for configuration, and configuration is now kept internally. +- **BREAKING:** Remove `notify`, `subscribe`, and `unsubscribe` methods from `AccountTrackerController` ([#4407](https://github.com/MetaMask/core/pull/4407)) + - Use the controller messenger for subscribing to and publishing events instead. +- **BREAKING:** Remove `provider`, `getMultiAccountBalancesEnabled`, `getCurrentChainId`, and `getNetworkClientById` from configuration options for `AccountTrackerController` ([#4407](https://github.com/MetaMask/core/pull/4407)) + - The provider is now obtained directly from the network controller on demand. + - The messenger is now used in place of the callbacks. + ## [33.0.0] ### Added @@ -940,7 +981,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845)) -[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@33.0.0...HEAD +[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@34.0.0...HEAD +[34.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@33.0.0...@metamask/assets-controllers@34.0.0 [33.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@32.0.0...@metamask/assets-controllers@33.0.0 [32.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@31.0.0...@metamask/assets-controllers@32.0.0 [31.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@30.0.0...@metamask/assets-controllers@31.0.0 diff --git a/packages/assets-controllers/package.json b/packages/assets-controllers/package.json index f592e17c74..45ae61cbad 100644 --- a/packages/assets-controllers/package.json +++ b/packages/assets-controllers/package.json @@ -1,6 +1,6 @@ { "name": "@metamask/assets-controllers", - "version": "33.0.0", + "version": "34.0.0", "description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)", "keywords": [ "MetaMask", @@ -47,7 +47,7 @@ "@ethersproject/contracts": "^5.7.0", "@ethersproject/providers": "^5.7.0", "@metamask/abi-utils": "^2.0.2", - "@metamask/accounts-controller": "^17.0.0", + "@metamask/accounts-controller": "^17.1.0", "@metamask/approval-controller": "^7.0.0", "@metamask/base-controller": "^6.0.0", "@metamask/contract-metadata": "^2.4.0", diff --git a/packages/transaction-controller/CHANGELOG.md b/packages/transaction-controller/CHANGELOG.md index 65809c324a..0eb4380faa 100644 --- a/packages/transaction-controller/CHANGELOG.md +++ b/packages/transaction-controller/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [33.0.1] + +### Changed + +- Document TransactionStatus enum ([#4380](https://github.com/MetaMask/core/pull/4380)) +- Bump `@metamask/accounts-controller` to `^17.1.0` ([#4460](https://github.com/MetaMask/core/pull/4460)) + ## [33.0.0] ### Changed @@ -896,7 +903,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 All changes listed after this point were applied to this package following the monorepo conversion. -[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@33.0.0...HEAD +[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@33.0.1...HEAD +[33.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@33.0.0...@metamask/transaction-controller@33.0.1 [33.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@32.0.0...@metamask/transaction-controller@33.0.0 [32.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@31.0.0...@metamask/transaction-controller@32.0.0 [31.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@30.0.0...@metamask/transaction-controller@31.0.0 diff --git a/packages/transaction-controller/package.json b/packages/transaction-controller/package.json index 1b34db2bf6..8bd09156be 100644 --- a/packages/transaction-controller/package.json +++ b/packages/transaction-controller/package.json @@ -1,6 +1,6 @@ { "name": "@metamask/transaction-controller", - "version": "33.0.0", + "version": "33.0.1", "description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation", "keywords": [ "MetaMask", @@ -47,7 +47,7 @@ "@ethersproject/abi": "^5.7.0", "@ethersproject/contracts": "^5.7.0", "@ethersproject/providers": "^5.7.0", - "@metamask/accounts-controller": "^17.0.0", + "@metamask/accounts-controller": "^17.1.0", "@metamask/approval-controller": "^7.0.0", "@metamask/base-controller": "^6.0.0", "@metamask/controller-utils": "^11.0.0", diff --git a/packages/user-operation-controller/CHANGELOG.md b/packages/user-operation-controller/CHANGELOG.md index c6812db3ae..509bce212a 100644 --- a/packages/user-operation-controller/CHANGELOG.md +++ b/packages/user-operation-controller/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [12.0.1] + +### Changed + +- Bump `@metamask/transaction-controller` to `^33.0.1` ([#4460](https://github.com/MetaMask/core/pull/4460)) + ## [12.0.0] ### Changed @@ -163,7 +169,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial Release ([#3749](https://github.com/MetaMask/core/pull/3749)) -[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@12.0.0...HEAD +[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@12.0.1...HEAD +[12.0.1]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@12.0.0...@metamask/user-operation-controller@12.0.1 [12.0.0]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@11.0.0...@metamask/user-operation-controller@12.0.0 [11.0.0]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@10.0.0...@metamask/user-operation-controller@11.0.0 [10.0.0]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@9.0.0...@metamask/user-operation-controller@10.0.0 diff --git a/packages/user-operation-controller/package.json b/packages/user-operation-controller/package.json index bac9c0a988..d9b2d23f2f 100644 --- a/packages/user-operation-controller/package.json +++ b/packages/user-operation-controller/package.json @@ -1,6 +1,6 @@ { "name": "@metamask/user-operation-controller", - "version": "12.0.0", + "version": "12.0.1", "description": "Creates user operations and manages their life cycle", "keywords": [ "MetaMask", @@ -51,7 +51,7 @@ "@metamask/network-controller": "^19.0.0", "@metamask/polling-controller": "^8.0.0", "@metamask/rpc-errors": "^6.2.1", - "@metamask/transaction-controller": "^33.0.0", + "@metamask/transaction-controller": "^33.0.1", "@metamask/utils": "^8.3.0", "bn.js": "^5.2.1", "immer": "^9.0.6", diff --git a/yarn.lock b/yarn.lock index 7d3f5cedb5..64b7706189 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2195,7 +2195,7 @@ __metadata: languageName: node linkType: hard -"@metamask/accounts-controller@^17.0.0, @metamask/accounts-controller@workspace:packages/accounts-controller": +"@metamask/accounts-controller@^17.1.0, @metamask/accounts-controller@workspace:packages/accounts-controller": version: 0.0.0-use.local resolution: "@metamask/accounts-controller@workspace:packages/accounts-controller" dependencies: @@ -2313,7 +2313,7 @@ __metadata: "@ethersproject/contracts": ^5.7.0 "@ethersproject/providers": ^5.7.0 "@metamask/abi-utils": ^2.0.2 - "@metamask/accounts-controller": ^17.0.0 + "@metamask/accounts-controller": ^17.1.0 "@metamask/approval-controller": ^7.0.0 "@metamask/auto-changelog": ^3.4.4 "@metamask/base-controller": ^6.0.0 @@ -3770,7 +3770,7 @@ __metadata: languageName: node linkType: hard -"@metamask/transaction-controller@^33.0.0, @metamask/transaction-controller@workspace:packages/transaction-controller": +"@metamask/transaction-controller@^33.0.1, @metamask/transaction-controller@workspace:packages/transaction-controller": version: 0.0.0-use.local resolution: "@metamask/transaction-controller@workspace:packages/transaction-controller" dependencies: @@ -3781,7 +3781,7 @@ __metadata: "@ethersproject/abi": ^5.7.0 "@ethersproject/contracts": ^5.7.0 "@ethersproject/providers": ^5.7.0 - "@metamask/accounts-controller": ^17.0.0 + "@metamask/accounts-controller": ^17.1.0 "@metamask/approval-controller": ^7.0.0 "@metamask/auto-changelog": ^3.4.4 "@metamask/base-controller": ^6.0.0 @@ -3837,7 +3837,7 @@ __metadata: "@metamask/network-controller": ^19.0.0 "@metamask/polling-controller": ^8.0.0 "@metamask/rpc-errors": ^6.2.1 - "@metamask/transaction-controller": ^33.0.0 + "@metamask/transaction-controller": ^33.0.1 "@metamask/utils": ^8.3.0 "@types/jest": ^27.4.1 bn.js: ^5.2.1 From 676d28b9422a61fd7bd1b823ec9c1c70b003f8f7 Mon Sep 17 00:00:00 2001 From: Derek Brans Date: Wed, 26 Jun 2024 16:07:21 -0400 Subject: [PATCH 2/2] chore: reduce diffs to GasFeeController.test.ts introduced by 2b1841c (#4463) ## Explanation Commit 2b1841c introduced [unnecessary changes to `GasFeeController.test.ts`](https://github.com/MetaMask/core/commit/2b1841c#diff-46b4165a6fef6c662829473a7ae3dd5c12454ca7ea811b539c0e88dc464f7e3b), complicating the process of rebasing and merging subsequent changes to this file. To see the net diffs to `GasFeeController.test.ts` in this branch, you can compare that file to 2b1841c's parent commit, ca683e8: ```bash git diff ca683e8...djb/gas-fee-tests packages/gas-fee-controller/src/GasFeeController.test.ts ``` ## References ## Changelog ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've highlighted breaking changes using the "BREAKING" category above as appropriate --- .../src/GasFeeController.test.ts | 260 ++++-------------- 1 file changed, 53 insertions(+), 207 deletions(-) diff --git a/packages/gas-fee-controller/src/GasFeeController.test.ts b/packages/gas-fee-controller/src/GasFeeController.test.ts index 84d25a03dc..e4d68dd1f4 100644 --- a/packages/gas-fee-controller/src/GasFeeController.test.ts +++ b/packages/gas-fee-controller/src/GasFeeController.test.ts @@ -734,6 +734,12 @@ describe('GasFeeController', () => { describe('fetchGasFeeEstimates', () => { describe('when on any network supporting legacy gas estimation api', () => { + const getDefaultOptions = () => ({ + getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), + getCurrentNetworkLegacyGasAPICompatibility: jest + .fn() + .mockReturnValue(true), + }); const mockDetermineGasFeeCalculations = buildMockGasFeeStateLegacy(); beforeEach(() => { @@ -744,10 +750,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), - getCurrentNetworkLegacyGasAPICompatibility: jest - .fn() - .mockReturnValue(true), + ...getDefaultOptions(), networkControllerState: { networkConfigurations: { 'AAAA-BBBB-CCCC-DDDD': { @@ -788,12 +791,7 @@ describe('GasFeeController', () => { }); it('should update the state with a fetched set of estimates', async () => { - await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), - getCurrentNetworkLegacyGasAPICompatibility: jest - .fn() - .mockReturnValue(true), - }); + await setupGasFeeController(getDefaultOptions()); await gasFeeController.fetchGasFeeEstimates(); @@ -803,12 +801,7 @@ describe('GasFeeController', () => { }); it('should return the same data that it puts into state', async () => { - await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), - getCurrentNetworkLegacyGasAPICompatibility: jest - .fn() - .mockReturnValue(true), - }); + await setupGasFeeController(getDefaultOptions()); const estimateData = await gasFeeController.fetchGasFeeEstimates(); @@ -817,10 +810,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when getChainId returns a number input', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), - getCurrentNetworkLegacyGasAPICompatibility: jest - .fn() - .mockReturnValue(true), + ...getDefaultOptions(), getChainId: jest.fn().mockReturnValue(1), }); @@ -835,10 +825,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when getChainId returns a hexstring input', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), - getCurrentNetworkLegacyGasAPICompatibility: jest - .fn() - .mockReturnValue(true), + ...getDefaultOptions(), getChainId: jest.fn().mockReturnValue('0x1'), }); @@ -853,10 +840,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when nonRPCGasFeeApisDisabled is true', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), - getCurrentNetworkLegacyGasAPICompatibility: jest - .fn() - .mockReturnValue(true), + ...getDefaultOptions(), state: { ...buildMockGasFeeStateEthGasPrice(), nonRPCGasFeeApisDisabled: true, @@ -874,10 +858,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when nonRPCGasFeeApisDisabled is false', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), - getCurrentNetworkLegacyGasAPICompatibility: jest - .fn() - .mockReturnValue(true), + ...getDefaultOptions(), state: { ...buildMockGasFeeStateEthGasPrice(), nonRPCGasFeeApisDisabled: false, @@ -895,10 +876,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly when getChainId returns a numeric string input', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(false), - getCurrentNetworkLegacyGasAPICompatibility: jest - .fn() - .mockReturnValue(true), + ...getDefaultOptions(), getChainId: jest.fn().mockReturnValue('1'), }); @@ -913,6 +891,9 @@ describe('GasFeeController', () => { }); describe('when on any network supporting EIP-1559', () => { + const getDefaultOptions = () => ({ + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + }); const mockDetermineGasFeeCalculations = buildMockGasFeeStateFeeMarket(); beforeEach(() => { @@ -923,7 +904,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + ...getDefaultOptions(), networkControllerState: { networkConfigurations: { 'AAAA-BBBB-CCCC-DDDD': { @@ -964,9 +945,7 @@ describe('GasFeeController', () => { }); it('should update the state with a fetched set of estimates', async () => { - await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - }); + await setupGasFeeController(getDefaultOptions()); await gasFeeController.fetchGasFeeEstimates(); @@ -976,9 +955,7 @@ describe('GasFeeController', () => { }); it('should return the same data that it puts into state', async () => { - await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - }); + await setupGasFeeController(getDefaultOptions()); const estimateData = await gasFeeController.fetchGasFeeEstimates(); @@ -987,7 +964,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations with a URL that contains the chain ID', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + ...getDefaultOptions(), getChainId: jest.fn().mockReturnValue('0x1'), }); @@ -1001,6 +978,31 @@ describe('GasFeeController', () => { }); }); describe('when passed a networkClientId in options object', () => { + const getDefaultOptions = () => ({ + getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), + networkControllerState: { + networksMetadata: { + goerli: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + sepolia: { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + 'test-network-client-id': { + EIPS: { + 1559: true, + }, + status: NetworkStatus.Available, + }, + }, + }, + }); const mockDetermineGasFeeCalculations = buildMockGasFeeStateFeeMarket(); beforeEach(() => { @@ -1011,29 +1013,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations correctly', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - networkControllerState: { - networksMetadata: { - goerli: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - sepolia: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - 'test-network-client-id': { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - }, - }, + ...getDefaultOptions(), clientId: '99999', }); @@ -1068,29 +1048,7 @@ describe('GasFeeController', () => { describe("the chainId of the networkClientId matches the globally selected network's chainId", () => { it('should update the globally selected network state with a fetched set of estimates', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - networkControllerState: { - networksMetadata: { - goerli: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - sepolia: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - 'test-network-client-id': { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - }, - }, + ...getDefaultOptions(), getChainId: jest.fn().mockReturnValue(ChainId.goerli), onNetworkDidChange: jest.fn(), }); @@ -1106,29 +1064,7 @@ describe('GasFeeController', () => { it('should update the gasFeeEstimatesByChainId state with a fetched set of estimates', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - networkControllerState: { - networksMetadata: { - goerli: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - sepolia: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - 'test-network-client-id': { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - }, - }, + ...getDefaultOptions(), getChainId: jest.fn().mockReturnValue(ChainId.goerli), onNetworkDidChange: jest.fn(), }); @@ -1146,29 +1082,7 @@ describe('GasFeeController', () => { describe("the chainId of the networkClientId does not match the globally selected network's chainId", () => { it('should not update the globally selected network state with a fetched set of estimates', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - networkControllerState: { - networksMetadata: { - goerli: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - sepolia: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - 'test-network-client-id': { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - }, - }, + ...getDefaultOptions(), getChainId: jest.fn().mockReturnValue(ChainId.mainnet), onNetworkDidChange: jest.fn(), }); @@ -1186,29 +1100,7 @@ describe('GasFeeController', () => { it('should update the gasFeeEstimatesByChainId state with a fetched set of estimates', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - networkControllerState: { - networksMetadata: { - goerli: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - sepolia: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - 'test-network-client-id': { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - }, - }, + ...getDefaultOptions(), getChainId: jest.fn().mockReturnValue(ChainId.mainnet), onNetworkDidChange: jest.fn(), }); @@ -1224,31 +1116,7 @@ describe('GasFeeController', () => { }); it('should return the same data that it puts into state', async () => { - await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - networkControllerState: { - networksMetadata: { - goerli: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - sepolia: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - 'test-network-client-id': { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - }, - }, - }); + await setupGasFeeController(getDefaultOptions()); const estimateData = await gasFeeController.fetchGasFeeEstimates({ networkClientId: 'sepolia', @@ -1259,29 +1127,7 @@ describe('GasFeeController', () => { it('should call determineGasFeeCalculations with a URL that contains the chain ID', async () => { await setupGasFeeController({ - getIsEIP1559Compatible: jest.fn().mockResolvedValue(true), - networkControllerState: { - networksMetadata: { - goerli: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - sepolia: { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - 'test-network-client-id': { - EIPS: { - 1559: true, - }, - status: NetworkStatus.Available, - }, - }, - }, + ...getDefaultOptions(), }); await gasFeeController.fetchGasFeeEstimates({