Wallet: use assert for consistency
This commit is contained in:
parent
5b7873d05b
commit
3bce535e36
2 changed files with 5 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
var assert = require('assert')
|
||||||
var networks = require('./networks')
|
var networks = require('./networks')
|
||||||
var rng = require('secure-random')
|
var rng = require('secure-random')
|
||||||
|
|
||||||
|
@ -169,7 +170,7 @@ function Wallet(seed, network) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createTx = function(to, value, fixedFee, changeAddress) {
|
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 utxos = getCandidateOutputs(value)
|
||||||
var accum = 0
|
var accum = 0
|
||||||
|
@ -198,9 +199,7 @@ function Wallet(seed, network) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accum < subTotal) {
|
assert(accum >= subTotal, 'Not enough funds (incl. fee): ' + accum + ' < ' + subTotal)
|
||||||
throw new Error('Not enough funds: ' + accum + ' < ' + subTotal)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sign(tx)
|
this.sign(tx)
|
||||||
return tx
|
return tx
|
||||||
|
|
|
@ -546,7 +546,7 @@ describe('Wallet', function() {
|
||||||
|
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
wallet.createTx(to, value)
|
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() {
|
assert.throws(function() {
|
||||||
wallet.createTx(to, value)
|
wallet.createTx(to, value)
|
||||||
}, /Not enough funds: 1420000 < 1420001/)
|
}, /Not enough funds \(incl. fee\): 1420000 < 1420001/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue