Skip to content

[base-controller] Controller constructors accept messengers with incomplete allowlists #4414

Description

@MajorLift

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

/** * 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(),})

Playground link

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingteam-wallet-frameworkDeprecated: Please use `team-core-platform` instead.wf-bugs

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions