@@ -175,4 +175,61 @@ describe('switchEthereumChainHandler', () => {
175
175
} ,
176
176
) ;
177
177
} ) ;
178
+
179
+ it ( 'calls `grantPermittedChainsPermissionIncremental` if the origin is a Snap' , async ( ) => {
180
+ const mocks = makeMocks ( {
181
+ overrides : {
182
+ grantPermittedChainsPermissionIncremental : jest . fn ( ) ,
183
+ } ,
184
+ } ) ;
185
+
186
+ const switchEthereumChainHandler = switchEthereumChain . implementation ;
187
+ await switchEthereumChainHandler (
188
+ {
189
+ origin : 'npm:foo-snap' ,
190
+ params : [ { chainId : CHAIN_IDS . MAINNET } ] ,
191
+ } ,
192
+ { } ,
193
+ jest . fn ( ) ,
194
+ jest . fn ( ) ,
195
+ mocks ,
196
+ ) ;
197
+
198
+ expect (
199
+ mocks . grantPermittedChainsPermissionIncremental ,
200
+ ) . toHaveBeenCalledTimes ( 1 ) ;
201
+ expect ( mocks . setActiveNetwork ) . toHaveBeenCalledTimes ( 1 ) ;
202
+ expect ( mocks . setActiveNetwork ) . toHaveBeenCalledWith (
203
+ createMockMainnetConfiguration ( ) . rpcEndpoints [ 0 ] . networkClientId ,
204
+ ) ;
205
+ } ) ;
206
+
207
+ it ( 'does not call `grantPermittedChainsPermissionIncremental` if the origin is a Snap, but the permission is already set' , async ( ) => {
208
+ const mocks = makeMocks ( {
209
+ permissionedChainIds : [ CHAIN_IDS . MAINNET ] ,
210
+ overrides : {
211
+ grantPermittedChainsPermissionIncremental : jest . fn ( ) ,
212
+ } ,
213
+ } ) ;
214
+
215
+ const switchEthereumChainHandler = switchEthereumChain . implementation ;
216
+ await switchEthereumChainHandler (
217
+ {
218
+ origin : 'npm:foo-snap' ,
219
+ params : [ { chainId : CHAIN_IDS . MAINNET } ] ,
220
+ } ,
221
+ { } ,
222
+ jest . fn ( ) ,
223
+ jest . fn ( ) ,
224
+ mocks ,
225
+ ) ;
226
+
227
+ expect (
228
+ mocks . grantPermittedChainsPermissionIncremental ,
229
+ ) . not . toHaveBeenCalled ( ) ;
230
+ expect ( mocks . setActiveNetwork ) . toHaveBeenCalledTimes ( 1 ) ;
231
+ expect ( mocks . setActiveNetwork ) . toHaveBeenCalledWith (
232
+ createMockMainnetConfiguration ( ) . rpcEndpoints [ 0 ] . networkClientId ,
233
+ ) ;
234
+ } ) ;
178
235
} ) ;
0 commit comments