File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
packages/snaps-controllers/src/snaps Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -2192,6 +2192,27 @@ describe('SnapController', () => {
21922192 } ) ;
21932193
21942194 describe ( 'handleRequest' , ( ) => {
2195+ it ( 'throws if the Snap is not installed' , async ( ) => {
2196+ const snapController = getSnapController ( ) ;
2197+
2198+ await expect (
2199+ snapController . handleRequest ( {
2200+ snapId : 'npm:foo' as SnapId ,
2201+ origin : METAMASK_ORIGIN ,
2202+ handler : HandlerType . OnUserInput ,
2203+ request : {
2204+ jsonrpc : '2.0' ,
2205+ method : 'test' ,
2206+ params : { id : MOCK_INTERFACE_ID } ,
2207+ } ,
2208+ } ) ,
2209+ ) . rejects . toThrow (
2210+ 'The Snap "npm:foo" is not installed. Please install it before invoking it.' ,
2211+ ) ;
2212+
2213+ snapController . destroy ( ) ;
2214+ } ) ;
2215+
21952216 it . each (
21962217 Object . keys ( handlerEndowments ) . filter (
21972218 ( handler ) => handlerEndowments [ handler as HandlerType ] ,
Original file line number Diff line number Diff line change @@ -3588,6 +3588,13 @@ export class SnapController extends BaseController<
35883588 } : SnapRpcHookArgs & { snapId : SnapId } ) : Promise < unknown > {
35893589 this . #assertCanUsePlatform( ) ;
35903590
3591+ const snap = this . get ( snapId ) ;
3592+
3593+ assert (
3594+ snap ,
3595+ `The Snap "${ snapId } " is not installed. Please install it before invoking it.` ,
3596+ ) ;
3597+
35913598 assert (
35923599 origin === METAMASK_ORIGIN || isValidUrl ( origin ) ,
35933600 "'origin' must be a valid URL or 'metamask'." ,
@@ -3666,11 +3673,11 @@ export class SnapController extends BaseController<
36663673 throw new Error ( `"${ handlerType } " can only be invoked by MetaMask.` ) ;
36673674 }
36683675
3669- if ( ! this . state . snaps [ snapId ] . enabled ) {
3676+ if ( ! snap . enabled ) {
36703677 throw new Error ( `Snap "${ snapId } " is disabled.` ) ;
36713678 }
36723679
3673- if ( this . state . snaps [ snapId ] . status === SnapStatus . Installing ) {
3680+ if ( snap . status === SnapStatus . Installing ) {
36743681 throw new Error (
36753682 `Snap "${ snapId } " is currently being installed. Please try again later.` ,
36763683 ) ;
You can’t perform that action at this time.
0 commit comments