Skip to content

Commit

Permalink
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
Browse files Browse the repository at this point in the history
…k-meta
  • Loading branch information
jiexi committed Sep 18, 2023
2 parents 692f461 + 62c7353 commit baefdb0
Show file tree
Hide file tree
Showing 129 changed files with 5,542 additions and 1,907 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ workflows:
- test-e2e-firefox
- test-e2e-chrome-snaps
- test-e2e-firefox-snaps
- test-e2e-chrome-snaps-flask
- test-e2e-firefox-snaps-flask
- test-storybook
- benchmark:
requires:
Expand Down
4 changes: 2 additions & 2 deletions .circleci/scripts/chrome-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ set -o pipefail
sudo apt-get update

# To get the latest version, see <https://www.ubuntuupdates.org/ppa/google_chrome?dist=stable>
CHROME_VERSION='114.0.5735.133-1'
CHROME_VERSION='116.0.5845.179-1'
CHROME_BINARY="google-chrome-stable_${CHROME_VERSION}_amd64.deb"
CHROME_BINARY_URL="https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/${CHROME_BINARY}"

# To retrieve this checksum, run the `wget` and `shasum` commands below
CHROME_BINARY_SHA512SUM='0b1a18c44efb72ed3e69a5f78419ff5fa973df42b18a8becfcc3d4f6825957c637e9396d07756f910f2d9c7c85a3e2b64cc30cca18182ae8811feadd609f159d'
CHROME_BINARY_SHA512SUM='cbdad3f5c928ef79a46a3619054b3c4a73a99f942f9bf4ea75d37d6434912da5c01f6ee30718a58e869ff6b57b10bb7fea1cf91885a25aac290a50a2ee3c03c4'

wget -O "${CHROME_BINARY}" -t 5 "${CHROME_BINARY_URL}"

Expand Down
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ module.exports = {
'app/scripts/controllers/permissions/**/*.test.js',
'app/scripts/controllers/preferences.test.js',
'app/scripts/lib/**/*.test.js',
'app/scripts/metamask-controller.test.js',
'app/scripts/migrations/*.test.js',
'app/scripts/platforms/*.test.js',
'development/**/*.test.js',
Expand Down Expand Up @@ -271,6 +272,7 @@ module.exports = {
'app/scripts/controllers/permissions/**/*.test.js',
'app/scripts/controllers/preferences.test.js',
'app/scripts/lib/**/*.test.js',
'app/scripts/metamask-controller.test.js',
'app/scripts/migrations/*.test.js',
'app/scripts/platforms/*.test.js',
'development/**/*.test.js',
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/trigger-metamask-institutional-e2e-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Trigger MetaMask Institutional E2E CI

on:
push:
branches: [ Version-v*, master ]
pull_request:
branches: [ Version-v*, master ]
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
trigger-mmi-e2e-ci:
runs-on: ubuntu-latest
if: ${{ (!github.event.pull_request.draft && (startsWith(github.head_ref, 'Version-v') || github.head_ref == 'master')) || (!github.event.pull_request) }}
steps:
- name: Trigger MetaMask Institutional E2E CI
env:
MMI_E2E_CI_TOKEN: ${{ secrets.MMI_E2E_CI_TOKEN }}
run: |
curl -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $MMI_E2E_CI_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/consensys-vertical-apps/mmi-extension-e2e/dispatches \
-d '{"event_type": "mm-triggered", "client_payload":{"ref_name": "${{ github.ref_name }}", "sha": "${{ github.sha }}"}}'
1 change: 1 addition & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'./app/scripts/controllers/mmi-controller.test.js',
'./app/scripts/controllers/preferences.test.js',
'./app/scripts/constants/error-utils.test.js',
'./app/scripts/metamask-controller.test.js',
'./development/fitness-functions/**/*.test.ts',
'./test/e2e/helpers.test.js',
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/dist/KeyringController.d.ts b/dist/KeyringController.d.ts
index ccfd5ca9accf782b0a612ab1666501898cf2abb9..f772552156491b308f2aa29a734a5138237d951e 100644
index d6d70eea2de56310b49fa9dcf1e90afae3ddb202..4518aed8e03376d76e5ab6ef0971529e65563fd3 100644
--- a/dist/KeyringController.d.ts
+++ b/dist/KeyringController.d.ts
@@ -1,10 +1,11 @@
Expand All @@ -10,13 +10,12 @@ index ccfd5ca9accf782b0a612ab1666501898cf2abb9..f772552156491b308f2aa29a734a5138
import { BaseControllerV2 } from '@metamask/base-controller';
import type { PersonalMessageParams, TypedMessageParams } from '@metamask/message-manager';
import type { PreferencesController } from '@metamask/preferences-controller';
-import { type Hex, type Keyring, type Json } from '@metamask/utils';
+import type { Hex, Keyring, Json } from '@metamask/utils';
import type { Eip1024EncryptedData, Hex, Keyring, Json } from '@metamask/utils';
+import type { KeyringController as EthKeyringController } from '@metamask/eth-keyring-controller';
import type { Patch } from 'immer';
declare const name = "KeyringController";
/**
@@ -135,6 +136,10 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
@@ -155,6 +156,10 @@ export declare class KeyringController extends BaseControllerV2<typeof name, Key
* @param opts.state - Initial state to set on this controller.
*/
constructor({ removeIdentity, syncIdentities, updateIdentities, setSelectedAddress, setAccountLabel, encryptor, keyringBuilders, cacheEncryptionKey, messenger, state, }: KeyringControllerOptions);
Expand All @@ -28,12 +27,12 @@ index ccfd5ca9accf782b0a612ab1666501898cf2abb9..f772552156491b308f2aa29a734a5138
* Adds a new account to the default (first) HD seed phrase keyring.
*
diff --git a/dist/KeyringController.js b/dist/KeyringController.js
index 9e241ba3b5445a053e3b20ee70a579118b7b2934..eb1f7bce9d3607017b39e087db227e8a7dadd849 100644
index bce9884ea54bf8e24274dee3876db95ed862abf0..471a06b30f2275de821c33b7d94cb1de85b074c7 100644
--- a/dist/KeyringController.js
+++ b/dist/KeyringController.js
@@ -153,6 +153,12 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
this.setSelectedAddress = setSelectedAddress;
@@ -154,6 +154,12 @@ class KeyringController extends base_controller_1.BaseControllerV2 {
this.setAccountLabel = setAccountLabel;
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_registerMessageHandlers).call(this);
}
+ /**
+ * Gets the internal keyring controller.
Expand Down
50 changes: 50 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.

10 changes: 6 additions & 4 deletions app/scripts/controllers/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export default class AppStateController extends EventEmitter {
preferencesStore,
qrHardwareStore,
messenger,
extension,
} = opts;
super();

this.extension = extension;
this.onInactiveTimeout = onInactiveTimeout || (() => undefined);
this.store = new ObservableStore({
timeoutMinutes: DEFAULT_AUTO_LOCK_TIME_LIMIT,
Expand Down Expand Up @@ -249,22 +251,22 @@ export default class AppStateController extends EventEmitter {
if (this.timer) {
clearTimeout(this.timer);
} else if (isManifestV3) {
chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM);
this.extension.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM);
}

if (!timeoutMinutes) {
return;
}

if (isManifestV3) {
chrome.alarms.create(AUTO_LOCK_TIMEOUT_ALARM, {
this.extension.alarms.create(AUTO_LOCK_TIMEOUT_ALARM, {
delayInMinutes: timeoutMinutes,
periodInMinutes: timeoutMinutes,
});
chrome.alarms.onAlarm.addListener((alarmInfo) => {
this.extension.alarms.onAlarm.addListener((alarmInfo) => {
if (alarmInfo.name === AUTO_LOCK_TIMEOUT_ALARM) {
this.onInactiveTimeout();
chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM);
this.extension.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM);
}
});
} else {
Expand Down
70 changes: 61 additions & 9 deletions app/scripts/controllers/decrypt-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const messageMock = {
type: 'testType',
rawSig: undefined,
} as any as AbstractMessage;
const messageDataMock =
'0x7b2276657273696f6e223a227832353531392d7873616c736132302d706f6c7931333035222c226e6f6e6365223a226b45586143524c3045646142766f77756e35675979357175784a4a6967304548222c22657068656d5075626c69634b6579223a224863334636506d314734385a567955424763365866537839682b77784b6958587238456a51434253466e553d222c2263697068657274657874223a22546a41556b68554a5968656e7a2f655a6e57454a2b31456c7861354f77765939613830507a62746c7a7a48746934634175525941227d';

const mockExtState = {};

Expand Down Expand Up @@ -52,7 +54,7 @@ const createDecryptMessageManagerMock = <T>() =>
},
} as any as jest.Mocked<T>);

describe('EncryptionPublicKeyController', () => {
describe('DecryptMessageController', () => {
let decryptMessageController: DecryptMessageController;

const decryptMessageManagerConstructorMock =
Expand All @@ -65,6 +67,19 @@ describe('EncryptionPublicKeyController', () => {
const decryptMessageManagerMock =
createDecryptMessageManagerMock<DecryptMessageManager>();

const mockMessengerAction = (
action: string,
callback: (actionName: string, ...args: any[]) => any,
) => {
messengerMock.call.mockImplementation((actionName, ...rest) => {
if (actionName === action) {
return callback(actionName, ...rest);
}

return Promise.resolve();
});
};

beforeEach(() => {
jest.resetAllMocks();

Expand Down Expand Up @@ -116,12 +131,18 @@ describe('EncryptionPublicKeyController', () => {
it('should decrypt message', async () => {
const messageToDecrypt = {
...messageMock,
data: '0x7b22666f6f223a22626172227d',
data: messageDataMock,
};
const decryptMessageActionCallbackMock = jest
.fn()
.mockReturnValue('decryptedMessage');
decryptMessageManagerMock.approveMessage.mockResolvedValue(
messageToDecrypt,
);
keyringControllerMock.decryptMessage.mockResolvedValue('decryptedMessage');
mockMessengerAction(
'KeyringController:decryptMessage',
decryptMessageActionCallbackMock,
);
getStateMock.mockReturnValue(mockExtState);

const result = await decryptMessageController.decryptMessage(
Expand All @@ -132,8 +153,9 @@ describe('EncryptionPublicKeyController', () => {
expect(decryptMessageManagerMock.approveMessage).toBeCalledWith(
messageToDecrypt,
);
expect(keyringControllerMock.decryptMessage).toBeCalledTimes(1);
expect(keyringControllerMock.decryptMessage).toBeCalledWith(
expect(decryptMessageActionCallbackMock).toBeCalledTimes(1);
expect(decryptMessageActionCallbackMock).toBeCalledWith(
'KeyringController:decryptMessage',
messageToDecrypt,
);
expect(decryptMessageManagerMock.setMessageStatusAndResult).toBeCalledTimes(
Expand All @@ -147,15 +169,31 @@ describe('EncryptionPublicKeyController', () => {
expect(result).toBe(mockExtState);
});

it('should throw when decrypting invalid message', async () => {
const messageToDecrypt = {
...messageMock,
data: '0x7b2022666f6f223a202262617222207d',
};
decryptMessageManagerMock.approveMessage.mockResolvedValue(
messageToDecrypt,
);

expect(
decryptMessageController.decryptMessage(messageToDecrypt),
).rejects.toThrow('Invalid encrypted data.');
});

it('should cancel decrypt request', async () => {
const messageToDecrypt = {
...messageMock,
data: '0x7b22666f6f223a22626172227d',
data: messageDataMock,
};
decryptMessageManagerMock.approveMessage.mockResolvedValue(
messageToDecrypt,
);
keyringControllerMock.decryptMessage.mockRejectedValue(new Error('error'));
mockMessengerAction('KeyringController:decryptMessage', async () => {
throw new Error('error');
});
getStateMock.mockReturnValue(mockExtState);

return expect(
Expand All @@ -166,10 +204,13 @@ describe('EncryptionPublicKeyController', () => {
it('should decrypt message inline', async () => {
const messageToDecrypt = {
...messageMock,
data: '0x7b22666f6f223a22626172227d',
data: messageDataMock,
};
decryptMessageManagerMock.getMessage.mockReturnValue(messageToDecrypt);
keyringControllerMock.decryptMessage.mockResolvedValue('decryptedMessage');
mockMessengerAction(
'KeyringController:decryptMessage',
async () => 'decryptedMessage',
);
getStateMock.mockReturnValue(mockExtState);

const result = await decryptMessageController.decryptMessageInline(
Expand All @@ -184,6 +225,17 @@ describe('EncryptionPublicKeyController', () => {
expect(result).toBe(mockExtState);
});

it('should throw when decrypting invalid message inline', async () => {
const messageToDecrypt = {
...messageMock,
data: '0x7b2022666f6f223a202262617222207d',
};

expect(
decryptMessageController.decryptMessageInline(messageToDecrypt),
).rejects.toThrow('Invalid encrypted data.');
});

it('should be able to cancel decrypt message', async () => {
decryptMessageManagerMock.rejectMessage.mockResolvedValue(messageMock);
getStateMock.mockReturnValue(mockExtState);
Expand Down
Loading

0 comments on commit baefdb0

Please sign in to comment.