2023-04-06 17:07:34 +02:00
|
|
|
const { strict: assert } = require('assert');
|
|
|
|
const FixtureBuilder = require('../fixture-builder');
|
2023-05-05 15:56:08 +02:00
|
|
|
const { convertToHexValue, withFixtures, openDapp } = require('../helpers');
|
2023-04-06 17:07:34 +02:00
|
|
|
|
2023-07-12 10:29:54 +02:00
|
|
|
describe('Switch ethereum chain', function () {
|
2023-04-06 17:07:34 +02:00
|
|
|
const ganacheOptions = {
|
|
|
|
accounts: [
|
|
|
|
{
|
|
|
|
secretKey:
|
|
|
|
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
|
|
|
|
balance: convertToHexValue(25000000000000000000),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
concurrent: { port: 8546, chainId: 1338, ganacheOptions2: {} },
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should successfully change the network in response to wallet_switchEthereumChain', async function () {
|
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
dapp: true,
|
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withPermissionControllerConnectedToTestDapp()
|
|
|
|
.build(),
|
|
|
|
ganacheOptions,
|
|
|
|
title: this.test.title,
|
|
|
|
failOnConsoleError: false,
|
|
|
|
},
|
|
|
|
async ({ driver }) => {
|
|
|
|
await driver.navigate();
|
|
|
|
await driver.fill('#password', 'correct horse battery staple');
|
|
|
|
await driver.press('#password', driver.Key.ENTER);
|
|
|
|
|
|
|
|
const windowHandles = await driver.getAllWindowHandles();
|
|
|
|
const extension = windowHandles[0];
|
|
|
|
|
2023-05-05 15:56:08 +02:00
|
|
|
await openDapp(driver);
|
2023-04-06 17:07:34 +02:00
|
|
|
|
|
|
|
await driver.clickElement({
|
|
|
|
tag: 'button',
|
|
|
|
text: 'Add Localhost 8546',
|
|
|
|
});
|
|
|
|
|
|
|
|
await driver.waitUntilXWindowHandles(3);
|
|
|
|
|
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
|
|
|
|
|
|
|
await driver.clickElement({
|
|
|
|
tag: 'button',
|
|
|
|
text: 'Approve',
|
|
|
|
});
|
|
|
|
|
|
|
|
await driver.findElement({
|
|
|
|
tag: 'h3',
|
|
|
|
text: 'Allow this site to switch the network?',
|
|
|
|
});
|
|
|
|
|
|
|
|
// Don't switch to network now, because we will click the 'Switch to Localhost 8546' button below
|
|
|
|
await driver.clickElement({
|
|
|
|
tag: 'button',
|
|
|
|
text: 'Cancel',
|
|
|
|
});
|
|
|
|
|
|
|
|
await driver.waitUntilXWindowHandles(2);
|
|
|
|
|
|
|
|
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
|
|
|
await driver.clickElement({
|
|
|
|
tag: 'button',
|
|
|
|
text: 'Switch to Localhost 8546',
|
|
|
|
});
|
|
|
|
|
|
|
|
await driver.waitUntilXWindowHandles(3);
|
|
|
|
|
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
|
|
|
|
|
|
|
await driver.clickElement({
|
|
|
|
tag: 'button',
|
|
|
|
text: 'Switch network',
|
|
|
|
});
|
|
|
|
|
|
|
|
await driver.waitUntilXWindowHandles(2);
|
|
|
|
|
|
|
|
await driver.switchToWindow(extension);
|
|
|
|
|
|
|
|
const currentNetworkName = await driver.findElement({
|
2023-06-01 23:14:38 +02:00
|
|
|
tag: 'p',
|
2023-04-06 17:07:34 +02:00
|
|
|
text: 'Localhost 8546',
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
Boolean(currentNetworkName),
|
|
|
|
'Failed to switch to custom network',
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|