1- import { Ledger , LedgerSigner } from './ledger'
1+ import { DerivationPathLegacy , DerivationPathAdr8 , Ledger , LedgerSigner } from './ledger'
22import OasisApp from '@oasisprotocol/ledger'
33import { WalletError , WalletErrors } from 'types/errors'
44import { Wallet , WalletType } from 'app/state/wallet/types'
@@ -18,18 +18,23 @@ describe('Ledger Library', () => {
1818 describe ( 'Ledger' , ( ) => {
1919 it ( 'enumerateAccounts should pass when Oasis App is open' , async ( ) => {
2020 mockAppIsOpen ( 'Oasis' )
21- const accounts = Ledger . enumerateAccounts ( { } as any , 0 )
21+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy , 0 )
22+ await expect ( accounts ) . resolves . toEqual ( [ ] )
23+ } )
24+ it ( 'enumerateAccounts should pass when Oasis App is open' , async ( ) => {
25+ mockAppIsOpen ( 'Oasis' )
26+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathAdr8 , 0 )
2227 await expect ( accounts ) . resolves . toEqual ( [ ] )
2328 } )
2429
2530 it ( 'Should catch "Oasis App is not open"' , async ( ) => {
2631 mockAppIsOpen ( 'BOLOS' )
27- const accountsMainMenu = Ledger . enumerateAccounts ( { } as any , 0 )
32+ const accountsMainMenu = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy , 0 )
2833 await expect ( accountsMainMenu ) . rejects . toThrowError ( WalletError )
2934 await expect ( accountsMainMenu ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerOasisAppIsNotOpen )
3035
3136 mockAppIsOpen ( 'Ethereum' )
32- const accountsEth = Ledger . enumerateAccounts ( { } as any , 0 )
37+ const accountsEth = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy , 0 )
3338 await expect ( accountsEth ) . rejects . toThrowError ( WalletError )
3439 await expect ( accountsEth ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerOasisAppIsNotOpen )
3540 } )
@@ -40,7 +45,7 @@ describe('Ledger Library', () => {
4045 pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) } )
4146 pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 4 , 5 , 6 ] ) ) } )
4247
43- const accounts = await Ledger . enumerateAccounts ( { } as any , 2 )
48+ const accounts = await Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy , 2 )
4449 expect ( accounts ) . toHaveLength ( 2 )
4550 expect ( accounts ) . toContainEqual ( { path : [ 44 , 474 , 0 , 0 , 0 ] , publicKey : new Uint8Array ( [ 1 , 2 , 3 ] ) } )
4651 expect ( accounts ) . toContainEqual ( { path : [ 44 , 474 , 0 , 0 , 1 ] , publicKey : new Uint8Array ( [ 4 , 5 , 6 ] ) } )
@@ -51,7 +56,7 @@ describe('Ledger Library', () => {
5156 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
5257 pubKey . mockResolvedValueOnce ( { return_code : 0x6804 } )
5358
54- const accounts = Ledger . enumerateAccounts ( { } as any )
59+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy )
5560 await expect ( accounts ) . rejects . toThrowError ( WalletError )
5661 await expect ( accounts ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerCannotOpenOasisApp )
5762 } )
@@ -61,7 +66,7 @@ describe('Ledger Library', () => {
6166 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
6267 pubKey . mockResolvedValueOnce ( { return_code : 0x6400 } )
6368
64- const accounts = Ledger . enumerateAccounts ( { } as any )
69+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy )
6570 await expect ( accounts ) . rejects . toThrowError ( WalletError )
6671 await expect ( accounts ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerAppVersionNotSupported )
6772 } )
@@ -71,7 +76,7 @@ describe('Ledger Library', () => {
7176 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
7277 pubKey . mockResolvedValueOnce ( { return_code : - 1 , error_message : 'unknown dummy error' } )
7378
74- const accounts = Ledger . enumerateAccounts ( { } as any )
79+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy )
7580 await expect ( accounts ) . rejects . toThrowError ( WalletError )
7681 await expect ( accounts ) . rejects . toThrow ( / u n k n o w n d u m m y e r r o r / )
7782 await expect ( accounts ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerUnknownError )
@@ -111,7 +116,7 @@ describe('Ledger Library', () => {
111116
112117 const signer = new LedgerSigner ( {
113118 type : WalletType . Ledger ,
114- path : [ 44 , 474 , 0 , 0 , 0 ] ,
119+ path : Ledger . mustGetPath ( DerivationPathLegacy , 0 ) ,
115120 publicKey : 'aabbcc' ,
116121 } as Wallet )
117122
0 commit comments