@@ -13,7 +13,7 @@ import * as sinon from "sinon"
1313// consts
1414const bitbox : BITBOX = new BITBOX ( )
1515const assert : Chai . AssertStatic = chai . assert
16- const rtMock = require ( "./fixtures /rawtransactions-mock" )
16+ const rtMock = require ( "./mocks /rawtransactions-mock" )
1717
1818// Used for debugging
1919util . inspect . defaultOptions = { depth : 1 }
@@ -277,138 +277,103 @@ describe("#RawTransactions", (): void => {
277277 )
278278 }
279279 } )
280-
281- it ( `should throw error on array size rate limit` , async ( ) : Promise <
282- any
283- > => {
284- try {
285- const dataMock : string =
286- "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1"
287- const data : string [ ] = [ ]
288- for ( let i : number = 0 ; i < 25 ; i ++ ) data . push ( dataMock )
289-
290- const result :
291- | VerboseRawTransactionResult
292- | VerboseRawTransactionResult [ ]
293- | string
294- | string [ ] = await bitbox . RawTransactions . getRawTransaction ( data )
295-
296- console . log ( `result: ${ util . inspect ( result ) } ` )
297- assert . equal ( true , false , "Unexpected result!" )
298- } catch ( err ) {
299- assert . hasAnyKeys ( err , [ "error" ] )
300- assert . include ( err . error , "Array too large" )
301- }
302- } )
303280 } )
304281
305282 describe ( "#decodeScript" , ( ) => {
306283 it ( "should decode script for a single hex" , async ( ) : Promise < any > => {
284+ // Mock the call to rest to prevent live network calls.
285+ const resolved = new Promise ( r => r ( { data : rtMock . decodedScript } ) )
286+ sandbox . stub ( axios , "get" ) . returns ( resolved )
287+
307288 const hex : string =
308289 "4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16"
309290
310291 const result = await bitbox . RawTransactions . decodeScript ( hex )
292+ //console.log(`result: ${JSON.stringify(result,null,2)}`)
311293
312294 assert . hasAllKeys ( result , [ "asm" , "type" , "p2sh" ] )
313295 } )
314296
315- // CT 2/20/19 - Waiting for this PR to be merged complete the test:
316- // https://github.com/Bitcoin-com/rest.bitcoin.com/pull/312
317- /*
318297 it ( "should decode an array of tx hexes" , async ( ) => {
298+ // Mock the call to rest to prevent live network calls.
299+ const testData = [ rtMock . decodedScript , rtMock . decodedScript ]
300+ const resolved = new Promise ( r => r ( { data : testData } ) )
301+ sandbox . stub ( axios , "post" ) . returns ( resolved )
302+
319303 const hexes = [
320304 "4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16" ,
321305 "4830450221009a51e00ec3524a7389592bc27bea4af5104a59510f5f0cfafa64bbd5c164ca2e02206c2a8bbb47eabdeed52f17d7df668d521600286406930426e3a9415fe10ed592012102e6e1423f7abde8b70bca3e78a7d030e5efabd3eb35c19302542b5fe7879c1a16"
322306 ]
323307
324308 const result = await bitbox . RawTransactions . decodeScript ( hexes )
325- console.log(`result ${JSON.stringify(result, null, 2)}`)
309+ //console.log(`result ${JSON.stringify(result, null, 2)}`)
310+
311+ assert . isArray ( result )
312+ assert . hasAnyKeys ( result [ 0 ] , [ "asm" , "type" , "p2sh" ] )
326313 } )
327- */
328- /*
329- it(`should throw an error for improper single input`, async () => {
314+
315+ it ( `should pass error from server to user` , async ( ) : Promise < any > => {
330316 try {
331- const addr = 12345
317+ // Mock out data for unit test, to prevent live network call.
318+ sandbox
319+ . stub ( axios , "get" )
320+ . throws ( "error" , "Input must be a string or array of strings" )
332321
333- await bitbox.RawTransactions.decodeRawTransaction(addr)
322+ const hexes : any = 12345
323+
324+ await bitbox . RawTransactions . decodeScript ( hexes )
334325 assert . equal ( true , false , "Unexpected result!" )
335326 } catch ( err ) {
336- //console.log(`err: `, err)
327+ //console.log(`err: ${util.inspect( err)}` )
337328 assert . include (
338329 err . message ,
339- `Input must be a string or array of strings. `
330+ `Input must be a string or array of strings`
340331 )
341332 }
342333 } )
343- */
344334 } )
345335
346336 /*
347- Testing sentRawTransaction isn't really possible with an integration test,
337+ Testing sendRawTransaction isn't really possible with an integration test,
348338 as the endpoint really needs an e2e test to be properly tested. The tests
349339 below expect error messages returned from the server, but at least test
350340 that the server is responding on those endpoints, and responds consistently.
351341 */
352342 describe ( "sendRawTransaction" , ( ) => {
353343 it ( "should send a single transaction hex" , async ( ) : Promise < any > => {
354344 try {
345+ // Mock out data for unit test, to prevent live network call.
346+ sandbox . stub ( axios , "get" ) . throws ( { error : "Missing inputs" } )
347+
355348 const hex : string =
356349 "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000"
357350
358351 await bitbox . RawTransactions . sendRawTransaction ( hex )
359352
360353 assert . equal ( true , false , "Unexpected result!" )
361354 } catch ( err ) {
355+ //console.log(`err: ${util.inspect(err)}`)
362356 assert . hasAllKeys ( err , [ "error" ] )
363357 assert . include ( err . error , "Missing inputs" )
364358 }
365359 } )
366360
367361 it ( "should send an array of tx hexes" , async ( ) : Promise < any > => {
368362 try {
363+ // Mock out data for unit test, to prevent live network call.
364+ sandbox . stub ( axios , "post" ) . throws ( { error : "Missing inputs" } )
365+
369366 const hexes : string [ ] = [
370367 "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000" ,
371368 "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000"
372369 ]
373370
374371 const result = await bitbox . RawTransactions . sendRawTransaction ( hexes )
375372 } catch ( err ) {
373+ // console.log(`err: ${util.inspect(err)}`)
376374 assert . hasAllKeys ( err , [ "error" ] )
377375 assert . include ( err . error , "Missing inputs" )
378376 }
379377 } )
380-
381- it ( `should throw an error for improper single input` , async ( ) : Promise <
382- any
383- > => {
384- try {
385- const addr : any = 12345
386-
387- await bitbox . RawTransactions . sendRawTransaction ( addr )
388- assert . equal ( true , false , "Unexpected result!" )
389- } catch ( err ) {
390- assert . include (
391- err . message ,
392- `Input hex must be a string or array of strings`
393- )
394- }
395- } )
396-
397- it ( `should throw error on array size rate limit` , async ( ) : Promise <
398- any
399- > => {
400- try {
401- const dataMock : string =
402- "01000000013ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000006a4730440220540986d1c58d6e76f8f05501c520c38ce55393d0ed7ed3c3a82c69af04221232022058ea43ed6c05fec0eccce749a63332ed4525460105346f11108b9c26df93cd72012103083dfc5a0254613941ddc91af39ff90cd711cdcde03a87b144b883b524660c39ffffffff01807c814a000000001976a914d7e7c4e0b70eaa67ceff9d2823d1bbb9f6df9a5188ac00000000"
403- const data : string [ ] = [ ]
404- for ( let i : number = 0 ; i < 25 ; i ++ ) data . push ( dataMock )
405-
406- await bitbox . RawTransactions . sendRawTransaction ( data )
407- assert . equal ( true , false , "Unexpected result!" )
408- } catch ( err ) {
409- assert . hasAnyKeys ( err , [ "error" ] )
410- assert . include ( err . error , "Array too large" )
411- }
412- } )
413378 } )
414379} )
0 commit comments