TxBuilder: add more failing cases and error handling

This commit is contained in:
Daniel Cousens 2014-08-30 14:35:46 +10:00
parent e1479b6fa5
commit 1d0fd3e9a4
3 changed files with 25 additions and 1 deletions

View file

@ -34,6 +34,10 @@ TransactionBuilder.fromTransaction = function(transaction) {
// Ignore empty scripts // Ignore empty scripts
if (txin.script.buffer.length === 0) return if (txin.script.buffer.length === 0) return
assert(!Array.prototype.every.call(txin.hash, function(x) {
return x === 0
}), 'coinbase inputs not supported')
var redeemScript var redeemScript
var scriptSig = txin.script var scriptSig = txin.script
var scriptType = scripts.classifyInput(scriptSig) var scriptType = scripts.classifyInput(scriptSig)
@ -83,7 +87,7 @@ TransactionBuilder.fromTransaction = function(transaction) {
break break
default: default:
assert(false, scriptType + ' not supported') assert(false, scriptType + ' inputs not supported')
} }
txb.signatures[i] = { txb.signatures[i] = {

View file

@ -167,6 +167,16 @@
} }
] ]
} }
],
"fromTransaction": [
{
"exception": "coinbase inputs not supported",
"hex":"01000000010000000000000000000000000000000000000000000000000000000000000000000000006b483045022100a3b254e1c10b5d039f36c05f323995d6e5a367d98dd78a13d5bbc3991b35720e022022fccea3897d594de0689601fbd486588d5bfa6915be2386db0397ee9a6e80b601210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ffffffff0110270000000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac00000000"
},
{
"exception": "nonstandard inputs not supported",
"hex": "0100000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000023aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d619000000000087ffffffff0110270000000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac00000000"
}
] ]
} }
} }

View file

@ -256,6 +256,16 @@ describe('TransactionBuilder', function() {
}) })
}) })
fixtures.invalid.fromTransaction.forEach(function(f,i) {
it('throws on ' + f.exception, function() {
var tx = Transaction.fromHex(f.hex)
assert.throws(function() {
TransactionBuilder.fromTransaction(tx)
}, new RegExp(f.exception))
})
})
it('works for the P2SH multisig case', function() { it('works for the P2SH multisig case', function() {
var privKeys = [ var privKeys = [
"91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgwmaKkrx", "91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgwmaKkrx",