Skip to content

Commit 94e606c

Browse files
committed
chore: improve coverage
1 parent 7abbbd0 commit 94e606c

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (c) Hathor Labs and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { getWalletConfigFromSeed } from '../../src/helpers/wallet.helper';
9+
import { WalletStartError } from '../../src/errors';
10+
import * as loggerModule from '../../src/logger';
11+
12+
const STUB_SEED = 'upon tennis increase embark dismiss diamond monitor face magnet jungle scout salute rural master shoulder cry juice jeans radar present close meat antenna mind';
13+
14+
describe('getWalletConfigFromSeed', () => {
15+
it('should return a wallet config for a valid seed', () => {
16+
const config = getWalletConfigFromSeed({ seed: STUB_SEED });
17+
expect(config).toHaveProperty('seed');
18+
expect(config).toHaveProperty('password');
19+
expect(config).toHaveProperty('pinCode');
20+
});
21+
22+
it('should throw WalletStartError for an invalid seed', () => {
23+
expect(() => getWalletConfigFromSeed({ seed: 'invalid seed words' })).toThrow(WalletStartError);
24+
});
25+
26+
it('should throw WalletStartError when passphrase is provided but not allowed', () => {
27+
const mockError = jest.fn();
28+
jest.spyOn(loggerModule, 'buildAppLogger').mockReturnValue({ error: mockError });
29+
30+
expect(() => getWalletConfigFromSeed({
31+
seed: STUB_SEED,
32+
passphrase: 'my-passphrase',
33+
allowPassphrase: false,
34+
})).toThrow(WalletStartError);
35+
36+
expect(mockError).toHaveBeenCalledWith(
37+
expect.stringContaining('passphrase is not allowed')
38+
);
39+
});
40+
41+
it('should set passphrase when allowed', () => {
42+
const config = getWalletConfigFromSeed({
43+
seed: STUB_SEED,
44+
passphrase: 'my-passphrase',
45+
allowPassphrase: true,
46+
});
47+
expect(config.passphrase).toBe('my-passphrase');
48+
});
49+
});

__tests__/plugins/child.test.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { bigIntUtils } from '@hathor/wallet-lib';
2-
import { handleMessage } from '../../src/plugins/child';
2+
import { handleMessage, loadPlugins } from '../../src/plugins/child';
33
import { notificationBus, EVENTBUS_EVENT_NAME } from '../../src/services/notification.service';
4+
import * as loggerModule from '../../src/logger';
45

56
jest.mock('../../src/services/notification.service', () => ({
67
notificationBus: {
@@ -9,6 +10,34 @@ jest.mock('../../src/services/notification.service', () => ({
910
EVENTBUS_EVENT_NAME: 'eventbus_event',
1011
}));
1112

13+
describe('loadPlugins', () => {
14+
it('should warn and skip unknown plugins', async () => {
15+
const mockWarn = jest.fn();
16+
jest.spyOn(loggerModule, 'buildAppLogger').mockReturnValue({ warn: mockWarn });
17+
18+
const plugins = await loadPlugins(['nonexistent_plugin'], {});
19+
20+
expect(mockWarn).toHaveBeenCalledWith('Unable to find plugin nonexistent_plugin, skipping.');
21+
expect(plugins).toEqual([]);
22+
});
23+
24+
it('should load known hathor plugins', async () => {
25+
const plugins = await loadPlugins(['debug'], {});
26+
27+
expect(plugins).toHaveLength(1);
28+
expect(plugins[0]).toHaveProperty('eventHandler');
29+
});
30+
31+
it('should load custom plugins from config', async () => {
32+
const plugins = await loadPlugins(['my_plugin'], {
33+
my_plugin: { name: 'debug', file: 'hathor_debug.js' },
34+
});
35+
36+
expect(plugins).toHaveLength(1);
37+
expect(plugins[0]).toHaveProperty('eventHandler');
38+
});
39+
});
40+
1241
describe('handleMessage', () => {
1342
afterEach(() => {
1443
jest.clearAllMocks();

0 commit comments

Comments
 (0)