forked from nervosnetwork/neuron
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/neuron-wallet/tests/services/hardware/ledger.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Ledger from '../../../src/services/hardware/ledger' | ||
|
||
const getWalletExtendedPublicKeyMock = jest.fn() | ||
|
||
jest.mock('hw-app-ckb', () => { | ||
return function () { | ||
return { | ||
getWalletExtendedPublicKey: getWalletExtendedPublicKeyMock, | ||
} | ||
} | ||
}) | ||
|
||
jest.mock('@ledgerhq/hw-transport-node-hid', () => ({ | ||
open: jest.fn(), | ||
})) | ||
|
||
const pk = | ||
'04d061e9c5891f579fd548cfd22ff29f5c642714cc7e7a9215f0071ef5a5723f691757b28e31be71f09f24673eed52348e58d53bcfd26f4d96ec6bf1489eab429d' | ||
const zipPk = '03d061e9c5891f579fd548cfd22ff29f5c642714cc7e7a9215f0071ef5a5723f69' | ||
|
||
describe('test for ledger', () => { | ||
describe('test getExtendedPublicKey', () => { | ||
it('if the return pk is unzip', async () => { | ||
getWalletExtendedPublicKeyMock.mockResolvedValueOnce({ public_key: pk, chain_code: '0x' }) | ||
const ledger = new Ledger({} as any) | ||
await ledger.connect() | ||
const res = await ledger.getExtendedPublicKey() | ||
expect(res.publicKey).toBe(zipPk) | ||
}) | ||
|
||
it('if the return pk is zip', async () => { | ||
getWalletExtendedPublicKeyMock.mockResolvedValueOnce({ public_key: zipPk, chain_code: '0x' }) | ||
const ledger = new Ledger({} as any) | ||
await ledger.connect() | ||
const res = await ledger.getExtendedPublicKey() | ||
expect(res.publicKey).toBe(zipPk) | ||
}) | ||
}) | ||
}) |
b81b534
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Packaging for test is done in 9265716889