-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Explanation Helps to alleviate `window.ethereum` conflicts by supporting an alternative way for Dapps to discover and interact with providers. This PR implements [EIP-6963](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-6963.md) which adds an async event based provider discovery standard. ~~NOTE: I'm not sure if we strictly need the changes I made that add EIP-6963 support to the test dapp, but we probably want to add an e2e test for EIP-6963 and I'm not sure if we want our tests to rely on an external site like https://eip6963.org/ . Maybe we can test this by running some js in page like we do for testing parts of the json rpc in e2e environment.~~ I've added a spec for this that tests it directly in the browser console instead Ticket: [mmp-869](MetaMask/MetaMask-planning#869) Related: MetaMask/providers#263 ~~Related: MetaMask/test-dapp#243 # Screenshot <img width="470" alt="Screenshot 2023-09-27 at 4 41 13 PM" src="https://github.com/MetaMask/metamask-extension/assets/918701/88a0e334-fed9-45e8-80a2-329cb4c94ded"> ## Manual Testing Steps * Install and enable a few other browser extension wallets * Visit https://eip6963.org/ * MetaMask should show up in the list of providers and play nicely with all of them ## Pre-merge author checklist - [x] I've clearly explained: - [x] What problem this PR is solving - [x] How this problem was solved - [x] How reviewers can test my changes - [x] 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.
- Loading branch information
Showing
8 changed files
with
206 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const { strict: assert } = require('assert'); | ||
const FixtureBuilder = require('../fixture-builder'); | ||
const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); | ||
|
||
// https://github.com/thenativeweb/uuidv4/blob/bdcf3a3138bef4fb7c51f389a170666f9012c478/lib/uuidv4.ts#L5 | ||
const UUID_V4_REGEX = | ||
/(?:^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}$)|(?:^0{8}-0{4}-0{4}-0{4}-0{12}$)/u; | ||
|
||
const SVG_DATA_URI_REGEX = /^data:image\/svg\+xml,/u; | ||
|
||
describe('EIP-6963 Provider', function () { | ||
const ganacheOptions = { | ||
accounts: [ | ||
{ | ||
secretKey: | ||
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', | ||
balance: convertToHexValue(25000000000000000000), | ||
}, | ||
], | ||
}; | ||
|
||
it('should respond to the request provider event', async function () { | ||
await withFixtures( | ||
{ | ||
dapp: true, | ||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.build(), | ||
ganacheOptions, | ||
title: this.test.title, | ||
}, | ||
async ({ driver }) => { | ||
await driver.navigate(); | ||
await driver.fill('#password', 'correct horse battery staple'); | ||
await driver.press('#password', driver.Key.ENTER); | ||
|
||
await openDapp(driver); | ||
await driver.executeScript(` | ||
window.announceProviderEvents = [] | ||
window.addEventListener( | ||
"eip6963:announceProvider", | ||
(event) => { | ||
window.announceProviderEvents.push(event) | ||
} | ||
); | ||
window.dispatchEvent(new Event("eip6963:requestProvider")); | ||
`); | ||
const announceProviderEvents = await driver.executeScript(` | ||
return window.announceProviderEvents.map(event => { | ||
return { | ||
type: event.type, | ||
detail: { | ||
...event.detail, | ||
provider: Boolean(event.detail.provider) | ||
} | ||
} | ||
}) | ||
`); | ||
|
||
assert.match(announceProviderEvents[0].detail.info.uuid, UUID_V4_REGEX); | ||
delete announceProviderEvents[0].detail.info.uuid; | ||
assert.match( | ||
announceProviderEvents[0].detail.info.icon, | ||
SVG_DATA_URI_REGEX, | ||
); | ||
delete announceProviderEvents[0].detail.info.icon; | ||
assert.deepStrictEqual(announceProviderEvents, [ | ||
{ | ||
type: 'eip6963:announceProvider', | ||
detail: { | ||
info: { | ||
name: 'MetaMask Main', | ||
rdns: 'io.metamask', | ||
}, | ||
provider: true, | ||
}, | ||
}, | ||
]); | ||
|
||
const request = JSON.stringify({ | ||
jsonrpc: '2.0', | ||
method: 'eth_chainId', | ||
params: [], | ||
id: 0, | ||
}); | ||
const result = await driver.executeScript(` | ||
return window.announceProviderEvents[0].detail.provider.request(${request}) | ||
`); | ||
|
||
assert.equal(result, '0x539'); | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters