Skip to content

Commit

Permalink
Get accounts-controller and assets-controllers tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed May 20, 2024
1 parent b773dc2 commit 7f4d92b
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ async function setupAssetContractControllers() {
const network = new NetworkController({
infuraProjectId: networkClientConfiguration.infuraProjectId,
messenger,
trackMetaMetricsEvent: jest.fn(),
});

const provider = new HttpProvider(
Expand Down
4 changes: 2 additions & 2 deletions packages/assets-controllers/src/NftController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
NetworkClientId,
NetworkState,
} from '@metamask/network-controller';
import { defaultState as defaultNetworkState } from '@metamask/network-controller';
import { getDefaultNetworkControllerState } from '@metamask/network-controller';
import {
getDefaultPreferencesState,
type PreferencesState,
Expand Down Expand Up @@ -136,7 +136,7 @@ function setupController({
}) => {
onNetworkDidChangeListeners.forEach((listener) => {
listener({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId,
});
});
Expand Down
51 changes: 27 additions & 24 deletions packages/assets-controllers/src/TokenDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
NetworkType,
convertHexToDecimal,
BUILT_IN_NETWORKS,

Check failure on line 7 in packages/assets-controllers/src/TokenDetectionController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

'BUILT_IN_NETWORKS' is defined but never used
InfuraNetworkType,
} from '@metamask/controller-utils';
import type { InternalAccount } from '@metamask/keyring-api';
import type { KeyringControllerState } from '@metamask/keyring-controller';
Expand All @@ -14,9 +15,10 @@ import type {
NetworkController,
NetworkClientId,
} from '@metamask/network-controller';
import { defaultState as defaultNetworkState } from '@metamask/network-controller';
import { getDefaultNetworkControllerState } from '@metamask/network-controller';
import type { AutoManagedNetworkClient } from '@metamask/network-controller/src/create-auto-managed-network-client';
import type { CustomNetworkClientConfiguration } from '@metamask/network-controller/src/types';
import { buildCustomRpcEndpoint, buildInfuraNetworkConfiguration } from '@metamask/network-controller/tests/helpers';

Check failure on line 21 in packages/assets-controllers/src/TokenDetectionController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Replace `·buildCustomRpcEndpoint,·buildInfuraNetworkConfiguration·` with `⏎··buildCustomRpcEndpoint,⏎··buildInfuraNetworkConfiguration,⏎`
import {
getDefaultPreferencesState,
type PreferencesState,
Expand Down Expand Up @@ -106,22 +108,23 @@ const sampleTokenB = {
};

const mockNetworkConfigurations: Record<string, NetworkConfiguration> = {
[NetworkType.mainnet]: {
...BUILT_IN_NETWORKS[NetworkType.mainnet],
rpcUrl: 'https://mainnet.infura.io/v3/fakekey',
},
[NetworkType.goerli]: {
...BUILT_IN_NETWORKS[NetworkType.goerli],
rpcUrl: 'https://goerli.infura.io/v3/fakekey',
},
[InfuraNetworkType.mainnet]: buildInfuraNetworkConfiguration(
InfuraNetworkType.mainnet,
),
[InfuraNetworkType.goerli]: buildInfuraNetworkConfiguration(
InfuraNetworkType.goerli,
),
polygon: {
blockExplorerUrl: 'https://polygonscan.com/',
chainId: '0x89',
nickname: 'Polygon Mainnet',
rpcUrl: `https://polygon-mainnet.infura.io/v3/fakekey`,
ticker: 'MATIC',
rpcPrefs: {
blockExplorerUrl: 'https://polygonscan.com/',
},
defaultRpcEndpointUrl: 'https://polygon-mainnet.infura.io/v3/fakekey',
name: 'Polygon Mainnet',
nativeTokenName: 'MATIC',
rpcEndpoints: [
buildCustomRpcEndpoint({
url: 'https://polygon-mainnet.infura.io/v3/fakekey',
}),
],
},
};

Expand Down Expand Up @@ -276,7 +279,7 @@ describe('TokenDetectionController', () => {
},
async ({ controller, mockNetworkState }) => {
mockNetworkState({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: NetworkType.goerli,
});
await controller.start();
Expand Down Expand Up @@ -353,7 +356,7 @@ describe('TokenDetectionController', () => {
callActionSpy,
}) => {
mockNetworkState({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'polygon',
});
mockGetNetworkClientById(
Expand Down Expand Up @@ -1281,7 +1284,7 @@ describe('TokenDetectionController', () => {
});

triggerNetworkDidChange({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'polygon',
});
await advanceTime({ clock, duration: 1 });
Expand Down Expand Up @@ -1337,7 +1340,7 @@ describe('TokenDetectionController', () => {
});

triggerNetworkDidChange({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'goerli',
});
await advanceTime({ clock, duration: 1 });
Expand Down Expand Up @@ -1383,7 +1386,7 @@ describe('TokenDetectionController', () => {
});

triggerNetworkDidChange({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'mainnet',
});
await advanceTime({ clock, duration: 1 });
Expand Down Expand Up @@ -1431,7 +1434,7 @@ describe('TokenDetectionController', () => {
});

triggerNetworkDidChange({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'polygon',
});
await advanceTime({ clock, duration: 1 });
Expand Down Expand Up @@ -1480,7 +1483,7 @@ describe('TokenDetectionController', () => {
});

triggerNetworkDidChange({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'polygon',
});
await advanceTime({ clock, duration: 1 });
Expand Down Expand Up @@ -1786,7 +1789,7 @@ describe('TokenDetectionController', () => {
callActionSpy,
}) => {
mockNetworkState({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: NetworkType.goerli,
});
triggerPreferencesStateChange({
Expand Down Expand Up @@ -2088,7 +2091,7 @@ async function withController<ReturnValue>(
const mockNetworkState = jest.fn<NetworkState, []>();
controllerMessenger.registerActionHandler(
'NetworkController:getState',
mockNetworkState.mockReturnValue({ ...defaultNetworkState }),
mockNetworkState.mockReturnValue({ ...getDefaultNetworkControllerState() }),
);
const mockTokensState = jest.fn<TokensState, []>();
controllerMessenger.registerActionHandler(
Expand Down
10 changes: 5 additions & 5 deletions packages/assets-controllers/src/TokenListController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ describe('TokenListController', () => {
);
onNetworkStateChangeCallback({
selectedNetworkClientId,
networkConfigurations: {},
networkConfigurationsByChainId: {},
networksMetadata: {},
});
await new Promise<void>((resolve) => setTimeout(() => resolve(), 500));
Expand Down Expand Up @@ -993,7 +993,7 @@ describe('TokenListController', () => {
'NetworkController:stateChange',
{
selectedNetworkClientId: InfuraNetworkType.goerli,
networkConfigurations: {},
networkConfigurationsByChainId: {},
networksMetadata: {},
},
[],
Expand All @@ -1012,7 +1012,7 @@ describe('TokenListController', () => {
'NetworkController:stateChange',
{
selectedNetworkClientId: selectedCustomNetworkClientId,
networkConfigurations: {},
networkConfigurationsByChainId: {},
networksMetadata: {},
},
[],
Expand Down Expand Up @@ -1090,7 +1090,7 @@ describe('TokenListController', () => {
'NetworkController:stateChange',
{
selectedNetworkClientId: InfuraNetworkType.mainnet,
networkConfigurations: {},
networkConfigurationsByChainId: {},
networksMetadata: {},
},
[],
Expand Down Expand Up @@ -1138,7 +1138,7 @@ describe('TokenListController', () => {
'NetworkController:stateChange',
{
selectedNetworkClientId: selectedCustomNetworkClientId,
networkConfigurations: {},
networkConfigurationsByChainId: {},
networksMetadata: {},
},
[],
Expand Down
20 changes: 10 additions & 10 deletions packages/assets-controllers/src/TokenRatesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
NetworkClientId,
NetworkState,
} from '@metamask/network-controller';
import { defaultState as defaultNetworkState } from '@metamask/network-controller';
import { getDefaultNetworkControllerState } from '@metamask/network-controller';
import type { PreferencesState } from '@metamask/preferences-controller';
import type { Hex } from '@metamask/utils';
import { add0x } from '@metamask/utils';
Expand Down Expand Up @@ -780,7 +780,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

Expand Down Expand Up @@ -818,7 +818,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

Expand Down Expand Up @@ -854,7 +854,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

Expand Down Expand Up @@ -890,7 +890,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

Expand Down Expand Up @@ -928,7 +928,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

Expand Down Expand Up @@ -967,7 +967,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

Expand Down Expand Up @@ -1004,7 +1004,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

Expand Down Expand Up @@ -1039,7 +1039,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

Expand Down Expand Up @@ -1074,7 +1074,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

Expand Down
4 changes: 2 additions & 2 deletions packages/assets-controllers/src/TokensController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
NetworkClientConfiguration,
NetworkClientId,
} from '@metamask/network-controller';
import { defaultState as defaultNetworkState } from '@metamask/network-controller';
import { getDefaultNetworkControllerState } from '@metamask/network-controller';
import type { PreferencesState } from '@metamask/preferences-controller';
import { getDefaultPreferencesState } from '@metamask/preferences-controller';
import nock from 'nock';
Expand Down Expand Up @@ -2380,7 +2380,7 @@ async function withController<ReturnValue>(
selectedNetworkClientId: NetworkClientId;
}) => {
messenger.publish('NetworkController:networkDidChange', {
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId,
});
};
Expand Down
4 changes: 2 additions & 2 deletions packages/ens-controller/src/EnsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
toHex,
InfuraNetworkType,
} from '@metamask/controller-utils';
import { defaultState as defaultNetworkState } from '@metamask/network-controller';
import { getDefaultNetworkControllerState } from '@metamask/network-controller';

import type {
ExtractAvailableAction,
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('EnsController', () => {
provider: getProvider(),
onNetworkDidChange: (listener) => {
listener({
...defaultNetworkState,
...getDefaultNetworkControllerState(),
selectedNetworkClientId: InfuraNetworkType.mainnet,
});
},
Expand Down
3 changes: 1 addition & 2 deletions packages/network-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export type {
Block,
NetworkMetadata,
NetworkConfiguration,
NetworkConfigurationV2,
BuiltInNetworkClientId,
CustomNetworkClientId,
NetworkClientId,
Expand Down Expand Up @@ -30,8 +29,8 @@ export type {
NetworkControllerOptions,
} from './NetworkController';
export {
getDefaultNetworkControllerState,
knownKeysOf,
defaultState,
NetworkController,
} from './NetworkController';
export * from './constants';
Expand Down
Loading

0 comments on commit 7f4d92b

Please sign in to comment.