From d642931de25c93c942e8ec5c2cc754c206501f21 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 3 Jun 2016 20:59:54 -0300 Subject: [PATCH] fix 0 UTXOs & locked inputs + test --- lib/server.js | 3 ++- test/integration/server.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index f8636d1..8c3ccd2 100644 --- a/lib/server.js +++ b/lib/server.js @@ -922,7 +922,8 @@ WalletService.prototype._getUtxosForCurrentWallet = function(addresses, cb) { var addressStrs = _.pluck(allAddresses, 'address'); self._getUtxos(addressStrs, function(err, utxos) { if (err) return next(err); - if (utxos.length == 0) return next(null, []); + + if (utxos.length == 0) return cb(null, []); allUtxos = utxos; utxoIndex = _.indexBy(allUtxos, utxoKey); return next(); diff --git a/test/integration/server.js b/test/integration/server.js index e4dfb6c..57b5f9e 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1416,6 +1416,28 @@ describe('Wallet service', function() { }); }); }); + it('should not fail when getting UTXOs for wallet with 0 UTXOs and pending txps', function(done) { + helpers.stubUtxos(server, wallet, [1, 1], function() { + var txOpts = { + outputs: [{ + toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', + amount: 1e8, + }], + feePerKb: 100e2, + }; + helpers.createAndPublishTx(server, txOpts, TestData.copayers[0].privKey_1H_0, function(txp) { + blockchainExplorer.getUtxos = function(addresses, cb) { + return cb(null, []); + }; + + server.getUtxos({}, function(err, utxos) { + should.not.exist(err); + utxos.should.be.empty; + done(); + }); + }); + }); + }); }); describe('Multiple request Pub Keys', function() {