Skip to content

Commit

Permalink
Merge branch 'main' into 230113-consolidate-TokenDetectionController-…
Browse files Browse the repository at this point in the history
…DetectTokensController
  • Loading branch information
MajorLift committed Jan 29, 2024
2 parents aed885a + 8c09b16 commit ed74732
Show file tree
Hide file tree
Showing 17 changed files with 587 additions and 77 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": "112.0.0",
"version": "113.0.0",
"private": true,
"description": "Monorepo for packages shared between MetaMask clients",
"repository": {
Expand Down
10 changes: 9 additions & 1 deletion packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [21.0.1]

### Fixed

- Resolves transaction custodian promise when setting transaction status to `submitted` or `failed` ([#3845](https://github.com/MetaMask/core/pull/3845))
- Fix normalizer ensuring property `type` is always present in `TransactionParams` ([#3817](https://github.com/MetaMask/core/pull/3817))

## [21.0.0]

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

All changes listed after this point were applied to this package following the monorepo conversion.

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@21.0.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@21.0.1...HEAD
[21.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@21.0.0...@metamask/transaction-controller@21.0.1
[21.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@20.0.0...@metamask/transaction-controller@21.0.0
[20.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@19.0.1...@metamask/transaction-controller@20.0.0
[19.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@19.0.0...@metamask/transaction-controller@19.0.1
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/transaction-controller",
"version": "21.0.0",
"version": "21.0.1",
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
"keywords": [
"MetaMask",
Expand Down
15 changes: 14 additions & 1 deletion packages/user-operation-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.0.0]

### Changed

- **BREAKING**: Add required `from` property to `PrepareUserOperationRequest` ([#3844](https://github.com/MetaMask/core/pull/3844))
- **BREAKING**: Add required `from` property to `AddUserOperationRequest` ([#3844](https://github.com/MetaMask/core/pull/3844))
- **BREAKING**: Make `smartContractAccount` optional in `AddUserOperationOptions` ([#3844](https://github.com/MetaMask/core/pull/3844))
- Use current account snap by default if not provided ([#3844](https://github.com/MetaMask/core/pull/3844))
- Delete user operation if rejected during approval ([#3844](https://github.com/MetaMask/core/pull/3844))
- Set `userFeeLevel` to `custom` in transaction event if using a paymaster ([#3844](https://github.com/MetaMask/core/pull/3844))
- Validate arguments when calling `addUserOperationFromTransaction` ([#3844](https://github.com/MetaMask/core/pull/3844))

## [2.0.0]

### Changed
Expand All @@ -31,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@2.0.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@3.0.0...HEAD
[3.0.0]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@2.0.0...@metamask/user-operation-controller@3.0.0
[2.0.0]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@1.0.0...@metamask/user-operation-controller@2.0.0
[1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/user-operation-controller@1.0.0
9 changes: 6 additions & 3 deletions packages/user-operation-controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/user-operation-controller",
"version": "2.0.0",
"version": "3.0.0",
"description": "Creates user operations and manages their life cycle",
"keywords": [
"MetaMask",
Expand Down Expand Up @@ -37,9 +37,11 @@
"@metamask/controller-utils": "^8.0.2",
"@metamask/eth-query": "^4.0.0",
"@metamask/gas-fee-controller": "^13.0.0",
"@metamask/keyring-controller": "^12.2.0",
"@metamask/network-controller": "^17.2.0",
"@metamask/polling-controller": "^5.0.0",
"@metamask/transaction-controller": "^21.0.0",
"@metamask/rpc-errors": "^6.1.0",
"@metamask/transaction-controller": "^21.0.1",
"@metamask/utils": "^8.3.0",
"ethereumjs-util": "^7.0.10",
"immer": "^9.0.6",
Expand All @@ -60,8 +62,9 @@
"peerDependencies": {
"@metamask/approval-controller": "^5.1.2",
"@metamask/gas-fee-controller": "^13.0.0",
"@metamask/keyring-controller": "^12.2.0",
"@metamask/network-controller": "^17.2.0",
"@metamask/transaction-controller": "^21.0.0"
"@metamask/transaction-controller": "^21.0.1"
},
"engines": {
"node": ">=16.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApprovalType } from '@metamask/controller-utils';
import { errorCodes } from '@metamask/rpc-errors';
import {
determineTransactionType,
TransactionType,
Expand All @@ -9,6 +10,7 @@ import { EventEmitter } from 'stream';
import { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants';
import * as BundlerHelper from './helpers/Bundler';
import * as PendingUserOperationTrackerHelper from './helpers/PendingUserOperationTracker';
import { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount';
import type { UserOperationMetadata } from './types';
import {
UserOperationStatus,
Expand Down Expand Up @@ -39,6 +41,7 @@ jest.mock('./utils/gas-fees');
jest.mock('./utils/validation');
jest.mock('./helpers/Bundler');
jest.mock('./helpers/PendingUserOperationTracker');
jest.mock('./helpers/SnapSmartContractAccount');

const CHAIN_ID_MOCK = '0x5';
const USER_OPERATION_HASH_MOCK = '0x123';
Expand Down Expand Up @@ -78,15 +81,16 @@ const SIGN_USER_OPERATION_RESPONSE_MOCK: SignUserOperationResponse = {
signature: '0xB',
};

const ADD_USER_OPERATION_REQUEST_MOCK = {
const ADD_USER_OPERATION_REQUEST_MOCK: AddUserOperationRequest = {
data: '0x1',
from: '0x12',
to: '0x2',
value: '0x3',
maxFeePerGas: '0x4',
maxPriorityFeePerGas: '0x5',
};

const ADD_USER_OPERATION_OPTIONS_MOCK = {
const ADD_USER_OPERATION_OPTIONS_MOCK: AddUserOperationOptions = {
networkClientId: NETWORK_CLIENT_ID_MOCK,
origin: ORIGIN_MOCK,
};
Expand Down Expand Up @@ -257,10 +261,10 @@ describe('UserOperationController', () => {
updateGasFeesMock
.mockImplementationOnce(async ({ metadata }) => {
metadata.userOperation.maxFeePerGas =
ADD_USER_OPERATION_REQUEST_MOCK.maxFeePerGas;
ADD_USER_OPERATION_REQUEST_MOCK.maxFeePerGas as string;

metadata.userOperation.maxPriorityFeePerGas =
ADD_USER_OPERATION_REQUEST_MOCK.maxPriorityFeePerGas;
ADD_USER_OPERATION_REQUEST_MOCK.maxPriorityFeePerGas as string;
})
.mockImplementationOnce(async ({ metadata }) => {
metadata.userOperation.maxFeePerGas = '0x6';
Expand Down Expand Up @@ -589,6 +593,26 @@ describe('UserOperationController', () => {
);
});

it('deletes user operation if rejected', async () => {
const controller = new UserOperationController(optionsMock);

const error = new Error(ERROR_MESSAGE_MOCK);
(error as unknown as Record<string, unknown>).code =
errorCodes.provider.userRejectedRequest;

approvalControllerAddRequestMock.mockClear();
approvalControllerAddRequestMock.mockRejectedValue(error);

const { hash } = await controller.addUserOperation(
ADD_USER_OPERATION_REQUEST_MOCK,
{ ...ADD_USER_OPERATION_OPTIONS_MOCK, smartContractAccount },
);

await expect(hash()).rejects.toThrow(ERROR_MESSAGE_MOCK);

expect(Object.keys(controller.state.userOperations)).toHaveLength(0);
});

// eslint-disable-next-line jest/expect-expect
it('does not throw if hash function not invoked', async () => {
const controller = new UserOperationController(optionsMock);
Expand Down Expand Up @@ -782,6 +806,24 @@ describe('UserOperationController', () => {
expect(resultCallbackSuccessMock).not.toHaveBeenCalled();
});

it('uses snap smart contract account if no smart contract account provided', async () => {
const prepareMock = jest.spyOn(
SnapSmartContractAccount.prototype,
'prepareUserOperation',
);

const controller = new UserOperationController(optionsMock);

await addUserOperation(controller, ADD_USER_OPERATION_REQUEST_MOCK, {
...ADD_USER_OPERATION_OPTIONS_MOCK,
smartContractAccount: undefined,
});

await flushPromises();

expect(prepareMock).toHaveBeenCalledTimes(1);
});

describe('if approval request resolved with updated transaction', () => {
it('updates gas fees without regeneration if paymaster data not set', async () => {
const controller = new UserOperationController(optionsMock);
Expand Down Expand Up @@ -1078,27 +1120,25 @@ describe('UserOperationController', () => {
});
});

if (method === 'addUserOperation') {
it('validates arguments', async () => {
const controller = new UserOperationController(optionsMock);
it('validates arguments', async () => {
const controller = new UserOperationController(optionsMock);

await addUserOperation(controller, ADD_USER_OPERATION_REQUEST_MOCK, {
...ADD_USER_OPERATION_OPTIONS_MOCK,
smartContractAccount,
});
await addUserOperation(controller, ADD_USER_OPERATION_REQUEST_MOCK, {
...ADD_USER_OPERATION_OPTIONS_MOCK,
smartContractAccount,
});

expect(validateAddUserOperationRequestMock).toHaveBeenCalledTimes(1);
expect(validateAddUserOperationRequestMock).toHaveBeenCalledWith(
ADD_USER_OPERATION_REQUEST_MOCK,
);
expect(validateAddUserOperationRequestMock).toHaveBeenCalledTimes(1);
expect(validateAddUserOperationRequestMock).toHaveBeenCalledWith(
ADD_USER_OPERATION_REQUEST_MOCK,
);

expect(validateAddUserOperationOptionsMock).toHaveBeenCalledTimes(1);
expect(validateAddUserOperationOptionsMock).toHaveBeenCalledWith({
...ADD_USER_OPERATION_OPTIONS_MOCK,
smartContractAccount,
});
expect(validateAddUserOperationOptionsMock).toHaveBeenCalledTimes(1);
expect(validateAddUserOperationOptionsMock).toHaveBeenCalledWith({
...ADD_USER_OPERATION_OPTIONS_MOCK,
smartContractAccount,
});
}
});

if (method === 'addUserOperationFromTransaction') {
it('sets data as undefined if empty string', async () => {
Expand Down
Loading

0 comments on commit ed74732

Please sign in to comment.