Skip to content

Commit

Permalink
test: chainid, switch custom net, batch tx diff, snaps (#27725)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27725?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
seaona authored Oct 9, 2024
1 parent 19b5764 commit c3201f2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 62 deletions.
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' });

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

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

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
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({
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' });

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

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

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
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({
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);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await switchToNotificationWindow(driver);

await driver.clickElement({
await driver.clickElementAndWaitForWindowToClose({
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' });
await driver.clickElement('#connectButton');

await driver.delay(regularDelayMs);
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(
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({
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(
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);
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',
});

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',
});
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
Expand Down

0 comments on commit c3201f2

Please sign in to comment.