shuffle outputs

This commit is contained in:
Ivan Socolsky 2015-03-12 12:01:44 -03:00
parent e06a788e05
commit 4a53da8690
2 changed files with 15 additions and 1 deletions

View File

@ -32,6 +32,7 @@ TxProposal.create = function(opts) {
x.requiredRejections = opts.requiredRejections;
x.status = 'pending';
x.actions = [];
x.outputOrder = _.shuffle(_.range(2));
return x;
};
@ -58,6 +59,7 @@ TxProposal.fromObj = function(obj) {
x.actions = _.map(obj.actions, function(action) {
return TxProposalAction.fromObj(action);
});
x.outputOrder = obj.outputOrder;
return x;
};

View File

@ -22,6 +22,17 @@ describe('TXProposal', function() {
var t = txp.getBitcoreTx();
should.exist(t);
});
it('should order ouputs as specified by outputOrder', function() {
var txp = TXP.fromObj(aTXP());
txp.outputOrder = [0, 1];
var t = txp._getBitcoreTx();
t.getChangeOutput().should.deep.equal(t.outputs[1]);
txp.outputOrder = [1, 0];
var t = txp._getBitcoreTx();
t.getChangeOutput().should.deep.equal(t.outputs[0]);
});
});
@ -108,6 +119,7 @@ var aTXP = function() {
"requiredSignatures": 2,
"requiredRejections": 1,
"status": "pending",
"actions": []
"actions": [],
"outputOrder": [0, 1],
}
};