-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
118 additions
and
98 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
95 changes: 0 additions & 95 deletions
95
test/e2e/tests/request-queuing/dapp1-subscribe-network-switch.spec.js
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
test/e2e/tests/request-queuing/dapp1-subscribe-network-switch.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,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); | ||
}, | ||
); | ||
}); | ||
}); |