Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion eslint-warning-thresholds.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
},
"packages/controller-utils/src/util.test.ts": {
"import-x/no-named-as-default": 1,
"import-x/order": 1,
"jest/no-conditional-in-test": 1,
"promise/param-names": 2
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@metamask/eth-block-tracker": "^12.0.1",
"@metamask/eth-json-rpc-provider": "^4.1.8",
"@metamask/json-rpc-engine": "^10.0.3",
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"@ts-bridge/cli": "^0.6.1",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
Expand Down
1 change: 1 addition & 0 deletions packages/accounts-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **BREAKING:** Bump peer dependency `@metamask/snaps-controllers` from `^12.0.0` to `^14.0.0` ([#6035](https://github.com/MetaMask/core/pull/6035))
- Bump `@metamask/snaps-sdk` from `^7.1.0` to `^9.0.0` ([#6035](https://github.com/MetaMask/core/pull/6035))
- Bump `@metamask/snaps-utils` from `^9.4.0` to `^11.0.0` ([#6035](https://github.com/MetaMask/core/pull/6035))
- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

## [31.0.0]

Expand Down
2 changes: 1 addition & 1 deletion packages/accounts-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@metamask/keyring-utils": "^3.0.0",
"@metamask/snaps-sdk": "^9.0.0",
"@metamask/snaps-utils": "^11.0.0",
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"deepmerge": "^4.2.2",
"ethereum-cryptography": "^2.1.2",
"immer": "^9.0.6",
Expand Down
1 change: 1 addition & 0 deletions packages/address-book-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
- Bump `@metamask/controller-utils` to `^11.10.0` ([#5935](https://github.com/MetaMask/core/pull/5935))

## [6.1.0]
Expand Down
2 changes: 1 addition & 1 deletion packages/address-book-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"@metamask/base-controller": "^8.0.1",
"@metamask/controller-utils": "^11.10.0",
"@metamask/utils": "^11.2.0"
"@metamask/utils": "^11.4.2"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
Expand Down
1 change: 1 addition & 0 deletions packages/approval-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
- Bump `@metamask/base-controller` from ^8.0.0 to ^8.0.1 ([#5722](https://github.com/MetaMask/core/pull/5722))

## [7.1.3]
Expand Down
2 changes: 1 addition & 1 deletion packages/approval-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"@metamask/base-controller": "^8.0.1",
"@metamask/rpc-errors": "^7.0.2",
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"nanoid": "^3.3.8"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

## [70.0.0]

### Changed
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@metamask/rpc-errors": "^7.0.2",
"@metamask/snaps-sdk": "^9.0.0",
"@metamask/snaps-utils": "^11.0.0",
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"@types/bn.js": "^5.1.5",
"@types/uuid": "^8.3.0",
"async-mutex": "^0.5.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/base-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

## [8.0.1]

### Changed
Expand Down
2 changes: 1 addition & 1 deletion packages/base-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"immer": "^9.0.6"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/bridge-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- **BREAKING:** Bump peer dependency `@metamask/assets-controllers` from `^69.0.0` to `^70.0.0` ([#6061](https://github.com/MetaMask/core/pull/6061))
- **BREAKING:** Bump peer dependency `@metamask/snaps-controllers` from `^12.0.0` to `^14.0.0` ([#6035](https://github.com/MetaMask/core/pull/6035))
- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

## [34.0.0]

Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/multichain-network-controller": "^0.9.0",
"@metamask/polling-controller": "^14.0.0",
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"bignumber.js": "^9.1.2",
"reselect": "^5.1.1",
"uuid": "^8.3.2"
Expand Down
4 changes: 4 additions & 0 deletions packages/bridge-status-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

## [34.0.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-status-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@metamask/keyring-api": "^18.0.0",
"@metamask/polling-controller": "^14.0.0",
"@metamask/superstruct": "^3.1.0",
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"bignumber.js": "^9.1.2",
"uuid": "^8.3.2"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/build-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

## [3.0.3]

### Changed
Expand Down
2 changes: 1 addition & 1 deletion packages/build-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"@types/eslint": "^8.44.7"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/chain-agnostic-permission/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

## [1.0.0]

### Changed
Expand Down
2 changes: 1 addition & 1 deletion packages/chain-agnostic-permission/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@metamask/network-controller": "^24.0.0",
"@metamask/permission-controller": "^11.0.6",
"@metamask/rpc-errors": "^7.0.2",
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/controller-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
- Improve performance of `isValidHexAddress` and `toChecksumHexAddress` ([#6054](https://github.com/MetaMask/core/pull/6054))
- Replace `ethereumjs-util` lib with faster `@metamask/utils` functions
- Memoize `isValidHexAddress` and `toChecksumHexAddress` functions
- Update `createServicePolicy` to reduce circuit break duration from 30 minutes to 2 minutes ([#6015](https://github.com/MetaMask/core/pull/6015))
- When hitting an API, this reduces the default duration for which requests to the API are paused when perceived to be unavailable

Expand Down
7 changes: 4 additions & 3 deletions packages/controller-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,23 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@ethereumjs/util": "^9.1.0",
"@metamask/eth-query": "^4.0.0",
"@metamask/ethjs-unit": "^0.3.0",
"@metamask/utils": "^11.2.0",
"@metamask/utils": "^11.4.2",
"@spruceid/siwe-parser": "2.1.0",
"@types/bn.js": "^5.1.5",
"bignumber.js": "^9.1.2",
"bn.js": "^5.2.1",
"cockatiel": "^3.1.2",
"eth-ens-namehash": "^2.0.8",
"fast-deep-equal": "^3.1.3"
"fast-deep-equal": "^3.1.3",
"lodash": "^4.17.21"
},
"devDependencies": {
"@babel/runtime": "^7.23.9",
"@metamask/auto-changelog": "^3.4.4",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
Expand Down
129 changes: 128 additions & 1 deletion packages/controller-utils/src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import BigNumber from 'bignumber.js';
import BN from 'bn.js';
import nock from 'nock';

import { FakeProvider } from '../../../tests/fake-provider';
import { MAX_SAFE_CHAIN_ID } from './constants';
import * as util from './util';
import { FakeProvider } from '../../../tests/fake-provider';

const VALID = '4e1fF7229BDdAf0A73DF183a88d9c3a04cc975e0';
const SOME_API = 'https://someapi.com';
Expand Down Expand Up @@ -320,6 +320,56 @@ describe('util', () => {
it('should return the input untouched if it is null', () => {
expect(util.toChecksumHexAddress(null)).toBeNull();
});

it('should return the address untouched if it is not a valid hex address', () => {
expect(util.toChecksumHexAddress('0x1')).toBe('0x1');
});

it('should memoize results for same input', () => {
const testAddress = '4e1ff7229bddaf0a73df183a88d9c3a04cc975e0';

// Call the function multiple times with the same input
const result1 = util.toChecksumHexAddress(testAddress);
const result2 = util.toChecksumHexAddress(testAddress);
const result3 = util.toChecksumHexAddress(testAddress);

// All results should be identical
expect(result1).toBe('0x4e1fF7229BDdAf0A73DF183a88d9c3a04cc975e0');
expect(result2).toBe(result1);
expect(result3).toBe(result1);
});

it('should return different results for different inputs but still memoize each', () => {
const testAddress1 = '4e1ff7229bddaf0a73df183a88d9c3a04cc975e0';
const testAddress2 = '742d35cc6ba4c0a2b7e8b4c0b1b0c2b2b2b2b2b2';

// Call with first address multiple times
const result1a = util.toChecksumHexAddress(testAddress1);
const result1b = util.toChecksumHexAddress(testAddress1);

// Call with second address multiple times
const result2a = util.toChecksumHexAddress(testAddress2);
const result2b = util.toChecksumHexAddress(testAddress2);

// Results for same address should be identical
expect(result1b).toBe(result1a);
expect(result2b).toBe(result2a);

// Results for different addresses should be different
expect(result1a).not.toBe(result2a);
});

it('should memoize based on complete argument signature', () => {
const testAddress = '4e1ff7229bddaf0a73df183a88d9c3a04cc975e0';

// Call with string argument
const result1 = util.toChecksumHexAddress(testAddress);
const result2 = util.toChecksumHexAddress(testAddress);

// Both should be memoized and return the same result
expect(result2).toBe(result1);
expect(result1).toBe('0x4e1fF7229BDdAf0A73DF183a88d9c3a04cc975e0');
});
});

describe('isValidHexAddress', () => {
Expand All @@ -336,6 +386,83 @@ describe('util', () => {
false,
);
});

it('should memoize results for same input', () => {
const validAddress = '4e1fF7229BDdAf0A73DF183a88d9c3a04cc975e0';

// Call the function multiple times with the same input
const result1 = util.isValidHexAddress(validAddress);
const result2 = util.isValidHexAddress(validAddress);
const result3 = util.isValidHexAddress(validAddress);

// All results should be identical
expect(result1).toBe(true);
expect(result2).toBe(result1);
expect(result3).toBe(result1);
});

it('should memoize results for same input with options', () => {
const validAddress = '4e1fF7229BDdAf0A73DF183a88d9c3a04cc975e0';
const options = { allowNonPrefixed: true };

// Call the function multiple times with the same input and options
const result1 = util.isValidHexAddress(validAddress, options);
const result2 = util.isValidHexAddress(validAddress, options);
const result3 = util.isValidHexAddress(validAddress, options);

// All results should be identical
expect(result1).toBe(true);
expect(result2).toBe(result1);
expect(result3).toBe(result1);
});

it('should return different results for different option combinations', () => {
const addressWithoutPrefix = '4e1fF7229BDdAf0A73DF183a88d9c3a04cc975e0';

// Call with different options
const result1 = util.isValidHexAddress(addressWithoutPrefix, {
allowNonPrefixed: true,
});
const result2 = util.isValidHexAddress(addressWithoutPrefix, {
allowNonPrefixed: false,
});

// Should return different results for different options
expect(result1).toBe(true);
expect(result2).toBe(false);

// But calling again with same options should return memoized results
const result1Again = util.isValidHexAddress(addressWithoutPrefix, {
allowNonPrefixed: true,
});
const result2Again = util.isValidHexAddress(addressWithoutPrefix, {
allowNonPrefixed: false,
});

expect(result1Again).toBe(result1);
expect(result2Again).toBe(result2);
});

it('should handle memoization with different address inputs', () => {
const validAddress = '4e1fF7229BDdAf0A73DF183a88d9c3a04cc975e0';
const invalidAddress = '0x00';

// Call with valid address multiple times
const validResult1 = util.isValidHexAddress(validAddress);
const validResult2 = util.isValidHexAddress(validAddress);

// Call with invalid address multiple times
const invalidResult1 = util.isValidHexAddress(invalidAddress);
const invalidResult2 = util.isValidHexAddress(invalidAddress);

// Results for same address should be identical
expect(validResult2).toBe(validResult1);
expect(invalidResult2).toBe(invalidResult1);

// Results should be correct
expect(validResult1).toBe(true);
expect(invalidResult1).toBe(false);
});
});

it('messageHexToString', () => {
Expand Down
Loading
Loading