Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flaky test Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx should queue send tx after switch network confirmation and transaction should target the correct network after switch is confirmed #27352

Merged
merged 15 commits into from
Sep 26, 2024
92 changes: 45 additions & 47 deletions test/e2e/tests/request-queuing/dapp1-switch-dapp2-send.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const FixtureBuilder = require('../../fixture-builder');
const {
withFixtures,
DAPP_ONE_URL,
DAPP_URL,
defaultGanacheOptions,
openDapp,
unlockWallet,
DAPP_URL,
DAPP_ONE_URL,
regularDelayMs,
WINDOW_TITLES,
defaultGanacheOptions,
switchToNotificationWindow,
withFixtures,
} = require('../../helpers');

describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
Expand Down Expand Up @@ -51,17 +49,15 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
await driver.findClickableElement({ text: 'Connect', tag: 'button' });
await driver.clickElement('#connectButton');

await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver);
Copy link
Contributor Author

@seaona seaona Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed deprecated method and using the correct one (no need to add the delay)

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.clickElement({
text: 'Next',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
});

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
Expand All @@ -80,9 +76,6 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
css: 'p',
});

// Wait for the first dapp's connect confirmation to disappear
await driver.waitUntilXWindowHandles(2);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to add this, as we handle the close window into the `clickElementAndWaitForWindowToClose

// TODO: Request Queuing bug when opening both dapps at the same time will have them stuck on the same network, with will be incorrect for one of them.
// Open Dapp Two
await openDapp(driver, undefined, DAPP_ONE_URL);
Expand All @@ -91,17 +84,15 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
await driver.findClickableElement({ text: 'Connect', tag: 'button' });
await driver.clickElement('#connectButton');

await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver, 4);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.clickElement({
text: 'Next',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
});

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
Expand All @@ -121,31 +112,39 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
`window.ethereum.request(${switchEthereumChainRequest})`,
);

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.findElement({
text: 'Allow this site to switch the network?',
tag: 'h3',
});

await driver.switchToWindowWithUrl(DAPP_ONE_URL);

await driver.clickElement('#sendButton');

await switchToNotificationWindow(driver, 4);
await driver.findClickableElements({
text: 'Switch network',
tag: 'button',
});
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.clickElement({ text: 'Switch network', tag: 'button' });

await driver.switchToWindowWithUrl(DAPP_ONE_URL);

// Wait for switch confirmation to close then tx confirmation to show.
await driver.waitUntilXWindowHandles(3);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this point is where test breaks in webpack: if the next dialog window is opened really fast, this condition is never met

await driver.delay(regularDelayMs);
// There is an extra window appearing and disappearing
// so we leave this delay until the issue is fixed (#27360)
await driver.delay(5000);

await switchToNotificationWindow(driver, 4);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

// Check correct network on the send confirmation.
await driver.findElement({
css: '[data-testid="network-display"]',
text: 'Localhost 8546',
});

await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
});

// Switch back to the extension
await driver.switchToWindowWithTitle(
Expand Down Expand Up @@ -206,17 +205,15 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
await driver.findClickableElement({ text: 'Connect', tag: 'button' });
await driver.clickElement('#connectButton');

await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.clickElement({
text: 'Next',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
});

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
Expand All @@ -235,9 +232,6 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
css: 'p',
});

// Wait for the first dapp's connect confirmation to disappear
await driver.waitUntilXWindowHandles(2);

// TODO: Request Queuing bug when opening both dapps at the same time will have them stuck on the same network, with will be incorrect for one of them.
// Open Dapp Two
await openDapp(driver, undefined, DAPP_ONE_URL);
Expand All @@ -246,17 +240,15 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
await driver.findClickableElement({ text: 'Connect', tag: 'button' });
await driver.clickElement('#connectButton');

await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver, 4);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.clickElement({
text: 'Next',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
});

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
Expand All @@ -276,31 +268,37 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
`window.ethereum.request(${switchEthereumChainRequest})`,
);

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.findElement({
text: 'Allow this site to switch the network?',
tag: 'h3',
});

await driver.switchToWindowWithUrl(DAPP_ONE_URL);

await driver.clickElement('#sendButton');

await switchToNotificationWindow(driver, 4);
await driver.findClickableElements({
text: 'Cancel',
tag: 'button',
});
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.clickElement({ text: 'Cancel', tag: 'button' });
await driver.switchToWindowWithUrl(DAPP_ONE_URL);

// Wait for switch confirmation to close then tx confirmation to show.
await driver.waitUntilXWindowHandles(3);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this point is where test breaks in webpack: if the next dialog window is opened really fast, this condition is never met

await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver, 4);
// There is an extra window appearing and disappearing
// so we leave this delay until the issue is fixed (#27360)
await driver.delay(5000);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

// Check correct network on the send confirmation.
await driver.findElement({
css: '[data-testid="network-display"]',
text: 'Localhost 8546',
});

await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
});

// Switch back to the extension
await driver.switchToWindowWithTitle(
Expand Down