forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.conversion.test.js
More file actions
30 lines (25 loc) · 894 Bytes
/
Copy pathutils.conversion.test.js
File metadata and controls
30 lines (25 loc) · 894 Bytes
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
const { xlmToStroops, stroopsToXlm, pointsToTokens, bytesToHuman, toSafeInt } = require('../src/utils/conversion');
describe('conversion utils', () => {
it('xlmToStroops', () => {
expect(xlmToStroops(1)).toBe(10_000_000);
expect(xlmToStroops(0.5)).toBe(5_000_000);
});
it('stroopsToXlm', () => {
expect(stroopsToXlm(10_000_000)).toBe(1);
expect(stroopsToXlm(5_000_000)).toBe(0.5);
});
it('pointsToTokens', () => {
expect(pointsToTokens(100, 0.01)).toBeCloseTo(1);
expect(pointsToTokens(500, 0.005)).toBeCloseTo(2.5);
});
it('bytesToHuman', () => {
expect(bytesToHuman(0)).toBe('0 B');
expect(bytesToHuman(1024)).toBe('1.00 KB');
expect(bytesToHuman(1024 * 1024)).toBe('1.00 MB');
});
it('toSafeInt', () => {
expect(toSafeInt('42')).toBe(42);
expect(toSafeInt('abc')).toBeNull();
expect(toSafeInt('3.7')).toBe(3);
});
});