Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Apply major ComposableController API updates that fix broken functionality #10441

Draft
wants to merge 68 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
c522e14
Install preview build for `@metamask/composable-controller`
MajorLift Sep 6, 2024
8e0a4a7
Convert interfaces `EngineState`, `Controllers` to use type alias syntax
MajorLift Jul 22, 2024
e0d4c33
Naive application of new `ComposableController` API
MajorLift Jul 22, 2024
4230f50
Narrow engine datamodel's events allowlist and document required updates
MajorLift Jul 26, 2024
0223858
Apply `@ts-expect-error` directive for type error caused by mobile's …
MajorLift Jul 26, 2024
b75a118
Add `@ts-expect-error` directives for `stateChange` events that need …
MajorLift Jul 26, 2024
90a85df
Update Engine API test to include all controllers in engine context
MajorLift Jul 29, 2024
04f49ce
Update `@metamask/composable-controller` preview build
MajorLift Sep 6, 2024
4e505b3
Remove `ts-expect-error` directive from `TransactionController:stateC…
MajorLift Jul 31, 2024
7d8d12b
Fix type error caused by `CurrencyRateController` `18.0.0` breaking c…
MajorLift Aug 1, 2024
942c36d
Bump `@metamask/composable-controller` from `^3.0.0` to `^8.0.0`
MajorLift Sep 12, 2024
eb7f970
Remove `ts-expect-error` directive for base-controller version mismat…
MajorLift Aug 23, 2024
4c46164
Fix redundant, incomplete entries in `Global{Actions,Events}` types
MajorLift Aug 27, 2024
6f91ad5
Remove unused `ts-expect-error` directive for `TokenBalancesControlle…
MajorLift Aug 27, 2024
23664dd
Bump `@metamask/logging-controller` from `^3.0.0` to `^6.0.0`
MajorLift Sep 12, 2024
d94b202
Add `LoggingControllerEvents` to `GlobalEvents`
MajorLift Aug 29, 2024
69198bd
Bump `@metamask/base-controller` to `^7.0.0`, `@metamask/composable-c…
MajorLift Sep 12, 2024
c53e8f9
Add/remove `ts-expect-error` directives for resolving mismatch betwee…
MajorLift Aug 29, 2024
6489509
test: `ComposableController` updates engine state when it receives a …
MajorLift Sep 12, 2024
b9115c2
Add more granular TODO comments
MajorLift Sep 3, 2024
3eb5305
Remove unused `stateChange` entries for non-controllers in `Composabl…
MajorLift Sep 3, 2024
c630e1d
test(currency-controller): normalize `conversionRate` from `null` to 0
MajorLift Sep 3, 2024
74879b3
Remove unused `eslint-disable` directive
MajorLift Sep 6, 2024
97cea4c
Fix test so its recognized as coverage
MajorLift Sep 6, 2024
818eba3
Fix `ts-expect-error` errors
MajorLift Sep 9, 2024
1e8d992
Revert addition of `PPOMController{Actions,Events}` to `Global{Action…
MajorLift Sep 9, 2024
495f0e6
Restore `@ts-expect-error` directive for `PhishingControllerMessenger`
MajorLift Sep 9, 2024
c6f70c9
Restore `@ts-expect-error` for base-controller alignment on `Approval…
MajorLift Sep 9, 2024
2a6d5d0
Reorder test expect entries to minimize diff
MajorLift Sep 9, 2024
59afca8
Restore `PPOMControllerEvents` to `GlobalEvents`
MajorLift Sep 10, 2024
2bfb7ac
Reorganize code to minimize diffs
MajorLift Sep 10, 2024
a850cf9
Remove unnecessary `async`/`await` from test
MajorLift Sep 11, 2024
116b85a
Dedupe yarn lockfile, update Podfile.lock
MajorLift Sep 12, 2024
fa0e6c1
Update TODO for removing `TransactionControllerOptions` subpath import
MajorLift Sep 12, 2024
2178825
Add TODO for resolving base-controller mismatch between `AccountsCont…
MajorLift Sep 12, 2024
62094e1
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 13, 2024
4970923
Add comment explaining console errors for failed `stateChange` subscr…
MajorLift Sep 13, 2024
0f965d8
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 13, 2024
04958bf
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 18, 2024
d78d0cc
Remove unused `ts-expect-error`
MajorLift Sep 18, 2024
15d633c
Revert "Dedupe yarn lockfile, update Podfile.lock"
MajorLift Sep 18, 2024
b9b8ae2
Remove unused `ts-expect-error`
MajorLift Sep 18, 2024
93add3c
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 18, 2024
390d0e5
Run `git checkout main ios/Podfile.lock`
MajorLift Sep 18, 2024
d2fb6e9
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 18, 2024
d82c4b7
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 20, 2024
e333d8b
Add `AddressBookController:stateChange` to composable controller even…
MajorLift Sep 20, 2024
ce96d32
Deduplicate lockfile
MajorLift Sep 20, 2024
c8d030f
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 20, 2024
83bc5ca
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 20, 2024
07ee35b
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 23, 2024
83c59ea
Add notifications controllers actions/events to `Global{Actions,Event…
MajorLift Sep 23, 2024
7833177
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 23, 2024
78ff64b
Remove duplicate controller entries in `EngineService`
MajorLift Sep 23, 2024
bba0f53
Add `SnapsRegistry` `stateChange` event to composable controller mess…
MajorLift Sep 23, 2024
1896175
Add `SmartTransactionsController:stateChange` to composable controlle…
MajorLift Sep 23, 2024
db5be57
Fix circular typing for `this.context` in `Engine`
MajorLift Sep 23, 2024
7a4fd30
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Sep 23, 2024
305e9f0
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Oct 3, 2024
0e2a97a
Remove `@ts-expect-error` directive on `PhishingController:stateChang…
MajorLift Oct 3, 2024
42d13d2
Merge remote-tracking branch 'origin/main' into jongsun/fix-composabl…
cryptodev-2s Oct 14, 2024
fe66a38
Merge remote-tracking branch 'origin/main' into jongsun/fix-composabl…
cryptodev-2s Oct 23, 2024
e0ecbcc
Reflect V2 upgrades for `{AccountTracker,Nft,TokenRates}Controller` i…
MajorLift Nov 14, 2024
51e3a5a
Merge branch 'main' into jongsun/fix-composable-controller
MajorLift Nov 14, 2024
e632f70
Apply changes from PPOMController update
MajorLift Nov 14, 2024
24d9936
Replace `BaseState` with `NonControllerEmptyState`
MajorLift Nov 14, 2024
c50e9e6
Dedupe lockfile
MajorLift Nov 14, 2024
eaf1ee2
Update `Global{Actions,Events}` with `NotificationServicesPushContro…
MajorLift Nov 14, 2024
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
59 changes: 58 additions & 1 deletion app/core/Engine.test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
import Engine from './Engine';
import { createMockAccountsControllerState } from '../util/test/accountsControllerTestUtils';
import { backgroundState } from '../util/test/initial-root-state';
import { zeroAddress } from 'ethereumjs-util';
import { createMockAccountsControllerState } from '../util/test/accountsControllerTestUtils';
import { LogType } from '@metamask/logging-controller';

jest.unmock('./Engine');
jest.mock('../store', () => ({ store: { getState: jest.fn(() => ({})) } }));

describe('Engine', () => {
it('should expose an API', () => {
const engine = Engine.init({});
expect(engine.context).toHaveProperty('AccountsController');
expect(engine.context).toHaveProperty('AccountTrackerController');
expect(engine.context).toHaveProperty('AddressBookController');
expect(engine.context).toHaveProperty('AssetsContractController');
expect(engine.context).toHaveProperty('ApprovalController');
expect(engine.context).toHaveProperty('TokenListController');
expect(engine.context).toHaveProperty('TokenDetectionController');
expect(engine.context).toHaveProperty('NftDetectionController');
expect(engine.context).toHaveProperty('NftController');
expect(engine.context).toHaveProperty('CurrencyRateController');
expect(engine.context).toHaveProperty('GasFeeController');
expect(engine.context).toHaveProperty('KeyringController');
expect(engine.context).toHaveProperty('NetworkController');
expect(engine.context).toHaveProperty('PermissionController');
expect(engine.context).toHaveProperty('PhishingController');
expect(engine.context).toHaveProperty('PreferencesController');
expect(engine.context).toHaveProperty('SignatureController');
expect(engine.context).toHaveProperty('PPOMController');
expect(engine.context).toHaveProperty('TokenBalancesController');
expect(engine.context).toHaveProperty('TokenRatesController');
expect(engine.context).toHaveProperty('TokensController');
expect(engine.context).toHaveProperty('LoggingController');
expect(engine.context).toHaveProperty('TransactionController');
expect(engine.context).toHaveProperty('SmartTransactionsController');
expect(engine.context).toHaveProperty('SnapController');
expect(engine.context).toHaveProperty('SubjectMetadataController');
expect(engine.context).toHaveProperty('SwapsController');
expect(engine.context).toHaveProperty('AuthenticationController');
expect(engine.context).toHaveProperty('UserStorageController');
expect(engine.context).toHaveProperty('NotificationServicesController');
Expand Down Expand Up @@ -87,6 +96,29 @@ describe('Engine', () => {
});
});

it("updates datamodel state when a controller's state is updated", () => {
const engine = Engine.init({});

expect(
engine.controllerMessenger.call('LoggingController:add', {
type: LogType.GenericLog,
data: `Generic log`,
}),
).toBeUndefined();

expect(engine.datamodel.state).toHaveProperty('LoggingController.logs');
const logs = Object.values(engine.datamodel.state.LoggingController.logs);
expect(logs).toHaveLength(1);
expect(Object.values(logs)).toContainEqual({
timestamp: expect.any(Number),
id: expect.any(String),
log: expect.objectContaining({
type: LogType.GenericLog,
data: 'Generic log',
}),
});
});

it('setSelectedAccount throws an error if no account exists for the given address', () => {
const engine = Engine.init(backgroundState);
const invalidAddress = '0xInvalidAddress';
Expand All @@ -96,6 +128,31 @@ describe('Engine', () => {
);
});

it('normalizes `null` `conversionRate` to 0', () => {
const chainId = '0x1';
const ticker = 'ETH';
const ethConversionRate = null;
const state = {
NetworkController: {
state: { providerConfig: { chainId, ticker } },
},
CurrencyRateController: {
currencyRates: {
[ticker]: { conversionRate: ethConversionRate },
},
},
};
Engine.init(state);
expect(Engine.state).toHaveProperty('CurrencyRateController.currencyRates');
expect(
Engine.state.CurrencyRateController.currencyRates[ticker],
).toStrictEqual({
conversionDate: 0,
conversionRate: 0,
usdConversionRate: null,
});
});

describe('getTotalFiatAccountBalance', () => {
let engine;
afterEach(() => engine?.destroyEngineInstance());
Expand Down
Loading
Loading