forked from Creditra/Creditra-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat-address.test.ts
More file actions
39 lines (32 loc) · 1.25 KB
/
Copy pathformat-address.test.ts
File metadata and controls
39 lines (32 loc) · 1.25 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
import { describe, it, expect } from 'vitest';
import { shortenAddress, looksLikeStellarAddress } from './format-address';
describe('shortenAddress', () => {
it('truncates long addresses with an ellipsis in the middle', () => {
const input = 'GABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJKLMNOPQRSTUVWX';
const result = shortenAddress(input);
expect(result.startsWith('GABCDE')).toBe(true);
expect(result.endsWith('UVWX')).toBe(true);
expect(result).toContain('…');
});
it('returns short inputs untouched', () => {
expect(shortenAddress('GABC')).toBe('GABC');
});
it('handles an empty string', () => {
expect(shortenAddress('')).toBe('');
});
it('respects custom lead and tail sizes', () => {
expect(shortenAddress('ABCDEFGHIJK', 2, 2)).toBe('AB…JK');
});
});
describe('looksLikeStellarAddress', () => {
it('accepts a well-shaped Stellar G-address', () => {
const address = 'G' + 'A'.repeat(55);
expect(looksLikeStellarAddress(address)).toBe(true);
});
it('rejects addresses with the wrong length', () => {
expect(looksLikeStellarAddress('GABC')).toBe(false);
});
it('rejects addresses that do not start with G', () => {
expect(looksLikeStellarAddress('A' + 'A'.repeat(55))).toBe(false);
});
});