TxBuilder: use data fixtures for invalid tests
This commit is contained in:
parent
bcbcd58964
commit
36b225a3df
3 changed files with 49 additions and 55 deletions
|
@ -189,40 +189,43 @@ describe('TransactionBuilder', function() {
|
|||
})
|
||||
})
|
||||
|
||||
it('throws if Transaction has no inputs', function() {
|
||||
txb.addOutput(privScript, value)
|
||||
fixtures.invalid.build.forEach(function(f) {
|
||||
it('throws on ' + f.exception, function() {
|
||||
f.inputs.forEach(function(input) {
|
||||
var prevTx
|
||||
if (input.prevTx.length === 64) {
|
||||
prevTx = input.prevTx
|
||||
} else {
|
||||
prevTx = Transaction.fromHex(input.prevTx)
|
||||
}
|
||||
|
||||
assert.throws(function() {
|
||||
txb.build()
|
||||
}, /Transaction has no inputs/)
|
||||
})
|
||||
txb.addInput(prevTx, input.index)
|
||||
})
|
||||
|
||||
it('throws if Transaction has no outputs', function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
f.outputs.forEach(function(output) {
|
||||
var script = Script.fromASM(output.script)
|
||||
|
||||
assert.throws(function() {
|
||||
txb.build()
|
||||
}, /Transaction has no outputs/)
|
||||
})
|
||||
txb.addOutput(script, output.value)
|
||||
})
|
||||
|
||||
it('throws if Transaction has no signatures', function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
txb.addOutput(privScript, value)
|
||||
f.inputs.forEach(function(input, index) {
|
||||
var redeemScript
|
||||
|
||||
assert.throws(function() {
|
||||
txb.build()
|
||||
}, /Transaction is missing signatures/)
|
||||
})
|
||||
if (input.redeemScript) {
|
||||
redeemScript = Script.fromASM(input.redeemScript)
|
||||
}
|
||||
|
||||
it('throws if Transaction has not enough signatures', function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
txb.addInput(prevTxHash, 1)
|
||||
txb.addOutput(privScript, value)
|
||||
txb.sign(0, privKey)
|
||||
input.privKeys.forEach(function(wif) {
|
||||
var privKey = ECKey.fromWIF(wif)
|
||||
|
||||
assert.throws(function() {
|
||||
txb.build()
|
||||
}, /Transaction is missing signatures/)
|
||||
txb.sign(index, privKey, redeemScript)
|
||||
})
|
||||
})
|
||||
|
||||
assert.throws(function() {
|
||||
txb.build()
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue