diff --git a/test/fixtures/transaction_builder.json b/test/fixtures/transaction_builder.json index 5964311..86ae18b 100644 --- a/test/fixtures/transaction_builder.json +++ b/test/fixtures/transaction_builder.json @@ -187,7 +187,9 @@ "value": 1000 } ] - }, + } + ], + "sign": [ { "exception": "nulldata not supported", "inputs": [ @@ -195,6 +197,7 @@ "index": 0, "prevTx": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "prevTxScript": "OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474", + "throws": true, "privKeys": [ "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn" ] diff --git a/test/transaction_builder.js b/test/transaction_builder.js index f743300..47f5d3e 100644 --- a/test/transaction_builder.js +++ b/test/transaction_builder.js @@ -205,6 +205,47 @@ describe('TransactionBuilder', function() { txb.sign(0, ECKey.makeRandom(), redeemScript) }, /privateKey cannot sign for this input/) }) + + fixtures.invalid.sign.forEach(function(f) { + it('throws on ' + f.exception, function() { + f.inputs.forEach(function(input) { + var prevTxScript + + if (input.prevTxScript) { + prevTxScript = Script.fromASM(input.prevTxScript) + } + + txb.addInput(input.prevTx, input.index, input.sequence, prevTxScript) + }) + + f.outputs.forEach(function(output) { + var script = Script.fromASM(output.script) + + txb.addOutput(script, output.value) + }) + + f.inputs.forEach(function(input, index) { + var redeemScript + + if (input.redeemScript) { + redeemScript = Script.fromASM(input.redeemScript) + } + + input.privKeys.forEach(function(wif) { + var privKey = ECKey.fromWIF(wif) + + if (!input.throws) { + txb.sign(index, privKey, redeemScript) + + } else { + assert.throws(function() { + txb.sign(index, privKey, redeemScript) + }, new RegExp(f.exception)) + } + }) + }) + }) + }) }) describe('build', function() {