Skip to content

Commit 7696599

Browse files
committed
Fixed coverage issue for unit test
1 parent 8b2d4a6 commit 7696599

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

src/modules/message/store/action.test.js

+46-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { cryptography } from '@liskhq/lisk-client';
2-
import { mockHWAccounts } from '@hardwareWallet/__fixtures__';
2+
import { mockHWAccounts, mockHWCurrentDevice } from '@hardwareWallet/__fixtures__';
33
import * as signMessageUtil from '@wallet/utils/signMessage';
44
import * as signMessageWithPrivateKeyUtils from '../utils/signMessageWithPrivateKey';
55
import { signMessage, signClaimMessage } from './action';
66

77
jest.spyOn(cryptography.ed, 'signAndPrintMessage');
88
jest.spyOn(cryptography.ed, 'printSignedMessage');
99
jest.spyOn(signMessageUtil, 'signMessageUsingHW');
10+
jest.spyOn(signMessageUtil, 'signClaimMessageUsingHW');
1011
jest.spyOn(signMessageWithPrivateKeyUtils, 'signClaimMessageWithPrivateKey');
1112

1213
const privateKey =
@@ -78,11 +79,38 @@ describe('signClaimMessage', () => {
7879
pubkey: '5bb1138c01b7762318f5e8a8799573077caadb1c7333a5c631773a2ade4bbdb5',
7980
},
8081
};
82+
const mockHWCurrentAccount = {
83+
hw: mockHWCurrentDevice,
84+
metadata: {
85+
pubkey: '5bb1138c01b7762318f5e8a8799573077caadb1c7333a5c631773a2ade4bbdb5',
86+
},
87+
};
8188
const portalMessage =
8289
'0xe4dbb94d0f19e47b0cff8206bebc1fcf8d892325ab851e1a5bdab954711d926e000000000000000000';
8390
afterEach(() => jest.clearAllMocks());
8491

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 () => {
86114
const claimResult =
87115
'15e546e6df7a17960c00c80cb42a3968ca004f2d8efd044cb2bb14e83ba173b02fc4c40ad47b0eca722f3022d5d82874fad25a7c0264d8a31e20f17741a4e602';
88116
signMessageWithPrivateKeyUtils.signClaimMessageWithPrivateKey.mockReturnValue(claimResult);
@@ -102,4 +130,20 @@ describe('signClaimMessage', () => {
102130
})();
103131
expect(nextStep).toHaveBeenCalledWith({ signature: signedClaim, portalMessage });
104132
});
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+
});
105149
});

0 commit comments

Comments
 (0)