shuffle inputs
This commit is contained in:
parent
49791bcfdf
commit
c3ee9e9b93
|
@ -1496,7 +1496,7 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
|
|||
if (err) return cb(err);
|
||||
if (selectionError || _.isEmpty(inputs)) return cb(selectionError || new Error('Could not select tx inputs'));
|
||||
|
||||
txp.setInputs(inputs);
|
||||
txp.setInputs(_.shuffle(inputs));
|
||||
txp.fee = fee;
|
||||
|
||||
var err = self._checkTx(txp);
|
||||
|
|
|
@ -3168,7 +3168,7 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe.only('UTXO Selection', function() {
|
||||
describe('UTXO Selection', function() {
|
||||
var server, wallet;
|
||||
beforeEach(function(done) {
|
||||
// log.level = 'debug';
|
||||
|
@ -3201,6 +3201,29 @@ 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) {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
amount: _.sum(utxos, 'satoshis') - 0.5e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
};
|
||||
server.createTx(txOpts, function(err, txp) {
|
||||
should.not.exist(err);
|
||||
should.exist(txp);
|
||||
var amounts = _.pluck(txp.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 select a confirmed utxos if within thresholds relative to tx amount', function(done) {
|
||||
helpers.stubUtxos(server, wallet, [1, 'u 350bit', '100bit', '100bit', '100bit'], function() {
|
||||
var txOpts = {
|
||||
|
@ -3492,7 +3515,6 @@ describe('Wallet service', function() {
|
|||
};
|
||||
server.createTx(txOpts, function(err, txp) {
|
||||
should.not.exist(err);
|
||||
txp.inputs[0].satoshis.should.equal(200e2);
|
||||
(_.sum(txp.inputs, 'satoshis') - txp.outputs[0].amount - txp.fee).should.equal(0);
|
||||
done();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue