@provex/utils 1.0.16 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chain.d.ts +446 -0
- package/dist/chain.js +98 -0
- package/dist/chain.test.js +112 -0
- package/dist/contracts.d.ts +206 -0
- package/dist/contracts.js +292 -0
- package/dist/contracts.test.js +243 -0
- package/dist/conversionRates.d.ts +215 -0
- package/dist/{src/conversionRates.js → conversionRates.js} +74 -4
- package/dist/conversionRates.test.js +473 -0
- package/dist/currencies.d.ts +248 -0
- package/dist/{src/currencies.js → currencies.js} +119 -38
- package/dist/currencies.test.js +343 -0
- package/dist/data/countries.json +1099 -0
- package/dist/deposit.d.ts +69 -0
- package/dist/deposit.js +52 -0
- package/dist/depositKeys.d.ts +154 -0
- package/dist/depositKeys.js +104 -0
- package/dist/depositKeys.test.d.ts +1 -0
- package/dist/depositKeys.test.js +231 -0
- package/dist/events.d.ts +41 -0
- package/dist/events.js +92 -0
- package/dist/events.test.d.ts +1 -0
- package/dist/events.test.js +111 -0
- package/dist/fees.d.ts +136 -0
- package/dist/fees.js +178 -0
- package/dist/fees.test.d.ts +1 -0
- package/dist/fees.test.js +165 -0
- package/dist/ids.d.ts +175 -0
- package/dist/ids.js +231 -0
- package/dist/ids.test.d.ts +1 -0
- package/dist/ids.test.js +607 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +45 -0
- package/dist/input.d.ts +26 -0
- package/dist/{src/input.js → input.js} +23 -4
- package/dist/intent.d.ts +50 -0
- package/dist/intent.js +28 -0
- package/dist/intent.test.d.ts +1 -0
- package/dist/intent.test.js +119 -0
- package/dist/json.d.ts +55 -0
- package/dist/json.js +80 -0
- package/dist/participants.d.ts +22 -0
- package/dist/participants.js +28 -0
- package/dist/payment.d.ts +481 -0
- package/dist/payment.js +1149 -0
- package/dist/payment.test.d.ts +1 -0
- package/dist/payment.test.js +272 -0
- package/dist/peer-types.d.ts +327 -0
- package/dist/peer-types.js +169 -0
- package/dist/profit.d.ts +49 -0
- package/dist/profit.js +57 -0
- package/dist/profit.test.d.ts +1 -0
- package/dist/profit.test.js +315 -0
- package/dist/reputation.d.ts +125 -0
- package/dist/reputation.js +188 -0
- package/dist/reputation.test.d.ts +1 -0
- package/dist/reputation.test.js +156 -0
- package/dist/sort.d.ts +75 -0
- package/dist/sort.js +70 -0
- package/dist/sort.test.d.ts +1 -0
- package/dist/sort.test.js +216 -0
- package/dist/stateKey.d.ts +35 -0
- package/dist/stateKey.js +36 -0
- package/dist/stats.d.ts +61 -0
- package/dist/stats.js +53 -0
- package/dist/stats.test.d.ts +1 -0
- package/dist/stats.test.js +104 -0
- package/dist/time.d.ts +104 -0
- package/dist/time.js +162 -0
- package/dist/time.test.d.ts +1 -0
- package/dist/time.test.js +231 -0
- package/dist/tokens.d.ts +15502 -0
- package/dist/{src/tokens.js → tokens.js} +98 -17
- package/dist/tokens.test.d.ts +1 -0
- package/dist/tokens.test.js +193 -0
- package/dist/units.d.ts +200 -0
- package/dist/units.js +279 -0
- package/dist/units.test.d.ts +1 -0
- package/dist/units.test.js +327 -0
- package/package.json +119 -29
- package/dist/scripts/convert-svg.js +0 -17
- package/dist/src/chain.d.ts +0 -14
- package/dist/src/chain.js +0 -18
- package/dist/src/contracts.d.ts +0 -30
- package/dist/src/contracts.js +0 -64
- package/dist/src/conversionRates.d.ts +0 -124
- package/dist/src/currencies.d.ts +0 -144
- package/dist/src/data/countries.json +0 -1099
- package/dist/src/deposit.d.ts +0 -1
- package/dist/src/events.d.ts +0 -3
- package/dist/src/events.js +0 -16
- package/dist/src/ids.d.ts +0 -72
- package/dist/src/ids.js +0 -81
- package/dist/src/index.d.ts +0 -16
- package/dist/src/index.js +0 -16
- package/dist/src/input.d.ts +0 -7
- package/dist/src/intent.d.ts +0 -14
- package/dist/src/json.d.ts +0 -18
- package/dist/src/json.js +0 -44
- package/dist/src/participants.d.ts +0 -7
- package/dist/src/participants.js +0 -13
- package/dist/src/payment.d.ts +0 -164
- package/dist/src/payment.js +0 -439
- package/dist/src/profit.d.ts +0 -28
- package/dist/src/profit.js +0 -34
- package/dist/src/sort.d.ts +0 -36
- package/dist/src/sort.js +0 -39
- package/dist/src/stats.d.ts +0 -7
- package/dist/src/stats.js +0 -8
- package/dist/src/time.d.ts +0 -54
- package/dist/src/time.js +0 -106
- package/dist/src/tokens.d.ts +0 -3675
- package/dist/src/units.d.ts +0 -17
- package/dist/src/units.js +0 -79
- package/dist/src/zkp2p-types.d.ts +0 -48
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/scripts/convert-svg.ts +0 -22
- package/src/chain.ts +0 -27
- package/src/contracts.ts +0 -89
- package/src/conversionRates.ts +0 -356
- package/src/currencies.ts +0 -286
- package/src/data/countries.json +0 -1099
- package/src/deposit.ts +0 -2
- package/src/events.ts +0 -21
- package/src/flags/eur.svg +0 -4
- package/src/flags/usd.svg +0 -25
- package/src/flags.ts +0 -4
- package/src/global.d.ts +0 -9
- package/src/ids.ts +0 -137
- package/src/index.ts +0 -16
- package/src/input.ts +0 -35
- package/src/intent.ts +0 -15
- package/src/json.ts +0 -42
- package/src/participants.ts +0 -14
- package/src/payment.ts +0 -573
- package/src/profit.ts +0 -55
- package/src/sort.ts +0 -49
- package/src/stats.ts +0 -10
- package/src/time.ts +0 -123
- package/src/tokens.ts +0 -159
- package/src/units.ts +0 -120
- package/src/zkp2p-types.ts +0 -55
- package/tsconfig.json +0 -18
- /package/dist/{scripts/convert-svg.d.ts → chain.test.d.ts} +0 -0
- /package/dist/{src/deposit.js → contracts.test.d.ts} +0 -0
- /package/dist/{src/intent.js → conversionRates.test.d.ts} +0 -0
- /package/dist/{src/zkp2p-types.js → currencies.test.d.ts} +0 -0
- /package/dist/{src/flags.d.ts → flags.d.ts} +0 -0
- /package/dist/{src/flags.js → flags.js} +0 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { SUPPORTED_CURRENCIES, getCurrencyInfo, getCurrencyByContractId, getCurrencyNameByContractId, getAllSupportedCurrencies, isSupportedCurrency, formatCurrencyAmount, tickerToContractId, generateCurrencyId, formatDefaultRate, Currency, } from './currencies.js';
|
|
4
|
+
describe('currencies', () => {
|
|
5
|
+
describe('SUPPORTED_CURRENCIES', () => {
|
|
6
|
+
it('should have exactly 36 supported currencies', () => {
|
|
7
|
+
const count = Object.keys(SUPPORTED_CURRENCIES).length;
|
|
8
|
+
assert.equal(count, 36, `Expected 36 currencies, but found ${count}`);
|
|
9
|
+
});
|
|
10
|
+
it('should have USD as the first major currency', () => {
|
|
11
|
+
assert.ok(SUPPORTED_CURRENCIES.USD);
|
|
12
|
+
assert.equal(SUPPORTED_CURRENCIES.USD.ticker, 'USD');
|
|
13
|
+
assert.equal(SUPPORTED_CURRENCIES.USD.symbol, '$');
|
|
14
|
+
assert.equal(SUPPORTED_CURRENCIES.USD.decimals, 2);
|
|
15
|
+
});
|
|
16
|
+
it('should have EUR as a supported currency', () => {
|
|
17
|
+
assert.ok(SUPPORTED_CURRENCIES.EUR);
|
|
18
|
+
assert.equal(SUPPORTED_CURRENCIES.EUR.ticker, 'EUR');
|
|
19
|
+
assert.equal(SUPPORTED_CURRENCIES.EUR.symbol, '€');
|
|
20
|
+
assert.equal(SUPPORTED_CURRENCIES.EUR.decimals, 2);
|
|
21
|
+
});
|
|
22
|
+
it('should include zero-decimal currencies', () => {
|
|
23
|
+
assert.equal(SUPPORTED_CURRENCIES.JPY.decimals, 0);
|
|
24
|
+
assert.equal(SUPPORTED_CURRENCIES.KRW.decimals, 0);
|
|
25
|
+
assert.equal(SUPPORTED_CURRENCIES.VND.decimals, 0);
|
|
26
|
+
assert.equal(SUPPORTED_CURRENCIES.UGX.decimals, 0);
|
|
27
|
+
});
|
|
28
|
+
it('should have unique contract IDs for all currencies', () => {
|
|
29
|
+
const contractIds = new Set();
|
|
30
|
+
const currencies = Object.values(SUPPORTED_CURRENCIES);
|
|
31
|
+
for (const currency of currencies) {
|
|
32
|
+
assert.ok(!contractIds.has(currency.contractId), `Duplicate contract ID found for ${currency.ticker}`);
|
|
33
|
+
contractIds.add(currency.contractId);
|
|
34
|
+
}
|
|
35
|
+
assert.equal(contractIds.size, currencies.length);
|
|
36
|
+
});
|
|
37
|
+
it('should have flags for all currencies', () => {
|
|
38
|
+
const currencies = Object.values(SUPPORTED_CURRENCIES);
|
|
39
|
+
for (const currency of currencies) {
|
|
40
|
+
assert.ok(currency.flag, `Missing flag for ${currency.ticker}`);
|
|
41
|
+
assert.ok(currency.flag.length > 0, `Empty flag for ${currency.ticker}`);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
it('should have valid ticker codes', () => {
|
|
45
|
+
const currencies = Object.values(SUPPORTED_CURRENCIES);
|
|
46
|
+
for (const currency of currencies) {
|
|
47
|
+
assert.ok(currency.ticker.length === 3, `Invalid ticker length for ${currency.ticker}`);
|
|
48
|
+
assert.equal(currency.ticker, currency.ticker.toUpperCase(), `Ticker should be uppercase: ${currency.ticker}`);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('getCurrencyInfo', () => {
|
|
53
|
+
it('should return currency info for valid currency code', () => {
|
|
54
|
+
const usd = getCurrencyInfo('USD');
|
|
55
|
+
assert.ok(usd);
|
|
56
|
+
assert.equal(usd.ticker, 'USD');
|
|
57
|
+
assert.equal(usd.symbol, '$');
|
|
58
|
+
assert.equal(usd.decimals, 2);
|
|
59
|
+
});
|
|
60
|
+
it('should be case-insensitive', () => {
|
|
61
|
+
const usdLower = getCurrencyInfo('usd');
|
|
62
|
+
const usdUpper = getCurrencyInfo('USD');
|
|
63
|
+
const usdMixed = getCurrencyInfo('UsD');
|
|
64
|
+
assert.deepEqual(usdLower, usdUpper);
|
|
65
|
+
assert.deepEqual(usdLower, usdMixed);
|
|
66
|
+
});
|
|
67
|
+
it('should return null for invalid currency code', () => {
|
|
68
|
+
const invalid = getCurrencyInfo('INVALID');
|
|
69
|
+
assert.equal(invalid, null);
|
|
70
|
+
});
|
|
71
|
+
it('should return null for empty string', () => {
|
|
72
|
+
const empty = getCurrencyInfo('');
|
|
73
|
+
assert.equal(empty, null);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('getCurrencyByContractId', () => {
|
|
77
|
+
it('should return currency for valid contract ID', () => {
|
|
78
|
+
const usdContractId = SUPPORTED_CURRENCIES.USD.contractId;
|
|
79
|
+
const currency = getCurrencyByContractId(usdContractId);
|
|
80
|
+
assert.ok(currency);
|
|
81
|
+
assert.equal(currency.ticker, 'USD');
|
|
82
|
+
});
|
|
83
|
+
it('should return null for invalid contract ID', () => {
|
|
84
|
+
const fakeHash = '0x' + '0'.repeat(64);
|
|
85
|
+
const currency = getCurrencyByContractId(fakeHash);
|
|
86
|
+
assert.equal(currency, null);
|
|
87
|
+
});
|
|
88
|
+
it('should throw for non-hash input', () => {
|
|
89
|
+
assert.throws(() => {
|
|
90
|
+
getCurrencyByContractId('not-a-hash');
|
|
91
|
+
}, /Invalid contract ID/);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('getCurrencyNameByContractId', () => {
|
|
95
|
+
it('should return ticker for valid contract ID', () => {
|
|
96
|
+
const usdContractId = SUPPORTED_CURRENCIES.USD.contractId;
|
|
97
|
+
const name = getCurrencyNameByContractId(usdContractId);
|
|
98
|
+
assert.equal(name, 'USD');
|
|
99
|
+
});
|
|
100
|
+
it('should return original contract ID for unknown ID', () => {
|
|
101
|
+
const fakeHash = '0x' + '1'.repeat(64);
|
|
102
|
+
const name = getCurrencyNameByContractId(fakeHash);
|
|
103
|
+
assert.equal(name, fakeHash);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe('getAllSupportedCurrencies', () => {
|
|
107
|
+
it('should return all currencies', () => {
|
|
108
|
+
const all = getAllSupportedCurrencies();
|
|
109
|
+
assert.equal(all.length, 36);
|
|
110
|
+
});
|
|
111
|
+
it('should return CurrencyInfo objects', () => {
|
|
112
|
+
const all = getAllSupportedCurrencies();
|
|
113
|
+
const first = all[0];
|
|
114
|
+
assert.ok(first.ticker);
|
|
115
|
+
assert.ok(first.symbol);
|
|
116
|
+
assert.ok(first.name);
|
|
117
|
+
assert.ok(typeof first.decimals === 'number');
|
|
118
|
+
assert.ok(first.contractId);
|
|
119
|
+
assert.ok(first.flag);
|
|
120
|
+
});
|
|
121
|
+
it('should return sorted currencies', () => {
|
|
122
|
+
const all = getAllSupportedCurrencies();
|
|
123
|
+
const tickers = all.map(c => c.ticker);
|
|
124
|
+
const sorted = [...tickers].sort();
|
|
125
|
+
assert.deepEqual(tickers, sorted);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('isSupportedCurrency', () => {
|
|
129
|
+
it('should return true for supported currencies', () => {
|
|
130
|
+
assert.equal(isSupportedCurrency('USD'), true);
|
|
131
|
+
assert.equal(isSupportedCurrency('EUR'), true);
|
|
132
|
+
assert.equal(isSupportedCurrency('GBP'), true);
|
|
133
|
+
});
|
|
134
|
+
it('should be case-insensitive', () => {
|
|
135
|
+
assert.equal(isSupportedCurrency('usd'), true);
|
|
136
|
+
assert.equal(isSupportedCurrency('USD'), true);
|
|
137
|
+
assert.equal(isSupportedCurrency('UsD'), true);
|
|
138
|
+
});
|
|
139
|
+
it('should return false for unsupported currencies', () => {
|
|
140
|
+
assert.equal(isSupportedCurrency('INVALID'), false);
|
|
141
|
+
assert.equal(isSupportedCurrency(''), false);
|
|
142
|
+
assert.equal(isSupportedCurrency('XXX'), false);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe('formatCurrencyAmount', () => {
|
|
146
|
+
it('should format USD amounts with 2 decimals', () => {
|
|
147
|
+
assert.equal(formatCurrencyAmount(100, 'USD'), '$100.00');
|
|
148
|
+
assert.equal(formatCurrencyAmount(1000, 'USD'), '$1,000.00');
|
|
149
|
+
assert.equal(formatCurrencyAmount(1234.56, 'USD'), '$1,234.56');
|
|
150
|
+
});
|
|
151
|
+
it('should format JPY amounts with 0 decimals', () => {
|
|
152
|
+
assert.equal(formatCurrencyAmount(100, 'JPY'), '¥100');
|
|
153
|
+
assert.equal(formatCurrencyAmount(1000, 'JPY'), '¥1,000');
|
|
154
|
+
assert.equal(formatCurrencyAmount(1234, 'JPY'), '¥1,234');
|
|
155
|
+
});
|
|
156
|
+
it('should format EUR amounts correctly', () => {
|
|
157
|
+
assert.equal(formatCurrencyAmount(100, 'EUR'), '€100.00');
|
|
158
|
+
assert.equal(formatCurrencyAmount(1234.56, 'EUR'), '€1,234.56');
|
|
159
|
+
});
|
|
160
|
+
it('should handle string inputs', () => {
|
|
161
|
+
assert.equal(formatCurrencyAmount('100', 'USD'), '$100.00');
|
|
162
|
+
assert.equal(formatCurrencyAmount('1234.56', 'USD'), '$1,234.56');
|
|
163
|
+
});
|
|
164
|
+
it('should handle unknown currencies', () => {
|
|
165
|
+
const result = formatCurrencyAmount(100, 'UNKNOWN');
|
|
166
|
+
assert.equal(result, '100 UNKNOWN');
|
|
167
|
+
});
|
|
168
|
+
it('should add thousands separators', () => {
|
|
169
|
+
assert.equal(formatCurrencyAmount(1000000, 'USD'), '$1,000,000.00');
|
|
170
|
+
assert.equal(formatCurrencyAmount(123456789, 'JPY'), '¥123,456,789');
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe('tickerToContractId', () => {
|
|
174
|
+
it('should generate consistent contract IDs', () => {
|
|
175
|
+
const id1 = tickerToContractId('USD');
|
|
176
|
+
const id2 = tickerToContractId('USD');
|
|
177
|
+
assert.equal(id1, id2);
|
|
178
|
+
});
|
|
179
|
+
it('should be case-insensitive', () => {
|
|
180
|
+
const idUpper = tickerToContractId('USD');
|
|
181
|
+
const idLower = tickerToContractId('usd');
|
|
182
|
+
const idMixed = tickerToContractId('UsD');
|
|
183
|
+
assert.equal(idUpper, idLower);
|
|
184
|
+
assert.equal(idUpper, idMixed);
|
|
185
|
+
});
|
|
186
|
+
it('should generate different IDs for different tickers', () => {
|
|
187
|
+
const usdId = tickerToContractId('USD');
|
|
188
|
+
const eurId = tickerToContractId('EUR');
|
|
189
|
+
const gbpId = tickerToContractId('GBP');
|
|
190
|
+
assert.notEqual(usdId, eurId);
|
|
191
|
+
assert.notEqual(usdId, gbpId);
|
|
192
|
+
assert.notEqual(eurId, gbpId);
|
|
193
|
+
});
|
|
194
|
+
it('should generate 32-byte hashes', () => {
|
|
195
|
+
const id = tickerToContractId('USD');
|
|
196
|
+
assert.equal(id.length, 66); // '0x' + 64 hex chars
|
|
197
|
+
assert.ok(id.startsWith('0x'));
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
describe('Currency class', () => {
|
|
201
|
+
it('should parse amounts correctly', () => {
|
|
202
|
+
const usd = SUPPORTED_CURRENCIES.USD;
|
|
203
|
+
const amount = usd.parseAmount('100.50');
|
|
204
|
+
assert.equal(amount, 10050n); // 100.50 with 2 decimals
|
|
205
|
+
});
|
|
206
|
+
it('should return null for invalid amounts', () => {
|
|
207
|
+
const usd = SUPPORTED_CURRENCIES.USD;
|
|
208
|
+
const amount = usd.parseAmount('invalid');
|
|
209
|
+
assert.equal(amount, null);
|
|
210
|
+
});
|
|
211
|
+
it('should format amounts correctly', () => {
|
|
212
|
+
const usd = SUPPORTED_CURRENCIES.USD;
|
|
213
|
+
const formatted = usd.formatAmount(10050n);
|
|
214
|
+
assert.equal(formatted, '100.50');
|
|
215
|
+
});
|
|
216
|
+
it('should handle null amounts', () => {
|
|
217
|
+
const usd = SUPPORTED_CURRENCIES.USD;
|
|
218
|
+
const formatted = usd.formatAmount(null);
|
|
219
|
+
assert.equal(formatted, null);
|
|
220
|
+
});
|
|
221
|
+
it('should format with custom options', () => {
|
|
222
|
+
const usd = SUPPORTED_CURRENCIES.USD;
|
|
223
|
+
const formatted = usd.formatAmount(10050n, { truncateDecimals: 0, padDecimals: 0 });
|
|
224
|
+
assert.ok(formatted, 'formatted should be truthy');
|
|
225
|
+
assert.ok(!formatted.includes('.'), `formatted should not include '.', but got: ${formatted}`);
|
|
226
|
+
});
|
|
227
|
+
it('should have default zoom of 1.5 when not specified', () => {
|
|
228
|
+
// GBP uses flagFromCountries and no explicit zoom
|
|
229
|
+
const gbp = SUPPORTED_CURRENCIES.GBP;
|
|
230
|
+
assert.equal(gbp.zoom, 1.5);
|
|
231
|
+
});
|
|
232
|
+
it('should use explicit zoom when specified', () => {
|
|
233
|
+
// USD has explicit zoom of 1
|
|
234
|
+
const usd = SUPPORTED_CURRENCIES.USD;
|
|
235
|
+
assert.equal(usd.zoom, 1);
|
|
236
|
+
});
|
|
237
|
+
it('should have flag from countries data', () => {
|
|
238
|
+
// GBP gets flag from countries.json
|
|
239
|
+
const gbp = SUPPORTED_CURRENCIES.GBP;
|
|
240
|
+
assert.ok(gbp.flag.length > 0);
|
|
241
|
+
});
|
|
242
|
+
it('should have explicit flag for USD/EUR', () => {
|
|
243
|
+
const usd = SUPPORTED_CURRENCIES.USD;
|
|
244
|
+
const eur = SUPPORTED_CURRENCIES.EUR;
|
|
245
|
+
assert.ok(usd.flag.startsWith('data:'));
|
|
246
|
+
assert.ok(eur.flag.startsWith('data:'));
|
|
247
|
+
});
|
|
248
|
+
it('should default flag to empty string when not provided', () => {
|
|
249
|
+
const currency = new Currency('TST', '$', 'Test', 2);
|
|
250
|
+
assert.equal(currency.flag, '');
|
|
251
|
+
});
|
|
252
|
+
it('should default zoom to 1.5 when not provided', () => {
|
|
253
|
+
const currency = new Currency('TST', '$', 'Test', 2);
|
|
254
|
+
assert.equal(currency.zoom, 1.5);
|
|
255
|
+
});
|
|
256
|
+
it('should use provided flag when specified', () => {
|
|
257
|
+
const currency = new Currency('TST', '$', 'Test', 2, 'custom-flag.png');
|
|
258
|
+
assert.equal(currency.flag, 'custom-flag.png');
|
|
259
|
+
});
|
|
260
|
+
it('should use provided zoom when specified', () => {
|
|
261
|
+
const currency = new Currency('TST', '$', 'Test', 2, '', 2.0);
|
|
262
|
+
assert.equal(currency.zoom, 2.0);
|
|
263
|
+
});
|
|
264
|
+
it('should use provided flag with default zoom', () => {
|
|
265
|
+
const currency = new Currency('TST', '$', 'Test', 2, 'flag.png');
|
|
266
|
+
assert.equal(currency.flag, 'flag.png');
|
|
267
|
+
assert.equal(currency.zoom, 1.5); // default
|
|
268
|
+
});
|
|
269
|
+
it('should handle empty string flag', () => {
|
|
270
|
+
const currency = new Currency('TST', '$', 'Test', 2, '');
|
|
271
|
+
assert.equal(currency.flag, '');
|
|
272
|
+
assert.equal(currency.zoom, 1.5);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
describe('generateCurrencyId', () => {
|
|
276
|
+
it('should generate consistent IDs', () => {
|
|
277
|
+
const id1 = generateCurrencyId('USD');
|
|
278
|
+
const id2 = generateCurrencyId('USD');
|
|
279
|
+
assert.equal(id1, id2);
|
|
280
|
+
});
|
|
281
|
+
it('should be case insensitive', () => {
|
|
282
|
+
const upper = generateCurrencyId('USD');
|
|
283
|
+
const lower = generateCurrencyId('usd');
|
|
284
|
+
const mixed = generateCurrencyId('UsD');
|
|
285
|
+
assert.equal(upper, lower);
|
|
286
|
+
assert.equal(upper, mixed);
|
|
287
|
+
});
|
|
288
|
+
it('should generate different IDs for different currencies', () => {
|
|
289
|
+
const usd = generateCurrencyId('USD');
|
|
290
|
+
const eur = generateCurrencyId('EUR');
|
|
291
|
+
assert.notEqual(usd, eur);
|
|
292
|
+
});
|
|
293
|
+
it('should match tickerToContractId output', () => {
|
|
294
|
+
const fromGenerate = generateCurrencyId('USD');
|
|
295
|
+
const fromTicker = tickerToContractId('USD');
|
|
296
|
+
assert.equal(fromGenerate, fromTicker);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
describe('formatDefaultRate', () => {
|
|
300
|
+
it('returns "1" for zero-decimal currencies (JPY)', () => {
|
|
301
|
+
const result = formatDefaultRate(SUPPORTED_CURRENCIES.JPY);
|
|
302
|
+
assert.equal(result, '1');
|
|
303
|
+
});
|
|
304
|
+
it('returns "1" for zero-decimal currencies (KRW)', () => {
|
|
305
|
+
const result = formatDefaultRate(SUPPORTED_CURRENCIES.KRW);
|
|
306
|
+
assert.equal(result, '1');
|
|
307
|
+
});
|
|
308
|
+
it('returns "1" for zero-decimal currencies (VND)', () => {
|
|
309
|
+
const result = formatDefaultRate(SUPPORTED_CURRENCIES.VND);
|
|
310
|
+
assert.equal(result, '1');
|
|
311
|
+
});
|
|
312
|
+
it('returns "1" for zero-decimal currencies (UGX)', () => {
|
|
313
|
+
const result = formatDefaultRate(SUPPORTED_CURRENCIES.UGX);
|
|
314
|
+
assert.equal(result, '1');
|
|
315
|
+
});
|
|
316
|
+
it('returns "1.00" for 2-decimal currencies (USD)', () => {
|
|
317
|
+
const result = formatDefaultRate(SUPPORTED_CURRENCIES.USD);
|
|
318
|
+
assert.equal(result, '1.00');
|
|
319
|
+
});
|
|
320
|
+
it('returns "1.00" for 2-decimal currencies (EUR)', () => {
|
|
321
|
+
const result = formatDefaultRate(SUPPORTED_CURRENCIES.EUR);
|
|
322
|
+
assert.equal(result, '1.00');
|
|
323
|
+
});
|
|
324
|
+
it('returns "1.00" for 2-decimal currencies (GBP)', () => {
|
|
325
|
+
const result = formatDefaultRate(SUPPORTED_CURRENCIES.GBP);
|
|
326
|
+
assert.equal(result, '1.00');
|
|
327
|
+
});
|
|
328
|
+
it('returns "1.00" for 2-decimal currencies (ARS)', () => {
|
|
329
|
+
const result = formatDefaultRate(SUPPORTED_CURRENCIES.ARS);
|
|
330
|
+
assert.equal(result, '1.00');
|
|
331
|
+
});
|
|
332
|
+
it('works with CurrencyInfo (toJSON output)', () => {
|
|
333
|
+
const currencyInfo = SUPPORTED_CURRENCIES.USD.toJSON();
|
|
334
|
+
const result = formatDefaultRate(currencyInfo);
|
|
335
|
+
assert.equal(result, '1.00');
|
|
336
|
+
});
|
|
337
|
+
it('handles custom Currency with different decimals', () => {
|
|
338
|
+
const customCurrency = new Currency('TST', '$', 'Test', 3);
|
|
339
|
+
const result = formatDefaultRate(customCurrency);
|
|
340
|
+
assert.equal(result, '1.000');
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
});
|