You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BaseControllerV2 and its subclass controllers currently accept messengers as constructor options even if they are defined with incomplete or empty action/event allowlists.
Type errors are raised when the omitted actions/events are invoked. Runtime errors are also thrown when the call, subscribe, unsubscribe methods are invoked (or any method that uses the #isAllowedAction, #isAllowedEvent methods). However, these errors are produced by the messenger, not the controller.
Controller constructors do correctly raise type errors for messengers that allow actions or events that are not included in the controller's allowlists.
Repro
/** * Controller accepts messenger with "empty" allowlists */constemptyAllowlistControllerMessenger=newControllerMessenger<never,never>()// ControllerMessenger can be defined with any superset of the RestrictedControllerMessenger's empty allowlistsconstemptyAllowlistMessenger=emptyAllowlistControllerMessenger.getRestricted({name: '',allowedActions: [],allowedEvents: [],})constpreferencesController=newPreferencesController({messenger: emptyAllowlistMessenger,// No type or runtime error!})/** * Controller accepts messenger with "incomplete" allowlists */typeTokenRatesControllerAllowedActions=|PreferencesControllerGetStateAction|NetworkControllerGetStateAction|NetworkControllerGetNetworkClientByIdAction|TokensControllerGetStateActiontypeTokenRatesControllerAllowedEvents=|TokensControllerStateChangeEvent|PreferencesControllerStateChangeEvent|NetworkControllerStateChangeEventconstincompleteAllowlistControllerMessenger=newControllerMessenger<Exclude<TokenRatesControllerAllowedActions,NetworkControllerGetNetworkClientByIdAction>,Exclude<TokenRatesControllerAllowedEvents,NetworkControllerGetStateAction>>()// ControllerMessenger can be defined with any superset of the RestrictedControllerMessenger's incomplete allowlistsconstincompleteAllowlistMessenger=incompleteAllowlistControllerMessenger.getRestricted({name: 'TokenRatesController',allowedActions: [// 'NetworkController:getNetworkClientById','NetworkController:getState','PreferencesController:getState','TokensController:getState',],allowedEvents: [// 'NetworkController:stateChange','PreferencesController:stateChange','TokensController:stateChange',],})constincompleteTokenRatesController=newTokenRatesController({messenger: incompleteAllowlistMessenger,// No type or runtime error!tokenPricesService: buildMockTokenPricesService(),})
Controllers inheriting from BaseControllerV2 must raise a type and/or runtime error if they are initialized with a messenger that does not explicitly allow ALL of the actions or events in the controller's allowlists.
MajorLift
changed the title
[base-controller] Messengers with incomplete allowlists are accepted by controller constructors
[base-controller] Controller constructors accept messengers with incomplete allowlists
Jul 18, 2024
Problem
BaseControllerV2
and its subclass controllers currently accept messengers as constructor options even if they are defined with incomplete or empty action/event allowlists.Type errors are raised when the omitted actions/events are invoked. Runtime errors are also thrown when the
call
,subscribe
,unsubscribe
methods are invoked (or any method that uses the#isAllowedAction
,#isAllowedEvent
methods). However, these errors are produced by the messenger, not the controller.Controller constructors do correctly raise type errors for messengers that allow actions or events that are not included in the controller's allowlists.
Repro
Acceptance Criteria
Controllers inheriting from
BaseControllerV2
must raise a type and/or runtime error if they are initialized with a messenger that does not explicitly allow ALL of the actions or events in the controller's allowlists.References
The text was updated successfully, but these errors were encountered: