diff --git a/test/fixtures/transaction.json b/test/fixtures/transaction.json index 214b115..20de9a1 100644 --- a/test/fixtures/transaction.json +++ b/test/fixtures/transaction.json @@ -231,6 +231,45 @@ "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": { "addInput": [ { diff --git a/test/transaction.js b/test/transaction.js index 4aa7a27..d11ab29 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -172,6 +172,14 @@ describe('Transaction', function () { }) }) - // TODO: - // hashForSignature: [Function], + describe('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) + }) + }) + }) })