@psf/bch-js 6.1.0 → 6.2.0

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.
@@ -5,707 +5,23 @@
5
5
  // Public npm libraries
6
6
  const assert = require('chai').assert
7
7
  const sinon = require('sinon')
8
- const cloneDeep = require('lodash.clonedeep')
8
+ // const cloneDeep = require('lodash.clonedeep')
9
9
 
10
10
  const BCHJS = require('../../src/bch-js')
11
11
  const bchjs = new BCHJS()
12
12
 
13
- const mockDataLib = require('./fixtures/transaction-mock.js')
13
+ // const mockDataLib = require('./fixtures/transaction-mock.js')
14
14
 
15
15
  describe('#TransactionLib', () => {
16
- let sandbox, mockData
16
+ let sandbox
17
17
 
18
18
  beforeEach(() => {
19
19
  sandbox = sinon.createSandbox()
20
20
 
21
- mockData = cloneDeep(mockDataLib)
21
+ // mockData = cloneDeep(mockDataLib)
22
22
  })
23
23
  afterEach(() => sandbox.restore())
24
24
 
25
- describe('#getOld', () => {
26
- it('should throw an error if txid is not specified', async () => {
27
- try {
28
- await bchjs.Transaction.getOld()
29
-
30
- assert.fail('Unexpected code path!')
31
- } catch (err) {
32
- assert.include(
33
- err.message,
34
- 'Input to Transaction.get() must be a string containing a TXID.'
35
- )
36
- }
37
- })
38
-
39
- it('should get details about a non-SLP transaction', async () => {
40
- const txid =
41
- '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7'
42
-
43
- // Mock dependencies
44
- sandbox
45
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
46
- .resolves(mockData.nonSlpTxDetails)
47
-
48
- const result = await bchjs.Transaction.getOld(txid)
49
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
50
-
51
- // Assert that there are stanardized properties.
52
- assert.property(result, 'txid')
53
- assert.property(result, 'vin')
54
- assert.property(result, 'vout')
55
- assert.property(result.vout[0], 'value')
56
- assert.property(result.vout[0].scriptPubKey, 'addresses')
57
-
58
- // Assert that added properties exist.
59
- assert.property(result.vin[0], 'address')
60
- assert.property(result.vin[0], 'value')
61
- assert.property(result, 'isValidSLPTx')
62
- assert.equal(result.isValidSLPTx, false)
63
- })
64
-
65
- it('should get details about a SLP transaction', async () => {
66
- // Mock dependencies
67
- sandbox
68
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
69
- .resolves(mockData.slpTxDetails)
70
- sandbox
71
- .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
72
- .onCall(0)
73
- .resolves(mockData.mockOpReturnData01)
74
- .onCall(1)
75
- .resolves(mockData.mockOpReturnData02)
76
- .onCall(2)
77
- .resolves(mockData.mockOpReturnData03)
78
- .onCall(3)
79
- .rejects(new Error('No OP_RETURN'))
80
- sandbox
81
- .stub(bchjs.Transaction.slpUtils, 'waterfallValidateTxid')
82
- .resolves(true)
83
-
84
- const txid =
85
- '266844d53e46bbd7dd37134688dffea6e54d944edff27a0add63dd0908839bc1'
86
-
87
- const result = await bchjs.Transaction.getOld(txid)
88
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
89
-
90
- // Assert that there are stanardized properties.
91
- assert.property(result, 'txid')
92
- assert.property(result, 'vin')
93
- assert.property(result, 'vout')
94
- assert.property(result.vout[0], 'value')
95
- assert.property(result.vout[1].scriptPubKey, 'addresses')
96
-
97
- // Assert that added properties exist.
98
- assert.property(result.vout[0], 'tokenQty')
99
- assert.equal(result.vout[0].tokenQty, null)
100
- assert.property(result.vin[0], 'address')
101
- assert.property(result.vin[0], 'value')
102
- assert.property(result.vin[0], 'tokenQty')
103
- assert.property(result, 'isValidSLPTx')
104
- assert.equal(result.isValidSLPTx, true)
105
- })
106
-
107
- it('should catch and throw error on network error', async () => {
108
- try {
109
- const txid =
110
- '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7'
111
-
112
- // Force an error
113
- sandbox
114
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
115
- .rejects(new Error('test error'))
116
-
117
- await bchjs.Transaction.getOld(txid)
118
-
119
- assert.fail('Unexpected code path')
120
- } catch (err) {
121
- assert.include(err.message, 'test error')
122
- }
123
- })
124
-
125
- // This test case was created in response to a bug. When the input TX
126
- // was a Genesis SLP transaction, the inputs of the transaction were not
127
- // being hydrated properly.
128
- it('should get input details when input is a genesis tx', async () => {
129
- // Mock dependencies
130
- sandbox
131
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
132
- .resolves(mockData.genesisTestInputTx)
133
- sandbox
134
- .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
135
- .onCall(0)
136
- .resolves(mockData.genesisTestOpReturnData01)
137
- .onCall(1)
138
- .resolves(mockData.genesisTestOpReturnData02)
139
- .onCall(2)
140
- .resolves(mockData.genesisTestOpReturnData02)
141
- .onCall(3)
142
- .resolves(mockData.genesisTestOpReturnData02)
143
- sandbox
144
- .stub(bchjs.Transaction.slpUtils, 'waterfallValidateTxid')
145
- .resolves(true)
146
-
147
- const txid =
148
- '874306bda204d3a5dd15e03ea5732cccdca4c33a52df35162cdd64e30ea7f04e'
149
-
150
- const result = await bchjs.Transaction.getOld(txid)
151
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
152
-
153
- // Assert that there are stanardized properties.
154
- assert.property(result, 'txid')
155
- assert.property(result, 'vin')
156
- assert.property(result, 'vout')
157
- assert.property(result.vout[0], 'value')
158
- assert.property(result.vout[1].scriptPubKey, 'addresses')
159
-
160
- // Assert that added properties exist.
161
- assert.property(result.vout[0], 'tokenQty')
162
- assert.equal(result.vout[0].tokenQty, null)
163
- assert.property(result.vin[0], 'address')
164
- assert.property(result.vin[0], 'value')
165
- assert.property(result.vin[0], 'tokenQty')
166
- assert.property(result, 'isValidSLPTx')
167
- assert.equal(result.isValidSLPTx, true)
168
-
169
- // Assert inputs values unique to a Genesis input have the proper values.
170
- assert.equal(result.vin[0].tokenQty, 10000000)
171
- assert.equal(result.vin[1].tokenQty, null)
172
- })
173
-
174
- it('should get input details when input is a mint tx', async () => {
175
- // Mock dependencies
176
- sandbox
177
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
178
- .resolves(mockData.mintTestInputTx)
179
- sandbox
180
- .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
181
- .onCall(0)
182
- .resolves(mockData.mintTestOpReturnData01)
183
- .onCall(1)
184
- .resolves(mockData.mintTestOpReturnData02)
185
- .onCall(2)
186
- .resolves(mockData.mintTestOpReturnData02)
187
- .onCall(3)
188
- .resolves(mockData.mintTestOpReturnData03)
189
- .onCall(4)
190
- .resolves(mockData.mintTestOpReturnData03)
191
- sandbox
192
- .stub(bchjs.Transaction.slpUtils, 'waterfallValidateTxid')
193
- .resolves(true)
194
-
195
- const txid =
196
- '4640a734063ea79fa587a3cac38a70a2f6f3db0011e23514024185982110d0fa'
197
-
198
- const result = await bchjs.Transaction.getOld(txid)
199
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
200
-
201
- // Assert that there are stanardized properties.
202
- assert.property(result, 'txid')
203
- assert.property(result, 'vin')
204
- assert.property(result, 'vout')
205
- assert.property(result.vout[0], 'value')
206
- assert.property(result.vout[1].scriptPubKey, 'addresses')
207
-
208
- // Assert that added properties exist.
209
- assert.property(result.vout[0], 'tokenQty')
210
- assert.equal(result.vout[0].tokenQty, null)
211
- assert.property(result.vin[0], 'address')
212
- assert.property(result.vin[0], 'value')
213
- assert.property(result.vin[0], 'tokenQty')
214
- assert.property(result, 'isValidSLPTx')
215
- assert.equal(result.isValidSLPTx, true)
216
-
217
- // Assert inputs values unique to a Mint input have the proper values.
218
- assert.equal(result.vin[0].tokenQty, 43545.34534)
219
- assert.equal(result.vin[1].tokenQty, 2.34123)
220
- assert.equal(result.vin[2].tokenQty, null)
221
- })
222
-
223
- // This test case was generated from the problematic transaction that
224
- // used inputs in a 'non-standard' way.
225
- it('should correctly assign quantities to mixed mint inputs', async () => {
226
- // Mock dependencies
227
- sandbox
228
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
229
- .resolves(mockData.sendTestInputTx01)
230
- sandbox
231
- .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
232
- .onCall(0)
233
- .resolves(mockData.sendTestOpReturnData01)
234
- .onCall(1)
235
- .resolves(mockData.sendTestOpReturnData02)
236
- .onCall(2)
237
- .resolves(mockData.sendTestOpReturnData03)
238
- .onCall(3)
239
- .resolves(mockData.sendTestOpReturnData03)
240
- .onCall(4)
241
- .resolves(mockData.sendTestOpReturnData04)
242
- sandbox
243
- .stub(bchjs.Transaction.slpUtils, 'waterfallValidateTxid')
244
- .resolves(true)
245
-
246
- const txid =
247
- '6bc111fbf5b118021d68355ca19a0e77fa358dd931f284b2550f79a51ab4792a'
248
-
249
- const result = await bchjs.Transaction.getOld(txid)
250
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
251
-
252
- // Assert that there are stanardized properties.
253
- assert.property(result, 'txid')
254
- assert.property(result, 'vin')
255
- assert.property(result, 'vout')
256
- assert.property(result.vout[0], 'value')
257
- assert.property(result.vout[1].scriptPubKey, 'addresses')
258
-
259
- // Assert that added properties exist.
260
- assert.property(result.vout[0], 'tokenQty')
261
- assert.equal(result.vout[0].tokenQty, null)
262
- assert.property(result.vin[0], 'address')
263
- assert.property(result.vin[0], 'value')
264
- assert.property(result.vin[0], 'tokenQty')
265
- assert.property(result, 'isValidSLPTx')
266
- assert.equal(result.isValidSLPTx, true)
267
-
268
- // Assert inputs values unique to a Mint input have the proper values.
269
- assert.equal(result.vin[0].tokenQty, 100000000)
270
- assert.equal(result.vin[1].tokenQty, null)
271
- assert.equal(result.vin[2].tokenQty, 99000000)
272
- })
273
- })
274
-
275
- describe('#get3', () => {
276
- it('should throw an error if txid is not specified', async () => {
277
- try {
278
- await bchjs.Transaction.get3()
279
-
280
- assert.fail('Unexpected code path!')
281
- } catch (err) {
282
- assert.include(
283
- err.message,
284
- 'Input to Transaction.get() must be a string containing a TXID.'
285
- )
286
- }
287
- })
288
-
289
- it('should get details about a non-SLP transaction', async () => {
290
- const txid =
291
- '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7'
292
-
293
- // Mock dependencies
294
- sandbox
295
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
296
- .resolves(mockData.nonSlpTxDetails)
297
- sandbox
298
- .stub(bchjs.Transaction.blockchain, 'getBlockHeader')
299
- .resolves({ height: 602405 })
300
- sandbox.stub(bchjs.Transaction, 'getTokenInfo').resolves(false)
301
-
302
- const result = await bchjs.Transaction.get3(txid)
303
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
304
-
305
- // Assert that there are stanardized properties.
306
- assert.property(result, 'txid')
307
- assert.property(result, 'vin')
308
- assert.property(result, 'vout')
309
- assert.property(result.vout[0], 'value')
310
- assert.property(result.vout[0].scriptPubKey, 'addresses')
311
-
312
- // Assert that added properties exist.
313
- assert.property(result.vin[0], 'address')
314
- assert.property(result.vin[0], 'value')
315
-
316
- // Assert blockheight is added
317
- assert.equal(result.blockheight, 602405)
318
- assert.equal(result.isSlpTx, false)
319
- })
320
-
321
- it('should get details about a SLP SEND tx with SEND input', async () => {
322
- // Mock dependencies
323
- sandbox
324
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
325
- .resolves(mockData.slpTxDetails)
326
- sandbox
327
- .stub(bchjs.Transaction.blockchain, 'getBlockHeader')
328
- .resolves({ height: 603424 })
329
- sandbox
330
- .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
331
- .onCall(0)
332
- .resolves(mockData.mockOpReturnData01)
333
- .onCall(1)
334
- .resolves(mockData.mockOpReturnData02)
335
- .onCall(2)
336
- .resolves(mockData.mockOpReturnData03)
337
- .onCall(3)
338
- .rejects(new Error('No OP_RETURN'))
339
-
340
- const txid =
341
- '266844d53e46bbd7dd37134688dffea6e54d944edff27a0add63dd0908839bc1'
342
-
343
- const result = await bchjs.Transaction.get3(txid)
344
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
345
-
346
- // Assert that there are stanardized properties.
347
- assert.property(result, 'txid')
348
- assert.property(result, 'vin')
349
- assert.property(result, 'vout')
350
- assert.property(result.vout[0], 'value')
351
- assert.property(result.vout[1].scriptPubKey, 'addresses')
352
-
353
- // Assert outputs have expected properties
354
- assert.equal(result.vout[0].tokenQty, null)
355
- assert.equal(result.vout[0].tokenQtyStr, null)
356
- assert.equal(result.vout[1].tokenQty, 1)
357
- assert.equal(result.vout[1].tokenQtyStr, '1')
358
- assert.equal(result.vout[2].tokenQty, 998833)
359
- assert.equal(result.vout[2].tokenQtyStr, '998833')
360
- assert.equal(result.vout[3].tokenQty, null)
361
- assert.equal(result.vout[3].tokenQtyStr, null)
362
-
363
- // Assert that inputs have expected properties
364
- assert.equal(result.vin[0].tokenQtyStr, '998834')
365
- assert.equal(result.vin[0].tokenQty, 998834)
366
- assert.equal(
367
- result.vin[0].tokenId,
368
- '497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7'
369
- )
370
- assert.equal(result.vin[1].tokenQtyStr, '0')
371
- assert.equal(result.vin[1].tokenQty, 0)
372
- assert.equal(result.vin[1].tokenId, null)
373
-
374
- // Assert blockheight is added
375
- assert.equal(result.blockheight, 603424)
376
- assert.equal(result.isSlpTx, true)
377
- })
378
-
379
- it('should catch and throw error on network error', async () => {
380
- try {
381
- const txid =
382
- '2b37bdb3b63dd0bca720437754a36671431a950e684b64c44ea910ea9d5297c7'
383
-
384
- // Force an error
385
- sandbox
386
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
387
- .rejects(new Error('test error'))
388
-
389
- await bchjs.Transaction.get3(txid)
390
-
391
- assert.fail('Unexpected code path')
392
- } catch (err) {
393
- assert.include(err.message, 'test error')
394
- }
395
- })
396
-
397
- // This test case was created in response to a bug. When the input TX
398
- // was a Genesis SLP transaction, the inputs of the transaction were not
399
- // being hydrated properly.
400
- it('should get details about a SLP SEND tx with GENSIS input', async () => {
401
- // Mock dependencies
402
- sandbox
403
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
404
- .resolves(mockData.genesisTestInputTx)
405
- sandbox
406
- .stub(bchjs.Transaction.blockchain, 'getBlockHeader')
407
- .resolves({ height: 543409 })
408
- sandbox
409
- .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
410
- .onCall(0)
411
- .resolves(mockData.genesisTestOpReturnData01)
412
- .onCall(1)
413
- .resolves(mockData.genesisTestOpReturnData02)
414
- .onCall(2)
415
- .resolves(mockData.genesisTestOpReturnData02)
416
- .onCall(3)
417
- .resolves(mockData.genesisTestOpReturnData02)
418
-
419
- const txid =
420
- '874306bda204d3a5dd15e03ea5732cccdca4c33a52df35162cdd64e30ea7f04e'
421
-
422
- const result = await bchjs.Transaction.get3(txid)
423
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
424
-
425
- // Assert that there are stanardized properties.
426
- assert.property(result, 'txid')
427
- assert.property(result, 'vin')
428
- assert.property(result, 'vout')
429
- assert.property(result.vout[0], 'value')
430
- assert.property(result.vout[1].scriptPubKey, 'addresses')
431
-
432
- // Assert outputs have expected properties and values
433
- assert.equal(result.vout[0].tokenQty, null)
434
- assert.equal(result.vout[0].tokenQtyStr, null)
435
- assert.equal(result.vout[1].tokenQty, 5000000)
436
- assert.equal(result.vout[1].tokenQtyStr, '5000000')
437
- assert.equal(result.vout[2].tokenQty, 5000000)
438
- assert.equal(result.vout[2].tokenQtyStr, '5000000')
439
- assert.equal(result.vout[3].tokenQty, null)
440
- assert.equal(result.vout[3].tokenQtyStr, null)
441
-
442
- // Assert inputs have expected properties and values
443
- assert.equal(result.vin[0].tokenQty, 10000000)
444
- assert.equal(result.vin[0].tokenQtyStr, '10000000')
445
- assert.equal(
446
- result.vin[0].tokenId,
447
- '323a1e35ae0b356316093d20f2d9fbc995d19314b5c0148b78dc8d9c0dab9d35'
448
- )
449
- assert.equal(result.vin[1].tokenQty, 0)
450
- assert.equal(result.vin[1].tokenQtyStr, '0')
451
- assert.equal(result.vin[1].tokenId, null)
452
-
453
- // Assert blockheight is added
454
- assert.equal(result.blockheight, 543409)
455
- assert.equal(result.isSlpTx, true)
456
- })
457
-
458
- it('should get details about a SLP SEND tx with MINT (and GENESIS) input', async () => {
459
- // Mock dependencies
460
- sandbox
461
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
462
- .resolves(mockData.mintTestInputTx)
463
- sandbox
464
- .stub(bchjs.Transaction.blockchain, 'getBlockHeader')
465
- .resolves({ height: 543614 })
466
- sandbox
467
- .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
468
- .onCall(0)
469
- .resolves(mockData.mintTestOpReturnData01)
470
- .onCall(1)
471
- .resolves(mockData.mintTestOpReturnData02)
472
- .onCall(2)
473
- .resolves(mockData.mintTestOpReturnData02)
474
- .onCall(3)
475
- .resolves(mockData.mintTestOpReturnData03)
476
- .onCall(4)
477
- .resolves(mockData.mintTestOpReturnData03)
478
-
479
- const txid =
480
- '4640a734063ea79fa587a3cac38a70a2f6f3db0011e23514024185982110d0fa'
481
-
482
- const result = await bchjs.Transaction.get3(txid)
483
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
484
-
485
- // Assert that there are stanardized properties.
486
- assert.property(result, 'txid')
487
- assert.property(result, 'vin')
488
- assert.property(result, 'vout')
489
- assert.property(result.vout[0], 'value')
490
- assert.property(result.vout[1].scriptPubKey, 'addresses')
491
-
492
- // Assert expected output properties and values exist.
493
- assert.equal(result.vout[0].tokenQty, null)
494
- assert.equal(result.vout[1].tokenQty, 43547.68657)
495
- assert.equal(result.vout[1].tokenQtyStr, '43547.68657')
496
- assert.equal(result.vout[2].tokenQty, null)
497
-
498
- // Assert expected input properties and values exist.
499
- assert.equal(result.vin[0].tokenQty, 43545.34534)
500
- assert.equal(result.vin[0].tokenQtyStr, '43545.34534')
501
- assert.equal(
502
- result.vin[0].tokenId,
503
- '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8'
504
- )
505
- assert.equal(result.vin[1].tokenQty, 2.34123)
506
- assert.equal(result.vin[1].tokenQtyStr, '2.34123')
507
- assert.equal(
508
- result.vin[1].tokenId,
509
- '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8'
510
- )
511
- assert.equal(result.vin[2].tokenQty, 0)
512
- assert.equal(result.vin[2].tokenQtyStr, '0')
513
- assert.equal(result.vin[2].tokenId, null)
514
-
515
- // Assert blockheight is added
516
- assert.equal(result.blockheight, 543614)
517
- assert.equal(result.isSlpTx, true)
518
- })
519
-
520
- // This test case was generated from the problematic transaction that
521
- // used inputs in a 'non-standard' way.
522
- it('should get details about a SLP SEND tx with MINT (and SEND) input', async () => {
523
- // Mock dependencies
524
- sandbox
525
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
526
- .resolves(mockData.sendTestInputTx01)
527
- sandbox
528
- .stub(bchjs.Transaction.blockchain, 'getBlockHeader')
529
- .resolves({ height: 543957 })
530
- sandbox
531
- .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
532
- .onCall(0)
533
- .resolves(mockData.sendTestOpReturnData01)
534
- .onCall(1)
535
- .resolves(mockData.sendTestOpReturnData02)
536
- .onCall(2)
537
- .resolves(mockData.sendTestOpReturnData03)
538
- .onCall(3)
539
- .resolves(mockData.sendTestOpReturnData03)
540
- .onCall(4)
541
- .resolves(mockData.sendTestOpReturnData04)
542
-
543
- const txid =
544
- '6bc111fbf5b118021d68355ca19a0e77fa358dd931f284b2550f79a51ab4792a'
545
-
546
- const result = await bchjs.Transaction.get3(txid)
547
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
548
-
549
- // Assert that there are stanardized properties.
550
- assert.property(result, 'txid')
551
- assert.property(result, 'vin')
552
- assert.property(result, 'vout')
553
- assert.property(result.vout[0], 'value')
554
- assert.property(result.vout[1].scriptPubKey, 'addresses')
555
-
556
- // Assert the outputs have expected properties and values.
557
- assert.equal(result.vout[0].tokenQty, null)
558
- assert.equal(result.vout[1].tokenQty, 1000000)
559
- assert.equal(result.vout[1].tokenQtyStr, '1000000')
560
- assert.equal(result.vout[2].tokenQty, 198000000)
561
- assert.equal(result.vout[2].tokenQtyStr, '198000000')
562
- assert.equal(result.vout[3].tokenQty, null)
563
-
564
- // Assert the inputs have expected properties and values.
565
- assert.equal(result.vin[0].tokenQty, 100000000)
566
- assert.equal(result.vin[0].tokenQtyStr, '100000000')
567
- assert.equal(
568
- result.vin[0].tokenId,
569
- '550d19eb820e616a54b8a73372c4420b5a0567d8dc00f613b71c5234dc884b35'
570
- )
571
- assert.equal(result.vin[1].tokenQty, 0)
572
- assert.equal(result.vin[1].tokenQtyStr, 0)
573
- assert.equal(result.vin[1].tokenId, null)
574
- assert.equal(result.vin[2].tokenQty, 99000000)
575
- assert.equal(result.vin[2].tokenQtyStr, '99000000')
576
- assert.equal(
577
- result.vin[2].tokenId,
578
- '550d19eb820e616a54b8a73372c4420b5a0567d8dc00f613b71c5234dc884b35'
579
- )
580
-
581
- // Assert blockheight is added
582
- assert.equal(result.blockheight, 543957)
583
- assert.equal(result.isSlpTx, true)
584
- })
585
-
586
- // This was a problematic TX
587
- it('should process MINT TX with GENESIS input', async () => {
588
- // Mock dependencies
589
- sandbox
590
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
591
- .resolves(mockData.mintTestInputTx02)
592
- sandbox
593
- .stub(bchjs.Transaction.blockchain, 'getBlockHeader')
594
- .resolves({ height: 543614 })
595
- sandbox
596
- .stub(bchjs.Transaction.slpUtils, 'decodeOpReturn')
597
- .onCall(0)
598
- .resolves(mockData.mintTestOpReturnData04)
599
- .onCall(1)
600
- .resolves(mockData.mintTestOpReturnData05)
601
- .onCall(2)
602
- .resolves(mockData.mintTestOpReturnData05)
603
- .onCall(3)
604
- .resolves(mockData.mintTestOpReturnData05)
605
- .onCall(4)
606
- .resolves(mockData.mintTestOpReturnData05)
607
- .onCall(5)
608
- .resolves(mockData.mintTestOpReturnData05)
609
-
610
- const txid =
611
- 'ee9d3cf5153599c134147e3fac9844c68e216843f4452a1ce15a29452af6db34'
612
-
613
- const result = await bchjs.Transaction.get3(txid)
614
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
615
-
616
- // Assert that there are stanardized properties.
617
- assert.property(result, 'txid')
618
- assert.property(result, 'vin')
619
- assert.property(result, 'vout')
620
- assert.property(result.vout[0], 'value')
621
- assert.property(result.vout[1].scriptPubKey, 'addresses')
622
-
623
- // Assert outputs have expected properties and values
624
- assert.equal(result.vout[0].tokenQty, 0)
625
- assert.equal(result.vout[0].tokenQty, '0')
626
- assert.equal(result.vout[1].tokenQty, 2.34123)
627
- assert.equal(result.vout[1].tokenQty, '2.34123')
628
- assert.equal(result.vout[2].tokenQty, 0)
629
- assert.equal(result.vout[2].tokenQty, '0')
630
- assert.equal(result.vout[2].isMintBaton, true)
631
- assert.equal(result.vout[3].tokenQty, 0)
632
- assert.equal(result.vout[3].tokenQty, '0')
633
-
634
- // Assert inputs have expected properties and values
635
- assert.equal(result.vin[0].tokenQty, 0)
636
- assert.equal(result.vin[0].tokenQtyStr, '0')
637
- assert.equal(result.vin[0].tokenId, null)
638
- assert.equal(result.vin[1].tokenQty, 0)
639
- assert.equal(result.vin[1].tokenQtyStr, '0')
640
- assert.equal(
641
- result.vin[1].tokenId,
642
- '938cc18e618967d787897bbc64b9a8d201b94ec7c69b1a9949eab0433ba5cdf8'
643
- )
644
- assert.equal(result.vin[1].isMintBaton, true)
645
-
646
- // Assert added TX data exists.
647
- assert.equal(result.blockheight, 543614)
648
- assert.equal(result.isSlpTx, true)
649
- })
650
-
651
- // It should process a GENESIS tx
652
- it('should process a GENESIS tx', async () => {
653
- // Mock dependencies
654
- sandbox
655
- .stub(bchjs.Transaction.rawTransaction, 'getTxData')
656
- .resolves(mockData.genesisTestInputTx02)
657
- sandbox
658
- .stub(bchjs.Transaction.blockchain, 'getBlockHeader')
659
- .resolves({ height: 571212 })
660
- sandbox
661
- .stub(bchjs.Transaction, 'getTokenInfo')
662
- .onCall(0)
663
- .resolves(mockData.genesisTestOpReturn03)
664
- .onCall(1)
665
- .resolves(mockData.genesisTestOpReturn03)
666
- .onCall(2)
667
- .resolves(false)
668
- .onCall(3)
669
- .resolves(false)
670
- .onCall(4)
671
- .resolves(false)
672
-
673
- const txid =
674
- '4de69e374a8ed21cbddd47f2338cc0f479dc58daa2bbe11cd604ca488eca0ddf'
675
-
676
- const result = await bchjs.Transaction.get3(txid)
677
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
678
-
679
- // Assert that there are stanardized properties.
680
- assert.property(result, 'txid')
681
- assert.property(result, 'vin')
682
- assert.property(result, 'vout')
683
- assert.property(result.vout[0], 'value')
684
- assert.property(result.vout[1].scriptPubKey, 'addresses')
685
-
686
- // Assert output have expected properties and values
687
- assert.equal(result.vout[0].tokenQty, 0)
688
- assert.equal(result.vout[0].tokenQtyStr, '0')
689
- assert.equal(result.vout[0].isMintBaton, true)
690
- assert.equal(result.vout[1].tokenQty, 1000000000)
691
- assert.equal(result.vout[1].tokenQtyStr, '1000000000')
692
- assert.equal(result.vout[2].tokenQty, 0)
693
- assert.equal(result.vout[2].tokenQtyStr, '0')
694
-
695
- // Assert input have expected properties and values
696
- assert.equal(result.vin[0].tokenQty, 0)
697
- assert.equal(result.vin[0].tokenQtyStr, '0')
698
- assert.equal(result.vin[0].tokenId, null)
699
- assert.equal(result.vin[1].tokenQty, 0)
700
- assert.equal(result.vin[1].tokenQtyStr, '0')
701
- assert.equal(result.vin[1].tokenId, null)
702
-
703
- // Assert added TX data exists.
704
- assert.equal(result.blockheight, 571212)
705
- assert.equal(result.isSlpTx, true)
706
- })
707
- })
708
-
709
25
  describe('#get', () => {
710
26
  it('should proxy psf-slp-indexer', async () => {
711
27
  // console.log('bchjs.Transaction: ', bchjs.Transaction)