-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(metamask): Add support for adding/switching networks
- Loading branch information
1 parent
93424ca
commit 7bfef50
Showing
11 changed files
with
240 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './connectToDapp' | ||
export * from './signSimpleMessage' | ||
export * from './signStructuredMessage' | ||
export * from './network' |
25 changes: 25 additions & 0 deletions
25
wallets/metamask/src/pages/NotificationPage/actions/network.ts
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,25 @@ | ||
import type { Page } from '@playwright/test' | ||
import Selectors from '../selectors' | ||
|
||
const approveNewNetwork = async (notificationPage: Page) => { | ||
await notificationPage.locator(Selectors.NetworkPage.addNetwork.approveButton).click() | ||
} | ||
|
||
const rejectNewNetwork = async (notificationPage: Page) => { | ||
await notificationPage.locator(Selectors.NetworkPage.addNetwork.cancelButton).click() | ||
} | ||
|
||
const approveSwitchNetwork = async (notificationPage: Page) => { | ||
await notificationPage.locator(Selectors.NetworkPage.switchNetwork.switchNetworkButton).click() | ||
} | ||
|
||
const rejectSwitchNetwork = async (notificationPage: Page) => { | ||
await notificationPage.locator(Selectors.NetworkPage.switchNetwork.cancelButton).click() | ||
} | ||
|
||
export const network = { | ||
approveNewNetwork, | ||
rejectNewNetwork, | ||
approveSwitchNetwork, | ||
rejectSwitchNetwork | ||
} |
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
4 changes: 3 additions & 1 deletion
4
wallets/metamask/src/pages/NotificationPage/selectors/index.ts
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import NetworkPage from './networkPage' | ||
import SignaturePage from './signaturePage' | ||
|
||
export default { | ||
SignaturePage | ||
SignaturePage, | ||
NetworkPage | ||
} |
14 changes: 14 additions & 0 deletions
14
wallets/metamask/src/pages/NotificationPage/selectors/networkPage.ts
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,14 @@ | ||
const addNetwork = { | ||
approveButton: '.confirmation-footer__actions button.btn-primary', | ||
cancelButton: '.confirmation-footer__actions button.btn-secondary' | ||
} | ||
|
||
const switchNetwork = { | ||
switchNetworkButton: '.confirmation-footer__actions button.btn-primary', | ||
cancelButton: '.confirmation-footer__actions button.btn-secondary' | ||
} | ||
|
||
export default { | ||
addNetwork, | ||
switchNetwork | ||
} |
23 changes: 23 additions & 0 deletions
23
wallets/metamask/test/e2e/metamask/approveNewNetwork.spec.ts
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,23 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import connectedSetup from '../wallet-setup/connected.setup' | ||
|
||
const test = testWithSynpress(connectedSetup, unlockForFixture) | ||
|
||
const { expect } = test | ||
|
||
test('should add a new network', async ({ context, metamaskPage, page, extensionId }) => { | ||
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId) | ||
|
||
await page.goto('https://metamask.github.io/test-dapp/') | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x1') | ||
|
||
await page.locator('#addEthereumChain').click() | ||
|
||
await metamask.approveNewNetwork() | ||
await metamask.approveSwitchNetwork() | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x53a') | ||
}) |
44 changes: 44 additions & 0 deletions
44
wallets/metamask/test/e2e/metamask/approveSwitchNetwork.spec.ts
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,44 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import connectedSetup from '../wallet-setup/connected.setup' | ||
|
||
const test = testWithSynpress(connectedSetup, unlockForFixture) | ||
|
||
const { expect, describe } = test | ||
|
||
describe('when adding a new network', () => { | ||
test('should switch to the new network', async ({ context, metamaskPage, page, extensionId }) => { | ||
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId) | ||
|
||
await page.goto('https://metamask.github.io/test-dapp/') | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x1') | ||
|
||
await page.locator('#addEthereumChain').click() | ||
|
||
await metamask.approveNewNetwork() | ||
await metamask.approveSwitchNetwork() | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x53a') | ||
}) | ||
}) | ||
|
||
test('should switch to the requested network', async ({ context, metamaskPage, page, extensionId }) => { | ||
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId) | ||
|
||
await page.goto('https://metamask.github.io/test-dapp/') | ||
|
||
await page.locator('#addEthereumChain').click() | ||
|
||
await metamask.approveNewNetwork() | ||
await metamask.rejectSwitchNetwork() | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x1') | ||
|
||
await page.locator('#switchEthereumChain').click() | ||
|
||
await metamask.approveSwitchNetwork() | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x53a') | ||
}) |
22 changes: 22 additions & 0 deletions
22
wallets/metamask/test/e2e/metamask/rejectAddNetwork.spec.ts
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,22 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import connectedSetup from '../wallet-setup/connected.setup' | ||
|
||
const test = testWithSynpress(connectedSetup, unlockForFixture) | ||
|
||
const { expect } = test | ||
|
||
test('should reject new network request', async ({ context, metamaskPage, page, extensionId }) => { | ||
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId) | ||
|
||
await page.goto('https://metamask.github.io/test-dapp/') | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x1') | ||
|
||
await page.locator('#addEthereumChain').click() | ||
|
||
await metamask.rejectNewNetwork() | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x1') | ||
}) |
44 changes: 44 additions & 0 deletions
44
wallets/metamask/test/e2e/metamask/rejectSwitchNetwork.spec.ts
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,44 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import connectedSetup from '../wallet-setup/connected.setup' | ||
|
||
const test = testWithSynpress(connectedSetup, unlockForFixture) | ||
|
||
const { expect, describe } = test | ||
|
||
describe('when adding a new network', () => { | ||
test('should reject switch network request', async ({ context, metamaskPage, page, extensionId }) => { | ||
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId) | ||
|
||
await page.goto('https://metamask.github.io/test-dapp/') | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x1') | ||
|
||
await page.locator('#addEthereumChain').click() | ||
|
||
await metamask.approveNewNetwork() | ||
await metamask.rejectSwitchNetwork() | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x1') | ||
}) | ||
}) | ||
|
||
test('should reject switch network request', async ({ context, metamaskPage, page, extensionId }) => { | ||
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId) | ||
|
||
await page.goto('https://metamask.github.io/test-dapp/') | ||
|
||
await page.locator('#addEthereumChain').click() | ||
|
||
await metamask.approveNewNetwork() | ||
await metamask.rejectSwitchNetwork() | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x1') | ||
|
||
await page.locator('#switchEthereumChain').click() | ||
|
||
await metamask.rejectSwitchNetwork() | ||
|
||
await expect(page.locator('#chainId')).toHaveText('0x1') | ||
}) |