-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathfunding.test.ts
More file actions
105 lines (95 loc) · 3.18 KB
/
Copy pathfunding.test.ts
File metadata and controls
105 lines (95 loc) · 3.18 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
import { describe, expect, it } from 'vitest';
import {
FundingAddressSetResponseSchema,
FundingTransactionsPageSchema,
KnownFundingTransactionStatus,
} from './funding';
describe('FundingAddressSetResponseSchema', () => {
it('normalizes the response and retains Tron addresses and warnings', () => {
const result = FundingAddressSetResponseSchema.parse({
address: {
evm: '0x0000000000000000000000000000000000000001',
svm: '11111111111111111111111111111111',
btc: 'bc1qexample',
tron: 'TExample',
},
note: 'Use the address for the source chain.',
warnings: [
{
code: 'missing_builder_code',
message: 'Include a builder code for attribution.',
},
],
});
expect(result).toEqual({
addresses: {
evm: '0x0000000000000000000000000000000000000001',
svm: '11111111111111111111111111111111',
btc: 'bc1qexample',
tron: 'TExample',
},
note: 'Use the address for the source chain.',
warnings: [
{
code: 'missing_builder_code',
message: 'Include a builder code for attribution.',
},
],
});
});
it('normalizes the documented TVM key to tron', () => {
const result = FundingAddressSetResponseSchema.parse({
address: {
evm: '0x0000000000000000000000000000000000000001',
svm: '11111111111111111111111111111111',
btc: 'bc1qexample',
tvm: 'TExample',
},
});
expect(result.addresses.tron).toBe('TExample');
expect(result.addresses).not.toHaveProperty('tvm');
});
});
describe('FundingTransactionsPageSchema', () => {
it('accepts detected transactions before optional metadata is available', () => {
const result = FundingTransactionsPageSchema.parse({
transactions: [
{
fromChainId: '1',
fromTokenAddress: '0x0000000000000000000000000000000000000002',
fromAmountBaseUnit: '1000000',
toChainId: '137',
toTokenAddress: '0x0000000000000000000000000000000000000003',
status: 'DEPOSIT_DETECTED',
},
],
nextCursor: 'eyJsYXN0SWQiOiI0MiJ9',
});
expect(result.transactions[0]?.status).toBe(
KnownFundingTransactionStatus.DepositDetected,
);
expect(result.transactions[0]?.createdTimeMs).toBeUndefined();
expect(result.transactions[0]?.txHash).toBeUndefined();
expect(result.nextCursor).toBe('eyJsYXN0SWQiOiI0MiJ9');
});
it('preserves newly introduced statuses', () => {
const result = FundingTransactionsPageSchema.parse({
transactions: [
{
fromChainId: '1',
fromTokenAddress: '0x0000000000000000000000000000000000000002',
fromAmountBaseUnit: '1000000',
toChainId: '137',
toTokenAddress: '0x0000000000000000000000000000000000000003',
status: 'REFUNDING',
},
],
nextCursor: null,
});
expect(result.transactions[0]?.status).toBe('REFUNDING');
});
it('treats a pre-pagination response as a terminal page', () => {
const result = FundingTransactionsPageSchema.parse({ transactions: [] });
expect(result.nextCursor).toBeNull();
});
});