-
Notifications
You must be signed in to change notification settings - Fork 575
Expand file tree
/
Copy pathlib.spec.ts
More file actions
68 lines (57 loc) · 2.43 KB
/
lib.spec.ts
File metadata and controls
68 lines (57 loc) · 2.43 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
import { describe, expect, it } from 'vitest';
import { getReceiptAmount, getReceiptMint, getReceiptSymbol } from '../lib';
import type { FormattedReceipt } from '../types';
const SOL_RECEIPT: FormattedReceipt = {
date: { timestamp: 1700000000, utc: '2023-11-14 22:13:20 UTC' },
fee: { formatted: '0.000005', raw: 5000 },
kind: 'sol',
memo: undefined,
network: 'mainnet-beta',
receiver: { address: 'Recv2222', truncated: 'Recv...22' },
sender: { address: 'Send1111', truncated: 'Send...11' },
total: { formatted: '1.5', raw: 1_500_000_000, unit: 'SOL' },
};
const TOKEN_RECEIPT: FormattedReceipt = {
date: { timestamp: 1700000000, utc: '2023-11-14 22:13:20 UTC' },
fee: { formatted: '0.000005', raw: 5000 },
kind: 'token',
memo: undefined,
mint: '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU',
network: 'mainnet-beta',
receiver: { address: 'Recv2222', truncated: 'Recv...22' },
sender: { address: 'Send1111', truncated: 'Send...11' },
symbol: 'USDC',
total: { formatted: '143.25', raw: 143.25, unit: 'USDC' },
};
describe('getReceiptMint', () => {
it('should return undefined for SOL receipts', () => {
expect(getReceiptMint(SOL_RECEIPT)).toBeUndefined();
});
it('should return mint address for token receipts', () => {
expect(getReceiptMint(TOKEN_RECEIPT)).toBe('4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU');
});
it('should return undefined for token receipts without mint', () => {
const receipt: FormattedReceipt = { ...TOKEN_RECEIPT, mint: undefined };
expect(getReceiptMint(receipt)).toBeUndefined();
});
});
describe('getReceiptSymbol', () => {
it('should return undefined for SOL receipts', () => {
expect(getReceiptSymbol(SOL_RECEIPT)).toBeUndefined();
});
it('should return symbol for token receipts', () => {
expect(getReceiptSymbol(TOKEN_RECEIPT)).toBe('USDC');
});
it('should return undefined for token receipts without symbol', () => {
const receipt: FormattedReceipt = { ...TOKEN_RECEIPT, symbol: undefined };
expect(getReceiptSymbol(receipt)).toBeUndefined();
});
});
describe('getReceiptAmount', () => {
it('should convert lamports to SOL for SOL receipts', () => {
expect(getReceiptAmount(SOL_RECEIPT)).toBe(1.5);
});
it('should return raw amount for token receipts', () => {
expect(getReceiptAmount(TOKEN_RECEIPT)).toBe(143.25);
});
});