2022-03-29 17:47:45 +02:00
|
|
|
const { strict: assert } = require('assert');
|
2023-05-05 15:56:08 +02:00
|
|
|
const {
|
|
|
|
convertToHexValue,
|
|
|
|
withFixtures,
|
|
|
|
openDapp,
|
|
|
|
DAPP_URL,
|
|
|
|
DAPP_ONE_URL,
|
2023-07-13 14:02:06 +02:00
|
|
|
unlockWallet,
|
|
|
|
WINDOW_TITLES,
|
2023-05-05 15:56:08 +02:00
|
|
|
} = require('../helpers');
|
2022-10-28 10:42:12 +02:00
|
|
|
const FixtureBuilder = require('../fixture-builder');
|
2022-03-29 17:47:45 +02:00
|
|
|
|
|
|
|
describe('Dapp interactions', function () {
|
|
|
|
const ganacheOptions = {
|
|
|
|
accounts: [
|
|
|
|
{
|
|
|
|
secretKey:
|
|
|
|
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
|
|
|
|
balance: convertToHexValue(25000000000000000000),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
it('should trigger the add chain confirmation despite MetaMask being locked', async function () {
|
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
dapp: true,
|
2022-10-28 10:42:12 +02:00
|
|
|
fixtures: new FixtureBuilder().build(),
|
2022-06-15 15:50:37 +02:00
|
|
|
ganacheOptions: {
|
|
|
|
...ganacheOptions,
|
|
|
|
concurrent: { port: 8546, chainId: 1338 },
|
|
|
|
},
|
2022-03-29 17:47:45 +02:00
|
|
|
title: this.test.title,
|
|
|
|
},
|
|
|
|
async ({ driver }) => {
|
|
|
|
await driver.navigate();
|
2023-05-05 15:56:08 +02:00
|
|
|
await openDapp(driver);
|
2022-03-29 17:47:45 +02:00
|
|
|
|
|
|
|
// Trigger Notification
|
|
|
|
await driver.clickElement('#addEthereumChain');
|
2022-06-15 15:50:37 +02:00
|
|
|
await driver.waitUntilXWindowHandles(3);
|
2023-07-13 14:02:06 +02:00
|
|
|
await driver.switchToWindowWithTitle('MetaMask Notification');
|
|
|
|
await unlockWallet(driver);
|
2022-03-29 17:47:45 +02:00
|
|
|
const notification = await driver.isElementPresent({
|
|
|
|
text: 'Allow this site to add a network?',
|
|
|
|
tag: 'h3',
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.ok(notification, 'Dapp action does not appear in Metamask');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-06-03 18:32:50 +02:00
|
|
|
it('should connect a second Dapp despite MetaMask being locked', async function () {
|
2022-03-29 17:47:45 +02:00
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
dapp: true,
|
2022-10-28 10:42:12 +02:00
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withPermissionControllerConnectedToTestDapp()
|
|
|
|
.build(),
|
2022-03-29 17:47:45 +02:00
|
|
|
ganacheOptions,
|
|
|
|
dappOptions: { numberOfDapps: 2 },
|
|
|
|
title: this.test.title,
|
|
|
|
},
|
|
|
|
async ({ driver }) => {
|
|
|
|
await driver.navigate();
|
|
|
|
|
2023-07-13 14:02:06 +02:00
|
|
|
// Connect to 2nd dapp => DAPP_ONE
|
2023-05-05 15:56:08 +02:00
|
|
|
await openDapp(driver, null, DAPP_ONE_URL);
|
2022-03-29 17:47:45 +02:00
|
|
|
await driver.clickElement({ text: 'Connect', tag: 'button' });
|
2023-07-13 14:02:06 +02:00
|
|
|
await driver.waitUntilXWindowHandles(3);
|
2022-03-29 17:47:45 +02:00
|
|
|
|
2023-07-13 14:02:06 +02:00
|
|
|
await driver.switchToWindowWithTitle(WINDOW_TITLES.Notification);
|
2022-03-29 17:47:45 +02:00
|
|
|
|
2023-07-13 14:02:06 +02:00
|
|
|
await unlockWallet(driver);
|
2022-03-29 17:47:45 +02:00
|
|
|
await driver.clickElement({ text: 'Next', tag: 'button' });
|
|
|
|
await driver.clickElement({ text: 'Connect', tag: 'button' });
|
2023-07-13 14:02:06 +02:00
|
|
|
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
|
|
|
|
await driver.waitForSelector({
|
|
|
|
css: '#accounts',
|
|
|
|
text: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
|
|
|
|
});
|
2022-03-29 17:47:45 +02:00
|
|
|
|
|
|
|
// Assert Connection
|
2023-07-13 14:02:06 +02:00
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
WINDOW_TITLES.ExtensionInFullScreenView,
|
|
|
|
);
|
|
|
|
await unlockWallet(driver);
|
2022-03-29 17:47:45 +02:00
|
|
|
await driver.clickElement(
|
|
|
|
'[data-testid ="account-options-menu-button"]',
|
|
|
|
);
|
2023-07-13 14:02:06 +02:00
|
|
|
|
2023-02-21 16:50:54 +01:00
|
|
|
await driver.clickElement({ text: 'Connected sites', tag: 'div' });
|
2023-07-13 14:02:06 +02:00
|
|
|
|
2022-03-29 17:47:45 +02:00
|
|
|
const connectedDapp1 = await driver.isElementPresent({
|
2023-05-05 15:56:08 +02:00
|
|
|
text: DAPP_URL,
|
2022-11-04 14:26:51 +01:00
|
|
|
tag: 'bdi',
|
2022-03-29 17:47:45 +02:00
|
|
|
});
|
|
|
|
const connectedDapp2 = await driver.isElementPresent({
|
2023-05-05 15:56:08 +02:00
|
|
|
text: DAPP_ONE_URL,
|
2022-11-04 14:26:51 +01:00
|
|
|
tag: 'bdi',
|
2022-03-29 17:47:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.ok(connectedDapp1, 'Account not connected to Dapp1');
|
|
|
|
assert.ok(connectedDapp2, 'Account not connected to Dapp2');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|