diff --git a/lib/model/txproposal.js b/lib/model/txproposal.js index bc6dc76..1846e50 100644 --- a/lib/model/txproposal.js +++ b/lib/model/txproposal.js @@ -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; }; diff --git a/test/models/txproposal.js b/test/models/txproposal.js index 35b5ce8..58e5dd8 100644 --- a/test/models/txproposal.js +++ b/test/models/txproposal.js @@ -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], } };