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

test: add e2e for scenario where wallet_switchEthereumChain call is canceled with other confirmations queued behind it #25341

Merged
merged 6 commits into from
Jun 25, 2024
156 changes: 155 additions & 1 deletion test/e2e/tests/request-queuing/dapp1-switch-dapp2-send.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
} = require('../../helpers');

describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
it('should queue send tx after switch network confirmation.', async function () {
it('should queue send tx after switch network confirmation and transaction should target the correct network after switch is confirmed', async function () {
const port = 8546;
const chainId = 1338;
await withFixtures(
Expand Down Expand Up @@ -165,4 +165,158 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
},
);
});

it('should queue send tx after switch network confirmation and transaction should target the correct network after switch is cancelled.', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be helpful if there were a comment above this describing that the original bug was noticed on https://app.odos.xyz/, describing the manual procedure for reproducing, and pointing to the PRs that fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

this test is covering a different scenario from the eth_requestAccount requests not being passed through that you discovered with ODOS

Instead see: #25310

const port = 8546;
const chainId = 1338;
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withNetworkControllerTripleGanache()
.withPreferencesControllerUseRequestQueueEnabled()
.withSelectedNetworkControllerPerDomain()
.build(),
dappOptions: { numberOfDapps: 2 },
ganacheOptions: {
...defaultGanacheOptions,
concurrent: [
{
port,
chainId,
ganacheOptions2: defaultGanacheOptions,
},
{
port: 7777,
chainId: 1000,
ganacheOptions2: defaultGanacheOptions,
},
],
},
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);

// Open Dapp One
await openDapp(driver, undefined, DAPP_URL);

// Connect to dapp
await driver.findClickableElement({ text: 'Connect', tag: 'button' });
await driver.clickElement('#connectButton');

await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver);

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

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

await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);

// Network Selector
await driver.clickElement('[data-testid="network-display"]');

// Switch to second network
await driver.clickElement({
text: 'Localhost 8546',
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);

// Connect to dapp 2
await driver.findClickableElement({ text: 'Connect', tag: 'button' });
await driver.clickElement('#connectButton');

await driver.delay(regularDelayMs);

await switchToNotificationWindow(driver, 4);

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

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

await driver.switchToWindowWithUrl(DAPP_URL);

// switchEthereumChain request
const switchEthereumChainRequest = JSON.stringify({
jsonrpc: '2.0',
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x3e8' }],
});

// Initiate switchEthereumChain on Dapp Two
await driver.executeScript(
`window.ethereum.request(${switchEthereumChainRequest})`,
);

await driver.switchToWindowWithUrl(DAPP_ONE_URL);

await driver.clickElement('#sendButton');

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

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

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

await switchToNotificationWindow(driver, 4);

// 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' });

// Switch back to the extension
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);

await driver.clickElement(
'[data-testid="account-overview__activity-tab"]',
);

// Check for transaction
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
'.transaction-list__completed-transactions .activity-list-item',
);
return confirmedTxes.length === 1;
}, 10000);
},
);
});
});