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

feat: added test network as selected network if globally selected for connection Request #27980

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from

Conversation

NidhiKJha
Copy link
Member

@NidhiKJha NidhiKJha commented Oct 21, 2024

This PR is to select a test network in the default selected networks list if its the globally selected network at the time of connection request.

Related issues

Fixes: #27891

Manual testing steps

  1. Run extension with yarn start
  2. Switch to Sepolia
  3. Go to test-dapp, click on connect.
  4. In the connections page, check Sepolia is the selected along with non test networks
  5. Click confirm, dapp should be connected to MM and user should be on Sepolia network in MM.

Screenshots/Recordings

Before

Screen.Recording.2024-10-21.at.3.09.20.PM.mov

After

Screen.Recording.2024-10-21.at.3.07.23.PM.mov

Pre-merge author checklist

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.

@NidhiKJha NidhiKJha added team-wallet-ux needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. labels Oct 21, 2024
@NidhiKJha NidhiKJha requested a review from a team as a code owner October 21, 2024 09:39
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Oct 21, 2024
@NidhiKJha NidhiKJha requested a review from a team as a code owner October 21, 2024 09:51
@@ -240,37 +222,19 @@ describe('Request Queuing Dapp 1, Switch Tx -> Dapp 2 Send Tx', function () {
`window.ethereum.request(${switchEthereumChainRequest})`,
);

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
Copy link
Member Author

Choose a reason for hiding this comment

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

Since Dapp is already connected to Test Network, we don't need to show review permission screem

Copy link
Contributor

@jiexi jiexi Oct 24, 2024

Choose a reason for hiding this comment

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

the goal of the switch call is to trigger an approval to permit a chain that is not already permitted. This check still needs to occur. Instead the switch call above to should target 0x53a It may be easier to unselect 0x539 (Localhost 8545) when Dapp One is connecting

@metamaskbot
Copy link
Collaborator

Builds ready [0355cf1]
Page Load Metrics (2039 ± 204 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint35836041936558268
domContentLoaded157535161991414199
load158735912039425204
domInteractive2198512311
backgroundConnect990462813
firstReactRender46200974120
getState568222210
initialActions01000
loadScripts111324251456293141
setupStore1195322411
uiStartup180238042258430206
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 242 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [aec3385]
Page Load Metrics (2213 ± 106 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint191726682217215103
domContentLoaded186326542173224108
load187926682213220106
domInteractive30259695024
backgroundConnect977352412
firstReactRender542141213818
getState5154293517
initialActions01000
loadScripts13562142162218589
setupStore1189362813
uiStartup214131142497259124
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 242 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Comment on lines -76 to -89
const editButtons = await this.driver.findElements(
'[data-testid="edit"]',
);
await editButtons[1].click();

await this.driver.clickElement({
text: 'Localhost 8545',
tag: 'p',
});

await this.driver.clickElement(
'[data-testid="connect-more-chains-button"]',
);

Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed anymore since testnet is now included in the connections request

@metamaskbot
Copy link
Collaborator

Builds ready [a18a31d]
Page Load Metrics (1737 ± 127 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30018621550405194
domContentLoaded152228271718265127
load153128451737265127
domInteractive237344188
backgroundConnect96320147
firstReactRender43196964019
getState45915178
initialActions01000
loadScripts111121301289207100
setupStore1168242110
uiStartup171431051952287138
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 242 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Member

@FrederikBolding FrederikBolding left a comment

Choose a reason for hiding this comment

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

General logic looks good to me. Would appreciate if someone else reviews the E2E changes in detail

Comment on lines +102 to +105
const selectedTestNetwork = testNetworks.filter(
(network: { chainId: string }) =>
network.chainId === currentlySelectedNetworkChainId,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

there should only be one network that matches the chainId, does that sound right to you? We may want to use .find() here to make that clearer if so

);

const selectedNetworksList =
selectedTestNetwork === undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not clear to me how selectedTestNetwork would ever be undefined if it's the result of testNetworks.filter() which should always return an array

Comment on lines -101 to -106
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.findElement({
text: 'Use your enabled networks',
tag: 'p',
});

Copy link
Contributor

Choose a reason for hiding this comment

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

this check should still be valid. The globally selected network is 0x53a when Dapp Two connects, meaning that 0x539 should not be connected for Dapp Two and a Chain Permission approval should appear when trying to switch to it

Comment on lines -122 to -134
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.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
});

Copy link
Contributor

Choose a reason for hiding this comment

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

this should also still be valid, but I would assume the confirmation is on Localhost 8545

await driver.switchToWindowWithUrl(DAPP_ONE_URL);

await driver.clickElement('#sendButton');

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

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

Choose a reason for hiding this comment

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

this needs to stay the same as well since we are testing the scenario when there is an approval for permitting a chain

Comment on lines -262 to -273
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.clickElementAndWaitForWindowToClose({
text: 'Confirm',
tag: 'button',
});
Copy link
Contributor

Choose a reason for hiding this comment

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

this should stay as well. The goal here is to confirm that the network switch on Dapp One did not affect Dapp Two

Comment on lines +161 to +206
// Switch to Dapp One and connect it
await driver.switchToWindowWithUrl(DAPP_URL);
await driver.clickElement({ text: 'Connect', tag: 'button' });

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

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

// Switch to MM and disconnect localhost 8545 for Dapp One

await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElement(
'[data-testid ="account-options-menu-button"]',
);
await driver.clickElement({
text: 'All Permissions',
tag: 'div',
});
await driver.clickElementAndWaitToDisappear({
text: 'Got it',
tag: 'button',
});
await driver.clickElement({
text: '127.0.0.1:8080',
tag: 'p',
});
const editButtons = await driver.findElements('[data-testid="edit"]');

assert.ok(editButtons.length > 0, 'Edit buttons are available');

await editButtons[1].click();

// Disconnect Mainnet
await driver.clickElement({
text: 'Localhost 8546',
tag: 'p',
});

await driver.clickElement('[data-testid="connect-more-chains-button"]');
// Switch to Dapp Two
await driver.switchToWindowWithUrl(DAPP_ONE_URL);
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts on the connection happening right after line 147? You also had a nice pattern in the other test of deselecting a network during the connection flow which would be great to use here instead of opening the wallet and disconnecting the chain after connecting it

Comment on lines +329 to +358
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElement(
'[data-testid ="account-options-menu-button"]',
);
await driver.clickElement({ text: 'All Permissions', tag: 'div' });
await driver.clickElementAndWaitToDisappear({
text: 'Got it',
tag: 'button',
});
await driver.clickElement({
text: '127.0.0.1:8081',
tag: 'p',
});
const editButtons = await driver.findElements('[data-testid="edit"]');

// Ensure there are edit buttons
assert.ok(editButtons.length > 0, 'Edit buttons are available');

// Click the first (0th) edit button
await editButtons[1].click();

// Disconnect Mainnet
await driver.clickElement({
text: 'Localhost 8545',
tag: 'p',
});

await driver.clickElement('[data-testid="connect-more-chains-button"]');
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, would be nice to just not connect Dapp Two to 0x539 during the connection flow itself rather than disconnecting it afterwards

Comment on lines +478 to +507
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElement(
'[data-testid ="account-options-menu-button"]',
);
await driver.clickElement({ text: 'All Permissions', tag: 'div' });
await driver.clickElementAndWaitToDisappear({
text: 'Got it',
tag: 'button',
});
await driver.clickElement({
text: '127.0.0.1:8081',
tag: 'p',
});
const editButtons = await driver.findElements('[data-testid="edit"]');

// Ensure there are edit buttons
assert.ok(editButtons.length > 0, 'Edit buttons are available');

// Click the first (0th) edit button
await editButtons[1].click();

// Disconnect Mainnet
await driver.clickElement({
text: 'Localhost 8545',
tag: 'p',
});

await driver.clickElement('[data-testid="connect-more-chains-button"]');
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
INVALID-PR-TEMPLATE PR's body doesn't match template needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. team-wallet-ux
Projects
None yet
5 participants