tests: add failing test for #633

This commit is contained in:
Daniel Cousens 2016-09-28 01:05:01 +10:00
parent b3fd50ffd6
commit 76c7c77311
2 changed files with 59 additions and 15 deletions

View file

@ -633,7 +633,7 @@
{ {
"description": "Incomplete transaction w/ prevTxScript defined", "description": "Incomplete transaction w/ prevTxScript defined",
"exception": "Not enough signatures provided", "exception": "Not enough signatures provided",
"alwaysThrows": true, "incomplete": true,
"inputs": [ "inputs": [
{ {
"txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "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", "description": "Complete transaction w/ non-standard inputs",
"exception": "nonstandard not supported", "exception": "nonstandard not supported",

View file

@ -285,32 +285,53 @@ describe('TransactionBuilder', function () {
it('builds "' + f.description + '"', function () { it('builds "' + f.description + '"', function () {
var txb = construct(f) var txb = construct(f)
var tx = txb.build() var tx = txb.build()
assert.strictEqual(tx.toHex(), f.txHex) assert.strictEqual(tx.toHex(), f.txHex)
}) })
}) })
// TODO: remove duplicate test code
fixtures.invalid.build.forEach(function (f) { fixtures.invalid.build.forEach(function (f) {
describe('for ' + (f.description || f.exception), function () { 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 () { it('throws ' + f.exception, function () {
assert.throws(function () { assert.throws(function () {
var txb
if (f.txHex) {
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
} else {
txb = construct(f)
}
txb.build() txb.build()
}, new RegExp(f.exception)) }, new RegExp(f.exception))
}) })
if (f.alwaysThrows) return // if throws on incomplete too, enforce that
it("doesn't throw if building incomplete", function () { if (f.incomplete) {
txb.buildIncomplete() 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()
})
}
}) })
}) })
}) })