From 6d224f6910f77a7552e732ef41a86d18b8bc1baa Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 28 Apr 2015 10:58:00 +1000 Subject: [PATCH] tests: core tests to use bufferutils.reverse --- test/bitcoin.core.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/test/bitcoin.core.js b/test/bitcoin.core.js index bce7741..12ae2ce 100644 --- a/test/bitcoin.core.js +++ b/test/bitcoin.core.js @@ -11,6 +11,7 @@ var ECSignature = Bitcoin.ECSignature var Transaction = Bitcoin.Transaction var Script = Bitcoin.Script +var bufferutils = Bitcoin.bufferutils var networks = Bitcoin.networks var base58_encode_decode = require('./fixtures/core/base58_encode_decode.json') @@ -158,21 +159,18 @@ describe('Bitcoin-core', function () { it('can decode ' + fhex, function () { var transaction = Transaction.fromHex(fhex) - transaction.ins.forEach(function (txin, i) { + transaction.ins.forEach(function (txIn, i) { var input = inputs[i] - var prevOutHash = input[0] + + // reverse because test data is big-endian + var prevOutHash = bufferutils.reverse(new Buffer(input[0], 'hex')) var prevOutIndex = input[1] // var prevOutScriptPubKey = input[2] // TODO: we don't have a ASM parser - var actualHash = txin.hash - - // Test data is big-endian - Array.prototype.reverse.call(actualHash) - - assert.equal(actualHash.toString('hex'), prevOutHash) + assert.deepEqual(txIn.hash, prevOutHash) // we read UInt32, not Int32 - assert.equal(txin.index & 0xffffffff, prevOutIndex) + assert.equal(txIn.index & 0xffffffff, prevOutIndex) }) }) }) @@ -188,7 +186,9 @@ describe('Bitcoin-core', function () { var scriptHex = f[1] var inIndex = f[2] var hashType = f[3] - var expectedHash = f[4] + + // reverse because test data is big-endian + var expectedHash = bufferutils.reverse(new Buffer(f[4], 'hex')) it('should hash ' + txHex + ' correctly', function () { var transaction = Transaction.fromHex(txHex) @@ -207,10 +207,7 @@ describe('Bitcoin-core', function () { } if (actualHash !== undefined) { - // Test data is big-endian - Array.prototype.reverse.call(actualHash) - - assert.equal(actualHash.toString('hex'), expectedHash) + assert.deepEqual(actualHash, expectedHash) } }) })