1
1
import { cryptography } from '@liskhq/lisk-client' ;
2
- import { mockHWAccounts } from '@hardwareWallet/__fixtures__' ;
2
+ import { mockHWAccounts , mockHWCurrentDevice } from '@hardwareWallet/__fixtures__' ;
3
3
import * as signMessageUtil from '@wallet/utils/signMessage' ;
4
4
import * as signMessageWithPrivateKeyUtils from '../utils/signMessageWithPrivateKey' ;
5
5
import { signMessage , signClaimMessage } from './action' ;
6
6
7
7
jest . spyOn ( cryptography . ed , 'signAndPrintMessage' ) ;
8
8
jest . spyOn ( cryptography . ed , 'printSignedMessage' ) ;
9
9
jest . spyOn ( signMessageUtil , 'signMessageUsingHW' ) ;
10
+ jest . spyOn ( signMessageUtil , 'signClaimMessageUsingHW' ) ;
10
11
jest . spyOn ( signMessageWithPrivateKeyUtils , 'signClaimMessageWithPrivateKey' ) ;
11
12
12
13
const privateKey =
@@ -78,11 +79,38 @@ describe('signClaimMessage', () => {
78
79
pubkey : '5bb1138c01b7762318f5e8a8799573077caadb1c7333a5c631773a2ade4bbdb5' ,
79
80
} ,
80
81
} ;
82
+ const mockHWCurrentAccount = {
83
+ hw : mockHWCurrentDevice ,
84
+ metadata : {
85
+ pubkey : '5bb1138c01b7762318f5e8a8799573077caadb1c7333a5c631773a2ade4bbdb5' ,
86
+ } ,
87
+ } ;
81
88
const portalMessage =
82
89
'0xe4dbb94d0f19e47b0cff8206bebc1fcf8d892325ab851e1a5bdab954711d926e000000000000000000' ;
83
90
afterEach ( ( ) => jest . clearAllMocks ( ) ) ;
84
91
85
- it ( 'should call next step with signature' , async ( ) => {
92
+ it ( 'should call next step with signature for hardware wallet accounts' , async ( ) => {
93
+ const claimResult =
94
+ '15e546e6df7a17960c00c80cb42a3968ca004f2d8efd044cb2bb14e83ba173b02fc4c40ad47b0eca722f3022d5d82874fad25a7c0264d8a31e20f17741a4e602' ;
95
+ signMessageUtil . signClaimMessageUsingHW . mockResolvedValue ( claimResult ) ;
96
+
97
+ const signedClaim = {
98
+ data : {
99
+ pubKey : '5bb1138c01b7762318f5e8a8799573077caadb1c7333a5c631773a2ade4bbdb5' ,
100
+ r : '0x15e546e6df7a17960c00c80cb42a3968ca004f2d8efd044cb2bb14e83ba173b0' ,
101
+ s : '0x2fc4c40ad47b0eca722f3022d5d82874fad25a7c0264d8a31e20f17741a4e602' ,
102
+ } ,
103
+ } ;
104
+ await signClaimMessage ( {
105
+ nextStep,
106
+ portalMessage,
107
+ privateKey,
108
+ currentAccount : mockHWCurrentAccount ,
109
+ } ) ( ) ;
110
+ expect ( nextStep ) . toHaveBeenCalledWith ( { signature : signedClaim , portalMessage } ) ;
111
+ } ) ;
112
+
113
+ it ( 'should call next step with signature for regular accounts' , async ( ) => {
86
114
const claimResult =
87
115
'15e546e6df7a17960c00c80cb42a3968ca004f2d8efd044cb2bb14e83ba173b02fc4c40ad47b0eca722f3022d5d82874fad25a7c0264d8a31e20f17741a4e602' ;
88
116
signMessageWithPrivateKeyUtils . signClaimMessageWithPrivateKey . mockReturnValue ( claimResult ) ;
@@ -102,4 +130,20 @@ describe('signClaimMessage', () => {
102
130
} ) ( ) ;
103
131
expect ( nextStep ) . toHaveBeenCalledWith ( { signature : signedClaim , portalMessage } ) ;
104
132
} ) ;
133
+
134
+ it ( 'should call nextStep with error for hardware wallet accounts' , async ( ) => {
135
+ const error = { name : 'An error' } ;
136
+ signMessageUtil . signClaimMessageUsingHW . mockRejectedValue ( error ) ;
137
+ await signClaimMessage ( {
138
+ nextStep,
139
+ privateKey,
140
+ portalMessage,
141
+ currentAccount : mockHWCurrentAccount ,
142
+ } ) ( ) ;
143
+
144
+ expect ( nextStep ) . toHaveBeenCalledWith ( {
145
+ error,
146
+ portalMessage,
147
+ } ) ;
148
+ } ) ;
105
149
} ) ;
0 commit comments