@@ -396,4 +396,105 @@ describe('migration #67', () => {
396
396
) ,
397
397
) ;
398
398
} ) ;
399
+
400
+ it ( 'updates accounts that were previously migrated with old scope values' , ( ) => {
401
+ // Old scope values for testing migration from previous state
402
+ const OLD_ETH_NAMESPACE_SCOPE = 'eip155' as `${string } :${string } `;
403
+ const OLD_SOL_NAMESPACE_SCOPE = 'solana' as `${string } :${string } `;
404
+ const OLD_BTC_NAMESPACE_SCOPE = 'bip122' as `${string } :${string } `;
405
+
406
+ const stateWithOldScopes : StateType = {
407
+ engine : {
408
+ backgroundState : {
409
+ AccountsController : {
410
+ internalAccounts : {
411
+ selectedAccount : 'evm-1' ,
412
+ accounts : {
413
+ 'evm-1' : {
414
+ id : 'evm-1' ,
415
+ type : 'eip155:eoa' ,
416
+ address : '0x123' ,
417
+ options : { } ,
418
+ metadata : {
419
+ name : 'Account 1' ,
420
+ keyring : { type : 'HD Key Tree' } ,
421
+ importTime : Date . now ( ) ,
422
+ } ,
423
+ methods : [
424
+ EthMethod . PersonalSign ,
425
+ EthMethod . SignTransaction ,
426
+ EthMethod . SignTypedDataV4 ,
427
+ ] ,
428
+ // This represents the old scope value from migration 66
429
+ scopes : [ OLD_ETH_NAMESPACE_SCOPE ] ,
430
+ } ,
431
+ 'evm-2' : {
432
+ id : 'evm-2' ,
433
+ type : 'eip155:erc4337' ,
434
+ address : '0x456' ,
435
+ options : { } ,
436
+ metadata : {
437
+ name : 'Account 2' ,
438
+ keyring : { type : 'HD Key Tree' } ,
439
+ importTime : Date . now ( ) ,
440
+ } ,
441
+ methods : [
442
+ EthMethod . PersonalSign ,
443
+ EthMethod . SignTransaction ,
444
+ EthMethod . SignTypedDataV4 ,
445
+ ] ,
446
+ // This represents the old scope value from migration 66
447
+ scopes : [ OLD_ETH_NAMESPACE_SCOPE ] ,
448
+ } ,
449
+ 'sol-1' : {
450
+ id : 'sol-1' ,
451
+ type : 'solana:data-account' ,
452
+ address : 'solana123' ,
453
+ options : { } ,
454
+ metadata : {
455
+ name : 'Solana Account' ,
456
+ keyring : { type : 'HD Key Tree' } ,
457
+ importTime : Date . now ( ) ,
458
+ } ,
459
+ methods : [ ] ,
460
+ // Old Solana namespace scope
461
+ scopes : [ OLD_SOL_NAMESPACE_SCOPE ] ,
462
+ } ,
463
+ 'btc-1' : {
464
+ id : 'btc-1' ,
465
+ type : 'bip122:p2wpkh' ,
466
+ address : 'bc1abc' ,
467
+ options : { } ,
468
+ metadata : {
469
+ name : 'BTC Account' ,
470
+ keyring : { type : 'HD Key Tree' } ,
471
+ importTime : Date . now ( ) ,
472
+ } ,
473
+ methods : [ ] ,
474
+ // Old BTC namespace scope
475
+ scopes : [ OLD_BTC_NAMESPACE_SCOPE ] ,
476
+ } ,
477
+ } ,
478
+ } ,
479
+ } ,
480
+ } ,
481
+ } ,
482
+ } ;
483
+
484
+ const stateCopy = JSON . parse ( JSON . stringify ( stateWithOldScopes ) ) ;
485
+ const result = migration ( stateCopy ) as StateType ;
486
+ const accounts =
487
+ result . engine . backgroundState . AccountsController . internalAccounts
488
+ . accounts ;
489
+
490
+ // Check that old scope values were updated to new ones
491
+ expect ( accounts [ 'evm-1' ] ?. scopes ) . toEqual ( [ EthScope . Eoa ] ) ;
492
+ expect ( accounts [ 'evm-2' ] ?. scopes ) . toEqual ( [ EthScope . Eoa ] ) ;
493
+ expect ( accounts [ 'sol-1' ] ?. scopes ) . toEqual ( [
494
+ SolScope . Mainnet ,
495
+ SolScope . Testnet ,
496
+ SolScope . Devnet ,
497
+ ] ) ;
498
+ expect ( accounts [ 'btc-1' ] ?. scopes ) . toEqual ( [ BtcScope . Mainnet ] ) ;
499
+ } ) ;
399
500
} ) ;
0 commit comments