|
| 1 | +const { strict: assert } = require('assert'); |
| 2 | +const { By, Key } = require('selenium-webdriver'); |
| 3 | +const { withFixtures, regularDelayMs } = require('../helpers'); |
| 4 | + |
| 5 | +describe('MetaMask', function () { |
| 6 | + it('provider should inform dapp when switching networks', async function () { |
| 7 | + const ganacheOptions = { |
| 8 | + accounts: [ |
| 9 | + { |
| 10 | + secretKey: |
| 11 | + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', |
| 12 | + balance: 25000000000000000000, |
| 13 | + }, |
| 14 | + ], |
| 15 | + }; |
| 16 | + await withFixtures( |
| 17 | + { |
| 18 | + dapp: true, |
| 19 | + fixtures: 'connected-state', |
| 20 | + ganacheOptions, |
| 21 | + title: this.test.title, |
| 22 | + }, |
| 23 | + async ({ driver }) => { |
| 24 | + await driver.navigate(); |
| 25 | + const passwordField = await driver.findElement(By.css('#password')); |
| 26 | + await passwordField.sendKeys('correct horse battery staple'); |
| 27 | + await passwordField.sendKeys(Key.ENTER); |
| 28 | + |
| 29 | + await driver.openNewPage('http://127.0.0.1:8080/'); |
| 30 | + const networkDiv = await driver.findElement(By.css('#network')); |
| 31 | + const chainIdDiv = await driver.findElement(By.css('#chainId')); |
| 32 | + await driver.delay(regularDelayMs); |
| 33 | + assert.equal(await networkDiv.getText(), '1337'); |
| 34 | + assert.equal(await chainIdDiv.getText(), '0x539'); |
| 35 | + |
| 36 | + const windowHandles = await driver.getAllWindowHandles(); |
| 37 | + await driver.switchToWindow(windowHandles[0]); |
| 38 | + |
| 39 | + await driver.clickElement(By.css('.network-display')); |
| 40 | + await driver.clickElement( |
| 41 | + By.xpath(`//span[contains(text(), 'Ropsten')]`), |
| 42 | + ); |
| 43 | + await driver.delay(regularDelayMs); |
| 44 | + |
| 45 | + await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles); |
| 46 | + const switchedNetworkDiv = await driver.findElement(By.css('#network')); |
| 47 | + const switchedChainIdDiv = await driver.findElement(By.css('#chainId')); |
| 48 | + const accountsDiv = await driver.findElement(By.css('#accounts')); |
| 49 | + |
| 50 | + assert.equal(await switchedNetworkDiv.getText(), '3'); |
| 51 | + assert.equal(await switchedChainIdDiv.getText(), '0x3'); |
| 52 | + assert.equal( |
| 53 | + await accountsDiv.getText(), |
| 54 | + '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', |
| 55 | + ); |
| 56 | + }, |
| 57 | + ); |
| 58 | + }); |
| 59 | +}); |
0 commit comments