forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators.test.ts
More file actions
77 lines (65 loc) · 2.15 KB
/
Copy pathvalidators.test.ts
File metadata and controls
77 lines (65 loc) · 2.15 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
import { describe, it, expect } from 'vitest';
import { validateMoneyAmount, validateMemo } from '../src/validation';
import { LilyValidationError } from '../src/errors/sdk-error';
const TEST_ISSUER = 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN';
describe('validateMoneyAmount', () => {
it('accepts valid integer amount', () => {
expect(() => {
validateMoneyAmount({ assetCode: 'XLM', amount: '100' });
}).not.toThrow();
});
it('accepts valid decimal amount with 7 digits', () => {
expect(() => {
validateMoneyAmount({ assetCode: 'USDC', assetIssuer: TEST_ISSUER, amount: '123.4567890' });
}).not.toThrow();
});
it('rejects negative amount', () => {
expect(() => {
validateMoneyAmount({ assetCode: 'XLM', amount: '-1' });
}).toThrow(LilyValidationError);
});
it('rejects amount with more than 7 fractional digits', () => {
expect(() => {
validateMoneyAmount({ assetCode: 'XLM', amount: '1.12345678' });
}).toThrow(LilyValidationError);
});
it('rejects invalid asset code (too long)', () => {
expect(() => {
validateMoneyAmount({ assetCode: 'TOOLONGASSET123', amount: '1' });
}).toThrow(LilyValidationError);
});
it('rejects invalid asset code (special chars)', () => {
expect(() => {
validateMoneyAmount({ assetCode: 'X-L-M', amount: '1' });
}).toThrow(LilyValidationError);
});
it('rejects empty asset code', () => {
expect(() => {
validateMoneyAmount({ assetCode: '', amount: '1' });
}).toThrow(LilyValidationError);
});
});
describe('validateMemo', () => {
it('accepts undefined memo', () => {
expect(() => {
validateMemo(undefined);
}).not.toThrow();
});
it('accepts memo within byte limit', () => {
expect(() => {
validateMemo('hello');
}).not.toThrow();
});
it('rejects memo exceeding 28 bytes', () => {
const longMemo = 'a'.repeat(29);
expect(() => {
validateMemo(longMemo);
}).toThrow(LilyValidationError);
});
it('accepts memo exactly at 28 bytes', () => {
const exactMemo = 'a'.repeat(28);
expect(() => {
validateMemo(exactMemo);
}).not.toThrow();
});
});