@@ -16,6 +16,10 @@ const TEST_CHAIN_ID = '0x1' as const;
1616const TEST_EXPIRY = Math . floor ( Date . now ( ) / 1000 ) + 86400 ; // 24 hours from now
1717const TEST_CONTEXT = '0xabcd' as const ;
1818
19+ const TEST_SUPPORTED_CHAIN_IDS = [ 0x1 , 0x10 ] ;
20+
21+ const UNSUPPORTED_CHAIN_ID = '0xFA11' as const ;
22+
1923const VALID_PERMISSION_REQUEST : PermissionRequest = {
2024 chainId : TEST_CHAIN_ID ,
2125 rules : [
@@ -103,6 +107,7 @@ describe('RpcHandler', () => {
103107 handler = createRpcHandler ( {
104108 permissionHandlerFactory : mockHandlerFactory ,
105109 profileSyncManager : mockProfileSyncManager ,
110+ supportedChainIds : TEST_SUPPORTED_CHAIN_IDS ,
106111 } ) ;
107112 } ) ;
108113
@@ -130,6 +135,54 @@ describe('RpcHandler', () => {
130135 expect ( result ) . toStrictEqual ( [ VALID_PERMISSION_RESPONSE ] ) ;
131136 } ) ;
132137
138+ it ( 'should handle a permission request with a different supported chainId successfully' , async ( ) => {
139+ const differentSupportedChainId = '0x10' ;
140+ const permissionRequestWithDifferentSupportedChainId = {
141+ ...VALID_PERMISSION_REQUEST ,
142+ chainId : differentSupportedChainId ,
143+ } ;
144+
145+ const requestWithDifferentSupportedChainId = {
146+ permissionsRequest : [
147+ permissionRequestWithDifferentSupportedChainId ,
148+ ] as unknown as Json [ ] ,
149+ siteOrigin : TEST_SITE_ORIGIN ,
150+ } ;
151+
152+ const responseWithDifferentSupportedChainId = {
153+ approved : true ,
154+ response : {
155+ ...VALID_PERMISSION_RESPONSE ,
156+ chainId : differentSupportedChainId ,
157+ } ,
158+ } as const ;
159+
160+ mockHandler . handlePermissionRequest . mockImplementation (
161+ async ( ) => responseWithDifferentSupportedChainId ,
162+ ) ;
163+
164+ const result = await handler . grantPermission (
165+ requestWithDifferentSupportedChainId ,
166+ ) ;
167+
168+ expect ( mockHandlerFactory . createPermissionHandler ) . toHaveBeenCalledTimes (
169+ 1 ,
170+ ) ;
171+
172+ expect ( mockHandlerFactory . createPermissionHandler ) . toHaveBeenCalledWith (
173+ permissionRequestWithDifferentSupportedChainId ,
174+ ) ;
175+
176+ expect ( mockHandler . handlePermissionRequest ) . toHaveBeenCalledTimes ( 1 ) ;
177+ expect ( mockHandler . handlePermissionRequest ) . toHaveBeenCalledWith (
178+ TEST_SITE_ORIGIN ,
179+ ) ;
180+
181+ expect ( result ) . toStrictEqual ( [
182+ responseWithDifferentSupportedChainId . response ,
183+ ] ) ;
184+ } ) ;
185+
133186 it ( 'should throw an error if no parameters are provided' , async ( ) => {
134187 await expect ( handler . grantPermission ( ) ) . rejects . toThrow (
135188 'Failed type validation: : Required' ,
@@ -213,12 +266,12 @@ describe('RpcHandler', () => {
213266 it ( 'should handle multiple permission requests in parallel' , async ( ) => {
214267 const secondPermissionRequest = {
215268 ...VALID_PERMISSION_REQUEST ,
216- chainId : '0x2' as const ,
269+ chainId : TEST_CHAIN_ID ,
217270 } ;
218271
219272 const secondResponse = {
220273 ...VALID_PERMISSION_RESPONSE ,
221- chainId : '0x2' as const ,
274+ chainId : TEST_CHAIN_ID ,
222275 } ;
223276
224277 const request : Json = {
@@ -259,7 +312,7 @@ describe('RpcHandler', () => {
259312 it ( 'should handle mixed success/failure responses for multiple requests' , async ( ) => {
260313 const secondPermissionRequest = {
261314 ...VALID_PERMISSION_REQUEST ,
262- chainId : '0x2' as const ,
315+ chainId : TEST_CHAIN_ID ,
263316 } ;
264317
265318 const request : Json = {
@@ -290,12 +343,12 @@ describe('RpcHandler', () => {
290343 it ( 'should process multiple permission requests sequentially (no concurrency)' , async ( ) => {
291344 const secondPermissionRequest = {
292345 ...VALID_PERMISSION_REQUEST ,
293- chainId : '0x2' as const ,
346+ chainId : TEST_CHAIN_ID ,
294347 } ;
295348
296349 const secondResponse = {
297350 ...VALID_PERMISSION_RESPONSE ,
298- chainId : '0x2' as const ,
351+ chainId : TEST_CHAIN_ID ,
299352 } ;
300353
301354 const request : Json = {
@@ -448,12 +501,12 @@ describe('RpcHandler', () => {
448501 it ( 'should maintain response order matching request order' , async ( ) => {
449502 const secondPermissionRequest = {
450503 ...VALID_PERMISSION_REQUEST ,
451- chainId : '0x2' as const ,
504+ chainId : TEST_CHAIN_ID ,
452505 } ;
453506
454507 const secondResponse = {
455508 ...VALID_PERMISSION_RESPONSE ,
456- chainId : '0x2' as const ,
509+ chainId : TEST_CHAIN_ID ,
457510 } ;
458511
459512 const request : Json = {
@@ -480,6 +533,20 @@ describe('RpcHandler', () => {
480533 const result = await handler . grantPermission ( request ) ;
481534 expect ( result ) . toStrictEqual ( [ VALID_PERMISSION_RESPONSE , secondResponse ] ) ;
482535 } ) ;
536+
537+ it ( 'throws an error if the chain ID is not supported' , async ( ) => {
538+ const request : Json = {
539+ permissionsRequest : [
540+ VALID_PERMISSION_REQUEST ,
541+ { ...VALID_PERMISSION_REQUEST , chainId : UNSUPPORTED_CHAIN_ID } ,
542+ ] ,
543+ siteOrigin : TEST_SITE_ORIGIN ,
544+ } as unknown as Json ;
545+
546+ await expect ( handler . grantPermission ( request ) ) . rejects . toThrow (
547+ `Unsupported chain IDs: ${ UNSUPPORTED_CHAIN_ID } ` ,
548+ ) ;
549+ } ) ;
483550 } ) ;
484551
485552 describe ( 'getPermissionOffers' , ( ) => {
@@ -532,7 +599,7 @@ describe('RpcHandler', () => {
532599 } ,
533600 {
534601 permissionResponse : {
535- chainId : '0x2' as const ,
602+ chainId : TEST_CHAIN_ID ,
536603 expiry : TEST_EXPIRY + 1000 ,
537604 signer : {
538605 type : 'account' as const ,
0 commit comments