tests: add tests for Transaction.hashForSignature

This commit is contained in:
Daniel Cousens 2016-06-22 14:45:36 +10:00
parent 07628ff034
commit 4898cc7b67
2 changed files with 49 additions and 2 deletions

View file

@ -231,6 +231,45 @@
"coinbase": false "coinbase": false
} }
], ],
"hashForSignature": [
{
"description": "Out of range inIndex",
"txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
"inIndex": 2,
"script": "OP_0",
"type": 0,
"hash": "0000000000000000000000000000000000000000000000000000000000000001"
},
{
"description": "inIndex > nOutputs (SIGHASH_SINGLE)",
"txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
"inIndex": 2,
"script": "OP_0",
"type": 3,
"hash": "0000000000000000000000000000000000000000000000000000000000000001"
},
{
"txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
"inIndex": 0,
"script": "OP_0 OP_3",
"type": 0,
"hash": "3d56a632462b9fc9b89eeddcad7dbe476297f34aff7e5f9320e2a99fb5e97136"
},
{
"txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
"inIndex": 0,
"script": "OP_0 OP_CODESEPARATOR OP_3",
"type": 0,
"hash": "3d56a632462b9fc9b89eeddcad7dbe476297f34aff7e5f9320e2a99fb5e97136"
},
{
"txHex": "010000000200000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e8030000000000000000000000",
"inIndex": 0,
"script": "OP_0 OP_CODESEPARATOR OP_4",
"type": 0,
"hash": "fa075877cb54916236806a6562e4a8cdad48adf1268e73d72d1f9fdd867df463"
}
],
"invalid": { "invalid": {
"addInput": [ "addInput": [
{ {

View file

@ -172,6 +172,14 @@ describe('Transaction', function () {
}) })
}) })
// TODO: describe('hashForSignature', function () {
// hashForSignature: [Function], fixtures.hashForSignature.forEach(function (f) {
it('should return ' + f.hash + ' for ' + (f.description ? ('case "' + f.description + '"') : f.script), function () {
var tx = Transaction.fromHex(f.txHex)
var script = bscript.fromASM(f.script)
assert.strictEqual(tx.hashForSignature(f.inIndex, script, f.type).toString('hex'), f.hash)
})
})
})
}) })