From 30469f921dc8f8f0840f3501f296e6d74275d513 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 16 Mar 2016 16:46:11 -0300 Subject: [PATCH] shuffle inputs --- lib/server.js | 3 +-- test/integration/server.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/server.js b/lib/server.js index e7ac147..3748a18 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1211,8 +1211,7 @@ WalletService.prototype.getSendMaxInfo = function(opts, cb) { info.fee = txp.getEstimatedFee(); info.amount = _.sum(txp.inputs, 'satoshis') - info.fee; if (opts.returnInputs) { - // TODO: Shuffle inputs - info.inputs = txp.inputs; + info.inputs = _.shuffle(txp.inputs); } return cb(null, info); diff --git a/test/integration/server.js b/test/integration/server.js index 5fd3017..277abc0 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -3709,6 +3709,26 @@ describe('Wallet service', function() { }); }); }); + it('should return inputs in random order', function(done) { + // NOTE: this test has a chance of failing of 1 in 1'073'741'824 :P + helpers.stubUtxos(server, wallet, _.range(1, 31), function(utxos) { + server.getSendMaxInfo({ + feePerKb: 100e2, + returnInputs: true + }, function(err, info) { + should.not.exist(err); + should.exist(info); + var amounts = _.pluck(info.inputs, 'satoshis'); + amounts.length.should.equal(30); + _.all(amounts, function(amount, i) { + if (i == 0) return true; + return amount < amounts[i - 1]; + }).should.be.false; + done(); + }); + }); + }); + it('should exclude unconfirmed inputs', function(done) { helpers.stubUtxos(server, wallet, ['u0.1', 0.2, 0.3, 0.4], function() { server.getSendMaxInfo({