-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore: improve SDK and WalletConnect connection reliability #24217
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,86 @@ describe('DeeplinkProtocolService', () => { | |
| service.setupBridge(clientInfo); | ||
| expect(setupBridgeSpy).toHaveReturned(); | ||
| }); | ||
|
|
||
| it('should throw error when originatorInfo.url is "metamask"', () => { | ||
| const clientInfo: DappClient = { | ||
| clientId: 'client1', | ||
| originatorInfo: { | ||
| url: 'metamask', | ||
| title: 'Test', | ||
| platform: 'test', | ||
| dappId: 'dappId', | ||
| }, | ||
| connected: false, | ||
| validUntil: Date.now(), | ||
| scheme: 'test', | ||
| }; | ||
|
|
||
| expect(() => service.setupBridge(clientInfo)).toThrow( | ||
| 'Connections from metamask origin are not allowed', | ||
| ); | ||
| expect(service.bridgeByClientId[clientInfo.clientId]).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should throw error when originatorInfo.title is "metamask"', () => { | ||
| const clientInfo: DappClient = { | ||
| clientId: 'client1', | ||
| originatorInfo: { | ||
| url: 'https://example.com', | ||
| title: 'metamask', | ||
| platform: 'test', | ||
| dappId: 'dappId', | ||
| }, | ||
| connected: false, | ||
| validUntil: Date.now(), | ||
| scheme: 'test', | ||
| }; | ||
|
|
||
| expect(() => service.setupBridge(clientInfo)).toThrow( | ||
| 'Connections from metamask origin are not allowed', | ||
| ); | ||
| expect(service.bridgeByClientId[clientInfo.clientId]).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should allow connection when originatorInfo contains "metamask" as substring', () => { | ||
| const clientInfo: DappClient = { | ||
| clientId: 'client1', | ||
| originatorInfo: { | ||
| url: 'https://my-metamask-dapp.com', | ||
| title: 'My MetaMask App', | ||
| platform: 'test', | ||
| dappId: 'dappId', | ||
| }, | ||
| connected: false, | ||
| validUntil: Date.now(), | ||
| scheme: 'test', | ||
| }; | ||
|
|
||
| expect(() => service.setupBridge(clientInfo)).not.toThrow(); | ||
| expect(service.bridgeByClientId[clientInfo.clientId]).toBeInstanceOf( | ||
| BackgroundBridge, | ||
| ); | ||
| }); | ||
|
|
||
| it('should allow connection when originatorInfo has valid url and title', () => { | ||
| const clientInfo: DappClient = { | ||
| clientId: 'client1', | ||
| originatorInfo: { | ||
| url: 'https://example.com', | ||
| title: 'Example Dapp', | ||
| platform: 'test', | ||
| dappId: 'dappId', | ||
| }, | ||
| connected: false, | ||
| validUntil: Date.now(), | ||
| scheme: 'test', | ||
| }; | ||
|
|
||
| expect(() => service.setupBridge(clientInfo)).not.toThrow(); | ||
| expect(service.bridgeByClientId[clientInfo.clientId]).toBeInstanceOf( | ||
| BackgroundBridge, | ||
| ); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test names use "should" violating guidelines (Bugbot Rules)Multiple new tests use "should" in their names, violating the unit testing guidelines rule: "NEVER use 'should' in test names - this is a hard rule with zero exceptions". Examples include Additional Locations (2) |
||
| }); | ||
| describe('sendMessage', () => { | ||
| it('should handle sending messages correctly', async () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -600,6 +600,62 @@ describe('ConnectionRegistry', () => { | |
| expect(mockHostApp.hideConnectionLoading).toHaveBeenCalledTimes(1); | ||
| expect(mockStore.save).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('blocks connection requests with `metamask` as origin', async () => { | ||
| registry = new ConnectionRegistry( | ||
| RELAY_URL, | ||
| mockKeyManager, | ||
| mockHostApp, | ||
| mockStore, | ||
| ); | ||
|
|
||
| const blockedRequest = { | ||
| ...mockConnectionRequest, | ||
| metadata: { | ||
| ...mockConnectionRequest.metadata, | ||
| dapp: { | ||
| ...mockConnectionRequest.metadata.dapp, | ||
| url: 'metamask', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const blockedDeeplink = `metamask://connect/mwp?p=${encodeURIComponent( | ||
| JSON.stringify(blockedRequest), | ||
| )}`; | ||
|
|
||
| await registry.handleConnectDeeplink(blockedDeeplink); | ||
|
|
||
| expect(mockHostApp.showConnectionError).toHaveBeenCalledTimes(1); | ||
| expect(Connection.create).not.toHaveBeenCalled(); | ||
| expect(mockStore.save).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('blocks connection requests with `metamask` as dapp name', async () => { | ||
| registry = new ConnectionRegistry( | ||
| RELAY_URL, | ||
| mockKeyManager, | ||
| mockHostApp, | ||
| mockStore, | ||
| ); | ||
|
|
||
| const blockedRequest = { | ||
| ...mockConnectionRequest, | ||
| metadata: { | ||
| ...mockConnectionRequest.metadata, | ||
| dapp: { | ||
| ...mockConnectionRequest.metadata.dapp, | ||
| name: 'metamask', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const blockedDeeplink = `metamask://connect/mwp?p=${encodeURIComponent( | ||
| JSON.stringify(blockedRequest), | ||
| )}`; | ||
|
|
||
| await registry.handleConnectDeeplink(blockedDeeplink); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test has no assertions and always passesThe test |
||
| }); | ||
|
|
||
| describe('disconnect', () => { | ||
|
|
||
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.
Test names use prohibited "should" prefix (Bugbot Rules)
The unit testing guidelines explicitly state "NEVER use 'should' in test names - this is a hard rule with zero exceptions." The newly added tests use names like
'should throw error when originatorInfo.url is "metamask"','should allow connection when originatorInfo contains "metamask" as substring', and'should reject session proposal with "metamask" origin'. These violate the naming convention and should use action-oriented descriptions instead.Additional Locations (2)
app/core/SDKConnect/handlers/setupBridge.test.ts#L126-L164app/core/WalletConnect/WalletConnectV2.test.ts#L1457-L1592