@@ -1070,6 +1070,223 @@ describe('SCWSigner', () => {
10701070 } ) ;
10711071 } ) ;
10721072
1073+ describe ( 'wallet_getCapabilities' , ( ) => {
1074+ let stateSpy : MockInstance ;
1075+
1076+ beforeEach ( ( ) => {
1077+ stateSpy = vi . spyOn ( store , 'getState' ) . mockImplementation ( ( ) => ( {
1078+ account : {
1079+ accounts : [ globalAccountAddress ] ,
1080+ capabilities : {
1081+ '0x1' : {
1082+ atomicBatch : { supported : true } ,
1083+ paymasterService : { supported : true }
1084+ } ,
1085+ '0x5' : {
1086+ atomicBatch : { supported : false }
1087+ } ,
1088+ '0xa' : {
1089+ paymasterService : { supported : true }
1090+ }
1091+ } ,
1092+ } ,
1093+ chains : [ ] ,
1094+ keys : { } ,
1095+ spendLimits : [ ] ,
1096+ config : {
1097+ metadata : mockMetadata ,
1098+ preference : { keysUrl : CB_KEYS_URL , options : 'all' } ,
1099+ version : '1.0.0' ,
1100+ } ,
1101+ } ) ) ;
1102+
1103+ signer [ 'accounts' ] = [ globalAccountAddress ] ;
1104+ } ) ;
1105+
1106+ afterEach ( ( ) => {
1107+ stateSpy . mockRestore ( ) ;
1108+ } ) ;
1109+
1110+ it ( 'should return all capabilities when no filter is provided' , async ( ) => {
1111+ const request = {
1112+ method : 'wallet_getCapabilities' ,
1113+ params : [ globalAccountAddress ] ,
1114+ } ;
1115+
1116+ const result = await signer . request ( request ) ;
1117+
1118+ expect ( result ) . toEqual ( {
1119+ '0x1' : {
1120+ atomicBatch : { supported : true } ,
1121+ paymasterService : { supported : true }
1122+ } ,
1123+ '0x5' : {
1124+ atomicBatch : { supported : false }
1125+ } ,
1126+ '0xa' : {
1127+ paymasterService : { supported : true }
1128+ }
1129+ } ) ;
1130+ } ) ;
1131+
1132+ it ( 'should return filtered capabilities when chain filter is provided' , async ( ) => {
1133+ const request = {
1134+ method : 'wallet_getCapabilities' ,
1135+ params : [ globalAccountAddress , [ '0x1' , '0xa' ] ] ,
1136+ } ;
1137+
1138+ const result = await signer . request ( request ) ;
1139+
1140+ expect ( result ) . toEqual ( {
1141+ '0x1' : {
1142+ atomicBatch : { supported : true } ,
1143+ paymasterService : { supported : true }
1144+ } ,
1145+ '0xa' : {
1146+ paymasterService : { supported : true }
1147+ }
1148+ } ) ;
1149+ } ) ;
1150+
1151+ it ( 'should handle different hex formatting in filters' , async ( ) => {
1152+ // Test that '0x01' matches '0x1' capability
1153+ const request = {
1154+ method : 'wallet_getCapabilities' ,
1155+ params : [ globalAccountAddress , [ '0x01' , '0x05' ] ] ,
1156+ } ;
1157+
1158+ const result = await signer . request ( request ) ;
1159+
1160+ expect ( result ) . toEqual ( {
1161+ '0x1' : {
1162+ atomicBatch : { supported : true } ,
1163+ paymasterService : { supported : true }
1164+ } ,
1165+ '0x5' : {
1166+ atomicBatch : { supported : false }
1167+ }
1168+ } ) ;
1169+ } ) ;
1170+
1171+ it ( 'should return empty object when filter matches no capabilities' , async ( ) => {
1172+ const request = {
1173+ method : 'wallet_getCapabilities' ,
1174+ params : [ globalAccountAddress , [ '0x99' , '0x100' ] ] ,
1175+ } ;
1176+
1177+ const result = await signer . request ( request ) ;
1178+
1179+ expect ( result ) . toEqual ( { } ) ;
1180+ } ) ;
1181+
1182+ it ( 'should return empty object when capabilities is undefined' , async ( ) => {
1183+ stateSpy . mockImplementation ( ( ) => ( {
1184+ account : {
1185+ accounts : [ globalAccountAddress ] ,
1186+ capabilities : undefined ,
1187+ } ,
1188+ chains : [ ] ,
1189+ keys : { } ,
1190+ spendLimits : [ ] ,
1191+ config : {
1192+ metadata : mockMetadata ,
1193+ preference : { keysUrl : CB_KEYS_URL , options : 'all' } ,
1194+ version : '1.0.0' ,
1195+ } ,
1196+ } ) ) ;
1197+
1198+ const request = {
1199+ method : 'wallet_getCapabilities' ,
1200+ params : [ globalAccountAddress ] ,
1201+ } ;
1202+
1203+ const result = await signer . request ( request ) ;
1204+
1205+ expect ( result ) . toEqual ( { } ) ;
1206+ } ) ;
1207+
1208+ it ( 'should return empty object when empty filter array is provided' , async ( ) => {
1209+ const request = {
1210+ method : 'wallet_getCapabilities' ,
1211+ params : [ globalAccountAddress , [ ] ] ,
1212+ } ;
1213+
1214+ const result = await signer . request ( request ) ;
1215+
1216+ expect ( result ) . toEqual ( {
1217+ '0x1' : {
1218+ atomicBatch : { supported : true } ,
1219+ paymasterService : { supported : true }
1220+ } ,
1221+ '0x5' : {
1222+ atomicBatch : { supported : false }
1223+ } ,
1224+ '0xa' : {
1225+ paymasterService : { supported : true }
1226+ }
1227+ } ) ;
1228+ } ) ;
1229+
1230+ it ( 'should handle capabilities with non-hex keys gracefully' , async ( ) => {
1231+ stateSpy . mockImplementation ( ( ) => ( {
1232+ account : {
1233+ accounts : [ globalAccountAddress ] ,
1234+ capabilities : {
1235+ '0x1' : { atomicBatch : { supported : true } } ,
1236+ 'invalid-key' : { someFeature : true } ,
1237+ '0x5' : { paymasterService : { supported : true } }
1238+ } ,
1239+ } ,
1240+ chains : [ ] ,
1241+ keys : { } ,
1242+ spendLimits : [ ] ,
1243+ config : {
1244+ metadata : mockMetadata ,
1245+ preference : { keysUrl : CB_KEYS_URL , options : 'all' } ,
1246+ version : '1.0.0' ,
1247+ } ,
1248+ } ) ) ;
1249+
1250+ const request = {
1251+ method : 'wallet_getCapabilities' ,
1252+ params : [ globalAccountAddress , [ '0x1' ] ] ,
1253+ } ;
1254+
1255+ const result = await signer . request ( request ) ;
1256+
1257+ expect ( result ) . toEqual ( {
1258+ '0x1' : { atomicBatch : { supported : true } }
1259+ } ) ;
1260+ } ) ;
1261+
1262+ it ( 'should throw error when account is not in accounts list' , async ( ) => {
1263+ const request = {
1264+ method : 'wallet_getCapabilities' ,
1265+ params : [ subAccountAddress ] ,
1266+ } ;
1267+
1268+ await expect ( signer . request ( request ) ) . rejects . toThrow ( 'no active account found' ) ;
1269+ } ) ;
1270+
1271+ it ( 'should throw error when account parameter is invalid' , async ( ) => {
1272+ const request = {
1273+ method : 'wallet_getCapabilities' ,
1274+ params : [ 'invalid-address' ] ,
1275+ } ;
1276+
1277+ await expect ( signer . request ( request ) ) . rejects . toThrow ( ) ;
1278+ } ) ;
1279+
1280+ it ( 'should throw error when filter contains invalid hex strings' , async ( ) => {
1281+ const request = {
1282+ method : 'wallet_getCapabilities' ,
1283+ params : [ globalAccountAddress , [ '0x1' , 'invalid-hex' ] ] ,
1284+ } ;
1285+
1286+ await expect ( signer . request ( request ) ) . rejects . toThrow ( ) ;
1287+ } ) ;
1288+ } ) ;
1289+
10731290 describe ( 'coinbase_fetchPermissions' , ( ) => {
10741291 const mockSpendLimits = [
10751292 {
0 commit comments