diff --git a/src/wallet.js b/src/wallet.js index 0d41bb2..846a5ad 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -1,3 +1,4 @@ +var assert = require('assert') var networks = require('./networks') var rng = require('secure-random') @@ -169,7 +170,7 @@ function Wallet(seed, network) { } this.createTx = function(to, value, fixedFee, changeAddress) { - if (value <= this.dustThreshold) throw new Error("Value must be above dust threshold") + assert(value > this.dustThreshold, value + ' must be above dust threshold (' + this.dustThreshold + ' Satoshis)') var utxos = getCandidateOutputs(value) var accum = 0 @@ -198,9 +199,7 @@ function Wallet(seed, network) { } } - if (accum < subTotal) { - throw new Error('Not enough funds: ' + accum + ' < ' + subTotal) - } + assert(accum >= subTotal, 'Not enough funds (incl. fee): ' + accum + ' < ' + subTotal) this.sign(tx) return tx diff --git a/test/wallet.js b/test/wallet.js index ef2d152..c3b459b 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -546,7 +546,7 @@ describe('Wallet', function() { assert.throws(function() { wallet.createTx(to, value) - }, /Value must be above dust threshold/) + }, /5430 must be above dust threshold \(5430 Satoshis\)/) }) }) @@ -556,7 +556,7 @@ describe('Wallet', function() { assert.throws(function() { wallet.createTx(to, value) - }, /Not enough funds: 1420000 < 1420001/) + }, /Not enough funds \(incl. fee\): 1420000 < 1420001/) }) }) })