@@ -5778,6 +5778,139 @@ describe('SnapController', () => {
57785778 snapController . destroy ( ) ;
57795779 } ) ;
57805780
5781+ it ( 'grants the `endowment:caip25` permission when updating a Snap with `endowment:ethereum-provider` if the `useCaip25Permission` feature flag is enabled' , async ( ) => {
5782+ const newVersion = '1.0.2' ;
5783+ const newVersionRange = '>=1.0.1' ;
5784+
5785+ const rootMessenger = getControllerMessenger ( ) ;
5786+ const messenger = getSnapControllerMessenger ( rootMessenger ) ;
5787+
5788+ rootMessenger . registerActionHandler (
5789+ 'SelectedNetworkController:getNetworkClientIdForDomain' ,
5790+ ( ) => 'mainnet' ,
5791+ ) ;
5792+
5793+ rootMessenger . registerActionHandler (
5794+ 'NetworkController:getNetworkClientById' ,
5795+ ( ) => ( {
5796+ configuration : {
5797+ chainId : '0x1' ,
5798+ } ,
5799+ } ) ,
5800+ ) ;
5801+
5802+ const { manifest : originalManifest } =
5803+ await getMockSnapFilesWithUpdatedChecksum ( {
5804+ manifest : getSnapManifest ( {
5805+ initialPermissions : {
5806+ 'endowment:page-home' : { } ,
5807+ } ,
5808+ } ) ,
5809+ } ) ;
5810+
5811+ const { manifest : updatedManifest } =
5812+ await getMockSnapFilesWithUpdatedChecksum ( {
5813+ manifest : getSnapManifest ( {
5814+ version : newVersion ,
5815+ initialPermissions : {
5816+ 'endowment:page-home' : { } ,
5817+ 'endowment:ethereum-provider' : { } ,
5818+ } ,
5819+ } ) ,
5820+ } ) ;
5821+
5822+ const detectLocationMock = jest
5823+ . fn ( )
5824+ . mockImplementationOnce (
5825+ ( ) =>
5826+ new LoopbackLocation ( {
5827+ manifest : originalManifest ,
5828+ } ) ,
5829+ )
5830+ . mockImplementationOnce (
5831+ ( ) =>
5832+ new LoopbackLocation ( {
5833+ manifest : updatedManifest ,
5834+ } ) ,
5835+ ) ;
5836+
5837+ const controller = getSnapController (
5838+ getSnapControllerOptions ( {
5839+ messenger,
5840+ detectSnapLocation : detectLocationMock ,
5841+ featureFlags : {
5842+ useCaip25Permission : true ,
5843+ } ,
5844+ } ) ,
5845+ ) ;
5846+
5847+ await controller . installSnaps ( MOCK_ORIGIN , { [ MOCK_SNAP_ID ] : { } } ) ;
5848+ await controller . stopSnap ( MOCK_SNAP_ID ) ;
5849+
5850+ const approvedPermissions = {
5851+ 'endowment:page-home' : {
5852+ caveats : null ,
5853+ } ,
5854+ } ;
5855+
5856+ expect ( messenger . call ) . toHaveBeenCalledWith (
5857+ 'PermissionController:grantPermissions' ,
5858+ {
5859+ approvedPermissions,
5860+ subject : { origin : MOCK_SNAP_ID } ,
5861+ requestData : expect . any ( Object ) ,
5862+ } ,
5863+ ) ;
5864+
5865+ jest . mocked ( messenger . call ) . mockClear ( ) ;
5866+
5867+ const result = await controller . installSnaps ( MOCK_ORIGIN , {
5868+ [ MOCK_SNAP_ID ] : { version : newVersionRange } ,
5869+ } ) ;
5870+
5871+ const updatedApprovedPermissions = {
5872+ 'endowment:page-home' : {
5873+ caveats : null ,
5874+ } ,
5875+ 'endowment:ethereum-provider' : { } ,
5876+ 'endowment:caip25' : {
5877+ caveats : [
5878+ {
5879+ type : 'authorizedScopes' ,
5880+ value : {
5881+ requiredScopes : { } ,
5882+ optionalScopes : {
5883+ 'eip155:1' : {
5884+ accounts : [ ] ,
5885+ } ,
5886+ } ,
5887+ sessionProperties : { } ,
5888+ isMultichainOrigin : false ,
5889+ } ,
5890+ } ,
5891+ ] ,
5892+ } ,
5893+ } ;
5894+
5895+ expect ( messenger . call ) . toHaveBeenCalledWith (
5896+ 'PermissionController:grantPermissions' ,
5897+ {
5898+ approvedPermissions : updatedApprovedPermissions ,
5899+ subject : { origin : MOCK_SNAP_ID } ,
5900+ requestData : expect . any ( Object ) ,
5901+ } ,
5902+ ) ;
5903+
5904+ expect ( result ) . toStrictEqual ( {
5905+ [ MOCK_SNAP_ID ] : getTruncatedSnap ( {
5906+ version : newVersion ,
5907+ initialPermissions : updatedManifest . result . initialPermissions ,
5908+ } ) ,
5909+ } ) ;
5910+
5911+ controller . destroy ( ) ;
5912+ } ) ;
5913+
57815914 it ( 'does not grant the `endowment:caip25` permission to a Snap with `endowment:ethereum-provider` if the `useCaip25Permission` feature flag is disabled' , async ( ) => {
57825915 const rootMessenger = getControllerMessenger ( ) ;
57835916 const messenger = getSnapControllerMessenger ( rootMessenger ) ;
0 commit comments