Conversation
Gudahtt
left a comment
There was a problem hiding this comment.
LGTM! Left a couple of suggestions for additional tests though
| }); | ||
|
|
||
| describe('It updates domain state when the network controller state changes', () => { | ||
| describe('networkController:stateChange and useRequestQueuePreference is true', () => { |
There was a problem hiding this comment.
Nit: We may want a test for the opposite condition (i.e. when useRequestQueue is false)
|
|
||
| describe('Constructor checks for domains in permissions', () => { | ||
| it('should set networkClientId for domains not already in state', async () => { | ||
| it('should set networkClientId for domains not already in state when useRequestQueuePreference is true', async () => { |
There was a problem hiding this comment.
Nit: Likewise here, we may want to test the opposite case
) Core PR: MetaMask/core#4388 Patch Branch: [jl/patch-selected-network-controller-12.0.1-setNetworkClientId-guard](https://github.com/MetaMask/core/tree/jl/patch-selected-network-controller-12.0.1-setNetworkClientId-guard)
) Core PR: MetaMask/core#4388 Patch Branch: [jl/patch-selected-network-controller-12.0.1-setNetworkClientId-guard](https://github.com/MetaMask/core/tree/jl/patch-selected-network-controller-12.0.1-setNetworkClientId-guard)
| }); | ||
|
|
||
| describe('when the useRequestQueue is false', () => { | ||
| describe('when the requesting domain is not metamask', () => { |
There was a problem hiding this comment.
nit we can probably get rid of this nested describe block when the requesting domain is not metamask since the test applies whether or not the request domain is MetaMask
…kClientIdForDomain-guard
adonesky1
left a comment
There was a problem hiding this comment.
Both of my comments are non blocking
| it('does not update the networkClientId for domains which were previously set to the deleted networkClientId', () => { | ||
| const { controller, messenger } = setup({ | ||
| state: { | ||
| // normally there would not be any domains in state if useRequestQueuePreference is false |
There was a problem hiding this comment.
Lets remove this whole block now since this state shouldn't be possible?
| domains: { | ||
| 'existingdomain.com': 'initialNetworkId', | ||
| describe('when useRequestQueuePreference is false', () => { | ||
| it('should set networkClientId for domains not already in state', async () => { |
There was a problem hiding this comment.
So this seems like another one where there shouldn't be domains in state so maybe we don't need this test? But if we're going to have it the networkClientId for the existing domain should probably change?
There was a problem hiding this comment.
But it seems confusing to have this test at all.
There was a problem hiding this comment.
Sorry I misphrased my initial comment. This implication of this test is actually backwards. It should be should **not** set networkClientId for domains not already in state
There was a problem hiding this comment.
This is the only one that I think is kindof egregious enough to block merging
| expect(controller.state.domains['existingdomain.com']).toBe( | ||
| 'initialNetworkId', | ||
| ); | ||
| it('should not modify domains already in state', async () => { |
There was a problem hiding this comment.
This seems like one where there shouldn't be domains in state so maybe we don't need this test
|
|
||
| // Now, 'newdomain.com' should have the selectedNetworkClientId set | ||
| expect(controller.state.domains['newdomain.com']).toBe('mainnet'); | ||
| it('should not modify domains already in state', async () => { |
There was a problem hiding this comment.
this test seems redundant since the previous one tests this condition too?
Seems like the previous test could be called "should set networkClientId for domains not already in state and not modify domains already in state"?
| if (!this.#useRequestQueuePreference) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
nit this could be bundled with the snaps check below which returns
if (snapsPrefixes.some((prefix) => domain.startsWith(prefix)) || !this.#useRequestQueuePreference) {
return;
}
2afe972 to
e1a71e5
Compare
…kClientIdForDomain-guard
|
apologies, accidentally comingled some changes intended for another branch |
adonesky1
left a comment
There was a problem hiding this comment.
LGTM! I'll do some of the clean up I suggested here in follow up!
…work domain is incorrectly set (#25106) ## **Description** Pulls [this fix](MetaMask/core#4388) which adds a guard to the `setNetworkClientIdForDomain` method on the `SelectedNetworkController` to no longer add domains to domains state (nor create a selected network proxy for them) unless the `useRequestQueuePreference` flag is true Bumping the `@metamask/selected-network-controller` version required [bumping peer dependencies](https://github.com/MetaMask/core/blob/main/packages/selected-network-controller/CHANGELOG.md#changed): - `@metamask/network-controller` to v19.0.0 - An existing patch was repointed to this version. - `@metamask/permission-controller` to v10.0.0 -[ This required bumping its own peerDep](https://github.com/MetaMask/core/blob/main/packages/selected-network-controller/CHANGELOG.md#changed) `@metamask/approval-controller` to v7.0.0 [](https://codespaces.new/MetaMask/metamask-extension/pull/25106?quickstart=1) ## **Related issues** See: https://consensys.slack.com/archives/C1L7H42BT/p1717512150509719 ## **Manual testing steps** 1. Open settings -> experimental and toggle of the `Select networks for each site` setting 2. Go to any site 3. Open the console and execute: ``` await window.ethereum.request({ "method": "eth_chainId", "params": [] }); ``` 4. See that it matches the globally selected network 5. Manually change the network with the network switcher 6. Go back to the site and execute the same `eth_chainId` script 7. See that the result has changed to the chainId you switched to 8. Now execute ``` await window.ethereum.request({ "method": "wallet_requestPermissions", "params": [ { "eth_accounts": {} } ] }); ``` and connect an account to the site 9. Repeat steps 1 - 7 10. The `eth_chainId` results should still match the globally selected network ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> https://github.com/MetaMask/metamask-extension/assets/34557516/ff2f68ff-6ec8-495f-96c1-e938973ce59b ### **After** <!-- [screenshots/recordings] --> https://github.com/MetaMask/metamask-extension/assets/34557516/6061f4e2-faab-48a5-8c55-3b2a4e3aa9f2 ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
Explanation
Our previous SelectedNetworkController fix that added a guard to permission state changes was not sufficient. This PR properly addresses the underlying issue of setting networkClientId for domains when the
useRequestQueuePreferenceflag is false by moving the guard into thesetNetworkClientId()method itselfReferences
Changelog
@metamask/selected-network-controllersetNetworkClientId()will now result in a noop ifuseRequestQueuePreferenceis falseChecklist