@bitpay-labs/crypto-wallet-core 11.11.5 → 11.11.6
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/package.json +9 -3
- package/ts_build/src/transactions/index.d.ts +1 -1
- package/ts_build/src/transactions/index.d.ts.map +1 -1
- package/ts_build/src/transactions/index.js.map +1 -1
- package/ts_build/src/types/derivation.d.ts +1 -0
- package/ts_build/src/types/derivation.d.ts.map +1 -1
- package/.mocharc.json +0 -6
- package/LICENSE +0 -21
- package/mcr.config.js +0 -17
- package/src/constants/address.ts +0 -7
- package/src/constants/algorithms.ts +0 -9
- package/src/constants/arc.ts +0 -4
- package/src/constants/chains.ts +0 -68
- package/src/constants/feeMinimums.ts +0 -23
- package/src/constants/index.ts +0 -40
- package/src/constants/tokens.ts +0 -233
- package/src/constants/units.ts +0 -311
- package/src/derivation/arb/index.ts +0 -3
- package/src/derivation/base/index.ts +0 -3
- package/src/derivation/bch/index.ts +0 -11
- package/src/derivation/btc/index.ts +0 -68
- package/src/derivation/doge/index.ts +0 -6
- package/src/derivation/eth/index.ts +0 -86
- package/src/derivation/index.ts +0 -140
- package/src/derivation/ltc/index.ts +0 -6
- package/src/derivation/matic/index.ts +0 -3
- package/src/derivation/op/index.ts +0 -3
- package/src/derivation/paths.ts +0 -45
- package/src/derivation/sol/index.ts +0 -81
- package/src/derivation/xrp/index.ts +0 -63
- package/src/index.ts +0 -48
- package/src/message/btc.ts +0 -28
- package/src/message/eth.ts +0 -47
- package/src/message/index.ts +0 -71
- package/src/message/sol.ts +0 -3
- package/src/message/xrp.ts +0 -4
- package/src/transactions/arb/index.ts +0 -14
- package/src/transactions/base/index.ts +0 -13
- package/src/transactions/bch/index.ts +0 -25
- package/src/transactions/btc/index.ts +0 -316
- package/src/transactions/doge/index.ts +0 -31
- package/src/transactions/erc20/abi.ts +0 -418
- package/src/transactions/erc20/index.ts +0 -57
- package/src/transactions/eth/index.ts +0 -192
- package/src/transactions/eth-multisig/abi.ts +0 -724
- package/src/transactions/eth-multisig/index.ts +0 -172
- package/src/transactions/index.ts +0 -85
- package/src/transactions/ltc/index.ts +0 -31
- package/src/transactions/matic/index.ts +0 -14
- package/src/transactions/matic-multisig/index.ts +0 -172
- package/src/transactions/op/index.ts +0 -14
- package/src/transactions/sol/index.ts +0 -306
- package/src/transactions/spl/index.ts +0 -192
- package/src/transactions/xrp/index.ts +0 -167
- package/src/types/derivation.ts +0 -34
- package/src/types/index.ts +0 -3
- package/src/types/message.ts +0 -15
- package/src/types/utils.ts +0 -1
- package/src/types/validation.ts +0 -4
- package/src/utils/bigint.ts +0 -238
- package/src/utils/index.ts +0 -188
- package/src/validation/arb/index.ts +0 -8
- package/src/validation/arc/index.ts +0 -8
- package/src/validation/base/index.ts +0 -8
- package/src/validation/bch/index.ts +0 -17
- package/src/validation/btc/index.ts +0 -17
- package/src/validation/doge/index.ts +0 -16
- package/src/validation/eth/index.ts +0 -29
- package/src/validation/index.ts +0 -45
- package/src/validation/ltc/index.ts +0 -16
- package/src/validation/matic/index.ts +0 -8
- package/src/validation/op/index.ts +0 -8
- package/src/validation/sol/index.ts +0 -34
- package/src/validation/xrp/index.ts +0 -50
- package/test/address.test.ts +0 -190
- package/test/bigint.test.ts +0 -373
- package/test/deriver.test.ts +0 -126
- package/test/transactions.test.ts +0 -2103
- package/test/utils.test.ts +0 -446
- package/test/validation.test.ts +0 -282
- package/tsconfig.json +0 -29
package/test/utils.test.ts
DELETED
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import * as xrpl from 'xrpl';
|
|
3
|
-
import * as utils from '../src/utils';
|
|
4
|
-
|
|
5
|
-
describe('Utils', function() {
|
|
6
|
-
describe('isHexString', function() {
|
|
7
|
-
it('should return true for valid prefixed hex string', function() {
|
|
8
|
-
const str = '0xabcdef123456';
|
|
9
|
-
const result = utils.isHexString(str);
|
|
10
|
-
expect(result).to.equal(true);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should return true for valid non-prefixed hex string', function() {
|
|
14
|
-
const str = 'abcdef123456';
|
|
15
|
-
const result = utils.isHexString(str);
|
|
16
|
-
expect(result).to.equal(true);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should return true for valid odd-length hex string', function() {
|
|
20
|
-
const str = 'abcdef12345';
|
|
21
|
-
const result = utils.isHexString(str);
|
|
22
|
-
expect(result).to.be.true;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should return false for invalid prefixed hex string', function() {
|
|
26
|
-
const str = '0xabc123g';
|
|
27
|
-
const result = utils.isHexString(str);
|
|
28
|
-
expect(result).to.equal(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should return false for string with 0x somewhere in the middle', function() {
|
|
32
|
-
const str = 'abc0x123';
|
|
33
|
-
const result = utils.isHexString(str);
|
|
34
|
-
expect(result).to.equal(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should return false for invalid non-prefixed hex string', function() {
|
|
38
|
-
const str = 'abc123g';
|
|
39
|
-
const result = utils.isHexString(str);
|
|
40
|
-
expect(result).to.equal(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should return false for empty string', function() {
|
|
44
|
-
const str = '';
|
|
45
|
-
const result = utils.isHexString(str);
|
|
46
|
-
expect(result).to.equal(false);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should return false for null/undefined input', function() {
|
|
50
|
-
expect(utils.isHexString(null)).to.equal(false);
|
|
51
|
-
expect(utils.isHexString(undefined as any)).to.equal(false);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should return false for non-string input', function() {
|
|
55
|
-
expect(utils.isHexString(123 as any)).to.equal(false);
|
|
56
|
-
expect(utils.isHexString({} as any)).to.equal(false);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should return false for octal string', function() {
|
|
60
|
-
const str = '0o01234567';
|
|
61
|
-
const result = utils.isHexString(str);
|
|
62
|
-
expect(result).to.equal(false);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('toHex', function() {
|
|
67
|
-
it('should convert number to hex string', function() {
|
|
68
|
-
const input = 255;
|
|
69
|
-
const result = utils.toHex(input);
|
|
70
|
-
expect(result).to.equal('0xff');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should convert bigint to hex string', function() {
|
|
74
|
-
const input = BigInt('12345678901234567890');
|
|
75
|
-
const result = utils.toHex(input);
|
|
76
|
-
expect(result).to.equal('0xab54a98ceb1f0ad2');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should convert number string to hex string', function() {
|
|
80
|
-
const input = '4095';
|
|
81
|
-
const result = utils.toHex(input);
|
|
82
|
-
expect(result).to.equal('0xfff');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should convert prefixed hex string to hex string', function() {
|
|
86
|
-
const input = '0xabcdef';
|
|
87
|
-
const result = utils.toHex(input);
|
|
88
|
-
expect(result).to.equal('0xabcdef');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should convert non-prefixed hex string to hex string', function() {
|
|
92
|
-
const input = 'abcdef';
|
|
93
|
-
const result = utils.toHex(input);
|
|
94
|
-
expect(result).to.equal('0xabcdef');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should convert octal string to hex string', function() {
|
|
98
|
-
const input = '0o17';
|
|
99
|
-
const result = utils.toHex(input);
|
|
100
|
-
expect(result).to.equal('0xf');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should throw error for invalid string input', function() {
|
|
104
|
-
const input = 'notanumber';
|
|
105
|
-
expect(() => utils.toHex(input)).to.throw('Invalid input for toHex: notanumber');
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should throw error for unsupported input type', function() {
|
|
109
|
-
const input = { key: 'value' };
|
|
110
|
-
expect(() => utils.toHex(input as any)).to.throw('Input for toHex must be a number, string (non-empty), or bigint. Got typeof object');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should throw error for empty string input', function() {
|
|
114
|
-
const input = '';
|
|
115
|
-
expect(() => utils.toHex(input)).to.throw('Input for toHex must be a number, string (non-empty), or bigint. Got ""');
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should throw error for null/undefined input', function() {
|
|
119
|
-
expect(() => utils.toHex(null as any)).to.throw('Input for toHex must be a number, string (non-empty), or bigint. Got null');
|
|
120
|
-
expect(() => utils.toHex(undefined as any)).to.throw('Input for toHex must be a number, string (non-empty), or bigint. Got undefined');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should throw error for NaN input', function() {
|
|
124
|
-
const input = NaN;
|
|
125
|
-
expect(() => utils.toHex(input)).to.throw('Invalid input for toHex: NaN');
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe('difference', function() {
|
|
130
|
-
it('should return items from first array that are not in second array', function() {
|
|
131
|
-
const arr1 = [1, 2, 3, 4];
|
|
132
|
-
const arr2 = [2, 4, 6];
|
|
133
|
-
const result = utils.difference(arr1, arr2);
|
|
134
|
-
expect(result).to.deep.equal([1, 3]);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('should consider different pointer references as a difference', function() {
|
|
138
|
-
const arr1 = [1, 2, 3, {}];
|
|
139
|
-
const arr2 = [1, 2, 3, {}];
|
|
140
|
-
const result = utils.difference(arr1, arr2);
|
|
141
|
-
expect(result).to.deep.equal([{}]);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('should consider same pointer references as no difference', function() {
|
|
145
|
-
const obj = {};
|
|
146
|
-
const arr1 = [1, 2, 3, obj];
|
|
147
|
-
const arr2 = [1, 2, 3, obj];
|
|
148
|
-
const result = utils.difference(arr1, arr2);
|
|
149
|
-
expect(result).to.deep.equal([]);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('should remove all matching duplicates from first array', function() {
|
|
153
|
-
const arr1 = ['a', 'b', 'b', 'c'];
|
|
154
|
-
const arr2 = ['b'];
|
|
155
|
-
const result = utils.difference(arr1, arr2);
|
|
156
|
-
expect(result).to.deep.equal(['a', 'c']);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('should return empty array when first array is null/undefined', function() {
|
|
160
|
-
expect(utils.difference(null as any, [1, 2])).to.deep.equal([]);
|
|
161
|
-
expect(utils.difference(undefined as any, [1, 2])).to.deep.equal([]);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('should return first array unchanged when second array is null/undefined', function() {
|
|
165
|
-
expect(utils.difference([1, 2, 3], null as any)).to.deep.equal([1, 2, 3]);
|
|
166
|
-
expect(utils.difference([1, 2, 3], undefined as any)).to.deep.equal([1, 2, 3]);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('should not mutate input arrays', function() {
|
|
170
|
-
const arr1 = [1, 2, 3];
|
|
171
|
-
const arr2 = [2];
|
|
172
|
-
const arr1Copy = [...arr1];
|
|
173
|
-
const arr2Copy = [...arr2];
|
|
174
|
-
|
|
175
|
-
utils.difference(arr1, arr2);
|
|
176
|
-
|
|
177
|
-
expect(arr1).to.deep.equal(arr1Copy);
|
|
178
|
-
expect(arr2).to.deep.equal(arr2Copy);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('isEqual', function() {
|
|
183
|
-
it('should return true for the same object reference', function() {
|
|
184
|
-
const obj = { a: 1, b: { c: 2 } };
|
|
185
|
-
expect(utils.isEqual(obj, obj)).to.equal(true);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should return false when one object is null', function() {
|
|
189
|
-
expect(utils.isEqual(null as any, { a: 1 })).to.equal(false);
|
|
190
|
-
expect(utils.isEqual({ a: 1 }, null as any)).to.equal(false);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should return false for different primitive values', function() {
|
|
194
|
-
const obj1 = { a: 1, b: 'hello' };
|
|
195
|
-
const obj2 = { a: 2, b: 'hello' };
|
|
196
|
-
expect(utils.isEqual(obj1, obj2)).to.equal(false);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('should return false when one object has additional keys', function() {
|
|
200
|
-
const obj1 = { a: 1 };
|
|
201
|
-
const obj2 = { a: 1, b: 2 };
|
|
202
|
-
expect(utils.isEqual(obj1, obj2)).to.equal(false);
|
|
203
|
-
expect(utils.isEqual(obj2, obj1)).to.equal(false);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('should return false for different nested object values', function() {
|
|
207
|
-
const obj1 = { a: { b: 1 } };
|
|
208
|
-
const obj2 = { a: { b: 2 } };
|
|
209
|
-
expect(utils.isEqual(obj1, obj2)).to.equal(false);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('should handle implicit vs explicit undefined values', function() {
|
|
213
|
-
const obj1 = {}; // obj1.a is implicitly undefined
|
|
214
|
-
const obj2 = { a: undefined }; // obj2.a is explicitly undefined
|
|
215
|
-
expect(utils.isEqual(obj1, obj2)).to.equal(false);
|
|
216
|
-
expect(utils.isEqual(obj2, obj1)).to.equal(false);
|
|
217
|
-
|
|
218
|
-
const obj3 = { a: undefined };
|
|
219
|
-
expect(utils.isEqual(obj2, obj3)).to.equal(true);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('should handle null vs undefined values correctly', function() {
|
|
223
|
-
const obj1 = { a: null };
|
|
224
|
-
const obj2 = { a: undefined };
|
|
225
|
-
expect(utils.isEqual(obj1, obj2)).to.equal(false);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('should prevent infinite recursion on circular references', function() {
|
|
229
|
-
const obj1: any = { a: 1 };
|
|
230
|
-
obj1.self = obj1;
|
|
231
|
-
|
|
232
|
-
const obj2: any = { a: 1 };
|
|
233
|
-
obj2.self = obj2;
|
|
234
|
-
|
|
235
|
-
expect(utils.isEqual(obj1, obj2)).to.equal(true);
|
|
236
|
-
|
|
237
|
-
obj2.extra = 'value';
|
|
238
|
-
expect(utils.isEqual(obj1, obj2)).to.equal(false);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('should handle large complex objects (stress test)', function() {
|
|
242
|
-
const buildLargeObject = () => {
|
|
243
|
-
const root: any = {
|
|
244
|
-
meta: {
|
|
245
|
-
chain: 'eth',
|
|
246
|
-
network: 'mainnet',
|
|
247
|
-
createdAt: '2026-05-06T00:00:00.000Z'
|
|
248
|
-
},
|
|
249
|
-
buckets: [],
|
|
250
|
-
matrix: [],
|
|
251
|
-
lookup: {}
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
for (let i = 0; i < 120; i++) {
|
|
255
|
-
const bucket = {
|
|
256
|
-
id: i,
|
|
257
|
-
name: `bucket-${i}`,
|
|
258
|
-
flags: {
|
|
259
|
-
active: i % 2 === 0,
|
|
260
|
-
archived: i % 5 === 0
|
|
261
|
-
},
|
|
262
|
-
balances: [],
|
|
263
|
-
tokens: []
|
|
264
|
-
} as any;
|
|
265
|
-
|
|
266
|
-
for (let j = 0; j < 20; j++) {
|
|
267
|
-
bucket.balances.push({
|
|
268
|
-
height: j,
|
|
269
|
-
satoshis: i * 100000 + j,
|
|
270
|
-
confirmations: (i + j) % 18
|
|
271
|
-
});
|
|
272
|
-
bucket.tokens.push({
|
|
273
|
-
symbol: `T${j}`,
|
|
274
|
-
amount: `${i * j}`,
|
|
275
|
-
decimals: 18,
|
|
276
|
-
tags: [`g${i % 4}`, `t${j % 7}`]
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
root.buckets.push(bucket);
|
|
281
|
-
root.lookup[`k-${i}`] = {
|
|
282
|
-
index: i,
|
|
283
|
-
ref: `bucket-${i}`,
|
|
284
|
-
checksums: [i * 3, i * 7, i * 11]
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
for (let r = 0; r < 40; r++) {
|
|
289
|
-
const row: number[] = [];
|
|
290
|
-
for (let c = 0; c < 40; c++) {
|
|
291
|
-
row.push(r * 40 + c);
|
|
292
|
-
}
|
|
293
|
-
root.matrix.push(row);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return root;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
const left = buildLargeObject();
|
|
300
|
-
const right = buildLargeObject();
|
|
301
|
-
|
|
302
|
-
expect(utils.isEqual(left, right)).to.equal(true);
|
|
303
|
-
|
|
304
|
-
right.buckets[119].tokens[19].tags[1] = 'mutated-tag';
|
|
305
|
-
expect(utils.isEqual(left, right)).to.equal(false);
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
describe('normalizeXrpFlag', function() {
|
|
310
|
-
it('should return the same flag name when passed a valid AccountSetTfFlags string', function() {
|
|
311
|
-
const result = utils.normalizeXrpFlag('tfRequireDestTag');
|
|
312
|
-
expect(result).to.equal('tfRequireDestTag');
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('should return the same flag name when passed a valid PaymentFlags string', function() {
|
|
316
|
-
const result = utils.normalizeXrpFlag('tfPartialPayment', xrpl.PaymentFlags);
|
|
317
|
-
expect(result).to.equal('tfPartialPayment');
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
it('should convert numeric AccountSetTfFlags value to flag name', function() {
|
|
321
|
-
// 65536 maps to 'tfRequireDestTag' in xrpl.AccountSetTfFlags
|
|
322
|
-
const result = utils.normalizeXrpFlag(65536);
|
|
323
|
-
expect(result).to.equal('tfRequireDestTag');
|
|
324
|
-
expect(result).to.be.a('string');
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it('should convert numeric PaymentFlags value to flag name', function() {
|
|
328
|
-
// 131072 maps to 'tfPartialPayment' in xrpl.PaymentFlags
|
|
329
|
-
const result = utils.normalizeXrpFlag(131072, xrpl.PaymentFlags);
|
|
330
|
-
expect(result).to.equal('tfPartialPayment');
|
|
331
|
-
expect(result).to.be.a('string');
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it('should throw error for invalid string flag', function() {
|
|
335
|
-
expect(() => utils.normalizeXrpFlag('invalidFlag')).to.throw(Error).with.property('message', 'Invalid XRP flag: invalidFlag. Flag is not in enum AccountSetTfFlags');
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it('should throw error for numeric string that is not a valid flag', function() {
|
|
339
|
-
expect(() => utils.normalizeXrpFlag('999')).to.throw(Error).with.property('message', 'Invalid XRP flag: 999. Flag is not in enum AccountSetTfFlags');
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
it('should throw error for invalid numeric flag', function() {
|
|
343
|
-
expect(() => utils.normalizeXrpFlag(99999)).to.throw(Error).with.property('message', 'Invalid XRP flag: 99999. Flag is not in enum AccountSetTfFlags');
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it('should be case-sensitive for string flags', function() {
|
|
347
|
-
expect(() => utils.normalizeXrpFlag('tfrequiredestag')).to.throw(Error).with.property('message', 'Invalid XRP flag: tfrequiredestag. Flag is not in enum AccountSetTfFlags');
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
it('should handle negative numbers', function() {
|
|
351
|
-
expect(() => utils.normalizeXrpFlag(-1)).to.throw(Error).with.property('message', 'Invalid XRP flag: -1. Flag is not in enum AccountSetTfFlags');
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it('should handle zero as input', function() {
|
|
355
|
-
expect(() => utils.normalizeXrpFlag(0)).to.throw(Error).with.property('message', 'Invalid XRP flag: 0. Flag is not in enum AccountSetTfFlags');
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
it('should throw if flag enum provided does not contain the flag', function() {
|
|
359
|
-
expect(() => utils.normalizeXrpFlag('tfRequireDestTag', xrpl.PaymentFlags)).to.throw(Error).with.property('message', 'Invalid XRP flag: tfRequireDestTag. Flag is not in enum PaymentFlags');
|
|
360
|
-
enum MyCustomFlags {
|
|
361
|
-
CustomFlag1 = 1,
|
|
362
|
-
CustomFlag2 = 2
|
|
363
|
-
};
|
|
364
|
-
expect(() => utils.normalizeXrpFlag('tfRequireDestTag', MyCustomFlags as any)).to.throw(Error).with.property('message', 'Invalid XRP flag: tfRequireDestTag. Flag is not in enum <unknown>');
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
it('should accept numeric string input that maps to a valid AccountSetTfFlags', function() {
|
|
368
|
-
// '65536' should map to 'tfRequireDestTag'
|
|
369
|
-
const result = utils.normalizeXrpFlag('65536');
|
|
370
|
-
expect(result).to.equal('tfRequireDestTag');
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it('should accept numeric string input that maps to PaymentFlags', function() {
|
|
374
|
-
// '131072' should map to 'tfPartialPayment'
|
|
375
|
-
const result = utils.normalizeXrpFlag('131072', xrpl.PaymentFlags);
|
|
376
|
-
expect(result).to.equal('tfPartialPayment');
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
it('should handle multiple AccountSetTfFlags values', function() {
|
|
380
|
-
// Test another flag: 262144 maps to 'tfRequireAuth'
|
|
381
|
-
const result = utils.normalizeXrpFlag(262144);
|
|
382
|
-
expect(result).to.equal('tfRequireAuth');
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
it('should handle multiple PaymentFlags values', function() {
|
|
386
|
-
// Test another flag: 262144 maps to 'tfLimitQuality'
|
|
387
|
-
const result = utils.normalizeXrpFlag(262144, xrpl.PaymentFlags);
|
|
388
|
-
expect(result).to.equal('tfLimitQuality');
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
it('should normalize a flag with a custom enum', function() {
|
|
392
|
-
enum CustomFlags {
|
|
393
|
-
CustomFlag1 = 1,
|
|
394
|
-
CustomFlag2 = 2,
|
|
395
|
-
CustomFlagX = 123
|
|
396
|
-
};
|
|
397
|
-
const result = utils.normalizeXrpFlag(123, CustomFlags as any);
|
|
398
|
-
expect(result).to.equal('CustomFlagX');
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
it('should throw when a valid PaymentFlags string is passed without the enum', function() {
|
|
402
|
-
// tfPartialPayment is valid for PaymentFlags, but without the enum the function
|
|
403
|
-
// falls back to AccountSetTfFlags, so this should throw
|
|
404
|
-
expect(() => utils.normalizeXrpFlag('tfPartialPayment')).to.throw(Error).with.property('message', 'Invalid XRP flag: tfPartialPayment. Flag is not in enum AccountSetTfFlags');
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
describe('tryParse', function() {
|
|
409
|
-
it('should parse valid JSON', function() {
|
|
410
|
-
const json = '{"key":"value"}';
|
|
411
|
-
const result = utils.tryParse(json);
|
|
412
|
-
expect(result).to.deep.equal({ key: 'value' });
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it('should parse JSON primitives and arrays', function() {
|
|
416
|
-
expect(utils.tryParse('0')).to.equal(0);
|
|
417
|
-
expect(utils.tryParse('false')).to.equal(false);
|
|
418
|
-
expect(utils.tryParse('null', 'fallback')).to.equal(null);
|
|
419
|
-
expect(utils.tryParse('[1,2]')).to.deep.equal([1, 2]);
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
it('should return fallback for invalid JSON', function() {
|
|
423
|
-
const json = '{"key": "value"';
|
|
424
|
-
const fallback = { fallback: true };
|
|
425
|
-
const result = utils.tryParse(json, fallback);
|
|
426
|
-
expect(result).to.deep.equal(fallback);
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
it('should return undefined for invalid JSON without a fallback', function() {
|
|
430
|
-
expect(utils.tryParse('{invalid')).to.equal(undefined);
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it('should return the object itself if already parsed', function() {
|
|
434
|
-
const obj = { key: 'value' };
|
|
435
|
-
const result = utils.tryParse(obj);
|
|
436
|
-
expect(result).to.equal(obj);
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
it('should return non-string inputs unchanged even when a fallback is provided', function() {
|
|
440
|
-
expect(utils.tryParse(0, 'fallback')).to.equal(0);
|
|
441
|
-
expect(utils.tryParse(false, 'fallback')).to.equal(false);
|
|
442
|
-
expect(utils.tryParse(null, 'fallback')).to.equal(null);
|
|
443
|
-
expect(utils.tryParse(undefined, 'fallback')).to.equal(undefined);
|
|
444
|
-
});
|
|
445
|
-
});
|
|
446
|
-
});
|