Skip to content

Commit

Permalink
Merge branch 'develop' into hm/unblock-request-snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
hmalik88 committed Sep 2, 2024
2 parents 736aebd + e239d85 commit 53f11f8
Show file tree
Hide file tree
Showing 49 changed files with 1,769 additions and 628 deletions.
118 changes: 62 additions & 56 deletions .circleci/config.yml

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions .circleci/scripts/enable-vnc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# This script is based on the documentation from CircleCI, which does not work as written
# https://circleci.com/docs/browser-testing/#interacting-with-the-browser-over-vnc

set -e
set -u
set -o pipefail
set -x

cd "${HOME}/project"

# Install a VNC server
readonly LOCK_FILE="installed.lock"
if [ ! -f "${LOCK_FILE}" ]; then
sudo apt update
sudo apt install -y x11vnc

touch "${LOCK_FILE}"
fi

# Start VNC server
if ! pgrep x11vnc > /dev/null; then
x11vnc -display "$DISPLAY" -bg -forever -nopw -quiet -listen localhost -xkb -rfbport 5901 -passwd password
fi
11 changes: 10 additions & 1 deletion .circleci/scripts/test-run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ then
exit 1
fi

# Skip running e2e tests if we're doing "Rerun job with SSH" and we're not on the first node
if netstat -tnlp | grep -q 'circleci-agent' && [ "$CIRCLE_NODE_INDEX" -ne 0 ]
then
printf '"Rerun job with SSH" and not on the first node, shutting down\n'
circleci-agent step halt
exit 1
fi

# Run the actual test command from the parameters
timeout 20m "$@" --retries 1

# Error code 124 means the command timed out
if [ $? -eq 124 ]; then
if [ $? -eq 124 ]
then
# Once deleted, if someone tries to "Rerun failed tests" the result will be
# "Error: can not rerun failed tests: no failed tests could be found"
echo 'Timeout error, deleting the test results'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
payload=$(cat <<EOF
{
"title": "v${{ env.version }} Bug Report",
"body": "This bug report was automatically created by a GitHub action upon the creation of release branch \`Version-v${{ env.version }}\` (release cut).\n\n**Expected actions for release engineers:**\n\n1. Convert this issue into a Zenhub epic and link all bugs identified during the release regression testing phase to this epic.\n\n2. After completing the first regression run, move this epic to \"Regression Completed\" on the [Extension Release Regression board](https://app.zenhub.com/workspaces/extension-release-regression-6478c62d937eaa15e95c33c5/board?filterLogic=any&labels=release-${{ env.version }},release-task).\n\nNote that once the release is prepared for store submission, meaning the \`Version-v${{ env.version }}\` branch merges into \`master\`, another GitHub action will automatically close this epic.",
"body": "**What is this bug report issue for?**\n\n1. This issue is used to track release dates on this [Github Project board](https://github.com/orgs/MetaMask/projects/86/views/1), which content then gets pulled into our metrics system.\n\n2. This issue is also used by our Zapier automations, to determine if automated notifications shall be sent on Slack for release \`${{ env.version }}\`. Notifications will only be sent as long as this issue is open.\n\n**Who created and/or closed this issue?**\n\n- This issue was automatically created by a GitHub action upon the creation of the release branch \`Version-v${{ env.version }}\`, indicating the release was cut.\n\n- This issue gets automatically closed by another GitHub action, once the \`Version-v${{ env.version }}\` branch merges into \`master\`, indicating the release is prepared for store submission.",
"labels": ["type-bug", "team-extension-platform", "regression-RC-${{ env.version }}"]
}
EOF
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [12.1.1]
### Changed
- Update Polygon from MATIC to POL ([#26671](https://github.com/MetaMask/metamask-extension/pull/26671))

### Fixed
- Fix signature confirmation UI crash ([#26143](https://github.com/MetaMask/metamask-extension/pull/26143))
- Update current selected account when selected account is removed ([#26573](https://github.com/MetaMask/metamask-extension/pull/26573), [#26742](https://github.com/MetaMask/metamask-extension/pull/26742), [#26773](https://github.com/MetaMask/metamask-extension/pull/26773))
- This also includes a migration to reset the selected account if it's currently invalid
- Prevent pending confirmations from being inaccessible after attempting to add currently selected chain ([#26726](https://github.com/MetaMask/metamask-extension/pull/26726))

## [12.1.0]
### Added
- Launched a feature displaying the percentage increase or decrease for tokens within the UI ([#24223](https://github.com/MetaMask/metamask-extension/pull/24223))
Expand Down Expand Up @@ -4996,7 +5006,8 @@ Update styles and spacing on the critical error page ([#20350](https://github.c
- Added the ability to restore accounts from seed words.


[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v12.1.0...HEAD
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v12.1.1...HEAD
[12.1.1]: https://github.com/MetaMask/metamask-extension/compare/v12.1.0...v12.1.1
[12.1.0]: https://github.com/MetaMask/metamask-extension/compare/v12.0.6...v12.1.0
[12.0.6]: https://github.com/MetaMask/metamask-extension/compare/v12.0.5...v12.0.6
[12.0.5]: https://github.com/MetaMask/metamask-extension/compare/v12.0.4...v12.0.5
Expand Down
9 changes: 9 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions app/scripts/offscreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { captureException } from '@sentry/browser';
import { OffscreenCommunicationTarget } from '../../shared/constants/offscreen-communication';
import {
OFFSCREEN_LOAD_TIMEOUT,
OffscreenCommunicationTarget,
} from '../../shared/constants/offscreen-communication';
import { getSocketBackgroundToMocha } from '../../test/e2e/background-socket/socket-background-to-mocha';

/**
Expand Down Expand Up @@ -65,7 +68,7 @@ export async function createOffscreen() {

// In case we are in a bad state where the offscreen document is not loading, timeout and let execution continue.
const timeoutPromise = new Promise((resolve) => {
setTimeout(resolve, 5000);
setTimeout(resolve, OFFSCREEN_LOAD_TIMEOUT);
});

await Promise.race([loadPromise, timeoutPromise]);
Expand Down
33 changes: 33 additions & 0 deletions docs/ssh-to-circleci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Debugging E2E tests by connecting to CircleCI over SSH and VNC

Developers often say "I can't reproduce this CI failure locally, but it fails on CircleCI."

If you find yourself in that situation, one option is to use Codespaces, which can reproduce some of these failures, and is a little bit easier to use.

The other NEW option is to SSH into CircleCI and use VNC.

1. You must be logged into CircleCI and have access to metamask-extension
2. "Rerun job with SSH" [Documentation](https://circleci.com/docs/ssh-access-jobs/)
3. Look for this instruction inside the `Enable SSH` section

```
You can now SSH into this box if your SSH public key is added:
$ ssh -p xxxxx xxx.xxx.xxx.xxx
```

4. Copy the command that CircleCI gives you and append `-L 5901:localhost:5901` (this will tunnel the VNC connection over SSH)
5. Enter this in a terminal, for example `ssh -p xxxxx xxx.xxx.xxx.xxx -L 5901:localhost:5901`
6. When you login to SSH, it automatically executes `/.circleci/scripts/enable-vnc.sh` to set up the connection
7. Use your favorite VNC viewer on your local machine to connect to `localhost:5901`
- Mac: In the Terminal, run `open vnc://localhost:5901`
- Linux: `tigervnc-viewer` is a good package to match the server
- Windows: [RealVNC Viewer](https://www.realvnc.com/en/connect/download/viewer/windows/) or [TightVNC](https://www.tightvnc.com/download.php)
8. The VNC password is simply `password`
9. The normal E2E tests will already be running, and you can watch them run
10. If you want to stop the normal tests and run your own tests, run `pkill timeout` (this works because .circleci/scripts/test-run-e2e.sh runs the `timeout` command)

### Notes:

- This procedure was based on the documentation from CircleCI [here](https://circleci.com/docs/browser-testing/#interacting-with-the-browser-over-vnc). The way they wrote it doesn't really work correctly, but we fixed it.
- If you run "Rerun job with SSH" on a job that has `parallelism: 24`, it will rerun all 24 VMs, but quickly shut down all but the first one.
- **Advanced Usage:** If you don't want to run the `.bashrc` when you connect, append this to the SSH command `-t bash --norc --noprofile`
28 changes: 17 additions & 11 deletions offscreen/scripts/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ const LEDGER_KEYRING_IFRAME_CONNECTED_EVENT = 'ledger-connection-event';

const callbackProcessor = new CallbackProcessor();

export default function init() {
const iframe = document.createElement('iframe');
iframe.src = 'https://metamask.github.io/eth-ledger-bridge-keyring';
iframe.allow = 'hid';
document.body.appendChild(iframe);
function setupMessageListeners(iframe: HTMLIFrameElement) {
// This listener receives action responses from the live ledger iframe
// Then forwards the response to the offscreen bridge
window.addEventListener('message', ({ origin, data, source }) => {
if (origin !== KnownOrigins.ledger || source !== iframe?.contentWindow) {
if (origin !== KnownOrigins.ledger || source !== iframe.contentWindow) {
return;
}

Expand Down Expand Up @@ -64,7 +60,7 @@ export default function init() {
return;
}

if (!iframe?.contentWindow) {
if (!iframe.contentWindow) {
const error = new Error('Ledger iframe not present');
sendResponse({
success: false,
Expand All @@ -87,10 +83,7 @@ export default function init() {
messageId,
};

// It has already been checked that they are not null above, so the
// optional chaining here is for compiler typechecking only. This avoids
// overriding our non-null assertion rule.
iframe?.contentWindow?.postMessage(iframeMsg, KnownOrigins.ledger);
iframe.contentWindow.postMessage(iframeMsg, KnownOrigins.ledger);

// This keeps sendResponse function valid after return
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage
Expand All @@ -99,3 +92,16 @@ export default function init() {
},
);
}

export default async function init() {
return new Promise<void>((resolve) => {
const iframe = document.createElement('iframe');
iframe.src = 'https://metamask.github.io/eth-ledger-bridge-keyring';
iframe.allow = 'hid';
iframe.onload = () => {
setupMessageListeners(iframe);
resolve();
};
document.body.appendChild(iframe);
});
}
78 changes: 51 additions & 27 deletions offscreen/scripts/offscreen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';
import { ProxySnapExecutor } from '@metamask/snaps-execution-environments';
import { isObject } from '@metamask/utils';
import {
OFFSCREEN_LEDGER_INIT_TIMEOUT,
OffscreenCommunicationEvents,
OffscreenCommunicationTarget,
} from '../../shared/constants/offscreen-communication';
Expand All @@ -9,41 +11,63 @@ import initLedger from './ledger';
import initTrezor from './trezor';
import initLattice from './lattice';

initLedger();
initTrezor();
initLattice();

/**
* Initialize a post message stream with the parent window that is initialized
* in the metamask-controller (background/serivce worker) process. This will be
* utilized by snaps for communication with snaps running in the offscreen
* document.
*/
const parentStream = new BrowserRuntimePostMessageStream({
name: 'child',
target: 'parent',
});

ProxySnapExecutor.initialize(parentStream, './snaps/index.html');

if (process.env.IN_TEST) {
chrome.runtime.onMessage.addListener((message) => {
if (
message &&
typeof message === 'object' &&
message.event === OffscreenCommunicationEvents.metamaskBackgroundReady &&
message.target === OffscreenCommunicationTarget.extension
) {
window.document?.documentElement?.classList?.add('controller-loaded');
}
function initializePostMessageStream() {
const parentStream = new BrowserRuntimePostMessageStream({
name: 'child',
target: 'parent',
});

ProxySnapExecutor.initialize(parentStream, './snaps/index.html');
}

chrome.runtime.sendMessage({
target: OffscreenCommunicationTarget.extensionMain,
isBooted: true,
/**
* Initialize the ledger, trezor, and lattice keyring connections, and the
* post message stream for the Snaps environment.
*/
async function init(): Promise<void> {
initializePostMessageStream();
initTrezor();
initLattice();

// This message is being sent from the Offscreen Document to the Service Worker.
// The Service Worker has no way to query `navigator.webdriver`, so we send it here.
webdriverPresent: navigator.webdriver === true,
try {
const ledgerInitTimeout = new Promise((_, reject) => {
setTimeout(() => {
reject(new Error('Ledger initialization timed out'));
}, OFFSCREEN_LEDGER_INIT_TIMEOUT);
});
await Promise.race([initLedger(), ledgerInitTimeout]);
} catch (error) {
console.error('Ledger initialization failed:', error);
}
}

init().then(() => {
if (process.env.IN_TEST) {
chrome.runtime.onMessage.addListener((message) => {
if (
message &&
isObject(message) &&
message.event ===
OffscreenCommunicationEvents.metamaskBackgroundReady &&
message.target === OffscreenCommunicationTarget.extension
) {
window.document?.documentElement?.classList?.add('controller-loaded');
}
});
}

chrome.runtime.sendMessage({
target: OffscreenCommunicationTarget.extensionMain,
isBooted: true,

// This message is being sent from the Offscreen Document to the Service Worker.
// The Service Worker has no way to query `navigator.webdriver`, so we send it here.
webdriverPresent: navigator.webdriver === true,
});
});
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metamask-crx",
"version": "12.1.0",
"version": "12.1.1",
"private": true,
"repository": {
"type": "git",
Expand Down Expand Up @@ -137,6 +137,7 @@
"analytics-node/axios": "^0.21.2",
"bn.js": "^5.2.1",
"ganache-core/lodash": "^4.17.21",
"ganache/abstract-level": "1.0.4",
"git-url-parse@^12.0.0": "^13.1.0",
"glob-parent": "^6.0.2",
"netmask": "^2.0.1",
Expand Down Expand Up @@ -612,6 +613,7 @@
"lavamoat": "^8.0.2",
"lavamoat-browserify": "^17.0.4",
"lavamoat-viz": "^7.0.5",
"level": "^8.0.1",
"lockfile-lint": "^4.10.6",
"loose-envify": "^1.4.0",
"mocha": "^10.2.0",
Expand Down Expand Up @@ -755,7 +757,8 @@
"$root$": true,
"core-js-pure": true,
"resolve-url-loader>es6-iterator>d>es5-ext": false,
"resolve-url-loader>es6-iterator>d>es5-ext>esniff>es5-ext": false
"resolve-url-loader>es6-iterator>d>es5-ext>esniff>es5-ext": false,
"level>classic-level": false
}
},
"packageManager": "yarn@4.4.1"
Expand Down
3 changes: 3 additions & 0 deletions shared/constants/offscreen-communication.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export const OFFSCREEN_LEDGER_INIT_TIMEOUT = 4000;
export const OFFSCREEN_LOAD_TIMEOUT = OFFSCREEN_LEDGER_INIT_TIMEOUT + 1000;

/**
* Defines legal targets for offscreen communication. These values are used to
* filter and route messages to the correct target.
Expand Down
4 changes: 2 additions & 2 deletions shared/constants/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const BNB_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {
} as const;

export const MATIC_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {
symbol: CURRENCY_SYMBOLS.MATIC,
name: 'Matic',
symbol: CURRENCY_SYMBOLS.POL,
name: 'Polygon',
address: DEFAULT_TOKEN_ADDRESS,
decimals: 18,
iconUrl: POL_TOKEN_IMAGE_URL,
Expand Down
Loading

0 comments on commit 53f11f8

Please sign in to comment.