feat: Throw when encountering unexpected RPC method hooks
Description
Removes RPC handler hooks that had become unused. In order to prevent this from occurring again, also adds a check to fail immediately on dapp connections if extraneous hooks are provided. Finally, adds tests for createMethodMiddleware.js.
Note for reviewers
- In an indication that this is useful, you'll note that the set of hooks removed in this PR is different from that the original PR (#20580).
- In the commit history, you'll see an added and reverted TypeScript conversion of the method middleware and its tests. The RPC method handler types are a mess and we should probably wait to convert until we've resolved some upstream issues. Either way, the conversion would be too distracting for this PR.
Pre-merge author checklist
- [x] I’ve followed MetaMask Coding Standards.
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using JSDoc format if applicable
- [x] I’ve applied the right labels on the PR (see labeling guidelines). 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.
Codecov Report
Attention: Patch coverage is 78.57143% with 6 lines in your changes are missing coverage. Please review.
Project coverage is 67.46%. Comparing base (
d27a233) to head (38cf3c7). Report is 50 commits behind head on develop.
:exclamation: Current head 38cf3c7 differs from pull request most recent head 2c1d1a3. Consider uploading reports for the commit 2c1d1a3 to get more accurate results
| Files | Patch % | Lines |
|---|---|---|
| ...ib/rpc-method-middleware/createMethodMiddleware.js | 77.78% | 6 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## develop #24357 +/- ##
===========================================
+ Coverage 67.37% 67.46% +0.09%
===========================================
Files 1278 1286 +8
Lines 49881 50111 +230
Branches 12944 13006 +62
===========================================
+ Hits 33605 33805 +200
- Misses 16276 16306 +30
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Builds ready [350a322]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (659 ± 503 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 55 | 124 | 73 | 14 | 7 |
| domContentLoaded | 7 | 16 | 10 | 2 | 1 | ||
| load | 44 | 2691 | 659 | 1048 | 503 | ||
| domInteractive | 7 | 16 | 10 | 2 | 1 |
Bundle size diffs [🚀 Bundle size reduced!]
- background: -260 Bytes (-0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
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.
Builds ready [3a118aa]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (297 ± 345 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 54 | 109 | 70 | 12 | 6 |
| domContentLoaded | 8 | 61 | 12 | 11 | 5 | ||
| load | 43 | 2475 | 297 | 719 | 345 | ||
| domInteractive | 8 | 60 | 12 | 11 | 5 |
Bundle size diffs [🚀 Bundle size reduced!]
- background: -260 Bytes (-0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [de5d01f]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (634 ± 553 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 58 | 143 | 83 | 21 | 10 |
| domContentLoaded | 8 | 26 | 12 | 4 | 2 | ||
| load | 47 | 3518 | 634 | 1152 | 553 | ||
| domInteractive | 8 | 26 | 12 | 4 | 2 |
Bundle size diffs [🚀 Bundle size reduced!]
- background: -260 Bytes (-0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [62bbc83]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (984 ± 668 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 75 | 143 | 102 | 22 | 11 |
| domContentLoaded | 10 | 63 | 18 | 12 | 6 | ||
| load | 61 | 3725 | 984 | 1392 | 668 | ||
| domInteractive | 10 | 63 | 18 | 12 | 6 |
Bundle size diffs [🚀 Bundle size reduced!]
- background: -260 Bytes (-0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
It does seem like this could be handled more consistently at the type level by TypeScript, but I'm assuming the issue is that there is still a lot of unmigrated js code that will benefit from this in the meantime?
@legobeat there's definitely unmigrated JS code, but also the types for the method middleware and its handler + hooks pattern are currently broken and implemented in 3 different repositories. 🙃
We're all trying to find the guy who did this...
I may try to wrangle the types once this is in.
Builds ready [38cf3c7]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (736 ± 563 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 68 | 142 | 88 | 22 | 11 |
| domContentLoaded | 9 | 39 | 15 | 9 | 4 | ||
| load | 55 | 3067 | 736 | 1172 | 563 | ||
| domInteractive | 9 | 39 | 15 | 9 | 4 |
Bundle size diffs [🚀 Bundle size reduced!]
- background: -260 Bytes (-0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Builds ready [5edfc0d]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (745 ± 567 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 59 | 143 | 84 | 20 | 9 |
| domContentLoaded | 9 | 28 | 13 | 6 | 3 | ||
| load | 47 | 2893 | 745 | 1181 | 567 | ||
| domInteractive | 9 | 28 | 13 | 6 | 3 |
Bundle size diffs [🚀 Bundle size reduced!]
- background: -260 Bytes (-0.01%)
- ui: 0 Bytes (0.00%)
- common: 0 Bytes (0.00%)
Missing release label release-11.17.0 on PR. Adding release label release-11.17.0 on PR and removing other release labels(release-11.18.0), as PR was added to branch 11.17.0 when release was cut.