mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Add getProviderConfig action to NetworkController (#19317)
This controller action exists within the core version of NetworkController. Although there are no plans to make use of this action within the extension, it has accompanying tests. So ultimately, the goal of this commit (like others) is to make it easier to compare differences in the NetworkController tests between this repo and core by adding a test for the `getProviderConfig` action.
This commit is contained in:
parent
84d22e122c
commit
cc2e18b16a
@ -18,6 +18,7 @@ import {
|
|||||||
import { MetaMetricsNetworkEventSource } from '../../../../shared/constants/metametrics';
|
import { MetaMetricsNetworkEventSource } from '../../../../shared/constants/metametrics';
|
||||||
import {
|
import {
|
||||||
NetworkController,
|
NetworkController,
|
||||||
|
NetworkControllerAction,
|
||||||
NetworkControllerEvent,
|
NetworkControllerEvent,
|
||||||
NetworkControllerOptions,
|
NetworkControllerOptions,
|
||||||
NetworkControllerState,
|
NetworkControllerState,
|
||||||
@ -2451,6 +2452,31 @@ describe('NetworkController', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('NetworkController:getProviderConfig action', () => {
|
||||||
|
it('returns the provider config in state', async () => {
|
||||||
|
await withController(
|
||||||
|
{
|
||||||
|
state: {
|
||||||
|
providerConfig: buildProviderConfig({
|
||||||
|
type: NETWORK_TYPES.MAINNET,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
async ({ messenger }) => {
|
||||||
|
const providerConfig = await messenger.call(
|
||||||
|
'NetworkController:getProviderConfig',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(providerConfig).toStrictEqual(
|
||||||
|
buildProviderConfig({
|
||||||
|
type: NETWORK_TYPES.MAINNET,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('rollbackToPreviousProvider', () => {
|
describe('rollbackToPreviousProvider', () => {
|
||||||
for (const { networkType } of INFURA_NETWORKS) {
|
for (const { networkType } of INFURA_NETWORKS) {
|
||||||
describe(`if the previous provider configuration had a type of "${networkType}"`, () => {
|
describe(`if the previous provider configuration had a type of "${networkType}"`, () => {
|
||||||
@ -6088,7 +6114,10 @@ function lookupNetworkTests({
|
|||||||
* @returns The controller messenger.
|
* @returns The controller messenger.
|
||||||
*/
|
*/
|
||||||
function buildMessenger() {
|
function buildMessenger() {
|
||||||
return new ControllerMessenger<never, NetworkControllerEvent>();
|
return new ControllerMessenger<
|
||||||
|
NetworkControllerAction,
|
||||||
|
NetworkControllerEvent
|
||||||
|
>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -6100,6 +6129,7 @@ function buildMessenger() {
|
|||||||
function buildNetworkControllerMessenger(messenger = buildMessenger()) {
|
function buildNetworkControllerMessenger(messenger = buildMessenger()) {
|
||||||
return messenger.getRestricted({
|
return messenger.getRestricted({
|
||||||
name: 'NetworkController',
|
name: 'NetworkController',
|
||||||
|
allowedActions: ['NetworkController:getProviderConfig'],
|
||||||
allowedEvents: [
|
allowedEvents: [
|
||||||
'NetworkController:networkDidChange',
|
'NetworkController:networkDidChange',
|
||||||
'NetworkController:networkWillChange',
|
'NetworkController:networkWillChange',
|
||||||
@ -6116,7 +6146,10 @@ type WithControllerCallback<ReturnValue> = ({
|
|||||||
controller,
|
controller,
|
||||||
}: {
|
}: {
|
||||||
controller: NetworkController;
|
controller: NetworkController;
|
||||||
messenger: ControllerMessenger<never, NetworkControllerEvent>;
|
messenger: ControllerMessenger<
|
||||||
|
NetworkControllerAction,
|
||||||
|
NetworkControllerEvent
|
||||||
|
>;
|
||||||
}) => Promise<ReturnValue> | ReturnValue;
|
}) => Promise<ReturnValue> | ReturnValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,12 +130,19 @@ export type NetworkControllerEvent =
|
|||||||
| NetworkControllerInfuraIsBlockedEvent
|
| NetworkControllerInfuraIsBlockedEvent
|
||||||
| NetworkControllerInfuraIsUnblockedEvent;
|
| NetworkControllerInfuraIsUnblockedEvent;
|
||||||
|
|
||||||
|
export type NetworkControllerGetProviderConfigAction = {
|
||||||
|
type: `NetworkController:getProviderConfig`;
|
||||||
|
handler: () => ProviderConfiguration;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NetworkControllerAction = NetworkControllerGetProviderConfigAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The messenger that the NetworkController uses to publish events.
|
* The messenger that the NetworkController uses to publish events.
|
||||||
*/
|
*/
|
||||||
export type NetworkControllerMessenger = RestrictedControllerMessenger<
|
export type NetworkControllerMessenger = RestrictedControllerMessenger<
|
||||||
typeof name,
|
typeof name,
|
||||||
never,
|
NetworkControllerAction,
|
||||||
NetworkControllerEvent,
|
NetworkControllerEvent,
|
||||||
string,
|
string,
|
||||||
string
|
string
|
||||||
@ -477,6 +484,9 @@ export class NetworkController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
this.#infuraProjectId = infuraProjectId;
|
this.#infuraProjectId = infuraProjectId;
|
||||||
this.#trackMetaMetricsEvent = trackMetaMetricsEvent;
|
this.#trackMetaMetricsEvent = trackMetaMetricsEvent;
|
||||||
|
this.#messenger.registerActionHandler(`${name}:getProviderConfig`, () => {
|
||||||
|
return this.store.getState().providerConfig;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user