@psf/bch-js 4.22.0 → 5.2.1
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 +3 -3
- package/src/bch-js.js +0 -4
- package/src/psf-slp-indexer.js +81 -3
- package/src/slp/utils.js +1 -1
- package/src/transaction.js +11 -2
- package/src/utxo.js +211 -6
- package/test/integration/chains/bchn/psf-slp-indexer.integration.js +49 -2
- package/test/integration/chains/bchn/slp.js +229 -225
- package/test/integration/chains/bchn/utxo-integration.js +87 -1
- package/test/integration/slp.js +907 -901
- package/test/integration/transaction-integration.js +58 -55
- package/test/unit/fixtures/psf-slp-indexer-mock.js +37 -14
- package/test/unit/fixtures/utxo-mocks.js +184 -1
- package/test/unit/psf-slp-indexer.js +93 -12
- package/test/unit/transaction-unit.js +19 -8
- package/test/unit/utxo-unit.js +92 -7
- package/src/ninsight.js +0 -319
- package/test/unit/fixtures/ninsight-mock.js +0 -170
- package/test/unit/ninsight.js +0 -255
|
@@ -11,71 +11,74 @@ describe('#Transaction', () => {
|
|
|
11
11
|
if (process.env.IS_USING_FREE_TIER) await bchjs.Util.sleep(1000)
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (process.env.TESTSLP) {
|
|
15
|
+
describe('#getOld', () => {
|
|
16
|
+
it('should get details about a non-SLP transaction', async () => {
|
|
17
|
+
const txid =
|
|
18
|
+
'2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7'
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
21
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
// Assert that there are stanardized properties.
|
|
24
|
+
assert.property(result, 'txid')
|
|
25
|
+
assert.property(result, 'vin')
|
|
26
|
+
assert.property(result, 'vout')
|
|
27
|
+
assert.property(result.vout[0], 'value')
|
|
28
|
+
assert.property(result.vout[0].scriptPubKey, 'addresses')
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// Assert that added properties exist.
|
|
31
|
+
assert.property(result.vin[0], 'address')
|
|
32
|
+
assert.property(result.vin[0], 'value')
|
|
33
|
+
assert.property(result, 'isValidSLPTx')
|
|
34
|
+
assert.equal(result.isValidSLPTx, false)
|
|
35
|
+
})
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
it('should get details about a SLP transaction', async () => {
|
|
38
|
+
const txid =
|
|
39
|
+
'266844d53e46bbd7dd37134688dffea6e54d944edff27a0add63dd0908839bc1'
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
42
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
// Assert that there are stanardized properties.
|
|
45
|
+
assert.property(result, 'txid')
|
|
46
|
+
assert.property(result, 'vin')
|
|
47
|
+
assert.property(result, 'vout')
|
|
48
|
+
assert.property(result.vout[0], 'value')
|
|
49
|
+
assert.property(result.vout[1].scriptPubKey, 'addresses')
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
// Assert that added properties exist.
|
|
52
|
+
assert.property(result.vout[0], 'tokenQty')
|
|
53
|
+
assert.equal(result.vout[0].tokenQty, null)
|
|
54
|
+
assert.property(result.vin[0], 'address')
|
|
55
|
+
assert.property(result.vin[0], 'value')
|
|
56
|
+
assert.property(result.vin[0], 'tokenQty')
|
|
57
|
+
assert.property(result, 'isValidSLPTx')
|
|
58
|
+
assert.equal(result.isValidSLPTx, true)
|
|
59
|
+
})
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
// it('should get problematic transaction', async () => {
|
|
62
|
+
// const txid = 'a55515de32577e296c512840bcaabed5823bb773fb4f8fd8e5197cc96cbc54d1'
|
|
63
|
+
//
|
|
64
|
+
// const result = await bchjs.Transaction.get(txid)
|
|
65
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
66
|
+
// })
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
// TX a19f2f395a8b0e15b6202944c56834367d128f1e3630486a4756de53424a46fe has
|
|
69
|
+
// an input TXID (bd84bc1dd5ecd976165892306992401272f6bedeb37d7b2cdbf74fc4a55967a6)
|
|
70
|
+
// that is also a valid SLP tx, but is unrelated. Both TXs pass DAG validation,
|
|
71
|
+
// but for separate tokens.
|
|
72
|
+
it('should get problematic transaction', async () => {
|
|
73
|
+
const txid =
|
|
74
|
+
'a19f2f395a8b0e15b6202944c56834367d128f1e3630486a4756de53424a46fe'
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
const result = await bchjs.Transaction.getOld(txid)
|
|
77
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
// The token ID should equal the txid for this Vin.
|
|
80
|
+
assert.equal(result.vin[2].txid, result.vin[2].tokenId)
|
|
81
|
+
})
|
|
79
82
|
})
|
|
80
|
-
}
|
|
83
|
+
}
|
|
81
84
|
})
|
|
@@ -21,7 +21,8 @@ const tokenStats = {
|
|
|
21
21
|
totalMinted: '1',
|
|
22
22
|
txs: [
|
|
23
23
|
{
|
|
24
|
-
txid:
|
|
24
|
+
txid:
|
|
25
|
+
'13cad617d523c8eb4ab11fff19c010e0e0a4ea4360b58e0c8c955a45a146a669',
|
|
25
26
|
height: 722420,
|
|
26
27
|
type: 'GENESIS',
|
|
27
28
|
qty: '1'
|
|
@@ -39,11 +40,14 @@ const txData = {
|
|
|
39
40
|
locktime: 0,
|
|
40
41
|
vin: [
|
|
41
42
|
{
|
|
42
|
-
txid:
|
|
43
|
+
txid:
|
|
44
|
+
'8370db30d94761ab9a11b71ecd22541151bf6125c8c613f0f6fab8ab794565a7',
|
|
43
45
|
vout: 0,
|
|
44
46
|
scriptSig: {
|
|
45
|
-
asm:
|
|
46
|
-
|
|
47
|
+
asm:
|
|
48
|
+
'304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4[ALL|FORKID] 02791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851',
|
|
49
|
+
hex:
|
|
50
|
+
'47304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4412102791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851'
|
|
47
51
|
},
|
|
48
52
|
sequence: 4294967295,
|
|
49
53
|
address: 'bitcoincash:qpvsg9vl9a5mlf37a7n3yce6pktdctn73qwgaqm3wq',
|
|
@@ -58,16 +62,20 @@ const txData = {
|
|
|
58
62
|
value: 0,
|
|
59
63
|
n: 0,
|
|
60
64
|
scriptPubKey: {
|
|
61
|
-
asm:
|
|
62
|
-
|
|
65
|
+
asm:
|
|
66
|
+
'OP_RETURN 5262419 1 47454e45534953 54524f5554 54726f75742773207465737420746f6b656e 74726f757473626c6f672e636f6d 0 2 2 000000174876e800',
|
|
67
|
+
hex:
|
|
68
|
+
'6a04534c500001010747454e455349530554524f55541254726f75742773207465737420746f6b656e0e74726f757473626c6f672e636f6d4c000102010208000000174876e800',
|
|
63
69
|
type: 'nulldata'
|
|
64
70
|
},
|
|
65
71
|
tokenQtyStr: '0',
|
|
66
72
|
tokenQty: 0
|
|
67
73
|
}
|
|
68
74
|
],
|
|
69
|
-
hex:
|
|
70
|
-
|
|
75
|
+
hex:
|
|
76
|
+
'0200000001a7654579abb8faf6f013c6c82561bf51115422cd1eb7119aab6147d930db7083000000006a47304402207e9631c53dfc8a9a793d1916469628c6b7c5780c01c2f676d51ef21b0ba4926f022069feb471ec869a49f8d108d0aaba04e7cd36e60a7500109d86537f55698930d4412102791b19a39165dbd83403d6df268d44fd621da30581b0b6e5cb15a7101ed58851ffffffff040000000000000000476a04534c500001010747454e455349530554524f55541254726f75742773207465737420746f6b656e0e74726f757473626c6f672e636f6d4c000102010208000000174876e80022020000000000001976a914db4d39ceb7794ffe5d06855f249e1d3a7f1b024088ac22020000000000001976a914db4d39ceb7794ffe5d06855f249e1d3a7f1b024088accec20000000000001976a9145904159f2f69bfa63eefa712633a0d96dc2e7e8888ac00000000',
|
|
77
|
+
blockhash:
|
|
78
|
+
'0000000000000000009f65225a3e12e23a7ea057c869047e0f36563a1f410267',
|
|
71
79
|
confirmations: 97398,
|
|
72
80
|
time: 1581773131,
|
|
73
81
|
blocktime: 1581773131,
|
|
@@ -88,27 +96,32 @@ const balance = {
|
|
|
88
96
|
balance: {
|
|
89
97
|
utxos: [
|
|
90
98
|
{
|
|
91
|
-
txid:
|
|
99
|
+
txid:
|
|
100
|
+
'a24a6a4abf06fabd799ecea4f8fac6a9ff21e6a8dd6169a3c2ebc03665329db9',
|
|
92
101
|
vout: 1,
|
|
93
102
|
type: 'token',
|
|
94
103
|
qty: '1800',
|
|
95
|
-
tokenId:
|
|
104
|
+
tokenId:
|
|
105
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
|
96
106
|
address: 'bitcoincash:qrqy3kj7r822ps6628vwqq5k8hyjl6ey3y4eea2m4s'
|
|
97
107
|
}
|
|
98
108
|
],
|
|
99
109
|
txs: [
|
|
100
110
|
{
|
|
101
|
-
txid:
|
|
111
|
+
txid:
|
|
112
|
+
'078b2c48ed1db0d5d5996f2889b8d847a49200d0a781f6aa6752f740f312688f',
|
|
102
113
|
height: 717796
|
|
103
114
|
},
|
|
104
115
|
{
|
|
105
|
-
txid:
|
|
116
|
+
txid:
|
|
117
|
+
'a24a6a4abf06fabd799ecea4f8fac6a9ff21e6a8dd6169a3c2ebc03665329db9',
|
|
106
118
|
height: 717832
|
|
107
119
|
}
|
|
108
120
|
],
|
|
109
121
|
balances: [
|
|
110
122
|
{
|
|
111
|
-
tokenId:
|
|
123
|
+
tokenId:
|
|
124
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2',
|
|
112
125
|
qty: '1800'
|
|
113
126
|
}
|
|
114
127
|
]
|
|
@@ -122,9 +135,19 @@ const status = {
|
|
|
122
135
|
chainBlockHeight: 722679
|
|
123
136
|
}
|
|
124
137
|
}
|
|
138
|
+
|
|
139
|
+
const tokenData01 = {
|
|
140
|
+
tokenType: 1,
|
|
141
|
+
txType: 'MINT',
|
|
142
|
+
tokenId: 'dd21be4532d93661e8ffe16db6535af0fb8ee1344d1fef81a193e2b4cfa9fbc9',
|
|
143
|
+
mintBatonVout: 2,
|
|
144
|
+
qty: {}
|
|
145
|
+
}
|
|
146
|
+
|
|
125
147
|
module.exports = {
|
|
126
148
|
tokenStats,
|
|
127
149
|
txData,
|
|
128
150
|
balance,
|
|
129
|
-
status
|
|
151
|
+
status,
|
|
152
|
+
tokenData01
|
|
130
153
|
}
|
|
@@ -280,10 +280,193 @@ const electrumxUtxos = {
|
|
|
280
280
|
]
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
const fulcrumUtxos01 = {
|
|
284
|
+
success: true,
|
|
285
|
+
utxos: [
|
|
286
|
+
{
|
|
287
|
+
height: 674512,
|
|
288
|
+
tx_hash:
|
|
289
|
+
'acbb0d3ceef55aa3e5fafc19335ae4bf2f8edba3c0567547dfd402391db32230',
|
|
290
|
+
tx_pos: 1,
|
|
291
|
+
value: 546
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
height: 674512,
|
|
295
|
+
tx_hash:
|
|
296
|
+
'acbb0d3ceef55aa3e5fafc19335ae4bf2f8edba3c0567547dfd402391db32230',
|
|
297
|
+
tx_pos: 2,
|
|
298
|
+
value: 546
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
height: 674512,
|
|
302
|
+
tx_hash:
|
|
303
|
+
'eeddccc4d716f04157ea132ac93a48040fea34a6b57f3d8f0cccb7d1a731ab2b',
|
|
304
|
+
tx_pos: 1,
|
|
305
|
+
value: 546
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
height: 674513,
|
|
309
|
+
tx_hash:
|
|
310
|
+
'705bcc442e5a2770e560b528f52a47b1dcc9ce9ab6a8de9dfdefa55177f00d04',
|
|
311
|
+
tx_pos: 1,
|
|
312
|
+
value: 546
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
height: 674513,
|
|
316
|
+
tx_hash:
|
|
317
|
+
'705bcc442e5a2770e560b528f52a47b1dcc9ce9ab6a8de9dfdefa55177f00d04',
|
|
318
|
+
tx_pos: 2,
|
|
319
|
+
value: 546
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
height: 674513,
|
|
323
|
+
tx_hash:
|
|
324
|
+
'705bcc442e5a2770e560b528f52a47b1dcc9ce9ab6a8de9dfdefa55177f00d04',
|
|
325
|
+
tx_pos: 3,
|
|
326
|
+
value: 38134
|
|
327
|
+
}
|
|
328
|
+
]
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const psfSlpIndexerUtxos01 = {
|
|
332
|
+
balance: {
|
|
333
|
+
utxos: [
|
|
334
|
+
{
|
|
335
|
+
txid:
|
|
336
|
+
'acbb0d3ceef55aa3e5fafc19335ae4bf2f8edba3c0567547dfd402391db32230',
|
|
337
|
+
vout: 1,
|
|
338
|
+
type: 'token',
|
|
339
|
+
qty: '10000000000',
|
|
340
|
+
tokenId:
|
|
341
|
+
'acbb0d3ceef55aa3e5fafc19335ae4bf2f8edba3c0567547dfd402391db32230',
|
|
342
|
+
address: 'bitcoincash:qrm0c67wwqh0w7wjxua2gdt2xggnm90xws00a3lezv'
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
txid:
|
|
346
|
+
'acbb0d3ceef55aa3e5fafc19335ae4bf2f8edba3c0567547dfd402391db32230',
|
|
347
|
+
vout: 2,
|
|
348
|
+
type: 'baton',
|
|
349
|
+
tokenId:
|
|
350
|
+
'acbb0d3ceef55aa3e5fafc19335ae4bf2f8edba3c0567547dfd402391db32230',
|
|
351
|
+
address: 'bitcoincash:qrm0c67wwqh0w7wjxua2gdt2xggnm90xws00a3lezv'
|
|
352
|
+
}
|
|
353
|
+
],
|
|
354
|
+
txs: [
|
|
355
|
+
{
|
|
356
|
+
txid:
|
|
357
|
+
'acbb0d3ceef55aa3e5fafc19335ae4bf2f8edba3c0567547dfd402391db32230',
|
|
358
|
+
height: 674512
|
|
359
|
+
}
|
|
360
|
+
],
|
|
361
|
+
balances: [
|
|
362
|
+
{
|
|
363
|
+
tokenId:
|
|
364
|
+
'acbb0d3ceef55aa3e5fafc19335ae4bf2f8edba3c0567547dfd402391db32230',
|
|
365
|
+
qty: '10000000000'
|
|
366
|
+
}
|
|
367
|
+
]
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const tokenUtxos01 = [
|
|
372
|
+
{
|
|
373
|
+
txid: '384e1b8197e8de7d38f98317af2cf5f6bcb50007c46943b3498a6fab6e8aeb7c',
|
|
374
|
+
vout: 1,
|
|
375
|
+
type: 'token',
|
|
376
|
+
qty: '10000000',
|
|
377
|
+
tokenId: 'a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37',
|
|
378
|
+
address: 'bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m'
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
txid: '4fc789405d58ec612c69eba29aa56cf0c7f228349801114138424eb68df4479d',
|
|
382
|
+
vout: 1,
|
|
383
|
+
type: 'token',
|
|
384
|
+
qty: '100000000',
|
|
385
|
+
tokenId: 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb',
|
|
386
|
+
address: 'bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m'
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
txid: '42054bba4d69bfe7801ece0cffc754194b04239034fdfe9dbe321ef76c9a2d93',
|
|
390
|
+
vout: 5,
|
|
391
|
+
type: 'token',
|
|
392
|
+
qty: '4764',
|
|
393
|
+
tokenId: 'f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f',
|
|
394
|
+
address: 'bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m'
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
txid: '06938d0a0d15aa76524ffe61fe111d6d2b2ea9dd8dcd4c7c7744614ced370861',
|
|
398
|
+
vout: 5,
|
|
399
|
+
type: 'token',
|
|
400
|
+
qty: '238',
|
|
401
|
+
tokenId: 'f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f',
|
|
402
|
+
address: 'bitcoincash:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvg8nfhq4m'
|
|
403
|
+
}
|
|
404
|
+
]
|
|
405
|
+
|
|
406
|
+
const genesisData01 = {
|
|
407
|
+
tokenData: {
|
|
408
|
+
type: 1,
|
|
409
|
+
ticker: 'sleven',
|
|
410
|
+
name: 'sleven',
|
|
411
|
+
tokenId: 'a436c8e1b6bee3d701c6044d190f76f774be83c36de8d34a988af4489e86dd37',
|
|
412
|
+
documentUri: 'sleven',
|
|
413
|
+
documentHash: '',
|
|
414
|
+
decimals: 7,
|
|
415
|
+
mintBatonIsActive: false,
|
|
416
|
+
tokensInCirculationBN: '770059999999',
|
|
417
|
+
tokensInCirculationStr: '770059999999',
|
|
418
|
+
blockCreated: 555483,
|
|
419
|
+
totalBurned: '7711234568',
|
|
420
|
+
totalMinted: '777771234567'
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const genesisData02 = {
|
|
425
|
+
tokenData: {
|
|
426
|
+
type: 1,
|
|
427
|
+
ticker: 'NAKAMOTO',
|
|
428
|
+
name: 'NAKAMOTO',
|
|
429
|
+
tokenId: 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb',
|
|
430
|
+
documentUri: '',
|
|
431
|
+
documentHash: '',
|
|
432
|
+
decimals: 8,
|
|
433
|
+
mintBatonIsActive: false,
|
|
434
|
+
tokensInCirculationBN: '2099260968799900',
|
|
435
|
+
tokensInCirculationStr: '2099260968799900',
|
|
436
|
+
blockCreated: 555671,
|
|
437
|
+
totalBurned: '739031200100',
|
|
438
|
+
totalMinted: '2100000000000000'
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const genesisData03 = {
|
|
443
|
+
tokenData: {
|
|
444
|
+
type: 1,
|
|
445
|
+
ticker: 'AUDC',
|
|
446
|
+
name: 'AUD Coin',
|
|
447
|
+
tokenId: 'f05faf13a29c7f5e54ab921750aafb6afaa953db863bd2cf432e918661d4132f',
|
|
448
|
+
documentUri: 'audcoino@gmail.com',
|
|
449
|
+
documentHash: '',
|
|
450
|
+
decimals: 6,
|
|
451
|
+
mintBatonIsActive: false,
|
|
452
|
+
tokensInCirculationBN: '974791786216512742',
|
|
453
|
+
tokensInCirculationStr: '974791786216512742',
|
|
454
|
+
blockCreated: 603311,
|
|
455
|
+
totalBurned: '1025208213783487258',
|
|
456
|
+
totalMinted: '2000000000000000000'
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
283
460
|
module.exports = {
|
|
284
461
|
mockUtxoData,
|
|
285
462
|
mockHydratedUtxos,
|
|
286
463
|
mockTwoHydratedAddrs,
|
|
287
464
|
mockEveryUtxoType,
|
|
288
|
-
electrumxUtxos
|
|
465
|
+
electrumxUtxos,
|
|
466
|
+
fulcrumUtxos01,
|
|
467
|
+
psfSlpIndexerUtxos01,
|
|
468
|
+
tokenUtxos01,
|
|
469
|
+
genesisData01,
|
|
470
|
+
genesisData02,
|
|
471
|
+
genesisData03
|
|
289
472
|
}
|
|
@@ -38,6 +38,7 @@ describe('#PsfSlpIndexer', () => {
|
|
|
38
38
|
assert.include(err.message, 'test error')
|
|
39
39
|
}
|
|
40
40
|
})
|
|
41
|
+
|
|
41
42
|
it('should handle request error', async () => {
|
|
42
43
|
try {
|
|
43
44
|
// Stub the network call.
|
|
@@ -70,6 +71,7 @@ describe('#PsfSlpIndexer', () => {
|
|
|
70
71
|
assert.isArray(result.balance.txs)
|
|
71
72
|
assert.isArray(result.balance.balances)
|
|
72
73
|
})
|
|
74
|
+
|
|
73
75
|
it('should throw an error for improper input', async () => {
|
|
74
76
|
try {
|
|
75
77
|
const addr = 12345
|
|
@@ -81,6 +83,7 @@ describe('#PsfSlpIndexer', () => {
|
|
|
81
83
|
assert.include(err.message, 'Input address must be a string.')
|
|
82
84
|
}
|
|
83
85
|
})
|
|
86
|
+
|
|
84
87
|
it('should handle axios error', async () => {
|
|
85
88
|
try {
|
|
86
89
|
// Stub the network call.
|
|
@@ -95,6 +98,7 @@ describe('#PsfSlpIndexer', () => {
|
|
|
95
98
|
assert.include(err.message, 'test error')
|
|
96
99
|
}
|
|
97
100
|
})
|
|
101
|
+
|
|
98
102
|
it('should handle request error', async () => {
|
|
99
103
|
try {
|
|
100
104
|
// Stub the network call.
|
|
@@ -138,6 +142,7 @@ describe('#PsfSlpIndexer', () => {
|
|
|
138
142
|
assert.property(result.tokenData, 'totalMinted')
|
|
139
143
|
assert.property(result.tokenData, 'txs')
|
|
140
144
|
})
|
|
145
|
+
|
|
141
146
|
it('should throw an error for improper input', async () => {
|
|
142
147
|
try {
|
|
143
148
|
const tokenId = 12345
|
|
@@ -149,6 +154,7 @@ describe('#PsfSlpIndexer', () => {
|
|
|
149
154
|
assert.include(err.message, 'Input tokenId must be a string.')
|
|
150
155
|
}
|
|
151
156
|
})
|
|
157
|
+
|
|
152
158
|
it('should handle axios error', async () => {
|
|
153
159
|
try {
|
|
154
160
|
// Stub the network call.
|
|
@@ -163,6 +169,7 @@ describe('#PsfSlpIndexer', () => {
|
|
|
163
169
|
assert.include(err.message, 'test error')
|
|
164
170
|
}
|
|
165
171
|
})
|
|
172
|
+
|
|
166
173
|
it('should handle request error', async () => {
|
|
167
174
|
try {
|
|
168
175
|
// Stub the network call.
|
|
@@ -214,6 +221,7 @@ describe('#PsfSlpIndexer', () => {
|
|
|
214
221
|
assert.property(result.txData, 'tokenDocHash')
|
|
215
222
|
assert.property(result.txData, 'isValidSlp')
|
|
216
223
|
})
|
|
224
|
+
|
|
217
225
|
it('should throw an error for improper input', async () => {
|
|
218
226
|
try {
|
|
219
227
|
const txid = 12345
|
|
@@ -225,6 +233,7 @@ describe('#PsfSlpIndexer', () => {
|
|
|
225
233
|
assert.include(err.message, 'Input txid must be a string.')
|
|
226
234
|
}
|
|
227
235
|
})
|
|
236
|
+
|
|
228
237
|
it('should handle axios error', async () => {
|
|
229
238
|
try {
|
|
230
239
|
// Stub the network call.
|
|
@@ -239,20 +248,92 @@ describe('#PsfSlpIndexer', () => {
|
|
|
239
248
|
assert.include(err.message, 'test error')
|
|
240
249
|
}
|
|
241
250
|
})
|
|
242
|
-
it('should handle request error', async () => {
|
|
243
|
-
try {
|
|
244
|
-
// Stub the network call.
|
|
245
|
-
const testErr = new Error()
|
|
246
|
-
testErr.response = { data: { status: 422 } }
|
|
247
|
-
sandbox.stub(axios, 'post').throws(testErr)
|
|
248
251
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
} catch (err) {
|
|
254
|
-
assert.equal(err.status, 422)
|
|
252
|
+
it('should get tx from full node if not available from slp indexer', async () => {
|
|
253
|
+
// Stub the call to the SLP indexer.
|
|
254
|
+
const testErr = {
|
|
255
|
+
response: { data: { error: 'Key not found in database' } }
|
|
255
256
|
}
|
|
257
|
+
sandbox.stub(axios, 'post').rejects(testErr)
|
|
258
|
+
|
|
259
|
+
// Stub the call to the full node
|
|
260
|
+
sandbox.stub(bchjs.PsfSlpIndexer, 'checkBlacklist').resolves(false)
|
|
261
|
+
sandbox
|
|
262
|
+
.stub(bchjs.PsfSlpIndexer.rawTransaction, 'getTxData')
|
|
263
|
+
.resolves({ txid: 'fakeTxid' })
|
|
264
|
+
|
|
265
|
+
const txid =
|
|
266
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
267
|
+
const result = await bchjs.PsfSlpIndexer.tx(txid)
|
|
268
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
269
|
+
|
|
270
|
+
assert.equal(result.txData.txid, 'fakeTxid')
|
|
271
|
+
assert.equal(result.txData.isValidSlp, false)
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('should return isValidSlp=null for blacklisted token', async () => {
|
|
275
|
+
// Stub the call to the SLP indexer.
|
|
276
|
+
const testErr = {
|
|
277
|
+
response: { data: { error: 'Key not found in database' } }
|
|
278
|
+
}
|
|
279
|
+
sandbox.stub(axios, 'post').rejects(testErr)
|
|
280
|
+
|
|
281
|
+
// Stub the call to the full node
|
|
282
|
+
sandbox.stub(bchjs.PsfSlpIndexer, 'checkBlacklist').resolves(true)
|
|
283
|
+
sandbox
|
|
284
|
+
.stub(bchjs.PsfSlpIndexer.rawTransaction, 'getTxData')
|
|
285
|
+
.resolves({ txid: 'fakeTxid' })
|
|
286
|
+
|
|
287
|
+
const txid =
|
|
288
|
+
'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
|
|
289
|
+
const result = await bchjs.PsfSlpIndexer.tx(txid)
|
|
290
|
+
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
291
|
+
|
|
292
|
+
assert.equal(result.txData.txid, 'fakeTxid')
|
|
293
|
+
assert.equal(result.txData.isValidSlp, null)
|
|
294
|
+
})
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
describe('#checkBlacklist', () => {
|
|
298
|
+
it('should return true if txid contains token in blacklist', async () => {
|
|
299
|
+
// Mock dependencies
|
|
300
|
+
sandbox
|
|
301
|
+
.stub(bchjs.PsfSlpIndexer.slpUtils, 'decodeOpReturn')
|
|
302
|
+
.resolves(mockData.tokenData01)
|
|
303
|
+
|
|
304
|
+
const txid =
|
|
305
|
+
'302113c11b90edc5f36c073d2f8a75e1e0eaf59b56235491a843d3819cd6a85f'
|
|
306
|
+
|
|
307
|
+
const result = await bchjs.PsfSlpIndexer.checkBlacklist(txid)
|
|
308
|
+
// console.log('result: ', result)
|
|
309
|
+
|
|
310
|
+
assert.equal(result, true)
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
it('should return false if there is an error', async () => {
|
|
314
|
+
// Force an error
|
|
315
|
+
sandbox
|
|
316
|
+
.stub(bchjs.PsfSlpIndexer.slpUtils, 'decodeOpReturn')
|
|
317
|
+
.rejects(new Error('test error'))
|
|
318
|
+
|
|
319
|
+
const result = await bchjs.PsfSlpIndexer.checkBlacklist()
|
|
320
|
+
|
|
321
|
+
assert.equal(result, false)
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
it('should return false if there is no tokenId match', async () => {
|
|
325
|
+
// Mock dependencies
|
|
326
|
+
mockData.tokenData01.tokenId = 'abc123'
|
|
327
|
+
sandbox
|
|
328
|
+
.stub(bchjs.PsfSlpIndexer.slpUtils, 'decodeOpReturn')
|
|
329
|
+
.resolves(mockData.tokenData01)
|
|
330
|
+
|
|
331
|
+
const txid =
|
|
332
|
+
'302113c11b90edc5f36c073d2f8a75e1e0eaf59b56235491a843d3819cd6a85f'
|
|
333
|
+
|
|
334
|
+
const result = await bchjs.PsfSlpIndexer.checkBlacklist(txid)
|
|
335
|
+
|
|
336
|
+
assert.equal(result, false)
|
|
256
337
|
})
|
|
257
338
|
})
|
|
258
339
|
})
|