From 3ace170ac5ef1cb91245a004cb05b1dd3c51f127 Mon Sep 17 00:00:00 2001 From: David de Kloet Date: Thu, 21 May 2015 09:01:08 +0200 Subject: [PATCH] Ignore fee error when unspent output is actually negative, rather than already when the check for negative unspent output is disabled. --- lib/transaction/transaction.js | 2 +- test/transaction/transaction.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index dede08a9f..46983ad85 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -205,7 +205,7 @@ Transaction.prototype._isInvalidSatoshis = function() { }; Transaction.prototype._hasFeeError = function(opts) { - if (opts.disableMoreOutputThanInput) { + if (this._getUnspentValue() < 0) { // The concept of a fee is meaningless when the unspent output value is negative. return; } diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index e445d417b..673a52f14 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -397,6 +397,18 @@ describe('Transaction', function() { return transaction.serialize(); }).to.throw(errors.Transaction.InvalidOutputAmountSum); }); + it('will throw fee error with disableMoreOutputThanInput enabled (but not triggered)', function() { + var transaction = new Transaction(); + transaction.from(simpleUtxoWith1BTC); + transaction + .to(toAddress, 90000000) + .change(changeAddress) + .fee(10000000); + + expect(function() { + return transaction.serialize({disableMoreOutputThanInput: true}); + }).to.throw(errors.Transaction.FeeError.TooLarge); + }); describe('skipping checks', function() { var buildSkipTest = function(builder, check, expectedError) { return function() {