generated from MetaMask/metamask-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathaccount-options.test.ts
More file actions
125 lines (110 loc) · 3.63 KB
/
account-options.test.ts
File metadata and controls
125 lines (110 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { assert } from '@metamask/superstruct';
import {
KeyringAccountEntropyTypeOption,
KeyringAccountOptionsStruct,
} from './account-options';
describe('api', () => {
describe('KeyringAccountOptionsStruct', () => {
const baseEntropyMnemonicOptions = {
type: KeyringAccountEntropyTypeOption.Mnemonic,
id: '01K0BX6VDR5DPDPGGNA8PZVBVB',
derivationPath: "m/44'/60'/0'/0/0",
};
it.each([
{},
{ exportable: true },
{ exportable: false },
{ entropy: { type: KeyringAccountEntropyTypeOption.PrivateKey } },
{
entropy: { type: KeyringAccountEntropyTypeOption.PrivateKey },
exportable: true,
},
{
entropy: { type: KeyringAccountEntropyTypeOption.PrivateKey },
exportable: false,
},
{
entropy: { type: KeyringAccountEntropyTypeOption.Custom },
},
{
entropy: { type: KeyringAccountEntropyTypeOption.Custom },
exportable: true,
},
{
entropy: {
...baseEntropyMnemonicOptions,
groupIndex: 0,
},
},
{
entropy: {
...baseEntropyMnemonicOptions,
groupIndex: 1,
},
exportable: true,
},
{
entropy: {
...baseEntropyMnemonicOptions,
groupIndex: 2,
},
exportable: false,
},
])('validates options for entropy source: %s', (options) => {
expect(() => assert(options, KeyringAccountOptionsStruct)).not.toThrow();
});
it('validates legacy options', () => {
const options = {
some: {
untyped: 'options',
something: true,
},
};
expect(() => assert(options, KeyringAccountOptionsStruct)).not.toThrow();
});
it('throws if legacy options partially matches options.entropy.type', () => {
const options = {
entropy: {
type: KeyringAccountEntropyTypeOption.Mnemonic,
// Nothing else, like if it was legacy.
},
};
expect(() => assert(options, KeyringAccountOptionsStruct)).toThrow(
'At path: entropy.id -- Expected a string, but received: undefined',
);
});
it('throws if legacy options partially matches options.exportable', () => {
const options = {
exportable: 'maybe',
};
expect(() => assert(options, KeyringAccountOptionsStruct)).toThrow(
'At path: exportable -- Expected a value of type `boolean`, but received: `"maybe"`',
);
});
});
it('throws if options.entropy.type is not known', () => {
const options = { entropy: { type: 'unknown', something: 'else' } };
expect(() => assert(options, KeyringAccountOptionsStruct)).toThrow(
`At path: entropy.type -- Expected the literal \`"mnemonic"\`, but received: "${options.entropy.type}"`,
);
});
it('throws if options.entropy.type is Hardware (not implemented)', () => {
const options = {
entropy: { type: KeyringAccountEntropyTypeOption.Hardware },
};
expect(() => assert(options, KeyringAccountOptionsStruct)).toThrow(
`At path: entropy.type -- Expected the literal \`"mnemonic"\`, but received: "${KeyringAccountEntropyTypeOption.Hardware}"`,
);
});
it('throws if options.entropy.type is Hardware with additional fields', () => {
const options = {
entropy: {
type: KeyringAccountEntropyTypeOption.Hardware,
deviceId: 'some-device-id',
},
};
expect(() => assert(options, KeyringAccountOptionsStruct)).toThrow(
`At path: entropy.type -- Expected the literal \`"mnemonic"\`, but received: "${KeyringAccountEntropyTypeOption.Hardware}"`,
);
});
});