mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +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 {
|
||||
NetworkController,
|
||||
NetworkControllerAction,
|
||||
NetworkControllerEvent,
|
||||
NetworkControllerOptions,
|
||||
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', () => {
|
||||
for (const { networkType } of INFURA_NETWORKS) {
|
||||
describe(`if the previous provider configuration had a type of "${networkType}"`, () => {
|
||||
@ -6088,7 +6114,10 @@ function lookupNetworkTests({
|
||||
* @returns The controller messenger.
|
||||
*/
|
||||
function buildMessenger() {
|
||||
return new ControllerMessenger<never, NetworkControllerEvent>();
|
||||
return new ControllerMessenger<
|
||||
NetworkControllerAction,
|
||||
NetworkControllerEvent
|
||||
>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -6100,6 +6129,7 @@ function buildMessenger() {
|
||||
function buildNetworkControllerMessenger(messenger = buildMessenger()) {
|
||||
return messenger.getRestricted({
|
||||
name: 'NetworkController',
|
||||
allowedActions: ['NetworkController:getProviderConfig'],
|
||||
allowedEvents: [
|
||||
'NetworkController:networkDidChange',
|
||||
'NetworkController:networkWillChange',
|
||||
@ -6116,7 +6146,10 @@ type WithControllerCallback<ReturnValue> = ({
|
||||
controller,
|
||||
}: {
|
||||
controller: NetworkController;
|
||||
messenger: ControllerMessenger<never, NetworkControllerEvent>;
|
||||
messenger: ControllerMessenger<
|
||||
NetworkControllerAction,
|
||||
NetworkControllerEvent
|
||||
>;
|
||||
}) => Promise<ReturnValue> | ReturnValue;
|
||||
|
||||
/**
|
||||
|
@ -130,12 +130,19 @@ export type NetworkControllerEvent =
|
||||
| NetworkControllerInfuraIsBlockedEvent
|
||||
| NetworkControllerInfuraIsUnblockedEvent;
|
||||
|
||||
export type NetworkControllerGetProviderConfigAction = {
|
||||
type: `NetworkController:getProviderConfig`;
|
||||
handler: () => ProviderConfiguration;
|
||||
};
|
||||
|
||||
export type NetworkControllerAction = NetworkControllerGetProviderConfigAction;
|
||||
|
||||
/**
|
||||
* The messenger that the NetworkController uses to publish events.
|
||||
*/
|
||||
export type NetworkControllerMessenger = RestrictedControllerMessenger<
|
||||
typeof name,
|
||||
never,
|
||||
NetworkControllerAction,
|
||||
NetworkControllerEvent,
|
||||
string,
|
||||
string
|
||||
@ -477,6 +484,9 @@ export class NetworkController extends EventEmitter {
|
||||
}
|
||||
this.#infuraProjectId = infuraProjectId;
|
||||
this.#trackMetaMetricsEvent = trackMetaMetricsEvent;
|
||||
this.#messenger.registerActionHandler(`${name}:getProviderConfig`, () => {
|
||||
return this.store.getState().providerConfig;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user