Browse Source

Give the 3 fee errors a common parent error.

patch-2
David de Kloet 10 years ago
parent
commit
8da9c4a44a
  1. 20
      lib/errors/spec.js
  2. 6
      lib/transaction/transaction.js
  3. 6
      test/transaction/transaction.js

20
lib/errors/spec.js

@ -85,14 +85,18 @@ module.exports = [{
name: 'InvalidSatoshis', name: 'InvalidSatoshis',
message: 'Output satoshis are invalid', message: 'Output satoshis are invalid',
}, { }, {
name: 'SmallFeeError', name: 'Fee',
message: 'Fee is too small: {0}', message: 'Internal Error on Fee {0}',
}, { errors: [{
name: 'LargeFeeError', name: 'TooSmallError',
message: 'Fee is too large: {0}', message: 'Fee is too small: {0}',
}, { }, {
name: 'DifferentFeeError', name: 'TooLargeError',
message: 'Unspent value is different from specified fee: {0}', message: 'Fee is too large: {0}',
}, {
name: 'DifferentError',
message: 'Unspent value is different from specified fee: {0}',
}]
}, { }, {
name: 'ChangeAddressMissing', name: 'ChangeAddressMissing',
message: 'Change address is missing' message: 'Change address is missing'

6
lib/transaction/transaction.js

@ -203,16 +203,16 @@ Transaction.prototype.getSerializationError = function(opts) {
var isFullySigned = this.isFullySigned(); var isFullySigned = this.isFullySigned();
if (!opts.disableDifferentFees && feeIsDifferent) { if (!opts.disableDifferentFees && feeIsDifferent) {
return new errors.Transaction.DifferentFeeError(feeIsDifferent); return new errors.Transaction.Fee.DifferentError(feeIsDifferent);
} }
if (!opts.disableLargeFees && feeIsTooLarge) { if (!opts.disableLargeFees && feeIsTooLarge) {
if (missingChange) { if (missingChange) {
return new errors.Transaction.ChangeAddressMissing('Fee is too large and no change address was provided'); return new errors.Transaction.ChangeAddressMissing('Fee is too large and no change address was provided');
} }
return new errors.Transaction.LargeFeeError(feeIsTooLarge); return new errors.Transaction.Fee.TooLargeError(feeIsTooLarge);
} }
if (!opts.disableSmallFees && feeIsTooSmall) { if (!opts.disableSmallFees && feeIsTooSmall) {
return new errors.Transaction.SmallFeeError(feeIsTooSmall); return new errors.Transaction.Fee.TooSmallError(feeIsTooSmall);
} }
if (!opts.disableDustOutputs && this._hasDustOutputs()) { if (!opts.disableDustOutputs && this._hasDustOutputs()) {
return new errors.Transaction.DustOutputs(); return new errors.Transaction.DustOutputs();

6
test/transaction/transaction.js

@ -266,7 +266,7 @@ describe('Transaction', function() {
.sign(privateKey); .sign(privateKey);
expect(function() { expect(function() {
return transaction.serialize(); return transaction.serialize();
}).to.throw(errors.Transaction.SmallFeeError); }).to.throw(errors.Transaction.Fee.TooSmallError);
}); });
it('on second call to sign, change is not recalculated', function() { it('on second call to sign, change is not recalculated', function() {
var transaction = new Transaction() var transaction = new Transaction()
@ -332,7 +332,7 @@ describe('Transaction', function() {
.to(toAddress, 40000000); .to(toAddress, 40000000);
expect(function() { expect(function() {
return transaction.serialize(); return transaction.serialize();
}).to.throw(errors.Transaction.LargeFeeError); }).to.throw(errors.Transaction.Fee.TooLargeError);
}); });
it('fails if a dust output is created', function() { it('fails if a dust output is created', function() {
var transaction = new Transaction() var transaction = new Transaction()
@ -372,7 +372,7 @@ describe('Transaction', function() {
.sign(privateKey); .sign(privateKey);
expect(function() { expect(function() {
return transaction.serialize(); return transaction.serialize();
}).to.throw(errors.Transaction.DifferentFeeError); }).to.throw(errors.Transaction.Fee.DifferentError);
}); });
describe('skipping checks', function() { describe('skipping checks', function() {
var buildSkipTest = function(builder, check) { var buildSkipTest = function(builder, check) {

Loading…
Cancel
Save