@@ -8,6 +8,8 @@ import { REST_URL } from "../../lib/BITBOX"
88import * as util from "util"
99import { BlockHeaderResult } from "bitcoin-com-rest"
1010
11+ const mockData = require ( "./mocks/blockchain-mock" )
12+
1113// consts
1214const bitbox : BITBOX = new BITBOX ( )
1315const assert : Chai . AssertStatic = chai . assert
@@ -347,27 +349,61 @@ describe("#Blockchain", (): void => {
347349 } )
348350
349351 describe ( "#getTxOut" , ( ) : void => {
350- // TODO finish this test
351352 let sandbox : any
352353 beforeEach ( ( ) => ( sandbox = sinon . sandbox . create ( ) ) )
353354 afterEach ( ( ) => sandbox . restore ( ) )
354355 const data = {
355356 result : { }
356357 }
357358
358- it ( "should get TODO" , done => {
359- const resolved = new Promise ( r => r ( { data : data } ) )
360- sandbox . stub ( axios , "get" ) . returns ( resolved )
359+ it ( "should throw an error for improper txid." , async ( ) => {
360+ try {
361+ await bitbox . Blockchain . getTxOut ( "badtxid" , 0 )
362+ } catch ( err ) {
363+ assert . include ( err . message , "txid needs to be a proper transaction ID" )
364+ }
365+ } )
361366
362- bitbox . Blockchain . getTxOut (
363- "daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88" ,
367+ it ( "should throw an error if vout is not an integer." , async ( ) => {
368+ try {
369+ await bitbox . Blockchain . getTxOut (
370+ "daf58932cb91619304dd4cbd03c7202e89ad7d6cbd6e2209e5f64ce3b6ed7c88" , 'a'
371+ )
372+ } catch ( err ) {
373+ assert . include ( err . message , "n must be an integer" )
374+ }
375+ } )
376+
377+ it ( "should get information on an unspent tx" , async ( ) => {
378+ sandbox . stub ( axios , "get" ) . resolves ( { data : mockData . txOutUnspent } )
379+
380+ const result = await bitbox . Blockchain . getTxOut (
381+ "62a3ea958a463a372bc0caf2c374a7f60be9c624be63a0db8db78f05809df6d8" ,
364382 0 ,
365383 true
366384 )
367- . then ( ( result : any ) => {
368- assert . deepEqual ( data , result )
369- } )
370- . then ( done , done )
385+ // console.log(`result: ${JSON.stringify(result, null, 2)}`)
386+
387+ assert . hasAllKeys ( result , [
388+ "bestblock" ,
389+ "confirmations" ,
390+ "value" ,
391+ "scriptPubKey" ,
392+ "coinbase"
393+ ] )
394+ } )
395+
396+ it ( "should get information on a spent tx" , async ( ) => {
397+ sandbox . stub ( axios , "get" ) . resolves ( { data : null } )
398+
399+ const result = await bitbox . Blockchain . getTxOut (
400+ "87380e52d151856b23173d6d8a3db01b984c6b50f77ea045a5a1cf4f54497871" ,
401+ 0 ,
402+ true
403+ )
404+ // console.log(`result: ${JSON.stringify(result, null, 2)}`)
405+
406+ assert . equal ( result , null )
371407 } )
372408 } )
373409
0 commit comments