Skip to content

Commit d504609

Browse files
authored
fix: Fix get1559CompatibilityWithNetworkClientId (#7532)
## Explanation This function assumed that metadata for a given network client would be `undefined` if an EIP-1559 compatibility check was needed. This used to be the case prior to `@metamask/[email protected]`, but as of that version we began regularly updating metadata without checking for EIP-1559 compatibility. The function `get1559CompatibilityWithNetworkClientI` now checks for whether EIP-1559 compatibility metadata is present, not just whether metadata is defined at all. ## References Fixes #7533 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Updates EIP-1559 compatibility check to refetch network metadata when the `EIPS[1559]` value is missing and adds tests plus changelog entry. > > - **NetworkController**: > - Update `get1559CompatibilityWithNetworkClientId` to call `lookupNetwork` when `networksMetadata[networkClientId].EIPS[1559]` is `undefined`, not only when metadata is absent, then return `EIPS[1559]`. > - **Tests** (`packages/network-controller/tests/NetworkController.test.ts`): > - Adjust existing test description and add test to verify metadata is updated when EIP-1559 compatibility is missing. > - **Changelog** (`packages/network-controller/CHANGELOG.md`): > - Add Fix entry describing the updated EIP-1559 metadata behavior. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 396375e. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent a943041 commit d504609

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

packages/network-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
- Bump `@metamask/eth-json-rpc-middleware` from `^22.0.0` to `^22.0.1` ([#7330](https://github.com/MetaMask/core/pull/7330))
1919

20+
### Fixed
21+
22+
- Ensure `get1559CompatibilityWithNetworkClientId` updates network metadata with EIP-1559 compatibility data missing ([#7532](https://github.com/MetaMask/core/pull/7532))
23+
2024
## [27.0.0]
2125

2226
### Added

packages/network-controller/src/NetworkController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ export class NetworkController extends BaseController<
21322132
networkClientId: NetworkClientId,
21332133
): Promise<boolean> {
21342134
let metadata = this.state.networksMetadata[networkClientId];
2135-
if (metadata === undefined) {
2135+
if (metadata?.EIPS[1559] === undefined) {
21362136
await this.lookupNetwork(networkClientId);
21372137
metadata = this.state.networksMetadata[networkClientId];
21382138
}

packages/network-controller/tests/NetworkController.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3590,7 +3590,7 @@ describe('NetworkController', () => {
35903590
},
35913591
);
35923592
});
3593-
it('calls provider of the networkClientId and returns true', async () => {
3593+
it('updates network metadata if undefined', async () => {
35943594
await withController(
35953595
{
35963596
infuraProjectId: 'some-infura-project-id',
@@ -3624,6 +3624,48 @@ describe('NetworkController', () => {
36243624
},
36253625
);
36263626
});
3627+
it('updates network metadata if EIP-1559 compatibility is missing', async () => {
3628+
await withController(
3629+
{
3630+
infuraProjectId: 'some-infura-project-id',
3631+
state: {
3632+
networksMetadata: {
3633+
'linea-mainnet': {
3634+
EIPS: {},
3635+
status: NetworkStatus.Unknown,
3636+
},
3637+
},
3638+
},
3639+
},
3640+
async ({ controller }) => {
3641+
await setFakeProvider(controller, {
3642+
stubs: [
3643+
{
3644+
request: {
3645+
method: 'eth_getBlockByNumber',
3646+
params: ['latest', false],
3647+
},
3648+
response: {
3649+
result: POST_1559_BLOCK,
3650+
},
3651+
},
3652+
{
3653+
request: {
3654+
method: 'eth_getBlockByNumber',
3655+
params: ['latest', false],
3656+
},
3657+
response: {
3658+
result: POST_1559_BLOCK,
3659+
},
3660+
},
3661+
],
3662+
});
3663+
const isEIP1559Compatible =
3664+
await controller.getEIP1559Compatibility('linea-mainnet');
3665+
expect(isEIP1559Compatible).toBe(true);
3666+
},
3667+
);
3668+
});
36273669
});
36283670

36293671
describe('if a provider has been set but networksMetadata[selectedNetworkClientId].EIPS in state already has a "1559" property', () => {

0 commit comments

Comments
 (0)