throw error when unspent output does not have required keys
This commit is contained in:
parent
26afbccc98
commit
01dc34d720
2 changed files with 70 additions and 9 deletions
test
|
@ -198,6 +198,32 @@ describe('Wallet', function() {
|
|||
verifyOutputs()
|
||||
})
|
||||
|
||||
describe('required fields', function(){
|
||||
it("throws an error when hash and hashLittleEndian are both missing", function(){
|
||||
delete utxo[0]['hash']
|
||||
delete utxo[0]['hashLittleEndian']
|
||||
|
||||
var errorMessage = 'Invalid unspent output: key hash(or hashLittleEndian) is missing. ' +
|
||||
'A valid unspent output must contain outputIndex, scriptPubKey, address, value and hash(or hashLittleEndian)'
|
||||
|
||||
assert.throws(function() {
|
||||
wallet.setUnspentOutputs(utxo)
|
||||
}, Error, errorMessage)
|
||||
});
|
||||
|
||||
['outputIndex', 'scriptPubKey', 'address', 'value'].forEach(function(field){
|
||||
it("throws an error when " + field + " is missing", function(){
|
||||
delete utxo[0][field]
|
||||
var errorMessage = 'Invalid unspent output: key ' + field +
|
||||
' is missing. A valid unspent output must contain outputIndex, scriptPubKey, address, value and hash(or hashLittleEndian)'
|
||||
|
||||
assert.throws(function() {
|
||||
wallet.setUnspentOutputs(utxo)
|
||||
}, Error, errorMessage)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function verifyOutputs() {
|
||||
var output = wallet.outputs[expectedOutputKey]
|
||||
assert(output)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue