Skip to content

Commit

Permalink
Merge branch 'main' into deps-eth-block-tracker-10
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat authored Aug 21, 2024
2 parents 93ac6ea + bc1d90b commit 30d210e
Show file tree
Hide file tree
Showing 59 changed files with 957 additions and 551 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/core-monorepo",
"version": "188.0.0",
"version": "190.0.0",
"private": true,
"description": "Monorepo for packages shared between MetaMask clients",
"repository": {
Expand Down
19 changes: 18 additions & 1 deletion packages/accounts-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [18.1.0]

### Added

- Export `AccountsControllerUpdateAccountMetadataAction` action ([#4590](https://github.com/MetaMask/core/pull/4590))
- Add new method `updateAccountMetadata` ([#4568](https://github.com/MetaMask/core/pull/4568))

### Changed

- Bump `@metamask/keyring-api` to version `8.1.0` ([#4594](https://github.com/MetaMask/core/pull/4594))

### Fixed

- Handle undefined `selectedAccount` in `updateAccounts` ([#4623](https://github.com/MetaMask/core/pull/4623))
- Fix `AccountsControllerUpdateAccountMetadataAction` action type name ([#4590](https://github.com/MetaMask/core/pull/4590))

## [18.0.0]

### Changed
Expand Down Expand Up @@ -261,7 +277,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release ([#1637](https://github.com/MetaMask/core/pull/1637))

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@18.0.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@18.1.0...HEAD
[18.1.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@18.0.0...@metamask/accounts-controller@18.1.0
[18.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@17.2.0...@metamask/accounts-controller@18.0.0
[17.2.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@17.1.1...@metamask/accounts-controller@17.2.0
[17.1.1]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@17.1.0...@metamask/accounts-controller@17.1.1
Expand Down
3 changes: 2 additions & 1 deletion packages/accounts-controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/accounts-controller",
"version": "18.0.0",
"version": "18.1.0",
"description": "Manages internal accounts",
"keywords": [
"MetaMask",
Expand Down Expand Up @@ -35,6 +35,7 @@
"changelog:update": "../../scripts/update-changelog.sh @metamask/accounts-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/accounts-controller",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
Expand Down
1 change: 1 addition & 0 deletions packages/address-book-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"changelog:update": "../../scripts/update-changelog.sh @metamask/address-book-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/address-book-controller",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
Expand Down
1 change: 1 addition & 0 deletions packages/announcement-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"changelog:update": "../../scripts/update-changelog.sh @metamask/announcement-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/announcement-controller",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
Expand Down
1 change: 1 addition & 0 deletions packages/approval-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"changelog:update": "../../scripts/update-changelog.sh @metamask/approval-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/approval-controller",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
Expand Down
3 changes: 2 additions & 1 deletion packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"changelog:update": "../../scripts/update-changelog.sh @metamask/assets-controllers",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/assets-controllers",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
Expand Down Expand Up @@ -67,7 +68,7 @@
"uuid": "^8.3.2"
},
"devDependencies": {
"@metamask/accounts-controller": "^18.0.0",
"@metamask/accounts-controller": "^18.1.0",
"@metamask/approval-controller": "^7.0.2",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/ethjs-provider-http": "^0.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/base-controller/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = merge(baseConfig, {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 96.29,
branches: 100,
functions: 100,
lines: 100,
statements: 100,
Expand Down
2 changes: 2 additions & 0 deletions packages/base-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"changelog:update": "../../scripts/update-changelog.sh @metamask/base-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/base-controller",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
Expand All @@ -45,6 +46,7 @@
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/json-rpc-engine": "^9.0.2",
"@types/jest": "^27.4.1",
"@types/sinon": "^9.0.10",
"deepmerge": "^4.2.2",
Expand Down
47 changes: 45 additions & 2 deletions packages/base-controller/src/BaseControllerV1.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,61 @@
import { JsonRpcEngine } from '@metamask/json-rpc-engine';
import * as sinon from 'sinon';

import type { BaseConfig, BaseState } from './BaseControllerV1';
import { BaseControllerV1 as BaseController } from './BaseControllerV1';
import {
BaseControllerV1 as BaseController,
isBaseControllerV1,
} from './BaseControllerV1';
import type {
CountControllerAction,
CountControllerEvent,
} from './BaseControllerV2.test';
import {
CountController,
countControllerName,
countControllerStateMetadata,
getCountMessenger,
} from './BaseControllerV2.test';
import { ControllerMessenger } from './ControllerMessenger';

const STATE = { name: 'foo' };
const CONFIG = { disabled: true };

class TestController extends BaseController<BaseConfig, BaseState> {
// eslint-disable-next-line jest/no-export
export class TestController extends BaseController<BaseConfig, BaseState> {
constructor(config?: BaseConfig, state?: BaseState) {
super(config, state);
this.initialize();
}
}

describe('isBaseControllerV1', () => {
it('should return false if passed a V1 controller', () => {
const controller = new TestController();
expect(isBaseControllerV1(controller)).toBe(true);
});

it('should return false if passed a V2 controller', () => {
const controllerMessenger = new ControllerMessenger<
CountControllerAction,
CountControllerEvent
>();
const controller = new CountController({
messenger: getCountMessenger(controllerMessenger),
name: countControllerName,
state: { count: 0 },
metadata: countControllerStateMetadata,
});
expect(isBaseControllerV1(controller)).toBe(false);
});

it('should return false if passed a non-controller', () => {
const notController = new JsonRpcEngine();
// @ts-expect-error Intentionally passing invalid input to test runtime behavior
expect(isBaseControllerV1(notController)).toBe(false);
});
});

describe('BaseController', () => {
afterEach(() => {
sinon.restore();
Expand Down
51 changes: 51 additions & 0 deletions packages/base-controller/src/BaseControllerV1.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
import type { PublicInterface } from '@metamask/utils';

import type { ControllerInstance } from './BaseControllerV2';

/**
* Determines if the given controller is an instance of `BaseControllerV1`
*
* @param controller - Controller instance to check
* @returns True if the controller is an instance of `BaseControllerV1`
*/
export function isBaseControllerV1(
controller: ControllerInstance,
): controller is BaseControllerV1Instance {
return (
'name' in controller &&
typeof controller.name === 'string' &&
'config' in controller &&
typeof controller.config === 'object' &&
'defaultConfig' in controller &&
typeof controller.defaultConfig === 'object' &&
'state' in controller &&
typeof controller.state === 'object' &&
'defaultState' in controller &&
typeof controller.defaultState === 'object' &&
'disabled' in controller &&
typeof controller.disabled === 'boolean' &&
'subscribe' in controller &&
typeof controller.subscribe === 'function'
);
}

/**
* State change callbacks
*/
Expand Down Expand Up @@ -31,6 +62,26 @@ export interface BaseState {
name?: string;
}

/**
* The narrowest supertype for `BaseControllerV1` config objects.
* This type can be assigned to any `BaseControllerV1` config object.
*/
export type ConfigConstraint = BaseConfig & object;

/**
* The narrowest supertype for `BaseControllerV1` state objects.
* This type can be assigned to any `BaseControllerV1` state object.
*/
export type StateConstraint = BaseState & object;

/**
* The widest subtype of all controller instances that extend from `BaseControllerV1`.
* Any `BaseControllerV1` instance can be assigned to this type.
*/
export type BaseControllerV1Instance = PublicInterface<
BaseControllerV1<ConfigConstraint, StateConstraint>
>;

/**
* @deprecated This class has been renamed to BaseControllerV1 and is no longer recommended for use for controllers. Please use BaseController (formerly BaseControllerV2) instead.
*
Expand Down
43 changes: 37 additions & 6 deletions packages/base-controller/src/BaseControllerV2.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable jest/no-export */
import type { Draft, Patch } from 'immer';
import * as sinon from 'sinon';

import { JsonRpcEngine } from '../../json-rpc-engine/src';
import { TestController } from './BaseControllerV1.test';
import type {
ControllerGetStateAction,
ControllerStateChangeEvent,
Expand All @@ -9,27 +12,28 @@ import {
BaseController,
getAnonymizedState,
getPersistentState,
isBaseController,
} from './BaseControllerV2';
import { ControllerMessenger } from './ControllerMessenger';
import type { RestrictedControllerMessenger } from './RestrictedControllerMessenger';

const countControllerName = 'CountController';
export const countControllerName = 'CountController';

type CountControllerState = {
count: number;
};

type CountControllerAction = ControllerGetStateAction<
export type CountControllerAction = ControllerGetStateAction<
typeof countControllerName,
CountControllerState
>;

type CountControllerEvent = ControllerStateChangeEvent<
export type CountControllerEvent = ControllerStateChangeEvent<
typeof countControllerName,
CountControllerState
>;

const countControllerStateMetadata = {
export const countControllerStateMetadata = {
count: {
persist: true,
anonymous: true,
Expand All @@ -50,7 +54,7 @@ type CountMessenger = RestrictedControllerMessenger<
* @param controllerMessenger - The controller messenger.
* @returns A restricted controller messenger for the Count controller.
*/
function getCountMessenger(
export function getCountMessenger(
controllerMessenger?: ControllerMessenger<
CountControllerAction,
CountControllerEvent
Expand All @@ -69,7 +73,7 @@ function getCountMessenger(
});
}

class CountController extends BaseController<
export class CountController extends BaseController<
typeof countControllerName,
CountControllerState,
CountMessenger
Expand Down Expand Up @@ -177,6 +181,33 @@ class MessagesController extends BaseController<
}
}

describe('isBaseController', () => {
it('should return true if passed a V2 controller', () => {
const controllerMessenger = new ControllerMessenger<
CountControllerAction,
CountControllerEvent
>();
const controller = new CountController({
messenger: getCountMessenger(controllerMessenger),
name: countControllerName,
state: { count: 0 },
metadata: countControllerStateMetadata,
});
expect(isBaseController(controller)).toBe(true);
});

it('should return false if passed a V1 controller', () => {
const controller = new TestController();
expect(isBaseController(controller)).toBe(false);
});

it('should return false if passed a non-controller', () => {
const notController = new JsonRpcEngine();
// @ts-expect-error Intentionally passing invalid input to test runtime behavior
expect(isBaseController(notController)).toBe(false);
});
});

describe('BaseController', () => {
afterEach(() => {
sinon.restore();
Expand Down
Loading

0 comments on commit 30d210e

Please sign in to comment.