From 76c7c773110f4cbd6378f1cf338484edfe6149a0 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 28 Sep 2016 01:05:01 +1000 Subject: [PATCH] tests: add failing test for #633 --- test/fixtures/transaction_builder.json | 25 ++++++++++++- test/transaction_builder.js | 49 ++++++++++++++++++-------- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/test/fixtures/transaction_builder.json b/test/fixtures/transaction_builder.json index 37be385..e57608e 100644 --- a/test/fixtures/transaction_builder.json +++ b/test/fixtures/transaction_builder.json @@ -633,7 +633,7 @@ { "description": "Incomplete transaction w/ prevTxScript defined", "exception": "Not enough signatures provided", - "alwaysThrows": true, + "incomplete": true, "inputs": [ { "txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", @@ -658,6 +658,29 @@ } ] }, + { + "description": "Duplicate transaction outs", + "exception": "Duplicate TxOut: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff:0", + "incomplete": true, + "inputs": [ + { + "txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "vout": 0, + "signs": [] + }, + { + "txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "vout": 0, + "signs": [] + } + ], + "outputs": [ + { + "script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG", + "value": 1000 + } + ] + }, { "description": "Complete transaction w/ non-standard inputs", "exception": "nonstandard not supported", diff --git a/test/transaction_builder.js b/test/transaction_builder.js index 53732d4..534f356 100644 --- a/test/transaction_builder.js +++ b/test/transaction_builder.js @@ -285,32 +285,53 @@ describe('TransactionBuilder', function () { it('builds "' + f.description + '"', function () { var txb = construct(f) var tx = txb.build() + assert.strictEqual(tx.toHex(), f.txHex) }) }) + // TODO: remove duplicate test code fixtures.invalid.build.forEach(function (f) { describe('for ' + (f.description || f.exception), function () { - var txb - - beforeEach(function () { - if (f.txHex) { - txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex)) - } else { - txb = construct(f) - } - }) - it('throws ' + f.exception, function () { assert.throws(function () { + var txb + if (f.txHex) { + txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex)) + } else { + txb = construct(f) + } + txb.build() }, new RegExp(f.exception)) }) - if (f.alwaysThrows) return - it("doesn't throw if building incomplete", function () { - txb.buildIncomplete() - }) + // if throws on incomplete too, enforce that + if (f.incomplete) { + it('throws ' + f.exception, function () { + assert.throws(function () { + var txb + if (f.txHex) { + txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex)) + } else { + txb = construct(f) + } + + txb.buildIncomplete() + }, new RegExp(f.exception)) + }) + } else { + it('does not throw if buildIncomplete', function () { + var txb + if (f.txHex) { + txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex)) + } else { + txb = construct(f) + } + + txb.buildIncomplete() + }) + } }) }) })