Add test for TxProposal

This commit is contained in:
Matias Pando 2015-01-23 12:08:09 -03:00
commit 63b4f2c649
2 changed files with 50 additions and 12 deletions

View file

@ -74,6 +74,7 @@ describe('HDParams model', function() {
}); });
it('should count generation indexes', function() { it('should count generation indexes', function() {
var j = new HDParams(); var j = new HDParams();
j.copayerIndex = 1; j.copayerIndex = 1;
@ -121,3 +122,28 @@ describe('HDParams model', function() {
}) })
}); });
describe('#checkRange', function() {
it('should throw an error', function() {
var hd = new HDParams();
(function() {
hd.checkRange(60, true);
}).should.throw('Out of bounds');
});
it('should throw an error', function() {
var hd = new HDParams();
(function() {
hd.checkRange(60, false);
}).should.throw('Out of bounds');
});
it('should not throw an error', function() {
var hd = new HDParams();
hd.checkRange(0, false);
hd.checkRange(0, true);
});
});

View file

@ -49,7 +49,7 @@ describe('TxProposal', function() {
function dummyBuilder(opts) { function dummyBuilder(opts) {
opts = opts || {}; opts = opts || {};
var index = opts.nsig ? opts.nsig - 1 : 1; var index = opts.nsig ? opts.nsig - 1 : 1;
var script = SCRIPTSIG[index]; var script = SCRIPTSIG[index];
var aIn = { var aIn = {
@ -85,7 +85,7 @@ describe('TxProposal', function() {
amountSatStr: '123', amountSatStr: '123',
}]), }]),
}; };
builder.inputsSigned =0; builder.inputsSigned = 0;
return builder; return builder;
}; };
@ -348,7 +348,7 @@ describe('TxProposal', function() {
describe('#addSignature', function() { describe('#addSignature', function() {
it('should add signatures maintaing pubkeys order', function() { it('should add signatures maintaing pubkeys order', function() {
var txp = dummyProposal({ var txp = dummyProposal({
nsig:1 nsig: 1
}); });
txp.getSignersPubKeys()[0].length.should.equal(1); txp.getSignersPubKeys()[0].length.should.equal(1);
@ -362,31 +362,43 @@ describe('TxProposal', function() {
}); });
it('should add signatures to incomplete txs ', function() { it('should add signatures to incomplete txs ', function() {
var txp = dummyProposal({ var txp = dummyProposal({
nsig:1 nsig: 1
}); });
txp.addSignature('pepe', [SIG1]); txp.addSignature('pepe', [SIG1]);
txp.builder.inputsSigned.should.be.equal(0); txp.builder.inputsSigned.should.be.equal(0);
}); });
it.only('should not add signatures to complete txs ', function() {
var txp = dummyProposal({
nsig: 1
});
txp.addSignature('pepe', [SIG1]);
txp.builder.inputsSigned.should.be.equal(0);
var r = txp.addSignature('lolo', [SIG0]);
r.should.be.false;
txp.builder.inputsSigned.should.be.equal(0);
});
it('should fail with invalid signatures', function() { it('should fail with invalid signatures', function() {
var txp = dummyProposal({ var txp = dummyProposal({
nsig:1 nsig: 1
}); });
txp.getSignersPubKeys()[0].length.should.equal(1); txp.getSignersPubKeys()[0].length.should.equal(1);
(function(){ (function() {
txp.addSignature('pepe', ['002030a77c9613d6ee010717c1abc494668d877e3fa0ae4c520f65cc3b308754c98c02205219d387bcb291bd44805b9468439e4168b02a6a180cdbcc24d84d71d696c1ae01']); txp.addSignature('pepe', ['002030a77c9613d6ee010717c1abc494668d877e3fa0ae4c520f65cc3b308754c98c02205219d387bcb291bd44805b9468439e4168b02a6a180cdbcc24d84d71d696c1ae01']);
}).should.throw('BADSIG'); }).should.throw('BADSIG');
}); });
it('should fail adding the same signature twice', function() { it('should fail adding the same signature twice', function() {
var txp = dummyProposal({ var txp = dummyProposal({
nsig:1 nsig: 1
}); });
txp.getSignersPubKeys()[0].length.should.equal(1); txp.getSignersPubKeys()[0].length.should.equal(1);
txp.addSignature('pepe', [SIG1]); txp.addSignature('pepe', [SIG1]);
(function(){ (function() {
txp.addSignature('pepe', [SIG1]); txp.addSignature('pepe', [SIG1]);
}).should.throw('BADSIG'); }).should.throw('BADSIG');
}); });
@ -533,7 +545,7 @@ describe('TxProposal', function() {
it('with less signatures', function() { it('with less signatures', function() {
var txp = dummyProposal(); var txp = dummyProposal();
var txp1Sig = dummyProposal({ var txp1Sig = dummyProposal({
nsig:1 nsig: 1
}); });
var backup = txp.builder.vanilla.scriptSig[0]; var backup = txp.builder.vanilla.scriptSig[0];
var hasChanged = txp.merge(txp); var hasChanged = txp.merge(txp);