Skip to content

Commit 6d224f6

Browse files
committed
tests: core tests to use bufferutils.reverse
1 parent 225cee8 commit 6d224f6

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

test/bitcoin.core.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var ECSignature = Bitcoin.ECSignature
1111
var Transaction = Bitcoin.Transaction
1212
var Script = Bitcoin.Script
1313

14+
var bufferutils = Bitcoin.bufferutils
1415
var networks = Bitcoin.networks
1516

1617
var base58_encode_decode = require('./fixtures/core/base58_encode_decode.json')
@@ -158,21 +159,18 @@ describe('Bitcoin-core', function () {
158159
it('can decode ' + fhex, function () {
159160
var transaction = Transaction.fromHex(fhex)
160161

161-
transaction.ins.forEach(function (txin, i) {
162+
transaction.ins.forEach(function (txIn, i) {
162163
var input = inputs[i]
163-
var prevOutHash = input[0]
164+
165+
// reverse because test data is big-endian
166+
var prevOutHash = bufferutils.reverse(new Buffer(input[0], 'hex'))
164167
var prevOutIndex = input[1]
165168
// var prevOutScriptPubKey = input[2] // TODO: we don't have a ASM parser
166169

167-
var actualHash = txin.hash
168-
169-
// Test data is big-endian
170-
Array.prototype.reverse.call(actualHash)
171-
172-
assert.equal(actualHash.toString('hex'), prevOutHash)
170+
assert.deepEqual(txIn.hash, prevOutHash)
173171

174172
// we read UInt32, not Int32
175-
assert.equal(txin.index & 0xffffffff, prevOutIndex)
173+
assert.equal(txIn.index & 0xffffffff, prevOutIndex)
176174
})
177175
})
178176
})
@@ -188,7 +186,9 @@ describe('Bitcoin-core', function () {
188186
var scriptHex = f[1]
189187
var inIndex = f[2]
190188
var hashType = f[3]
191-
var expectedHash = f[4]
189+
190+
// reverse because test data is big-endian
191+
var expectedHash = bufferutils.reverse(new Buffer(f[4], 'hex'))
192192

193193
it('should hash ' + txHex + ' correctly', function () {
194194
var transaction = Transaction.fromHex(txHex)
@@ -207,10 +207,7 @@ describe('Bitcoin-core', function () {
207207
}
208208

209209
if (actualHash !== undefined) {
210-
// Test data is big-endian
211-
Array.prototype.reverse.call(actualHash)
212-
213-
assert.equal(actualHash.toString('hex'), expectedHash)
210+
assert.deepEqual(actualHash, expectedHash)
214211
}
215212
})
216213
})

0 commit comments

Comments
 (0)