Skip to content

Commit

Permalink
spec migration
Browse files Browse the repository at this point in the history
  • Loading branch information
seaona committed Dec 19, 2024
1 parent 5aa2962 commit 5ae20ff
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 98 deletions.
15 changes: 12 additions & 3 deletions test/e2e/page-objects/pages/header-navbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class HeaderNavbar {
console.log('Header navbar is loaded');
}

async clickSwitchNetworkDropDown(): Promise<void> {
console.log(`Click switch network menu`);
await this.driver.clickElement(this.switchNetworkDropDown);
}

async lockMetaMask(): Promise<void> {
await this.openThreeDotMenu();
await this.driver.clickElement(this.lockMetaMaskButton);
Expand Down Expand Up @@ -75,9 +80,13 @@ class HeaderNavbar {
await this.driver.clickElement(this.settingsButton);
}

async clickSwitchNetworkDropDown(): Promise<void> {
console.log(`Click switch network menu`);
await this.driver.clickElement(this.switchNetworkDropDown);
async switchNetwork(network: string): Promise<void> {
console.log(`Switch to ${network} network`);
await this.clickSwitchNetworkDropDown();
await this.driver.clickElement({
tag: 'p',
text: network,
});
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/seeder/ganache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export class Ganache {
});
}

async mineBlock() {
return await this.getProvider()?.request({
method: 'evm_mine',
params: [],
});
}

async quit() {
if (!this.#server) {
throw new Error('Server not running yet');
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { strict as assert } from 'assert';
import FixtureBuilder from '../../fixture-builder';
import {
defaultGanacheOptions,
WINDOW_TITLES,
withFixtures,
} from '../../helpers';
import HeaderNavbar from '../../page-objects/pages/header-navbar';
import TestDapp from '../../page-objects/pages/test-dapp';
import { loginWithoutBalanceValidation } from '../../page-objects/flows/login.flow';

describe('Request Queueing', function () {
it('should keep subscription on dapp network when switching different mm network', async function () {
const port = 8546;
const chainId = 1338;
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withNetworkControllerDoubleGanache()
.withPreferencesControllerUseRequestQueueEnabled()
.build(),
ganacheOptions: {
...defaultGanacheOptions,
concurrent: [
{
port,
chainId,
ganacheOptions2: defaultGanacheOptions,
},
],
},
title: this.test?.fullTitle(),
},

async ({ driver, ganacheServer }) => {
await loginWithoutBalanceValidation(driver);

// Connect to dapp
const testDapp = new TestDapp(driver);
await testDapp.openTestDappPage();
await testDapp.check_pageIsLoaded();
await testDapp.connectAccount({});
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

// Subscribe to newHeads event
const subscribeRequest = JSON.stringify({
jsonrpc: '2.0',
method: 'eth_subscribe',
params: ['newHeads'],
});

await driver.executeScript(
`return window.ethereum.request(${subscribeRequest})`,
);

// Save event logs into the messages variable in the window context, to access it later
await driver.executeScript(`
window.messages = [];
window.ethereum.on('message', (message) => {
if (message.type === 'eth_subscription') {
console.log('New block header:', message.data.result);
window.messages.push(message.data.result);
}
});
`);

await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);

// Switch networks
const header = new HeaderNavbar(driver);
await header.switchNetwork('Localhost 8546');

// Navigate back to the test dapp
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

// Access to the window messages variable
const messagesBeforeMining = await driver.executeScript(
'return window.messages;',
);

// Mine a block deterministically
await ganacheServer.mineBlock();

// Wait a couple of seconds for the logs to populate into the messages window variable
await driver.delay(5000);

// Access the window messages variable and check there are more events than before mining
const messagesAfterMining = await driver.executeScript(
'return window.messages;',
);

assert.ok(messagesBeforeMining.length < messagesAfterMining.length);
},
);
});
});

0 comments on commit 5ae20ff

Please sign in to comment.