1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Convert NetworkController unit tests to TypeScript (#18476)

This helps us more easily compare the unit tests for NetworkController
in this repo and the NetworkController in the `core` repo.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
This commit is contained in:
Elliot Winkler 2023-04-12 13:53:34 -06:00 committed by GitHub
parent 065c499753
commit 6439551075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1145 additions and 929 deletions

View File

@ -266,6 +266,7 @@ module.exports = {
'**/__snapshots__/*.snap',
'app/scripts/controllers/app-state.test.js',
'app/scripts/controllers/network/**/*.test.js',
'app/scripts/controllers/network/**/*.test.ts',
'app/scripts/controllers/network/provider-api-tests/*.js',
'app/scripts/controllers/permissions/**/*.test.js',
'app/scripts/lib/**/*.test.js',

View File

@ -64,7 +64,7 @@ type Block = {
* Primarily used to build the network client and check the availability of a
* network.
*/
type ProviderType = BuiltInInfuraNetwork | typeof NETWORK_TYPES.RPC;
export type ProviderType = BuiltInInfuraNetwork | typeof NETWORK_TYPES.RPC;
/**
* The network ID of a network.
@ -85,14 +85,14 @@ type ChainId = Hex;
* The set of event types that NetworkController can publish via its messenger.
*/
export enum NetworkControllerEventType {
/**
* @see {@link NetworkControllerNetworkWillChangeEvent}
*/
NetworkWillChange = 'NetworkController:networkWillChange',
/**
* @see {@link NetworkControllerNetworkDidChangeEvent}
*/
NetworkDidChange = 'NetworkController:networkDidChange',
/**
* @see {@link NetworkControllerNetworkWillChangeEvent}
*/
NetworkWillChange = 'NetworkController:networkWillChange',
/**
* @see {@link NetworkControllerInfuraIsBlockedEvent}
*/
@ -108,7 +108,7 @@ export enum NetworkControllerEventType {
* switched, but the new provider has not been created and no state changes have
* occurred yet.
*/
type NetworkControllerNetworkWillChangeEvent = {
export type NetworkControllerNetworkWillChangeEvent = {
type: NetworkControllerEventType.NetworkWillChange;
payload: [];
};
@ -117,7 +117,7 @@ type NetworkControllerNetworkWillChangeEvent = {
* `networkDidChange` is published after a provider has been created for a newly
* switched network (but before the network has been confirmed to be available).
*/
type NetworkControllerNetworkDidChangeEvent = {
export type NetworkControllerNetworkDidChangeEvent = {
type: NetworkControllerEventType.NetworkDidChange;
payload: [];
};
@ -127,7 +127,7 @@ type NetworkControllerNetworkDidChangeEvent = {
* network, but when Infura returns an error blocking the user based on their
* location.
*/
type NetworkControllerInfuraIsBlockedEvent = {
export type NetworkControllerInfuraIsBlockedEvent = {
type: NetworkControllerEventType.InfuraIsBlocked;
payload: [];
};
@ -137,7 +137,7 @@ type NetworkControllerInfuraIsBlockedEvent = {
* Infura network and Infura does not return an error blocking the user based on
* their location, or the network is switched to a non-Infura network.
*/
type NetworkControllerInfuraIsUnblockedEvent = {
export type NetworkControllerInfuraIsUnblockedEvent = {
type: NetworkControllerEventType.InfuraIsUnblocked;
payload: [];
};
@ -145,7 +145,7 @@ type NetworkControllerInfuraIsUnblockedEvent = {
/**
* The set of events that the NetworkController messenger can publish.
*/
type NetworkControllerEvent =
export type NetworkControllerEvent =
| NetworkControllerNetworkDidChangeEvent
| NetworkControllerNetworkWillChangeEvent
| NetworkControllerInfuraIsBlockedEvent
@ -154,7 +154,7 @@ type NetworkControllerEvent =
/**
* The messenger that the NetworkController uses to publish events.
*/
type NetworkControllerMessenger = RestrictedControllerMessenger<
export type NetworkControllerMessenger = RestrictedControllerMessenger<
typeof name,
never,
NetworkControllerEvent,
@ -167,7 +167,7 @@ type NetworkControllerMessenger = RestrictedControllerMessenger<
* network. Currently has overlap with `NetworkConfiguration`, although the
* two will be merged down the road.
*/
type ProviderConfiguration = {
export type ProviderConfiguration = {
/**
* Either a type of Infura network, "localhost" for a locally operated
* network, or "rpc" for everything else.
@ -213,6 +213,7 @@ type NetworkDetails = {
EIPS: {
[eipNumber: number]: boolean | undefined;
};
[otherProperty: string]: unknown;
};
/**
@ -264,7 +265,7 @@ type NetworkConfigurations = Record<
/**
* The state that NetworkController holds after combining its individual stores.
*/
type CompositeState = {
export type NetworkControllerState = {
provider: ProviderConfiguration;
previousProviderStore: ProviderConfiguration;
networkId: NetworkIdState;
@ -276,7 +277,7 @@ type CompositeState = {
/**
* The options that NetworkController takes.
*/
type NetworkControllerOptions = {
export type NetworkControllerOptions = {
messenger: NetworkControllerMessenger;
state?: {
provider?: ProviderConfiguration;
@ -450,7 +451,7 @@ export class NetworkController extends EventEmitter {
* Observable store containing a combination of data from all of the
* individual stores.
*/
store: ComposedStore<CompositeState>;
store: ComposedStore<NetworkControllerState>;
_provider: SafeEventEmitterProvider | null;
@ -508,7 +509,7 @@ export class NetworkController extends EventEmitter {
state.networkConfigurations || buildDefaultNetworkConfigurationsState(),
);
this.store = new ComposedStore<CompositeState>({
this.store = new ComposedStore<NetworkControllerState>({
provider: this.providerStore,
previousProviderStore: this.previousProviderStore,
networkId: this.networkIdStore,

View File

@ -2,6 +2,7 @@ module.exports = {
collectCoverageFrom: [
'<rootDir>/app/scripts/constants/error-utils.js',
'<rootDir>/app/scripts/controllers/network/**/*.js',
'<rootDir>/app/scripts/controllers/network/**/*.ts',
'<rootDir>/app/scripts/controllers/permissions/**/*.js',
'<rootDir>/app/scripts/controllers/sign.ts',
'<rootDir>/app/scripts/flask/**/*.js',
@ -39,6 +40,7 @@ module.exports = {
'<rootDir>/app/scripts/constants/error-utils.test.js',
'<rootDir>/app/scripts/controllers/app-state.test.js',
'<rootDir>/app/scripts/controllers/network/**/*.test.js',
'<rootDir>/app/scripts/controllers/network/**/*.test.ts',
'<rootDir>/app/scripts/controllers/permissions/**/*.test.js',
'<rootDir>/app/scripts/controllers/sign.test.ts',
'<rootDir>/app/scripts/flask/**/*.test.js',

View File

@ -419,6 +419,7 @@
"@types/react-dom": "^17.0.11",
"@types/react-redux": "^7.1.25",
"@types/remote-redux-devtools": "^0.5.5",
"@types/sinon": "^10.0.13",
"@types/w3c-web-hid": "^1.0.3",
"@types/watchify": "^3.11.1",
"@types/yargs": "^17.0.8",

View File

@ -7726,6 +7726,22 @@ __metadata:
languageName: node
linkType: hard
"@types/sinon@npm:^10.0.13":
version: 10.0.13
resolution: "@types/sinon@npm:10.0.13"
dependencies:
"@types/sinonjs__fake-timers": "*"
checksum: 46a14c888db50f0098ec53d451877e0111d878ec4a653b9e9ed7f8e54de386d6beb0e528ddc3e95cd3361a8ab9ad54e4cca33cd88d45b9227b83e9fc8fb6688a
languageName: node
linkType: hard
"@types/sinonjs__fake-timers@npm:*":
version: 8.1.2
resolution: "@types/sinonjs__fake-timers@npm:8.1.2"
checksum: bbc73a5ab6c0ec974929392f3d6e1e8db4ebad97ec506d785301e1c3d8a4f98a35b1aa95b97035daef02886fd8efd7788a2fa3ced2ec7105988bfd8dce61eedd
languageName: node
linkType: hard
"@types/source-list-map@npm:*":
version: 0.1.2
resolution: "@types/source-list-map@npm:0.1.2"
@ -24308,6 +24324,7 @@ __metadata:
"@types/react-dom": ^17.0.11
"@types/react-redux": ^7.1.25
"@types/remote-redux-devtools": ^0.5.5
"@types/sinon": ^10.0.13
"@types/w3c-web-hid": ^1.0.3
"@types/watchify": ^3.11.1
"@types/yargs": ^17.0.8