@@ -312,9 +312,8 @@ describe('Transaction', function() {
312
312
. to ( toAddress , 500000 )
313
313
. change ( changeAddress )
314
314
. sign ( privateKey ) ;
315
-
316
315
transaction . outputs . length . should . equal ( 2 ) ;
317
- transaction . outputs [ 1 ] . satoshis . should . equal ( 400000 ) ;
316
+ transaction . outputs [ 1 ] . satoshis . should . equal ( 477100 ) ;
318
317
transaction . outputs [ 1 ] . script . toString ( )
319
318
. should . equal ( Script . fromAddress ( changeAddress ) . toString ( ) ) ;
320
319
var actual = transaction . getChangeOutput ( ) . script . toString ( ) ;
@@ -388,10 +387,10 @@ describe('Transaction', function() {
388
387
. sign ( privateKey ) ;
389
388
transaction . _estimateSize ( ) . should . be . within ( 1000 , 1999 ) ;
390
389
transaction . outputs . length . should . equal ( 2 ) ;
391
- transaction . outputs [ 1 ] . satoshis . should . equal ( 34000 ) ;
390
+ transaction . outputs [ 1 ] . satoshis . should . equal ( 40464 ) ;
392
391
} ) ;
393
- it ( 'fee per byte (low fee) can be set up manually' , function ( ) {
394
- var inputs = _ . map ( _ . range ( 10 ) , function ( i ) {
392
+ it ( 'fee per byte (low fee) can be set up manually' , function ( ) {
393
+ var inputs = _ . map ( _ . range ( 10 ) , function ( i ) {
395
394
var utxo = _ . clone ( simpleUtxoWith100000Satoshis ) ;
396
395
utxo . outputIndex = i ;
397
396
return utxo ;
@@ -406,8 +405,8 @@ describe('Transaction', function() {
406
405
transaction . outputs . length . should . equal ( 2 ) ;
407
406
transaction . outputs [ 1 ] . satoshis . should . be . within ( 48001 , 49000 ) ;
408
407
} ) ;
409
- it ( 'fee per byte (high fee) can be set up manually' , function ( ) {
410
- var inputs = _ . map ( _ . range ( 10 ) , function ( i ) {
408
+ it ( 'fee per byte (high fee) can be set up manually' , function ( ) {
409
+ var inputs = _ . map ( _ . range ( 10 ) , function ( i ) {
411
410
var utxo = _ . clone ( simpleUtxoWith100000Satoshis ) ;
412
411
utxo . outputIndex = i ;
413
412
return utxo ;
@@ -422,8 +421,8 @@ describe('Transaction', function() {
422
421
transaction . outputs . length . should . equal ( 2 ) ;
423
422
transaction . outputs [ 1 ] . satoshis . should . be . within ( 46002 , 48000 ) ;
424
423
} ) ;
425
- it ( 'fee per byte can be set up manually' , function ( ) {
426
- var inputs = _ . map ( _ . range ( 10 ) , function ( i ) {
424
+ it ( 'fee per byte can be set up manually' , function ( ) {
425
+ var inputs = _ . map ( _ . range ( 10 ) , function ( i ) {
427
426
var utxo = _ . clone ( simpleUtxoWith100000Satoshis ) ;
428
427
utxo . outputIndex = i ;
429
428
return utxo ;
@@ -438,8 +437,8 @@ describe('Transaction', function() {
438
437
transaction . outputs . length . should . equal ( 2 ) ;
439
438
transaction . outputs [ 1 ] . satoshis . should . be . within ( 24013 , 37000 ) ;
440
439
} ) ;
441
- it ( 'fee per byte not enough for change' , function ( ) {
442
- var inputs = _ . map ( _ . range ( 10 ) , function ( i ) {
440
+ it ( 'fee per byte not enough for change' , function ( ) {
441
+ var inputs = _ . map ( _ . range ( 10 ) , function ( i ) {
443
442
var utxo = _ . clone ( simpleUtxoWith100000Satoshis ) ;
444
443
utxo . outputIndex = i ;
445
444
return utxo ;
@@ -465,6 +464,16 @@ describe('Transaction', function() {
465
464
return transaction . serialize ( ) ;
466
465
} ) . to . throw ( errors . Transaction . InvalidSatoshis ) ;
467
466
} ) ;
467
+ it ( 'if fee is too small, fail serialization' , function ( ) {
468
+ var transaction = new Transaction ( { disableDustOutputs : true } )
469
+ . from ( simpleUtxoWith100000Satoshis )
470
+ . to ( toAddress , 99999 )
471
+ . change ( changeAddress )
472
+ . sign ( privateKey ) ;
473
+ expect ( function ( ) {
474
+ return transaction . serialize ( ) ;
475
+ } ) . to . throw ( errors . Transaction . FeeError . TooSmall ) ;
476
+ } ) ;
468
477
it ( 'on second call to sign, change is not recalculated' , function ( ) {
469
478
var transaction = new Transaction ( )
470
479
. from ( simpleUtxoWith100000Satoshis )
@@ -623,6 +632,14 @@ describe('Transaction', function() {
623
632
. sign ( privateKey ) ;
624
633
} , 'disableLargeFees' , errors . Transaction . FeeError . TooLarge
625
634
) ) ;
635
+ it ( 'can skip the check for a fee that is too small' , buildSkipTest (
636
+ function ( transaction ) {
637
+ return transaction
638
+ . fee ( 1 )
639
+ . change ( changeAddress )
640
+ . sign ( privateKey ) ;
641
+ } , 'disableSmallFees' , errors . Transaction . FeeError . TooSmall
642
+ ) ) ;
626
643
it ( 'can skip the check that prevents dust outputs' , buildSkipTest (
627
644
function ( transaction ) {
628
645
return transaction
@@ -987,7 +1004,7 @@ describe('Transaction', function() {
987
1004
. change ( changeAddress )
988
1005
. to ( toAddress , 1000 ) ;
989
1006
transaction . inputAmount . should . equal ( 100000000 ) ;
990
- transaction . outputAmount . should . equal ( 99900000 ) ;
1007
+ transaction . outputAmount . should . equal ( 99977100 ) ;
991
1008
} ) ;
992
1009
it ( 'returns correct values for coinjoin transaction' , function ( ) {
993
1010
// see livenet tx c16467eea05f1f30d50ed6dbc06a38539d9bb15110e4b7dc6653046a3678a718
@@ -1085,7 +1102,7 @@ describe('Transaction', function() {
1085
1102
tx . outputs . length . should . equal ( 2 ) ;
1086
1103
tx . outputs [ 0 ] . satoshis . should . equal ( 10000000 ) ;
1087
1104
tx . outputs [ 0 ] . script . toAddress ( ) . toString ( ) . should . equal ( toAddress ) ;
1088
- tx . outputs [ 1 ] . satoshis . should . equal ( 89900000 ) ;
1105
+ tx . outputs [ 1 ] . satoshis . should . equal ( 89977100 ) ;
1089
1106
tx . outputs [ 1 ] . script . toAddress ( ) . toString ( ) . should . equal ( changeAddress ) ;
1090
1107
} ) ;
1091
1108
0 commit comments