Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix switch-ethereum-chain handler by passing configuration id to setA… #18483

Merged
merged 7 commits into from
Apr 6, 2023

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Apr 6, 2023

Fixes #18453

Explanation

In a previous commit, we updated setActiveNetwork in the network controller to receive a network configuration id instead of a whole network object. However, the parameter passed to setActiveNetwork in the switch-ethereum-chain.js handler was still passed the object, not the id. See 23ca4460cf#diff-93f17dab5026baf840aec766ac5b6ebcd35d5bb0abb45e2c3f41791423f2a488R117

This PR corrects that, and adds an e2e test for the wallet_switchEthereumChain functionality, which would have caught this bug.

It is worth noting that the bug this PR fixes would not occur if you switched to the network immediately after adding it, because the correct parameter is passed to the setActiveNetwork call in add-ethereum-chain.js which happens after prompting the user to switch networks (23ca4460cf#diff-b3485a1ea9943fd380364f73a53295289f2ccd3817423d4f245b5102f8620b3cR170)

Manual Testing Steps

  1. Run $(yarn bin ganache) --port 8546 --chain.chainId 1338
  2. Go to https://metamask.github.io/test-dapp/ and connect to the dapp
  3. Click "Add Localhost 8546" and "Approve", BUT click "Cancel" once you get to the "Allow this site to switch the network?" screen (so that if you were to open MetaMask, the Localhost 8546 network would not be selected)
  4. Click "Switch to Localhost 8546" and then "Approve"
  5. If you open MetaMask, the Localhost 8546 network should now be selected

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2023

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@danjm danjm marked this pull request as ready for review April 6, 2023 10:19
@danjm danjm requested a review from a team as a code owner April 6, 2023 10:19
@danjm danjm requested a review from mcmire April 6, 2023 10:19
@metamaskbot
Copy link
Collaborator

Builds ready [a81dff7]
Page Load Metrics (1707 ± 87 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint94169124189
domContentLoaded14461995167114871
load14462116170718287
domInteractive14461995167114871
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3 bytes
  • ui: 0 bytes
  • common: 0 bytes

@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Merging #18483 (8e6eb11) into develop (f92e463) will not change coverage.
The diff coverage is 0.00%.

❗ Current head 8e6eb11 differs from pull request most recent head 90bf073. Consider uploading reports for the commit 90bf073 to get more accurate results

@@           Coverage Diff            @@
##           develop   #18483   +/-   ##
========================================
  Coverage    65.15%   65.15%           
========================================
  Files          936      936           
  Lines        35965    35965           
  Branches      9231     9231           
========================================
  Hits         23432    23432           
  Misses       12533    12533           
Impacted Files Coverage Δ
...ethod-middleware/handlers/switch-ethereum-chain.js 15.49% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -115,7 +115,7 @@ async function switchEthereumChainHandler(
) {
setProviderType(approvedRequestData.type);
} else {
await setActiveNetwork(approvedRequestData);
await setActiveNetwork(approvedRequestData.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codecov says Added line #L118 was not covered by tests but it looks like it should be covered looking at the test. Is it just codecov who doesn't handle e2e here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, codecov can't measure e2e tests

@metamaskbot
Copy link
Collaborator

Builds ready [d426fc7]
Page Load Metrics (1460 ± 31 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint85133101147
domContentLoaded1322156114516430
load1322156114606431
domInteractive1322156114516330
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3 bytes
  • ui: 0 bytes
  • common: 0 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [8e6eb11]
Page Load Metrics (1719 ± 67 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint922041192512
domContentLoaded14882029170314268
load15472056171913967
domInteractive14882029170314268
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3 bytes
  • ui: 0 bytes
  • common: 0 bytes

DDDDDanica
DDDDDanica previously approved these changes Apr 6, 2023
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
@danjm danjm dismissed stale reviews from DDDDDanica and pedronfigueiredo via be533ff April 6, 2023 13:47
DDDDDanica
DDDDDanica previously approved these changes Apr 6, 2023
@danjm
Copy link
Contributor Author

danjm commented Apr 6, 2023

reverted the last commit because it broke lint (no arrow functions in describe)

@metamaskbot
Copy link
Collaborator

Builds ready [90bf073]
Page Load Metrics (1666 ± 61 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint96135112115
domContentLoaded14451928164611756
load14461929166612861
domInteractive14451928164611756
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3 bytes
  • ui: 0 bytes
  • common: 0 bytes

@danjm danjm merged commit afa09dd into develop Apr 6, 2023
@danjm danjm deleted the fix-switch-ethereum-chain branch April 6, 2023 15:07
@github-actions github-actions bot locked and limited conversation to collaborators Apr 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: RPC Error when switching network on 10.28.1
5 participants