|
1 | 1 | import { create, StructError } from '@metamask/superstruct'; |
2 | | -import { Hex } from './common'; |
| 2 | +import { HexSchema } from './common'; |
3 | 3 |
|
4 | 4 | describe('Hex schema', () => { |
5 | 5 | it('validates a string starting with 0x', () => { |
6 | 6 | const input = '0xabc123'; |
7 | 7 |
|
8 | | - const result = create(input, Hex); |
| 8 | + const result = create(input, HexSchema); |
9 | 9 |
|
10 | 10 | expect(result).toBe('0xabc123'); |
11 | 11 | }); |
12 | 12 |
|
13 | 13 | it('validates a minimal 0x string', () => { |
14 | 14 | const input = '0x'; |
15 | 15 |
|
16 | | - const result = create(input, Hex); |
| 16 | + const result = create(input, HexSchema); |
17 | 17 |
|
18 | 18 | expect(result).toBe('0x'); |
19 | 19 | }); |
20 | 20 |
|
21 | 21 | it('validates a full-length Ethereum address', () => { |
22 | 22 | const input = '0xe6a2026d58eaff3c7ad7ba9386fb143388002382'; |
23 | 23 |
|
24 | | - const result = create(input, Hex); |
| 24 | + const result = create(input, HexSchema); |
25 | 25 |
|
26 | 26 | expect(result).toBe('0xe6a2026d58eaff3c7ad7ba9386fb143388002382'); |
27 | 27 | }); |
28 | 28 |
|
29 | 29 | it('throws for a string without 0x prefix', () => { |
30 | 30 | const input = 'abc123'; |
31 | 31 |
|
32 | | - expect(() => create(input, Hex)).toThrow(StructError); |
| 32 | + expect(() => create(input, HexSchema)).toThrow(StructError); |
33 | 33 | }); |
34 | 34 |
|
35 | 35 | it('throws for an empty string', () => { |
36 | 36 | const input = ''; |
37 | 37 |
|
38 | | - expect(() => create(input, Hex)).toThrow(StructError); |
| 38 | + expect(() => create(input, HexSchema)).toThrow(StructError); |
39 | 39 | }); |
40 | 40 |
|
41 | 41 | it('throws for a number value', () => { |
42 | 42 | const input = 123; |
43 | 43 |
|
44 | | - expect(() => create(input, Hex)).toThrow(StructError); |
| 44 | + expect(() => create(input, HexSchema)).toThrow(StructError); |
45 | 45 | }); |
46 | 46 |
|
47 | 47 | it('throws for null', () => { |
48 | 48 | const input = null; |
49 | 49 |
|
50 | | - expect(() => create(input, Hex)).toThrow(StructError); |
| 50 | + expect(() => create(input, HexSchema)).toThrow(StructError); |
51 | 51 | }); |
52 | 52 |
|
53 | 53 | it('throws for undefined', () => { |
54 | 54 | const input = undefined; |
55 | 55 |
|
56 | | - expect(() => create(input, Hex)).toThrow(StructError); |
| 56 | + expect(() => create(input, HexSchema)).toThrow(StructError); |
57 | 57 | }); |
58 | 58 |
|
59 | 59 | it('throws for a boolean value', () => { |
60 | 60 | const input = true; |
61 | 61 |
|
62 | | - expect(() => create(input, Hex)).toThrow(StructError); |
| 62 | + expect(() => create(input, HexSchema)).toThrow(StructError); |
63 | 63 | }); |
64 | 64 |
|
65 | 65 | it('throws for an object', () => { |
66 | 66 | const input = { value: '0x123' }; |
67 | 67 |
|
68 | | - expect(() => create(input, Hex)).toThrow(StructError); |
| 68 | + expect(() => create(input, HexSchema)).toThrow(StructError); |
69 | 69 | }); |
70 | 70 | }); |
0 commit comments