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: chainid, switch custom net, batch tx diff, snaps #27725

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions test/e2e/snaps/test-snap-txinsights-v2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const {
defaultGanacheOptions,
withFixtures,
unlockWallet,
switchToNotificationWindow,
WINDOW_TITLES,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
Expand Down Expand Up @@ -37,22 +36,18 @@ describe('Test Snap TxInsights-v2', function () {
await driver.clickElement('#connecttransaction-insights');

// switch to metamask extension and click connect
await switchToNotificationWindow(driver);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement({
text: 'Connect',
tag: 'button',
});

await driver.waitForSelector({ text: 'Connect' });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed as clicking the element already implies the button is there and clickable


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

await driver.waitForSelector({ text: 'OK' });

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
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 mitigates race conditions: we should not proceed to the next step until the dialog is closed

text: 'OK',
tag: 'button',
});
Expand All @@ -62,8 +57,8 @@ describe('Test Snap TxInsights-v2', function () {
await driver.clickElement('#getAccounts');

// switch back to MetaMask window and deal with dialogs
await switchToNotificationWindow(driver);
await driver.clickElement({
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElementAndWaitForWindowToClose({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same, wait for the dialog to close before proceeding

text: 'Connect',
tag: 'button',
});
Expand All @@ -74,7 +69,7 @@ describe('Test Snap TxInsights-v2', function () {

// switch back to MetaMask window and switch to tx insights pane
await driver.delay(2000);
await switchToNotificationWindow(driver);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.findClickableElement({
text: 'Confirm',
Expand Down
20 changes: 6 additions & 14 deletions test/e2e/snaps/test-snap-txinsights.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const {
defaultGanacheOptions,
withFixtures,
unlockWallet,
switchToNotificationWindow,
WINDOW_TITLES,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
Expand Down Expand Up @@ -37,22 +36,18 @@ describe('Test Snap TxInsights', function () {
await driver.clickElement('#connecttransaction-insights');

// switch to metamask extension and click connect
await switchToNotificationWindow(driver, 2);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement({
text: 'Connect',
tag: 'button',
});

await driver.waitForSelector({ text: 'Confirm' });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed


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

await driver.waitForSelector({ text: 'OK' });

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait for the dialog to close before proceeding

text: 'OK',
tag: 'button',
});
Expand All @@ -62,8 +57,8 @@ describe('Test Snap TxInsights', function () {
await driver.clickElement('#getAccounts');

// switch back to MetaMask window and deal with dialogs
await switchToNotificationWindow(driver, 2);
await driver.clickElement({
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElementAndWaitForWindowToClose({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait for the dialog to close before proceeding

text: 'Connect',
tag: 'button',
});
Expand All @@ -74,11 +69,8 @@ describe('Test Snap TxInsights', function () {

// switch back to MetaMask window and switch to tx insights pane
await driver.delay(2000);
await switchToNotificationWindow(driver, 2);
await driver.waitForSelector({
text: 'Insights Example Snap',
tag: 'button',
});
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.clickElement({
text: 'Insights Example Snap',
tag: 'button',
Expand Down
11 changes: 2 additions & 9 deletions test/e2e/tests/network/switch-custom-network.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,16 @@ describe('Switch ethereum chain', function () {
async ({ driver }) => {
await unlockWallet(driver);

const windowHandles = await driver.getAllWindowHandles();

await openDapp(driver);

await driver.clickElement({
tag: 'button',
text: 'Add Localhost 8546',
});

await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.switchToWindowWithTitle(
WINDOW_TITLES.Dialog,
windowHandles,
);

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
tag: 'button',
text: 'Approve',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ const {
unlockWallet,
DAPP_URL,
DAPP_ONE_URL,
regularDelayMs,
WINDOW_TITLES,
defaultGanacheOptions,
largeDelayMs,
switchToNotificationWindow,
} = require('../../helpers');
const { PAGES } = require('../../webdriver/driver');

Expand Down Expand Up @@ -49,14 +47,11 @@ describe('Request Queuing for Multiple Dapps and Txs on different networks', fun
await openDapp(driver, undefined, DAPP_URL);

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

await driver.delay(regularDelayMs);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await switchToNotificationWindow(driver);

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait for the dialog to close before proceeding

text: 'Connect',
tag: 'button',
});
Expand All @@ -82,14 +77,11 @@ describe('Request Queuing for Multiple Dapps and Txs on different networks', fun
await openDapp(driver, undefined, DAPP_ONE_URL);

// Connect to dapp 2
await driver.findClickableElement({ text: 'Connect', tag: 'button' });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed

await driver.clickElement('#connectButton');

await driver.delay(regularDelayMs);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed

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

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

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
text: 'Connect',
tag: 'button',
});
Expand All @@ -108,24 +100,29 @@ describe('Request Queuing for Multiple Dapps and Txs on different networks', fun
await driver.clickElement('#sendButton');
await driver.clickElement('#sendButton');

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

await driver.findElement(
await driver.waitForSelector(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just a nit

By.xpath("//div[normalize-space(.)='1 of 2']"),
);

// Reject All Transactions
await driver.clickElement('.page-container__footer-secondary a');

await driver.clickElement({ text: 'Reject all', tag: 'button' }); // TODO: Do we want to confirm here?
// TODO: Do we want to confirm here?
await driver.clickElementAndWaitForWindowToClose({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait for the dialog to close before proceeding

text: 'Reject all',
tag: 'button',
});

// Wait for confirmation to close
await driver.waitUntilXWindowHandles(3);
// TODO: find a better way to handle different dialog ids
await driver.delay(2000);

// Wait for new confirmations queued from second dapp to open
await switchToNotificationWindow(driver, 4);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await driver.findElement(
await driver.waitForSelector(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit

By.xpath("//div[normalize-space(.)='1 of 2']"),
);

Expand Down
23 changes: 14 additions & 9 deletions test/e2e/tests/request-queuing/chainid-check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,11 @@ describe('Request Queueing chainId proxy sync', function () {
assert.equal(chainIdBeforeConnectAfterManualSwitch, '0x1');

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

await driver.delay(regularDelayMs);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await switchToNotificationWindow(driver);
await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
text: 'Connect',
tag: 'button',
});
Expand All @@ -252,6 +250,10 @@ describe('Request Queueing chainId proxy sync', function () {

// should still be on the same chainId as the wallet after connecting
assert.equal(chainIdAfterConnect, '0x1');
await driver.waitForSelector({
css: '[id="chainId"]',
text: '0x1',
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ensure the test dapp has the new chain id too


const switchEthereumChainRequest = JSON.stringify({
jsonrpc: '2.0',
Expand All @@ -263,14 +265,13 @@ describe('Request Queueing chainId proxy sync', function () {
`window.ethereum.request(${switchEthereumChainRequest})`,
);

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

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

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

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

const chainIdAfterDappSwitch = await driver.executeScript(
Expand All @@ -280,6 +281,10 @@ describe('Request Queueing chainId proxy sync', function () {
// should be on the new chainId that was requested
assert.equal(chainIdAfterDappSwitch, '0x539'); // 1337

await driver.waitForSelector({
css: '[id="chainId"]',
text: '0x539',
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ensure the test dapp has the new chain id too

await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
Expand Down