forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoroban.contractErrors.test.ts
More file actions
71 lines (57 loc) · 2.51 KB
/
Copy pathsoroban.contractErrors.test.ts
File metadata and controls
71 lines (57 loc) · 2.51 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
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { getContractErrorMessage } from './soroban';
describe('getContractErrorMessage', () => {
// Enumerates every entry in CONTRACT_ERROR_MESSAGES (soroban.ts), sourced
// from the deployed farming-pool contract's PoolError enum for codes 2-9
// (#146). Code '1' predates this table — see the comment above
// CONTRACT_ERROR_MESSAGES in soroban.ts for why it's kept as-is.
it.each([
['1', 'Assets are still locked'],
['2', 'The pool has not been initialized yet'],
['3', 'Invalid credit rate configuration'],
['4', 'Invalid boost multiplier configuration'],
['5', 'This wallet is not on the whitelist for this pool'],
['6', 'Amount is below the minimum stake for this pool'],
['7', 'This action requires the pool to be paused first'],
['8', 'No active stake or locked position was found for this wallet'],
['9', 'This pool is currently paused'],
])('maps code %s to %j', (code, expected) => {
expect(getContractErrorMessage(code)).toBe(expected);
});
it('accepts a decimal-string error code embedded in a longer message', () => {
expect(getContractErrorMessage('Host function failed with contract code: 6')).toBe(
'Amount is below the minimum stake for this pool',
);
});
it('accepts a hex-encoded error code', () => {
expect(getContractErrorMessage('0x6')).toBe(
'Amount is below the minimum stake for this pool',
);
});
describe('unmapped codes', () => {
let warnSpy: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
});
afterEach(() => {
warnSpy.mockRestore();
});
it('returns undefined for an intentionally-unmapped code', () => {
expect(getContractErrorMessage('99')).toBeUndefined();
});
it('logs the unmapped code distinctly so gaps are discoverable', () => {
getContractErrorMessage('99');
expect(warnSpy).toHaveBeenCalledWith('[SmartDrop] Unmapped contract error code:', '99');
});
it('does not warn for a mapped code', () => {
getContractErrorMessage('1');
expect(warnSpy).not.toHaveBeenCalled();
});
});
it('returns undefined without warning when no error code was extracted', () => {
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
expect(getContractErrorMessage(undefined)).toBeUndefined();
expect(warnSpy).not.toHaveBeenCalled();
warnSpy.mockRestore();
});
});