@@ -12,6 +12,29 @@ jest.mock('store/account/slice', () => {
1212 }
1313} )
1414
15+ jest . mock ( 'store/wallet/slice' , ( ) => ( {
16+ selectWalletById : ( ) => ( ) => ( {
17+ id : 'wallet-1' ,
18+ name : 'Test Wallet' ,
19+ type : 'MNEMONIC'
20+ } )
21+ } ) )
22+
23+ jest . mock ( 'services/wallet/WalletService' , ( ) => ( {
24+ __esModule : true ,
25+ default : {
26+ getRawXpubXP : jest
27+ . fn ( )
28+ . mockResolvedValue (
29+ 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5'
30+ )
31+ }
32+ } ) )
33+
34+ jest . mock ( 'utils/Logger' , ( ) => ( {
35+ warn : jest . fn ( )
36+ } ) )
37+
1538const mockDispatch = jest . fn ( )
1639const mockListenerApi = {
1740 getState : jest . fn ( ) ,
@@ -44,7 +67,7 @@ describe('avalanche_getAccounts handler', () => {
4467 } )
4568
4669 describe ( 'handle' , ( ) => {
47- it ( 'should return success with the list of available accounts' , async ( ) => {
70+ it ( 'should return success with the list of available accounts including xpubXP for mnemonic wallets ' , async ( ) => {
4871 const result = await handler . handle ( testRequest , mockListenerApi )
4972
5073 expect ( result ) . toEqual ( {
@@ -63,7 +86,10 @@ describe('avalanche_getAccounts handler', () => {
6386 active : true ,
6487 type : 'primary' ,
6588 walletId : 'wallet-1' ,
66- walletType : 'mnemonic'
89+ walletType : 'MNEMONIC' ,
90+ walletName : 'Test Wallet' ,
91+ xpubXP :
92+ 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5'
6793 } ,
6894 {
6995 id : '1' ,
@@ -78,10 +104,40 @@ describe('avalanche_getAccounts handler', () => {
78104 active : false ,
79105 type : 'primary' ,
80106 walletId : 'wallet-1' ,
81- walletType : 'mnemonic'
107+ walletType : 'MNEMONIC' ,
108+ walletName : 'Test Wallet' ,
109+ xpubXP :
110+ 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5'
82111 }
83112 ]
84113 } )
85114 } )
115+
116+ it ( 'should return accounts without xpubXP for non-supported wallet types' , async ( ) => {
117+ // Mock a Ledger wallet (doesn't support xpubXP)
118+ const mockWalletSlice = require ( 'store/wallet/slice' )
119+ mockWalletSlice . selectWalletById = ( ) => ( ) => ( {
120+ id : 'wallet-1' ,
121+ name : 'Ledger Wallet' ,
122+ type : 'LEDGER'
123+ } )
124+
125+ // Mock WalletService to throw error for Ledger wallets
126+ const mockWalletService = require ( 'services/wallet/WalletService' )
127+ mockWalletService . default . getRawXpubXP . mockRejectedValueOnce (
128+ new Error ( 'Unsupported wallet type' )
129+ )
130+
131+ const result = await handler . handle ( testRequest , mockListenerApi )
132+
133+ expect ( result . success ) . toBe ( true )
134+ if ( result . success ) {
135+ const accounts = result . value as any [ ]
136+ expect ( accounts ) . toHaveLength ( 2 )
137+ expect ( accounts [ 0 ] . xpubXP ) . toBeUndefined ( )
138+ expect ( accounts [ 0 ] . walletType ) . toBe ( 'LEDGER' )
139+ expect ( accounts [ 0 ] . walletName ) . toBe ( 'Ledger Wallet' )
140+ }
141+ } )
86142 } )
87143} )
0 commit comments