formated using js-beautify / tests
This commit is contained in:
parent
68b1211c4c
commit
494fc25d27
|
@ -33,7 +33,10 @@ describe('TransactionBuilder', function() {
|
|||
});
|
||||
|
||||
it('should be able to create instance with params', function() {
|
||||
var t = new TransactionBuilder({spendUnconfirmed: true, lockTime: 10});
|
||||
var t = new TransactionBuilder({
|
||||
spendUnconfirmed: true,
|
||||
lockTime: 10
|
||||
});
|
||||
should.exist(t);
|
||||
should.exist(t.lockTime);
|
||||
t.spendUnconfirmed.should.equal(true);
|
||||
|
@ -46,7 +49,9 @@ describe('TransactionBuilder', function() {
|
|||
});
|
||||
|
||||
var getBuilder = function(spendUnconfirmed) {
|
||||
var t = new TransactionBuilder({spendUnconfirmed: spendUnconfirmed})
|
||||
var t = new TransactionBuilder({
|
||||
spendUnconfirmed: spendUnconfirmed
|
||||
})
|
||||
.setUnspent(testdata.dataUnspent);
|
||||
|
||||
return t;
|
||||
|
@ -75,16 +80,22 @@ describe('TransactionBuilder', function() {
|
|||
});
|
||||
|
||||
it('#_selectUnspent should return null if not enough utxos', function() {
|
||||
(function() { f(1.12); }).should.throw();
|
||||
(function() {
|
||||
f(1.12);
|
||||
}).should.throw();
|
||||
});
|
||||
|
||||
|
||||
it('#_selectUnspent should check confirmations', function() {
|
||||
(function() { f(0.9,false); }).should.throw();
|
||||
(function() {
|
||||
f(0.9, false);
|
||||
}).should.throw();
|
||||
f(0.9).length.should.equal(3);
|
||||
|
||||
f(0.11, false).length.should.equal(2);
|
||||
(function() { f(0.111,false); }).should.throw();
|
||||
(function() {
|
||||
f(0.111, false);
|
||||
}).should.throw();
|
||||
});
|
||||
|
||||
|
||||
|
@ -115,7 +126,9 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
var getBuilder2 = function(fee) {
|
||||
var opts = {
|
||||
remainderOut: {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'},
|
||||
remainderOut: {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
},
|
||||
spendUnconfirmed: true,
|
||||
};
|
||||
|
||||
|
@ -144,7 +157,9 @@ describe('TransactionBuilder', function() {
|
|||
var utxos = testdata.dataUnspent;
|
||||
|
||||
var opts = {
|
||||
remainderOut: {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'},
|
||||
remainderOut: {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
},
|
||||
spendUnconfirmed: true,
|
||||
};
|
||||
var outs = [{
|
||||
|
@ -221,7 +236,9 @@ describe('TransactionBuilder', function() {
|
|||
var getBuilder3 = function(outs, signhash) {
|
||||
|
||||
var opts = {
|
||||
remainderOut: {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'},
|
||||
remainderOut: {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
},
|
||||
spendUnconfirmed: true,
|
||||
signhash: signhash,
|
||||
};
|
||||
|
@ -484,7 +501,9 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
it('should sign a p2pubkey tx', function(done) {
|
||||
var opts = {
|
||||
remainderOut: {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'},
|
||||
remainderOut: {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
},
|
||||
};
|
||||
var outs = outs || [{
|
||||
address: 'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE',
|
||||
|
@ -517,7 +536,9 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
it('should sign a multisig tx', function(done) {
|
||||
var opts = {
|
||||
remainderOut: {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'},
|
||||
remainderOut: {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
},
|
||||
};
|
||||
var outs = outs || [{
|
||||
address: 'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE',
|
||||
|
@ -548,7 +569,9 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
it('should sign a multisig tx in steps (3-5)', function(done) {
|
||||
var opts = {
|
||||
remainderOut: {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'},
|
||||
remainderOut: {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
},
|
||||
};
|
||||
var outs = outs || [{
|
||||
address: 'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE',
|
||||
|
@ -589,7 +612,9 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
it('should count multisig signs (3-5)', function() {
|
||||
var opts = {
|
||||
remainderOut: {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'},
|
||||
remainderOut: {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
},
|
||||
};
|
||||
var outs = outs || [{
|
||||
address: 'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE',
|
||||
|
@ -627,7 +652,9 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
it('should avoid siging with the same key twice multisig signs (3-5)', function(done) {
|
||||
var opts = {
|
||||
remainderOut: {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'},
|
||||
remainderOut: {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
},
|
||||
};
|
||||
var outs = outs || [{
|
||||
address: 'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE',
|
||||
|
@ -673,8 +700,12 @@ describe('TransactionBuilder', function() {
|
|||
var privs = testdata.dataUnspentSign.keyStringsP2sh;
|
||||
var pubkeys = [];
|
||||
privs.forEach(function(p) {
|
||||
var wk = new WalletKey({network: networks.testnet});
|
||||
wk.fromObj({priv: p});
|
||||
var wk = new WalletKey({
|
||||
network: networks.testnet
|
||||
});
|
||||
wk.fromObj({
|
||||
priv: p
|
||||
});
|
||||
pubkeys.push(bitcore.buffertools.toHex(wk.privKey.public));
|
||||
});
|
||||
|
||||
|
@ -697,11 +728,16 @@ describe('TransactionBuilder', function() {
|
|||
var getP2shBuilder = function(setMap, opts) {
|
||||
var network = 'testnet';
|
||||
opts = opts || {};
|
||||
opts.remainderOut = opts.remainderOut || {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'};
|
||||
opts.remainderOut = opts.remainderOut || {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
};
|
||||
|
||||
var data = getInfoForP2sh();
|
||||
// multisig p2sh
|
||||
var p2shOpts = {nreq:3, pubkeys:data.pubkeys};
|
||||
var p2shOpts = {
|
||||
nreq: 3,
|
||||
pubkeys: data.pubkeys
|
||||
};
|
||||
var info = TransactionBuilder.infoForP2sh(p2shOpts, network);
|
||||
|
||||
var outs = outs || [{
|
||||
|
@ -722,7 +758,9 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
it('should fail to sign a p2sh/multisign tx if none script map was given', function() {
|
||||
var b = getP2shBuilder();
|
||||
(function() {b.sign(testdata.dataUnspentSign.keyStringsP2sh);}).should.throw();
|
||||
(function() {
|
||||
b.sign(testdata.dataUnspentSign.keyStringsP2sh);
|
||||
}).should.throw();
|
||||
});
|
||||
|
||||
|
||||
|
@ -744,7 +782,14 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
};
|
||||
|
||||
[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,2,1],[3,1,2]].forEach(function(order) {
|
||||
[
|
||||
[1, 2, 3],
|
||||
[1, 3, 2],
|
||||
[2, 1, 3],
|
||||
[2, 3, 1],
|
||||
[3, 2, 1],
|
||||
[3, 1, 2]
|
||||
].forEach(function(order) {
|
||||
it('should sign a p2sh/multisig tx in order ' + order.join(','), function(done) {
|
||||
var b = getP2shBuilder(1);
|
||||
b.sign([testdata.dataUnspentSign.keyStringsP2sh[3]]);
|
||||
|
@ -797,10 +842,14 @@ describe('TransactionBuilder', function() {
|
|||
var priv = 'cMpKwGr5oxEacN95WFKNEq6tTcvi11regFwS3muHvGYVxMPJX8JA';
|
||||
var network = 'testnet';
|
||||
var opts = {
|
||||
remainderOut: {address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'},
|
||||
remainderOut: {
|
||||
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
|
||||
},
|
||||
};
|
||||
// p2hash/ p2sh
|
||||
var p2shOpts = {address:'mgwqzy6pF5BSc72vxHBFSnnhNEBcV4TJzV'};
|
||||
var p2shOpts = {
|
||||
address: 'mgwqzy6pF5BSc72vxHBFSnnhNEBcV4TJzV'
|
||||
};
|
||||
var info = TransactionBuilder.infoForP2sh(p2shOpts, network);
|
||||
|
||||
//addr: 2NAwCQ1jPYPrSsyBQvfP6AJ6d6SSxnHsZ4e
|
||||
|
@ -841,7 +890,9 @@ describe('TransactionBuilder', function() {
|
|||
|
||||
it('should check sign parameters', function() {
|
||||
var b = getP2shBuilder(1);
|
||||
(function() { b.sign(testdata.dataUnspentSign.keyStringsP2sh[0]) }).should.throw('array');
|
||||
(function() {
|
||||
b.sign(testdata.dataUnspentSign.keyStringsP2sh[0])
|
||||
}).should.throw('array');
|
||||
});
|
||||
|
||||
|
||||
|
@ -977,7 +1028,9 @@ describe('TransactionBuilder', function() {
|
|||
address: 'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE',
|
||||
amount: 15
|
||||
}]);
|
||||
(function() {b2.merge(b);}).should.throw('NTXID');
|
||||
(function() {
|
||||
b2.merge(b);
|
||||
}).should.throw('NTXID');
|
||||
});
|
||||
it('should check addresses', function() {
|
||||
// bad out
|
||||
|
@ -985,7 +1038,9 @@ describe('TransactionBuilder', function() {
|
|||
address: 'muHct3YZ9Nd5Pq7uLYYhXRAxeW4EnpcaLz',
|
||||
amount: 16
|
||||
}]);
|
||||
(function() {b2.merge(b);}).should.throw('NTXID');
|
||||
(function() {
|
||||
b2.merge(b);
|
||||
}).should.throw('NTXID');
|
||||
});
|
||||
|
||||
|
||||
|
@ -1003,7 +1058,9 @@ describe('TransactionBuilder', function() {
|
|||
}], bitcore.Transaction.SIGHASH_NONE);
|
||||
b2.sign(testdata.dataUnspentSign.keyStrings);
|
||||
|
||||
(function() {b2.merge(b);}).should.throw('signhash');
|
||||
(function() {
|
||||
b2.merge(b);
|
||||
}).should.throw('signhash');
|
||||
});
|
||||
|
||||
|
||||
|
@ -1117,9 +1174,13 @@ describe('TransactionBuilder', function() {
|
|||
var tx = b.build();
|
||||
tx.isComplete().should.equal(false);
|
||||
|
||||
var b2 = getP2shBuilder(1, {signhash: bitcore.Transaction.SIGHASH_NONE });
|
||||
var b2 = getP2shBuilder(1, {
|
||||
signhash: bitcore.Transaction.SIGHASH_NONE
|
||||
});
|
||||
b2.sign(k2);
|
||||
(function() { b2.merge(b)}).should.throw();
|
||||
(function() {
|
||||
b2.merge(b)
|
||||
}).should.throw();
|
||||
});
|
||||
|
||||
it('#merge p2sh/steps change return address', function() {
|
||||
|
@ -1133,9 +1194,15 @@ describe('TransactionBuilder', function() {
|
|||
tx.isComplete().should.equal(false);
|
||||
b = TransactionBuilder.fromObj(b.toObj());
|
||||
|
||||
var b2 = getP2shBuilder(1, {remainderOut: {address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE' }});
|
||||
var b2 = getP2shBuilder(1, {
|
||||
remainderOut: {
|
||||
address: 'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE'
|
||||
}
|
||||
});
|
||||
b2.sign(k2);
|
||||
(function() { b2.merge(b)}).should.throw('NTXID');
|
||||
(function() {
|
||||
b2.merge(b)
|
||||
}).should.throw('NTXID');
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue