transaction: better errors for signature methods

Closes #868
This commit is contained in:
Esteban Ordano 2014-12-31 02:10:51 -03:00
parent 6d1c5d39a3
commit dbf47ef78f
3 changed files with 33 additions and 0 deletions

View File

@ -58,6 +58,9 @@ module.exports = [{
}, {
name: 'NeedMoreInfo',
message: format('{0}')
}, {
name: 'UnableToVerifySignature',
message: format('Unable to verify signature: {0}')
}, {
name: 'FeeError',
message: format('Fees are not correctly set {0}'),

View File

@ -657,6 +657,14 @@ Transaction.prototype.applySignature = function(signature) {
};
Transaction.prototype.isFullySigned = function() {
_.each(this.inputs, function(input) {
if (input.isFullySigned === Input.prototype.isFullySigned) {
throw new errors.Transaction.UnableToVerifySignature(
'Unrecognized script kind, or not enough information to execute script.' +
'This usually happens when creating a transaction from a serialized transaction'
);
}
});
return _.all(_.map(this.inputs, function(input) {
return input.isFullySigned();
}));
@ -664,6 +672,12 @@ Transaction.prototype.isFullySigned = function() {
Transaction.prototype.isValidSignature = function(signature) {
var self = this;
if (this.inputs[signature.inputIndex].isValidSignature === Input.prototype.isValidSignature) {
throw new errors.Transaction.UnableToVerifySignature(
'Unrecognized script kind, or not enough information to execute script.' +
'This usually happens when creating a transaction from a serialized transaction'
);
}
return this.inputs[signature.inputIndex].isValidSignature(self, signature);
};

View File

@ -197,6 +197,22 @@ describe('Transaction', function() {
satoshis: 1e8
};
describe('not enough information errors', function() {
it('fails when Inputs are not subclassed and isFullySigned is called', function() {
var tx = new Transaction(tx_1_hex);
expect(function() {
return tx.isFullySigned();
}).to.throw(errors.Transaction.UnableToVerifySignature);
});
it('fails when Inputs are not subclassed and verifySignature is called', function() {
var tx = new Transaction(tx_1_hex);
expect(function() {
return tx.isValidSignature({inputIndex: 0});
}).to.throw(errors.Transaction.UnableToVerifySignature);
});
});
describe('checked serialize', function() {
it('fails if no change address was set', function() {
var transaction = new Transaction()