From ac2fbe27771f467672484dfecd32cb5b36e5661d Mon Sep 17 00:00:00 2001 From: David de Kloet Date: Wed, 20 May 2015 21:56:52 +0200 Subject: [PATCH] When disableMoreOutputThanInput is set for getSerializationError, also disable the fee checks as the concept of a fee is meaningless when unspent output value is negative. This also allows for removing the opts from buildSkipTest again and simplifying the skip test for disableMoreOutputThanInput. --- lib/transaction/transaction.js | 4 ++++ test/transaction/transaction.js | 18 ++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index e5e60a7f1..dede08a9f 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -205,6 +205,10 @@ Transaction.prototype._isInvalidSatoshis = function() { }; Transaction.prototype._hasFeeError = function(opts) { + if (opts.disableMoreOutputThanInput) { + // The concept of a fee is meaningless when the unspent output value is negative. + return; + } return this._isFeeDifferent() || this._isFeeTooLarge(opts) || this._isFeeTooSmall(opts); diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index aea6f7e17..e445d417b 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -398,22 +398,20 @@ describe('Transaction', function() { }).to.throw(errors.Transaction.InvalidOutputAmountSum); }); describe('skipping checks', function() { - var buildSkipTest = function(builder, check, expectedError, opts) { + var buildSkipTest = function(builder, check, expectedError) { return function() { var transaction = new Transaction(); transaction.from(simpleUtxoWith1BTC); builder(transaction); - var options = opts || {}; + var options = {}; options[check] = true; expect(function() { return transaction.serialize(options); }).not.to.throw(); - - options[check] = false; expect(function() { - return transaction.serialize(options); + return transaction.serialize(); }).to.throw(expectedError); }; }; @@ -452,13 +450,9 @@ describe('Transaction', function() { function(transaction) { return transaction .to(toAddress, 10000000000000) - .change(changeAddress); - }, 'disableMoreOutputThanInput', - errors.Transaction.InvalidOutputAmountSum, - { - 'disableSmallFees': true, - 'disableIsFullySigned': true - } + .change(changeAddress) + .sign(privateKey); + }, 'disableMoreOutputThanInput', errors.Transaction.InvalidOutputAmountSum )); }); });