@@ -11,6 +11,7 @@ var ECSignature = Bitcoin.ECSignature
1111var Transaction = Bitcoin . Transaction
1212var Script = Bitcoin . Script
1313
14+ var bufferutils = Bitcoin . bufferutils
1415var networks = Bitcoin . networks
1516
1617var 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