forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoney-amount-passthrough.test.ts
More file actions
77 lines (64 loc) · 2.37 KB
/
Copy pathmoney-amount-passthrough.test.ts
File metadata and controls
77 lines (64 loc) · 2.37 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, expect, it } from 'vitest';
const TEST_ISSUER = 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN';
import { LilySdk } from '../src/sdk';
import { createMockHttpClient } from './helpers/mock-http-client';
import type { HttpRequest } from '../src/http/types';
describe('MoneyAmount decimal passthrough', () => {
const amounts = ['1', '1.0', '01.5', '0.000001'];
for (const amount of amounts) {
it(`passes "${amount}" unchanged through PaymentClient.quote`, async () => {
let capturedBody: unknown;
const httpClient = createMockHttpClient(async (req: HttpRequest) => {
capturedBody = req.body;
return {
status: 200,
headers: new Headers({ 'content-type': 'application/json' }),
data: {
amount: { assetCode: 'USDC', amount },
estimatedFee: { assetCode: 'USDC', amount: '0.01' },
expiresAt: '2026-08-26T00:00:00Z',
},
};
});
const sdk = new LilySdk(
{ baseUrl: 'https://api.lily.test', fetch: globalThis.fetch },
httpClient,
);
await sdk.payments.quote({
fromWalletId: 'wallet-1',
toAddress: 'GABC...',
amount: { assetCode: 'USDC', assetIssuer: TEST_ISSUER, amount },
});
expect((capturedBody as any).amount.amount).toBe(amount);
});
it(`passes "${amount}" unchanged through PaymentClient.execute`, async () => {
let capturedBody: unknown;
const httpClient = createMockHttpClient(async (req: HttpRequest) => {
capturedBody = req.body;
return {
status: 200,
headers: new Headers({ 'content-type': 'application/json' }),
data: {
id: 'pay-1',
fromWalletId: 'wallet-1',
toAddress: 'GABC...',
amount: { assetCode: 'USDC', amount },
status: 'queued',
createdAt: '2026-08-26T00:00:00Z',
updatedAt: '2026-08-26T00:00:00Z',
},
};
});
const sdk = new LilySdk(
{ baseUrl: 'https://api.lily.test', fetch: globalThis.fetch },
httpClient,
);
await sdk.payments.execute({
fromWalletId: 'wallet-1',
toAddress: 'GABC...',
amount: { assetCode: 'USDC', assetIssuer: TEST_ISSUER, amount },
});
expect((capturedBody as any).amount.amount).toBe(amount);
});
}
});