Skip to content

Commit dec2131

Browse files
afk11dcousens
authored andcommitted
Add test checking only old serialization is used in Transaction.hashForSignature
1 parent bec7f69 commit dec2131

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/transaction.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,29 @@ describe('Transaction', function () {
213213
})
214214

215215
describe('hashForSignature', function () {
216+
it('only uses V0 serialization', function () {
217+
var randScript = new Buffer('6a', 'hex')
218+
219+
var tmp = new Transaction()
220+
tmp.addInput(new Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex'), 0)
221+
tmp.addOutput(randScript, 5000000000)
222+
tmp.___toBuffer = tmp.__toBuffer
223+
tmp.__toBuffer = function (a, b, c) {
224+
if (c !== false) {
225+
throw new Error('Not meant to pass true to __toBuffer in hashForSignature')
226+
}
227+
return this.___toBuffer(a, b, c)
228+
}
229+
230+
assert.throws(function () {
231+
tmp.__toBuffer(undefined, undefined, true)
232+
}, 'Verify our replacement of __toBuffer can lead to an error if using witness')
233+
234+
assert.doesNotThrow(function () {
235+
tmp.hashForSignature(0, randScript, 1)
236+
}, "check that this situation doesn't occur normally")
237+
})
238+
216239
fixtures.hashForSignature.forEach(function (f) {
217240
it('should return ' + f.hash + ' for ' + (f.description ? ('case "' + f.description + '"') : f.script), function () {
218241
var tx = Transaction.fromHex(f.txHex)

0 commit comments

Comments
 (0)