forked from Lead-Studios/veritix-contract-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.test.ts
More file actions
87 lines (73 loc) · 3.47 KB
/
Copy patherrors.test.ts
File metadata and controls
87 lines (73 loc) · 3.47 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
import { parseSorobanError, VeriTixError, VeriTixErrorCode } from '../../src/utils/errors';
describe('VeriTixError', () => {
it('extends Error', () => {
const err = new VeriTixError(VeriTixErrorCode.Unknown, 'test message');
expect(err).toBeInstanceOf(Error);
expect(err).toBeInstanceOf(VeriTixError);
});
it('has code property', () => {
const err = new VeriTixError(VeriTixErrorCode.EscrowNotFound, 'not found');
expect(err.code).toBe(VeriTixErrorCode.EscrowNotFound);
});
it('has raw property (rawMessage) when provided', () => {
const err = new VeriTixError(VeriTixErrorCode.Unknown, 'msg', 'raw panic string');
expect(err.rawMessage).toBe('raw panic string');
});
it('rawMessage is undefined when not provided', () => {
const err = new VeriTixError(VeriTixErrorCode.Unknown, 'msg');
expect(err.rawMessage).toBeUndefined();
});
it('sets name to VeriTixError', () => {
const err = new VeriTixError(VeriTixErrorCode.Unknown, 'msg');
expect(err.name).toBe('VeriTixError');
});
// Property-structure regression guard — name / prototype chain / code / message
// are the four things consumers pattern-match on, so pin all four.
it('VeriTixError has name VeriTixError', () => {
const err = new VeriTixError(VeriTixErrorCode.ReadOnlyClient, 'test');
expect(err.name).toBe('VeriTixError');
expect(err instanceof Error).toBe(true);
expect(err instanceof VeriTixError).toBe(true);
});
it('VeriTixError.code is the enum value', () => {
const err = new VeriTixError(VeriTixErrorCode.EscrowNotFound, 'not found');
expect(err.code).toBe(VeriTixErrorCode.EscrowNotFound);
expect(err.message).toBe('not found');
});
});
describe('parseSorobanError', () => {
it('maps "escrow not found" → ESCROW_NOT_FOUND', () => {
const err = parseSorobanError('escrow not found');
expect(err).toBeInstanceOf(VeriTixError);
expect(err.code).toBe(VeriTixErrorCode.EscrowNotFound);
});
it('maps "DisputeAlreadyOpen" → DISPUTE_ALREADY_OPEN', () => {
const err = parseSorobanError('DisputeAlreadyOpen');
expect(err).toBeInstanceOf(VeriTixError);
expect(err.code).toBe(VeriTixErrorCode.DisputeAlreadyOpen);
});
it('maps unknown message → UNKNOWN_CONTRACT_ERROR with raw preserved', () => {
const err = parseSorobanError('some unknown message');
expect(err).toBeInstanceOf(VeriTixError);
expect(err.code).toBe(VeriTixErrorCode.Unknown);
expect(err.rawMessage).toBe('some unknown message');
});
it('throws an actual VeriTixError instance, not a plain Error', () => {
const err = parseSorobanError('escrow not found');
expect(err).toBeInstanceOf(VeriTixError);
expect(err.constructor.name).toBe('VeriTixError');
});
// Issue #203: ContractPaused has been removed; both "contract paused" and
// "contract is already paused" map to ContractAlreadyPaused.
it('maps "contract is already paused" → CONTRACT_ALREADY_PAUSED', () => {
const err = parseSorobanError('contract is already paused');
expect(err.code).toBe(VeriTixErrorCode.ContractAlreadyPaused);
});
it('maps the older "contract paused" panic → CONTRACT_ALREADY_PAUSED (canonical)', () => {
const err = parseSorobanError('the contract paused operations today');
expect(err.code).toBe(VeriTixErrorCode.ContractAlreadyPaused);
});
it('ContractPaused enum member is no longer exported', () => {
expect((VeriTixErrorCode as unknown as Record<string, unknown>).ContractPaused).toBeUndefined();
});
});