|
| 1 | +import { KeyringType } from '@metamask/keyring-api'; |
| 2 | + |
| 3 | +import { OneKeyKeyring } from './onekey-keyring'; |
| 4 | +import { OneKeyKeyringV2 } from './onekey-keyring-v2'; |
| 5 | +import type { TrezorBridge } from './trezor-bridge'; |
| 6 | +import { TrezorKeyringV2 } from './trezor-keyring-v2'; |
| 7 | + |
| 8 | +const entropySource = 'onekey-device-id-123'; |
| 9 | + |
| 10 | +/** |
| 11 | + * Get a mock bridge for the OneKeyKeyring. |
| 12 | + * |
| 13 | + * @returns A mock bridge. |
| 14 | + */ |
| 15 | +function getMockBridge(): TrezorBridge { |
| 16 | + return { |
| 17 | + init: jest.fn(), |
| 18 | + dispose: jest.fn(), |
| 19 | + getPublicKey: jest.fn(), |
| 20 | + ethereumSignTransaction: jest.fn(), |
| 21 | + ethereumSignMessage: jest.fn(), |
| 22 | + ethereumSignTypedData: jest.fn(), |
| 23 | + model: undefined, |
| 24 | + } as unknown as TrezorBridge; |
| 25 | +} |
| 26 | + |
| 27 | +describe('OneKeyKeyringV2', () => { |
| 28 | + const createInnerKeyring = (): OneKeyKeyring => { |
| 29 | + return new OneKeyKeyring({ bridge: getMockBridge() }); |
| 30 | + }; |
| 31 | + |
| 32 | + describe('constructor', () => { |
| 33 | + it('extends TrezorKeyringV2', () => { |
| 34 | + const inner = createInnerKeyring(); |
| 35 | + const wrapper = new OneKeyKeyringV2({ |
| 36 | + legacyKeyring: inner, |
| 37 | + entropySource, |
| 38 | + }); |
| 39 | + |
| 40 | + expect(wrapper).toBeInstanceOf(TrezorKeyringV2); |
| 41 | + }); |
| 42 | + |
| 43 | + it('sets the type to OneKey', () => { |
| 44 | + const inner = createInnerKeyring(); |
| 45 | + const wrapper = new OneKeyKeyringV2({ |
| 46 | + legacyKeyring: inner, |
| 47 | + entropySource, |
| 48 | + }); |
| 49 | + |
| 50 | + expect(wrapper.type).toBe(KeyringType.OneKey); |
| 51 | + }); |
| 52 | + |
| 53 | + it('stores the entropy source', () => { |
| 54 | + const inner = createInnerKeyring(); |
| 55 | + const wrapper = new OneKeyKeyringV2({ |
| 56 | + legacyKeyring: inner, |
| 57 | + entropySource, |
| 58 | + }); |
| 59 | + |
| 60 | + expect(wrapper.entropySource).toBe(entropySource); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments