From 6b8af51993473cf6c6ebf4d29dcdcb5d254f3fdd Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 18 Mar 2016 15:56:10 -0300 Subject: [PATCH] handle 0 input txs --- lib/server.js | 3 +++ test/integration/server.js | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index cb1cadc..b8d549b 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1207,6 +1207,9 @@ WalletService.prototype.getSendMaxInfo = function(opts, cb) { lastFee = fee; }); + + if (_.isEmpty(txp.inputs)) return cb(null, info); + info.size = txp.getEstimatedSize(); info.fee = txp.getEstimatedFee(); info.amount = _.sum(txp.inputs, 'satoshis') - info.fee; diff --git a/test/integration/server.js b/test/integration/server.js index 54cc81d..1c083e3 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -3745,7 +3745,6 @@ describe('Wallet service', function() { }); }); }); - it('should exclude unconfirmed inputs', function(done) { helpers.stubUtxos(server, wallet, ['u0.1', 0.2, 0.3, 0.4], function() { server.getSendMaxInfo({ @@ -3817,6 +3816,22 @@ describe('Wallet service', function() { }); }); }); + it('should work when all inputs are below their cost in fee', function(done) { + helpers.stubUtxos(server, wallet, ['u 10bit', '10bit', '20bit'], function() { + server.getSendMaxInfo({ + feePerKb: 500e2, + returnInputs: true, + }, function(err, info) { + should.not.exist(err); + should.exist(info); + info.inputs.should.be.empty; + info.size.should.equal(0); + info.fee.should.equal(0); + info.amount.should.equal(0); + done(); + }); + }); + }); it('should not go beyond max tx size', function(done) { var _oldDefault = Defaults.MAX_TX_SIZE_IN_KB; Defaults.MAX_TX_SIZE_IN_KB = 2;