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
feat: Throw when encountering unexpected RPC method hooks #24357
Conversation
168fef4
to
c1b9c73
Compare
c1b9c73
to
d84cfdb
Compare
app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js
Outdated
Show resolved
Hide resolved
d84cfdb
to
6ff3d6f
Compare
Fixes unit test failures by mocking the method middleware in metamask-controller.test.js.
Our RPC method middleware / handler types are a hot mess. This makes them slightly less odious to work with in the extension, although they will still have to be fixed upstream.
Reverts the TypeScript conversion of method middleware files to make review easier.
6ff3d6f
to
350a322
Compare
Codecov ReportAttention: Patch coverage is
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 ☔ View full report in Codecov by Sentry. |
Builds ready [350a322]
Page Load Metrics (659 ± 503 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
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]
Page Load Metrics (297 ± 345 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
type MessageType = (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE]; | ||
|
||
type HandlerInterface = { | ||
methodNames: MessageType[]; | ||
implementation: unknown; | ||
hookNames?: { [key: string]: boolean }; | ||
}; | ||
|
||
const handlers: HandlerInterface[] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handlers
is self-declaring.
|
||
const rpcMethodMiddlewareMock = { | ||
createMethodMiddleware: () => (_req, _res, next, _end) => { | ||
next(); | ||
}, | ||
}; | ||
jest.mock('./lib/rpc-method-middleware', () => rpcMethodMiddlewareMock); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests now blow up without this mock.
@@ -10,7 +10,6 @@ module.exports = { | |||
'<rootDir>/app/scripts/controllers/preferences.js', | |||
'<rootDir>/app/scripts/flask/**/*.js', | |||
'<rootDir>/app/scripts/lib/**/*.(js|ts)', | |||
'<rootDir>/app/scripts/lib/createRPCMethodTrackingMiddleware.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously extraneous due to the line above it.
Builds ready [de5d01f]
Page Load Metrics (634 ± 553 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
Builds ready [62bbc83]
Page Load Metrics (984 ± 668 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
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]
Page Load Metrics (736 ± 563 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
setNetworkClientIdForDomain: | ||
this.selectedNetworkController.setNetworkClientIdForDomain.bind( | ||
this.selectedNetworkController, | ||
), | ||
|
||
getUseRequestQueue: this.preferencesController.getUseRequestQueue.bind( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
Builds ready [5edfc0d]
Page Load Metrics (745 ± 567 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
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. |
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
Pre-merge author checklist
Pre-merge reviewer checklist