@@ -387,32 +387,37 @@ describe('Client', () => {
387
387
} ) ;
388
388
389
389
describe ( 'getTransactionByHash()' , ( ) => {
390
- it ( 'should return a transaction binary-encoded if extension is `bin`' , async ( ) => {
391
- const transaction = await client . getTransactionByHash ( 'b4dd08f32be15d96b7166fd77afd18aece7480f72af6c9c7f9c5cbeb01e686fe' , { extension : 'bin' } ) ;
390
+ it ( 'should return a transaction json-encoded by default' , async ( ) => {
391
+ const [ { txid } ] = await client . listUnspent ( ) ;
392
+ const transaction = await client . getTransactionByHash ( txid ) ;
392
393
393
- new Buffer ( transaction , 'binary' ) . toString ( 'hex' ) . should . endWith ( '206e6f7420666f756e640d0a ') ;
394
+ transaction . should . have . keys ( 'blockhash' , 'locktime' , 'hash' , 'size' , 'txid' , 'version' , 'vin' , 'vout' , 'vsize ') ;
394
395
} ) ;
395
396
396
397
it ( 'should return a transaction hex-encoded if extension is `hex`' , async ( ) => {
397
- const [ transaction ] = await client . listUnspent ( ) ;
398
- const hex = await client . getTransactionByHash ( transaction . txid , { extension : 'hex' } ) ;
398
+ const [ { txid } ] = await client . listUnspent ( ) ;
399
+ const { hex : rawTransaction } = await client . getTransaction ( txid ) ;
400
+ const hexTransaction = await client . getTransactionByHash ( txid , { extension : 'hex' } ) ;
399
401
400
- hex . should . endWith ( 'cf900000000\n' ) ;
402
+ hexTransaction . should . equal ( ` ${ rawTransaction } \n` ) ;
401
403
} ) ;
402
404
403
- it ( 'should return a transaction json-encoded by default' , async ( ) => {
404
- const [ transaction ] = await client . listUnspent ( ) ;
405
- const hex = await client . getTransactionByHash ( transaction . txid ) ;
405
+ it ( 'should return a transaction binary-encoded if extension is `bin`' , async ( ) => {
406
+ const [ { txid } ] = await client . listUnspent ( ) ;
407
+ const binaryTransaction = await client . getTransactionByHash ( txid , { extension : 'bin' } ) ;
408
+ const hexTransaction = await client . getTransactionByHash ( txid , { extension : 'hex' } ) ;
406
409
407
- hex . should . have . keys ( 'blockhash' , 'locktime' , 'hash' , 'size' , 'txid' , 'version' , 'vin' , 'vout' , 'vsize' ) ;
410
+ binaryTransaction . should . be . instanceOf ( Buffer ) ;
411
+ hexTransaction . should . equal ( `${ binaryTransaction . toString ( 'hex' ) } \n` ) ;
408
412
} ) ;
409
413
} ) ;
410
414
411
415
describe ( 'getBlockByHash()' , ( ) => {
412
- it ( 'should return a block binary -encoded if extension is `bin` ' , async ( ) => {
413
- const block = await client . getBlockByHash ( '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' , { extension : 'bin ' } ) ;
416
+ it ( 'should return a block json -encoded by default ' , async ( ) => {
417
+ const block = await client . getBlockByHash ( '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' , { extension : 'json ' } ) ;
414
418
415
- new Buffer ( block , 'binary' ) . toString ( 'hex' ) . should . equal ( '0100000000000000000000000000000000000000000000000000000000000000000000003bfdfdfd7a7b12fd7afd2c3e6776fd617ffd1bc8fd51323afdfdfd4b1e5e4afdfd494dfdfd7f20020000000101000000010000000000000000000000000000000000000000000000000000000000000000fdfdfdfd4d04fdfd001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73fdfdfdfd0100fd052a0100000043410467fdfdfdfd5548271967fdfd7130fd105ca828fd3909fd7962fdfd1f61b649fdfd3f4cfd38fdfd5504fd1efd12fd5c384dfdfd0bfd57fd4c702b6bfd1d5ffd00000000' ) ;
419
+ block . should . have . keys ( 'bits' , 'chainwork' , 'confirmations' , 'difficulty' , 'hash' , 'height' , 'mediantime' , 'merkleroot' , 'nextblockhash' , 'nonce' , 'size' , 'strippedsize' , 'time' , 'tx' , 'version' , 'versionHex' , 'weight' ) ;
420
+ block . tx . should . matchEach ( value => value . should . be . an . Object ( ) ) ;
416
421
} ) ;
417
422
418
423
it ( 'should return a block hex-encoded if extension is `hex`' , async ( ) => {
@@ -421,11 +426,11 @@ describe('Client', () => {
421
426
block . should . equal ( '0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff7f20020000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000\n' ) ;
422
427
} ) ;
423
428
424
- it ( 'should return a block json -encoded by default ' , async ( ) => {
425
- const block = await client . getBlockByHash ( '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' , { extension : 'json ' } ) ;
429
+ it ( 'should return a block binary -encoded if extension is `bin` ' , async ( ) => {
430
+ const block = await client . getBlockByHash ( '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' , { extension : 'bin ' } ) ;
426
431
427
- block . should . have . keys ( 'bits' , 'chainwork' , 'confirmations' , 'difficulty' , 'hash' , 'height' , 'mediantime' , 'merkleroot' , 'nextblockhash' , 'nonce' , 'size' , 'strippedsize' , 'time' , 'tx' , 'version' , 'versionHex' , 'weight' ) ;
428
- block . tx . should . matchEach ( value => value . should . be . an . Object ( ) ) ;
432
+ block . should . be . instanceOf ( Buffer ) ;
433
+ block . toString ( 'hex' ) . should . equal ( '0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff7f20020000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000' ) ;
429
434
} ) ;
430
435
431
436
it ( 'should return a block summary json-encoded if `summary` is enabled' , async ( ) => {
@@ -437,10 +442,15 @@ describe('Client', () => {
437
442
} ) ;
438
443
439
444
describe ( 'getBlockHeadersByHash()' , ( ) => {
440
- it ( 'should return block headers binary-encoded if extension is `bin`' , async ( ) => {
441
- const headers = await client . getBlockHeadersByHash ( '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' , 1 , { extension : 'bin' } ) ;
445
+ it ( 'should return a block json-encoded by default' , async ( ) => {
446
+ try {
447
+ await client . getBlockHeadersByHash ( '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' , 1 , { extension : 'json' } ) ;
442
448
443
- new Buffer ( headers , 'binary' ) . toString ( 'hex' ) . should . equal ( '0100000000000000000000000000000000000000000000000000000000000000000000003bfdfdfd7a7b12fd7afd2c3e6776fd617ffd1bc8fd51323afdfdfd4b1e5e4afdfd494dfdfd7f2002000000' ) ;
449
+ should . fail ( ) ;
450
+ } catch ( e ) {
451
+ e . should . be . an . instanceOf ( Error ) ;
452
+ e . message . should . equal ( 'Extension "json" is not supported' ) ;
453
+ }
444
454
} ) ;
445
455
446
456
it ( 'should return block headers hex-encoded if extension is `hex`' , async ( ) => {
@@ -449,15 +459,12 @@ describe('Client', () => {
449
459
headers . should . equal ( '0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff7f2002000000\n' ) ;
450
460
} ) ;
451
461
452
- it ( 'should return a block json-encoded by default' , async ( ) => {
453
- try {
454
- await client . getBlockHeadersByHash ( '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' , 1 , { extension : 'json' } ) ;
462
+ it ( 'should return block headers binary-encoded if extension is `bin`' , async ( ) => {
463
+ const hash = '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' ;
464
+ const binaryHeaders = await client . getBlockHeadersByHash ( hash , 1 , { extension : 'bin' } ) ;
465
+ const hexHeaders = await client . getBlockHeadersByHash ( hash , 1 , { extension : 'hex' } ) ;
455
466
456
- should . fail ( ) ;
457
- } catch ( e ) {
458
- e . should . be . an . instanceOf ( Error ) ;
459
- e . message . should . equal ( 'Extension "json" is not supported' ) ;
460
- }
467
+ binaryHeaders . toString ( 'hex' ) . should . equal ( `${ hexHeaders . toString ( 'hex' ) . replace ( '\n' , '' ) } ` ) ;
461
468
} ) ;
462
469
} ) ;
463
470
@@ -470,16 +477,17 @@ describe('Client', () => {
470
477
} ) ;
471
478
472
479
describe ( 'getUnspentTransactionOutputs()' , ( ) => {
473
- it ( 'should return unspent transaction outputs hex -encoded if extension is `bin` ' , async ( ) => {
480
+ it ( 'should return unspent transaction outputs json -encoded by default ' , async ( ) => {
474
481
const result = await new Client ( config . bitcoind ) . getUnspentTransactionOutputs ( [ {
475
482
id : '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' ,
476
483
index : 0
477
484
} , {
478
485
id : '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' ,
479
486
index : 1
480
- } ] , { extension : 'bin' } ) ;
487
+ } ] ) ;
481
488
482
- new Buffer ( result , 'binary' ) . toString ( 'hex' ) . should . endWith ( '010000' ) ;
489
+ result . should . have . keys ( 'bitmap' , 'chainHeight' , 'chaintipHash' , 'utxos' ) ;
490
+ result . chainHeight . should . be . a . Number ( ) ;
483
491
} ) ;
484
492
485
493
it ( 'should return unspent transaction outputs hex-encoded if extension is `hex`' , async ( ) => {
@@ -491,20 +499,22 @@ describe('Client', () => {
491
499
index : 1
492
500
} ] , { extension : 'hex' } ) ;
493
501
494
- result . should . endWith ( '010000 \n' ) ;
502
+ result . should . endWith ( '10000 \n' ) ;
495
503
} ) ;
496
504
497
- it ( 'should return unspent transaction outputs json -encoded by default ' , async ( ) => {
498
- const result = await new Client ( config . bitcoind ) . getUnspentTransactionOutputs ( [ {
505
+ it ( 'should return unspent transaction outputs binary -encoded if extension is `bin` ' , async ( ) => {
506
+ const outputs = [ {
499
507
id : '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' ,
500
508
index : 0
501
509
} , {
502
510
id : '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206' ,
503
511
index : 1
504
- } ] ) ;
512
+ } ] ;
513
+ const binaryUnspents = await new Client ( config . bitcoind ) . getUnspentTransactionOutputs ( outputs , { extension : 'bin' } ) ;
514
+ const hexUnspents = await new Client ( config . bitcoind ) . getUnspentTransactionOutputs ( outputs , { extension : 'hex' } ) ;
505
515
506
- result . should . have . keys ( 'bitmap' , 'chainHeight' , 'chaintipHash' , 'utxos' ) ;
507
- result . chainHeight . should . be . a . Number ( ) ;
516
+ binaryUnspents . should . be . instanceOf ( Buffer ) ;
517
+ hexUnspents . should . equal ( ` ${ binaryUnspents . toString ( 'hex' ) } \n` ) ;
508
518
} ) ;
509
519
} ) ;
510
520
0 commit comments