|
@ -6,19 +6,53 @@ var sinon = require('sinon'); |
|
|
var should = chai.should(); |
|
|
var should = chai.should(); |
|
|
var TXP = require('../../lib/model/txproposal'); |
|
|
var TXP = require('../../lib/model/txproposal'); |
|
|
var Bitcore = require('bitcore-wallet-utils').Bitcore; |
|
|
var Bitcore = require('bitcore-wallet-utils').Bitcore; |
|
|
var multiple_outputs = TXP.TYPE_MULTIPLEOUTPUTS; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('TXProposal', function() { |
|
|
describe('TXProposal', function() { |
|
|
|
|
|
|
|
|
describe('#fromObj', function() { |
|
|
describe('#create', function() { |
|
|
it('should create a TXP', function() { |
|
|
it('should create a TXP', function() { |
|
|
var txp = TXP.fromObj(aTXP()); |
|
|
var txp = TXP.create(aTxpOpts()); |
|
|
should.exist(txp); |
|
|
should.exist(txp); |
|
|
|
|
|
should.exist(txp.toAddress); |
|
|
|
|
|
should.not.exist(txp.outputs); |
|
|
}); |
|
|
}); |
|
|
it('should create a multiple-outputs TXP', function() { |
|
|
it('should create a multiple-outputs TXP', function() { |
|
|
var txp = TXP.fromObj(aTXP(multiple_outputs)); |
|
|
var txp = TXP.create(aTxpOpts(TXP.TYPE_MULTIPLEOUTPUTS)); |
|
|
|
|
|
should.exist(txp); |
|
|
|
|
|
should.not.exist(txp.toAddress); |
|
|
|
|
|
should.exist(txp.outputs); |
|
|
|
|
|
}); |
|
|
|
|
|
it('should fail to create a TXP of unknown type', function() { |
|
|
|
|
|
var txp; |
|
|
|
|
|
try { |
|
|
|
|
|
txp = TXP.create(aTxpOpts('bogus')); |
|
|
|
|
|
} catch(e) { |
|
|
|
|
|
should.exist(e); |
|
|
|
|
|
} |
|
|
|
|
|
should.not.exist(txp); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('#fromObj', function() { |
|
|
|
|
|
it('should copy a TXP', function() { |
|
|
|
|
|
var txp = TXP.fromObj(aTXP()); |
|
|
|
|
|
should.exist(txp); |
|
|
|
|
|
txp.toAddress.should.equal(aTXP().toAddress); |
|
|
|
|
|
}); |
|
|
|
|
|
it('should copy a multiple-outputs TXP', function() { |
|
|
|
|
|
var txp = TXP.fromObj(aTXP(TXP.TYPE_MULTIPLEOUTPUTS)); |
|
|
should.exist(txp); |
|
|
should.exist(txp); |
|
|
|
|
|
txp.outputs.should.deep.equal(aTXP(TXP.TYPE_MULTIPLEOUTPUTS).outputs); |
|
|
|
|
|
}); |
|
|
|
|
|
it('should fail to copy a TXP of unknown type', function() { |
|
|
|
|
|
var txp; |
|
|
|
|
|
try { |
|
|
|
|
|
txp = TXP.fromObj(aTxpOpts('bogus')); |
|
|
|
|
|
} catch(e) { |
|
|
|
|
|
should.exist(e); |
|
|
|
|
|
} |
|
|
|
|
|
should.not.exist(txp); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -40,7 +74,7 @@ describe('TXProposal', function() { |
|
|
t.getChangeOutput().should.deep.equal(t.outputs[0]); |
|
|
t.getChangeOutput().should.deep.equal(t.outputs[0]); |
|
|
}); |
|
|
}); |
|
|
it('should create a bitcore TX with multiple outputs', function() { |
|
|
it('should create a bitcore TX with multiple outputs', function() { |
|
|
var txp = TXP.fromObj(aTXP(multiple_outputs)); |
|
|
var txp = TXP.fromObj(aTXP(TXP.TYPE_MULTIPLEOUTPUTS)); |
|
|
txp.outputOrder = [0, 1, 2]; |
|
|
txp.outputOrder = [0, 1, 2]; |
|
|
var t = txp.getBitcoreTx(); |
|
|
var t = txp.getBitcoreTx(); |
|
|
t.getChangeOutput().should.deep.equal(t.outputs[2]); |
|
|
t.getChangeOutput().should.deep.equal(t.outputs[2]); |
|
@ -98,9 +132,36 @@ var theXPriv = 'xprv9s21ZrQH143K2rMHbXTJmWTuFx6ssqn1vyRoZqPkCXYchBSkp5ey8kMJe84s |
|
|
var theXPub = 'xpub661MyMwAqRbcFLRkhYzK8eQdoywNHJVsJCMQNDoMks5bZymuMcyDgYfnVQYq2Q9npnVmdTAthYGc3N3uxm5sEdnTpSqBc4YYTAhNnoSxCm9'; |
|
|
var theXPub = 'xpub661MyMwAqRbcFLRkhYzK8eQdoywNHJVsJCMQNDoMks5bZymuMcyDgYfnVQYq2Q9npnVmdTAthYGc3N3uxm5sEdnTpSqBc4YYTAhNnoSxCm9'; |
|
|
var theSignatures = ['3045022100896aeb8db75fec22fddb5facf791927a996eb3aee23ee6deaa15471ea46047de02204c0c33f42a9d3ff93d62738712a8c8a5ecd21b45393fdd144e7b01b5a186f1f9']; |
|
|
var theSignatures = ['3045022100896aeb8db75fec22fddb5facf791927a996eb3aee23ee6deaa15471ea46047de02204c0c33f42a9d3ff93d62738712a8c8a5ecd21b45393fdd144e7b01b5a186f1f9']; |
|
|
|
|
|
|
|
|
|
|
|
var aTxpOpts = function(type) { |
|
|
|
|
|
var opts = { |
|
|
|
|
|
type: type, |
|
|
|
|
|
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', |
|
|
|
|
|
amount: 50000000, |
|
|
|
|
|
message: 'some message' |
|
|
|
|
|
}; |
|
|
|
|
|
if (type == TXP.TYPE_MULTIPLEOUTPUTS) { |
|
|
|
|
|
opts.outputs = [ |
|
|
|
|
|
{ |
|
|
|
|
|
toAddress: "18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7", |
|
|
|
|
|
amount: 10000000, |
|
|
|
|
|
message: "first message" |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
toAddress: "18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7", |
|
|
|
|
|
amount: 20000000, |
|
|
|
|
|
message: "second message" |
|
|
|
|
|
}, |
|
|
|
|
|
]; |
|
|
|
|
|
delete opts.toAddress; |
|
|
|
|
|
delete opts.amount; |
|
|
|
|
|
} |
|
|
|
|
|
return opts; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
var aTXP = function(type) { |
|
|
var aTXP = function(type) { |
|
|
var txp = { |
|
|
var txp = { |
|
|
"version": "1.0.0", |
|
|
"version": "1.0.0", |
|
|
|
|
|
"type": type, |
|
|
"createdOn": 1423146231, |
|
|
"createdOn": 1423146231, |
|
|
"id": "75c34f49-1ed6-255f-e9fd-0c71ae75ed1e", |
|
|
"id": "75c34f49-1ed6-255f-e9fd-0c71ae75ed1e", |
|
|
"walletId": "1", |
|
|
"walletId": "1", |
|
@ -136,8 +197,7 @@ var aTXP = function(type) { |
|
|
"actions": [], |
|
|
"actions": [], |
|
|
"outputOrder": [0, 1], |
|
|
"outputOrder": [0, 1], |
|
|
}; |
|
|
}; |
|
|
if (type == 'multiple-outputs') { |
|
|
if (type == TXP.TYPE_MULTIPLEOUTPUTS) { |
|
|
txp.type = type; |
|
|
|
|
|
txp.outputs = [ |
|
|
txp.outputs = [ |
|
|
{ |
|
|
{ |
|
|
toAddress: "18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7", |
|
|
toAddress: "18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7", |
|
|