Skip to content

Commit 7ce2866

Browse files
committed
tests: enable all core SIGHASH_* tests
1 parent ab83f8f commit 7ce2866

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

test/bitcoin.core.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,25 +190,23 @@ describe('Bitcoin-core', function () {
190190
// reverse because test data is big-endian
191191
var expectedHash = bufferutils.reverse(new Buffer(f[4], 'hex'))
192192

193-
it('should hash ' + txHex + ' correctly', function () {
193+
var hashTypes = []
194+
if ((hashType & 0x1f) === Transaction.SIGHASH_NONE) hashTypes.push('SIGHASH_NONE')
195+
else if ((hashType & 0x1f) === Transaction.SIGHASH_SINGLE) hashTypes.push('SIGHASH_SINGLE')
196+
else hashTypes.push('SIGHASH_ALL')
197+
if (hashType & Transaction.SIGHASH_ANYONECANPAY) hashTypes.push('SIGHASH_ANYONECANPAY')
198+
199+
var hashTypeName = hashTypes.join(' | ')
200+
201+
it('should hash ' + txHex.slice(0, 40) + '... (' + hashTypeName + ')', function () {
194202
var transaction = Transaction.fromHex(txHex)
195203
assert.equal(transaction.toHex(), txHex)
196204

197205
var script = Script.fromHex(scriptHex)
198206
assert.equal(script.toHex(), scriptHex)
199207

200-
var actualHash
201-
try {
202-
actualHash = transaction.hashForSignature(inIndex, script, hashType)
203-
} catch (e) {
204-
// don't fail if we don't support it yet, TODO
205-
if (!e.message.match(/not yet supported/))
206-
throw e
207-
}
208-
209-
if (actualHash !== undefined) {
210-
assert.deepEqual(actualHash, expectedHash)
211-
}
208+
var hash = transaction.hashForSignature(inIndex, script, hashType)
209+
assert.deepEqual(hash, expectedHash)
212210
})
213211
})
214212
})

0 commit comments

Comments
 (0)