throw error when unspent output does not have required keys

This commit is contained in:
Wei Lu 2014-03-22 15:37:03 +08:00
parent 26afbccc98
commit 01dc34d720
2 changed files with 70 additions and 9 deletions

View file

@ -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)