From 0f17927fde637717274e27e964ee597ce81f3596 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 10 Feb 2015 18:29:14 -0300 Subject: [PATCH] fix 0 fee error --- lib/transaction/transaction.js | 2 +- test/transaction/transaction.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index 8b6a46d..e164559 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -628,7 +628,7 @@ Transaction.prototype.getFee = function() { if (!this._changeScript) { return this._getUnspentValue(); } - return this._fee || this._estimateFee(); + return _.isUndefined(this._fee) ? this._estimateFee() : this._fee; }; /** diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index 85282ec..dccd7b0 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -197,11 +197,17 @@ describe('Transaction', function() { .from(simpleUtxoWith100000Satoshis) .to(toAddress, 50000) .change(changeAddress) - .sign(privateKey) + .fee(0) + .sign(privateKey); + + transaction.getChangeOutput().satoshis.should.equal(50000); + + transaction = transaction .to(toAddress, 20000) .sign(privateKey); + transaction.outputs.length.should.equal(3); - transaction.outputs[2].satoshis.should.equal(20000); + transaction.outputs[2].satoshis.should.equal(30000); transaction.outputs[2].script.toString() .should.equal(Script.fromAddress(changeAddress).toString()); });