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 and create a success e2e tests pipeline against mv3 build #21496

Closed
DDDDDanica opened this issue Oct 23, 2023 · 6 comments · Fixed by #24675
Closed

Fix and create a success e2e tests pipeline against mv3 build #21496

DDDDDanica opened this issue Oct 23, 2023 · 6 comments · Fixed by #24675
Assignees
Labels
INVALID-ISSUE-TEMPLATE Issue's body doesn't match any issue template. MV3 release-11.16.6 Issue or pull request that will be included in release 11.16.6 release-12.0.0 Issue or pull request that will be included in release 12.0.0 team-extension-platform

Comments

@DDDDDanica
Copy link
Contributor

DDDDDanica commented Oct 23, 2023

  • Filtering out tests are flakier in MV3 than MV2,
  • Not necessary need to fix flaky ones overlapping
@DDDDDanica DDDDDanica changed the title Copy of Configure e2e tests so that all existing tests run against the mv3 build Fix and create a success e2e tests pipeline against mv3 build Oct 23, 2023
@DDDDDanica DDDDDanica self-assigned this Oct 23, 2023
@DDDDDanica
Copy link
Contributor Author

Notes: Document the flakyness difference between mv2 and mv3 , and the blocker for mv3 release

@gauthierpetetin
Copy link
Contributor

Notes: Snaps tests are currently failing and will have to be fixed once @brad-decker 's ticket is finalised.

@DDDDDanica
Copy link
Contributor Author

DDDDDanica commented Nov 1, 2023

Updates: report on flaky e2e tests against mv3 build (excluding snaps):

A. MV3 only

Test Name: should show the correct private key for a second account from global menu
Failure Frequency: 252

Test Name: 'should display correct new account name after create'
Failure Frequency: 252

Test Name: should not affect public address when using secret recovery phrase to recover account with non-zero balance @no-mmi
Failure Frequency: 252

Test Name: should be possible to remove an account imported with a private key, but should not be possible to remove an account generated from the SRP imported in onboarding @no-mmi
Failure Frequency: 252

B. Similar as MV2

Private Zenhub Image

@metamaskbot metamaskbot added needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) and removed in-progress labels Nov 10, 2023
@DDDDDanica
Copy link
Contributor Author

Top few after #21672

  'should not have extra properties in UI state mask @no-mmi'                                                          │                                                        'Sentry errors should not have extra properties in UI state mask @no-mmi'                                                         │    72     │
│    1    │                                                                    'should capture UI application state'                                                                     │                                       'Sentry errors after initialization, after opting into metrics @no-mmi should capture UI application state'                                        │    72     │
│    2    │                                                                  'Connects to a Hardware wallet for trezor'                                                                  │                                                              'Import flow @no-mmi Connects to a Hardware wallet for trezor'                                                              │    72     │
│    3    │                                                            'should not show security alerts for benign requests'                                                             │                                           'Confirmation Security Alert - Blockaid @no-mmi should not show security alerts for benign requests'                                           │    72     │
│    4    │                                                                'should capture background application state'                                                                 │                                   'Sentry errors after initialization, after opting into metrics @no-mmi should capture background application state'                                    │    71     │
│    5    │                                                                          'should show banner alert'                                                                          │                                                    'PPOM Blockaid Alert - Malicious ERC20 Approval @no-mmi should show banner alert'                                                     │    69     │
│    6    │                                                                          'should show banner alert'                                                                          │                                                    'PPOM Blockaid Alert - Malicious ERC20 Transfer @no-mmi should show banner alert'                                                     │    69     │
│    7    │                                       'should capture migration log breadcrumbs when there is an invariant state error in a migration'                                       │         'Sentry errors before initialization, after opting into metrics @no-mmi should capture migration log breadcrumbs when there is an invariant state error in a migration' 

danjm added a commit that referenced this issue May 23, 2024
… document under MV3 (#24675)

## **Description**

Our MV3 builds add a "Offscreen Document" to our extension. This means
that when our e2e tests call `driver.getAllWindowHandles()`, a new
window is included in the list (the window for the offscreen document).
This PR updates the e2e tests to handle this change. Comments are left
on each file to explain why the change was needed.

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

## **Related issues**

Fixes: #21496

## **Manual testing steps**

Any of the test files modified in this PR should pass when run locally
with MV3 builds

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.
@github-actions github-actions bot removed the blocked label May 23, 2024
@legobeat legobeat reopened this May 27, 2024
@legobeat
Copy link
Contributor

legobeat commented May 27, 2024

This is currently failing on develop: https://app.circleci.com/pipelines/github/MetaMask/metamask-extension/82879/workflows/3fe572a0-a25c-4c11-bbbc-eeca61cada94/jobs/2959568

<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Mocha Tests" time="59.707" tests="3" failures="3">
  <testsuite name="Root Suite" timestamp="2024-05-26T02:05:05" tests="0" time="0.000" failures="0">
  </testsuite>
  <testsuite name="Snap Account Signatures" timestamp="2024-05-26T02:05:05" tests="3" file="/home/circleci/project/test/e2e/accounts/snap-account-signatures.spec.ts" time="59.706" failures="3">
    <testcase name="Snap Account Signatures can sign with sync flow" time="20.428" classname="can sign with sync flow">
      <failure message="Waiting for element to be located By(xpath, //span[contains(text(), &quot;Connected&quot;)])
Wait timed out after 10154ms
  (Ran on CircleCI Node 0 of 16, Job test-e2e-chrome-mv3)" type="TimeoutError"><![CDATA[TimeoutError: Waiting for element to be located By(xpath, //span[contains(text(), "Connected")])
Wait timed out after 10154ms
  (Ran on CircleCI Node 0 of 16, Job test-e2e-chrome-mv3)
    at /home/circleci/project/node_modules/selenium-webdriver/lib/webdriver.js:929:17
    at processTicksAndRejections (node:internal/process/task_queues:95:5)]]></failure>
    </testcase>
    <testcase name="Snap Account Signatures can sign with approve flow" time="19.592" classname="can sign with approve flow">
      <failure message="Waiting for element to be located By(xpath, //span[contains(text(), &quot;Connected&quot;)])
Wait timed out after 10139ms
  (Ran on CircleCI Node 0 of 16, Job test-e2e-chrome-mv3)" type="TimeoutError"><![CDATA[TimeoutError: Waiting for element to be located By(xpath, //span[contains(text(), "Connected")])
Wait timed out after 10139ms
  (Ran on CircleCI Node 0 of 16, Job test-e2e-chrome-mv3)
    at /home/circleci/project/node_modules/selenium-webdriver/lib/webdriver.js:929:17
    at processTicksAndRejections (node:internal/process/task_queues:95:5)]]></failure>
    </testcase>
    <testcase name="Snap Account Signatures can sign with reject flow" time="19.682" classname="can sign with reject flow">
      <failure message="Waiting for element to be located By(xpath, //span[contains(text(), &quot;Connected&quot;)])
Wait timed out after 10146ms
  (Ran on CircleCI Node 0 of 16, Job test-e2e-chrome-mv3)" type="TimeoutError"><![CDATA[TimeoutError: Waiting for element to be located By(xpath, //span[contains(text(), "Connected")])
Wait timed out after 10146ms
  (Ran on CircleCI Node 0 of 16, Job test-e2e-chrome-mv3)
    at /home/circleci/project/node_modules/selenium-webdriver/lib/webdriver.js:929:17
    at processTicksAndRejections (node:internal/process/task_queues:95:5)]]></failure>
    </testcase>
  </testsuite>
</testsuites>

Does not appear to be overlapping.

danjm added a commit that referenced this issue May 29, 2024
…pps get correct response to 'seenRequests' (#24672)

## **Description**

This PR fixes the following problem:

1. Dapp sends a request to MetaMask shortly after the service worker
starts up, and _before_ the inpage provider receives the
`METAMASK_EXTENSION_CONNECT_CAN_RETRY` message from the content-script
(which happens after the metamask controller initializes and notifies
all connections of a `chainChanged` event)
2. The request hits the middleware created by
`createDupeReqFilterMiddleware.ts` and its id is added to
`seenRequestIds`
3. Before the necessary controller responds to the request, the inpage
provider _now_ receives the `METAMASK_EXTENSION_CONNECT_CAN_RETRY`
message from the content-script
4. The provider now retries the request. This happens without the dapp
doing anything; this is part of our MV3 retry logic to ensure requests
don't get lost under service worker stoppage / start-up conditions. (The
provider does this via the imported `createStreamMiddleware`
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L128-L130)
5. The new retry of the request hits the middleware created by
`createDupeReqFilterMiddleware`. (The original request still has not
been responded to.) The new retry of the request has the same id as the
original, so the middleware hits the `} else if
(!seenRequestIds.add(req.id)) {` condition and calls `end()`
6. The original request, which was being awaited by the dapp, now is
resolved but without a meaningful response (as the middleware just did
an `end()` call without the request being handled in any way)

This problem was discovered by some e2e tests which became very flaky
under MV3. Tests that involved the Simple Snap Keyring dapp would often
send a `wallet_requestSnaps` request, and then not get the necessary
response, due to the issue described above.

The solution to the problem presented in this PR is just to not call
`end` when seeing a duplicate request, because the original request
should be responded to eventually.

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

## **Related issues**

Part of the resolution to
#21496

## **Manual testing steps**

The bug is hard to repro manually. You could, perhaps, locally modify
the `createStreamMiddleware` code to call `sendToStream` a second time
for the same request after a short (e.g. 10 millisecond) timeout
(perhaps here:
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L50-L60).
On develop that should result in the original request receiving an empty
response but on this branch the original request should receive a
successful response.

This branch will also contribute to MV3 e2e tests passing, but that will
require some other PRs as well.

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Erik Marks <[email protected]>
danjm added a commit that referenced this issue May 31, 2024
… document under MV3 (#24675)

## **Description**

Our MV3 builds add a "Offscreen Document" to our extension. This means
that when our e2e tests call `driver.getAllWindowHandles()`, a new
window is included in the list (the window for the offscreen document).
This PR updates the e2e tests to handle this change. Comments are left
on each file to explain why the change was needed.

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

## **Related issues**

Fixes: #21496

## **Manual testing steps**

Any of the test files modified in this PR should pass when run locally
with MV3 builds

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.
danjm added a commit that referenced this issue May 31, 2024
…pps get correct response to 'seenRequests' (#24672)

## **Description**

This PR fixes the following problem:

1. Dapp sends a request to MetaMask shortly after the service worker
starts up, and _before_ the inpage provider receives the
`METAMASK_EXTENSION_CONNECT_CAN_RETRY` message from the content-script
(which happens after the metamask controller initializes and notifies
all connections of a `chainChanged` event)
2. The request hits the middleware created by
`createDupeReqFilterMiddleware.ts` and its id is added to
`seenRequestIds`
3. Before the necessary controller responds to the request, the inpage
provider _now_ receives the `METAMASK_EXTENSION_CONNECT_CAN_RETRY`
message from the content-script
4. The provider now retries the request. This happens without the dapp
doing anything; this is part of our MV3 retry logic to ensure requests
don't get lost under service worker stoppage / start-up conditions. (The
provider does this via the imported `createStreamMiddleware`
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L128-L130)
5. The new retry of the request hits the middleware created by
`createDupeReqFilterMiddleware`. (The original request still has not
been responded to.) The new retry of the request has the same id as the
original, so the middleware hits the `} else if
(!seenRequestIds.add(req.id)) {` condition and calls `end()`
6. The original request, which was being awaited by the dapp, now is
resolved but without a meaningful response (as the middleware just did
an `end()` call without the request being handled in any way)

This problem was discovered by some e2e tests which became very flaky
under MV3. Tests that involved the Simple Snap Keyring dapp would often
send a `wallet_requestSnaps` request, and then not get the necessary
response, due to the issue described above.

The solution to the problem presented in this PR is just to not call
`end` when seeing a duplicate request, because the original request
should be responded to eventually.

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

## **Related issues**

Part of the resolution to
#21496

## **Manual testing steps**

The bug is hard to repro manually. You could, perhaps, locally modify
the `createStreamMiddleware` code to call `sendToStream` a second time
for the same request after a short (e.g. 10 millisecond) timeout
(perhaps here:
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L50-L60).
On develop that should result in the original request receiving an empty
response but on this branch the original request should receive a
successful response.

This branch will also contribute to MV3 e2e tests passing, but that will
require some other PRs as well.

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Erik Marks <[email protected]>
danjm added a commit that referenced this issue May 31, 2024
…pps get correct response to 'seenRequests' (#24672)

## **Description**

This PR fixes the following problem:

1. Dapp sends a request to MetaMask shortly after the service worker
starts up, and _before_ the inpage provider receives the
`METAMASK_EXTENSION_CONNECT_CAN_RETRY` message from the content-script
(which happens after the metamask controller initializes and notifies
all connections of a `chainChanged` event)
2. The request hits the middleware created by
`createDupeReqFilterMiddleware.ts` and its id is added to
`seenRequestIds`
3. Before the necessary controller responds to the request, the inpage
provider _now_ receives the `METAMASK_EXTENSION_CONNECT_CAN_RETRY`
message from the content-script
4. The provider now retries the request. This happens without the dapp
doing anything; this is part of our MV3 retry logic to ensure requests
don't get lost under service worker stoppage / start-up conditions. (The
provider does this via the imported `createStreamMiddleware`
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L128-L130)
5. The new retry of the request hits the middleware created by
`createDupeReqFilterMiddleware`. (The original request still has not
been responded to.) The new retry of the request has the same id as the
original, so the middleware hits the `} else if
(!seenRequestIds.add(req.id)) {` condition and calls `end()`
6. The original request, which was being awaited by the dapp, now is
resolved but without a meaningful response (as the middleware just did
an `end()` call without the request being handled in any way)

This problem was discovered by some e2e tests which became very flaky
under MV3. Tests that involved the Simple Snap Keyring dapp would often
send a `wallet_requestSnaps` request, and then not get the necessary
response, due to the issue described above.

The solution to the problem presented in this PR is just to not call
`end` when seeing a duplicate request, because the original request
should be responded to eventually.

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

## **Related issues**

Part of the resolution to
#21496

## **Manual testing steps**

The bug is hard to repro manually. You could, perhaps, locally modify
the `createStreamMiddleware` code to call `sendToStream` a second time
for the same request after a short (e.g. 10 millisecond) timeout
(perhaps here:
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L50-L60).
On develop that should result in the original request receiving an empty
response but on this branch the original request should receive a
successful response.

This branch will also contribute to MV3 e2e tests passing, but that will
require some other PRs as well.

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Erik Marks <[email protected]>
danjm added a commit that referenced this issue May 31, 2024
… document under MV3 (#24675)

## **Description**

Our MV3 builds add a "Offscreen Document" to our extension. This means
that when our e2e tests call `driver.getAllWindowHandles()`, a new
window is included in the list (the window for the offscreen document).
This PR updates the e2e tests to handle this change. Comments are left
on each file to explain why the change was needed.

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

## **Related issues**

Fixes: #21496

## **Manual testing steps**

Any of the test files modified in this PR should pass when run locally
with MV3 builds

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.
danjm added a commit that referenced this issue May 31, 2024
…pps get correct response to 'seenRequests' (#24672)

## **Description**

This PR fixes the following problem:

1. Dapp sends a request to MetaMask shortly after the service worker
starts up, and _before_ the inpage provider receives the
`METAMASK_EXTENSION_CONNECT_CAN_RETRY` message from the content-script
(which happens after the metamask controller initializes and notifies
all connections of a `chainChanged` event)
2. The request hits the middleware created by
`createDupeReqFilterMiddleware.ts` and its id is added to
`seenRequestIds`
3. Before the necessary controller responds to the request, the inpage
provider _now_ receives the `METAMASK_EXTENSION_CONNECT_CAN_RETRY`
message from the content-script
4. The provider now retries the request. This happens without the dapp
doing anything; this is part of our MV3 retry logic to ensure requests
don't get lost under service worker stoppage / start-up conditions. (The
provider does this via the imported `createStreamMiddleware`
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L128-L130)
5. The new retry of the request hits the middleware created by
`createDupeReqFilterMiddleware`. (The original request still has not
been responded to.) The new retry of the request has the same id as the
original, so the middleware hits the `} else if
(!seenRequestIds.add(req.id)) {` condition and calls `end()`
6. The original request, which was being awaited by the dapp, now is
resolved but without a meaningful response (as the middleware just did
an `end()` call without the request being handled in any way)

This problem was discovered by some e2e tests which became very flaky
under MV3. Tests that involved the Simple Snap Keyring dapp would often
send a `wallet_requestSnaps` request, and then not get the necessary
response, due to the issue described above.

The solution to the problem presented in this PR is just to not call
`end` when seeing a duplicate request, because the original request
should be responded to eventually.

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

## **Related issues**

Part of the resolution to
#21496

## **Manual testing steps**

The bug is hard to repro manually. You could, perhaps, locally modify
the `createStreamMiddleware` code to call `sendToStream` a second time
for the same request after a short (e.g. 10 millisecond) timeout
(perhaps here:
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L50-L60).
On develop that should result in the original request receiving an empty
response but on this branch the original request should receive a
successful response.

This branch will also contribute to MV3 e2e tests passing, but that will
require some other PRs as well.

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Erik Marks <[email protected]>
danjm added a commit that referenced this issue May 31, 2024
… document under MV3 (#24675)

## **Description**

Our MV3 builds add a "Offscreen Document" to our extension. This means
that when our e2e tests call `driver.getAllWindowHandles()`, a new
window is included in the list (the window for the offscreen document).
This PR updates the e2e tests to handle this change. Comments are left
on each file to explain why the change was needed.

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

## **Related issues**

Fixes: #21496

## **Manual testing steps**

Any of the test files modified in this PR should pass when run locally
with MV3 builds

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.
danjm added a commit that referenced this issue May 31, 2024
…pps get correct response to 'seenRequests' (#24672)

## **Description**

This PR fixes the following problem:

1. Dapp sends a request to MetaMask shortly after the service worker
starts up, and _before_ the inpage provider receives the
`METAMASK_EXTENSION_CONNECT_CAN_RETRY` message from the content-script
(which happens after the metamask controller initializes and notifies
all connections of a `chainChanged` event)
2. The request hits the middleware created by
`createDupeReqFilterMiddleware.ts` and its id is added to
`seenRequestIds`
3. Before the necessary controller responds to the request, the inpage
provider _now_ receives the `METAMASK_EXTENSION_CONNECT_CAN_RETRY`
message from the content-script
4. The provider now retries the request. This happens without the dapp
doing anything; this is part of our MV3 retry logic to ensure requests
don't get lost under service worker stoppage / start-up conditions. (The
provider does this via the imported `createStreamMiddleware`
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L128-L130)
5. The new retry of the request hits the middleware created by
`createDupeReqFilterMiddleware`. (The original request still has not
been responded to.) The new retry of the request has the same id as the
original, so the middleware hits the `} else if
(!seenRequestIds.add(req.id)) {` condition and calls `end()`
6. The original request, which was being awaited by the dapp, now is
resolved but without a meaningful response (as the middleware just did
an `end()` call without the request being handled in any way)

This problem was discovered by some e2e tests which became very flaky
under MV3. Tests that involved the Simple Snap Keyring dapp would often
send a `wallet_requestSnaps` request, and then not get the necessary
response, due to the issue described above.

The solution to the problem presented in this PR is just to not call
`end` when seeing a duplicate request, because the original request
should be responded to eventually.

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

## **Related issues**

Part of the resolution to
#21496

## **Manual testing steps**

The bug is hard to repro manually. You could, perhaps, locally modify
the `createStreamMiddleware` code to call `sendToStream` a second time
for the same request after a short (e.g. 10 millisecond) timeout
(perhaps here:
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L50-L60).
On develop that should result in the original request receiving an empty
response but on this branch the original request should receive a
successful response.

This branch will also contribute to MV3 e2e tests passing, but that will
require some other PRs as well.

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Erik Marks <[email protected]>
danjm added a commit that referenced this issue May 31, 2024
… document under MV3 (#24675)

## **Description**

Our MV3 builds add a "Offscreen Document" to our extension. This means
that when our e2e tests call `driver.getAllWindowHandles()`, a new
window is included in the list (the window for the offscreen document).
This PR updates the e2e tests to handle this change. Comments are left
on each file to explain why the change was needed.

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

## **Related issues**

Fixes: #21496

## **Manual testing steps**

Any of the test files modified in this PR should pass when run locally
with MV3 builds

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.
danjm added a commit that referenced this issue May 31, 2024
…pps get correct response to 'seenRequests' (#24672)

## **Description**

This PR fixes the following problem:

1. Dapp sends a request to MetaMask shortly after the service worker
starts up, and _before_ the inpage provider receives the
`METAMASK_EXTENSION_CONNECT_CAN_RETRY` message from the content-script
(which happens after the metamask controller initializes and notifies
all connections of a `chainChanged` event)
2. The request hits the middleware created by
`createDupeReqFilterMiddleware.ts` and its id is added to
`seenRequestIds`
3. Before the necessary controller responds to the request, the inpage
provider _now_ receives the `METAMASK_EXTENSION_CONNECT_CAN_RETRY`
message from the content-script
4. The provider now retries the request. This happens without the dapp
doing anything; this is part of our MV3 retry logic to ensure requests
don't get lost under service worker stoppage / start-up conditions. (The
provider does this via the imported `createStreamMiddleware`
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L128-L130)
5. The new retry of the request hits the middleware created by
`createDupeReqFilterMiddleware`. (The original request still has not
been responded to.) The new retry of the request has the same id as the
original, so the middleware hits the `} else if
(!seenRequestIds.add(req.id)) {` condition and calls `end()`
6. The original request, which was being awaited by the dapp, now is
resolved but without a meaningful response (as the middleware just did
an `end()` call without the request being handled in any way)

This problem was discovered by some e2e tests which became very flaky
under MV3. Tests that involved the Simple Snap Keyring dapp would often
send a `wallet_requestSnaps` request, and then not get the necessary
response, due to the issue described above.

The solution to the problem presented in this PR is just to not call
`end` when seeing a duplicate request, because the original request
should be responded to eventually.

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

## **Related issues**

Part of the resolution to
#21496

## **Manual testing steps**

The bug is hard to repro manually. You could, perhaps, locally modify
the `createStreamMiddleware` code to call `sendToStream` a second time
for the same request after a short (e.g. 10 millisecond) timeout
(perhaps here:
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L50-L60).
On develop that should result in the original request receiving an empty
response but on this branch the original request should receive a
successful response.

This branch will also contribute to MV3 e2e tests passing, but that will
require some other PRs as well.

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Erik Marks <[email protected]>
danjm added a commit that referenced this issue Jun 4, 2024
… document under MV3 (#24675)

## **Description**

Our MV3 builds add a "Offscreen Document" to our extension. This means
that when our e2e tests call `driver.getAllWindowHandles()`, a new
window is included in the list (the window for the offscreen document).
This PR updates the e2e tests to handle this change. Comments are left
on each file to explain why the change was needed.

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

## **Related issues**

Fixes: #21496

## **Manual testing steps**

Any of the test files modified in this PR should pass when run locally
with MV3 builds

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.
danjm added a commit that referenced this issue Jun 4, 2024
…pps get correct response to 'seenRequests' (#24672)

## **Description**

This PR fixes the following problem:

1. Dapp sends a request to MetaMask shortly after the service worker
starts up, and _before_ the inpage provider receives the
`METAMASK_EXTENSION_CONNECT_CAN_RETRY` message from the content-script
(which happens after the metamask controller initializes and notifies
all connections of a `chainChanged` event)
2. The request hits the middleware created by
`createDupeReqFilterMiddleware.ts` and its id is added to
`seenRequestIds`
3. Before the necessary controller responds to the request, the inpage
provider _now_ receives the `METAMASK_EXTENSION_CONNECT_CAN_RETRY`
message from the content-script
4. The provider now retries the request. This happens without the dapp
doing anything; this is part of our MV3 retry logic to ensure requests
don't get lost under service worker stoppage / start-up conditions. (The
provider does this via the imported `createStreamMiddleware`
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L128-L130)
5. The new retry of the request hits the middleware created by
`createDupeReqFilterMiddleware`. (The original request still has not
been responded to.) The new retry of the request has the same id as the
original, so the middleware hits the `} else if
(!seenRequestIds.add(req.id)) {` condition and calls `end()`
6. The original request, which was being awaited by the dapp, now is
resolved but without a meaningful response (as the middleware just did
an `end()` call without the request being handled in any way)

This problem was discovered by some e2e tests which became very flaky
under MV3. Tests that involved the Simple Snap Keyring dapp would often
send a `wallet_requestSnaps` request, and then not get the necessary
response, due to the issue described above.

The solution to the problem presented in this PR is just to not call
`end` when seeing a duplicate request, because the original request
should be responded to eventually.

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

## **Related issues**

Part of the resolution to
#21496

## **Manual testing steps**

The bug is hard to repro manually. You could, perhaps, locally modify
the `createStreamMiddleware` code to call `sendToStream` a second time
for the same request after a short (e.g. 10 millisecond) timeout
(perhaps here:
https://github.com/MetaMask/json-rpc-middleware-stream/blob/main/src/createStreamMiddleware.ts#L50-L60).
On develop that should result in the original request receiving an empty
response but on this branch the original request should receive a
successful response.

This branch will also contribute to MV3 e2e tests passing, but that will
require some other PRs as well.

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask 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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Erik Marks <[email protected]>
@metamaskbot metamaskbot added the release-11.16.6 Issue or pull request that will be included in release 11.16.6 label Jun 4, 2024
@metamaskbot
Copy link
Collaborator

Missing release label release-11.16.6 on issue. Adding release label release-11.16.6 on issue, as issue is linked to PR #24675 which has this release label.

@gauthierpetetin gauthierpetetin added the release-12.0.0 Issue or pull request that will be included in release 12.0.0 label Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
INVALID-ISSUE-TEMPLATE Issue's body doesn't match any issue template. MV3 release-11.16.6 Issue or pull request that will be included in release 11.16.6 release-12.0.0 Issue or pull request that will be included in release 12.0.0 team-extension-platform
Projects
None yet
6 participants