@@ -142,8 +142,12 @@ test('blockchain test', t => {
142
142
st . error ( err , 'no error' )
143
143
blockchain . getBlock ( 1 , ( err ?: Error , block ?: Block ) => {
144
144
st . error ( err , 'no error' )
145
- st . equal ( block . hash ( ) . toString ( 'hex' ) , blocks [ 1 ] . hash ( ) . toString ( 'hex' ) )
146
- st . end ( )
145
+ if ( block ) {
146
+ st . equal ( block . hash ( ) . toString ( 'hex' ) , blocks [ 1 ] . hash ( ) . toString ( 'hex' ) )
147
+ st . end ( )
148
+ } else {
149
+ st . fail ( 'block is not defined!' )
150
+ }
147
151
} )
148
152
} )
149
153
} )
@@ -158,8 +162,12 @@ test('blockchain test', t => {
158
162
st . error ( err , 'no error' )
159
163
blockchain . getBlock ( genesisBlock . hash ( ) , ( err ?: Error , block ?: Block ) => {
160
164
st . error ( err , 'no error' )
161
- st . equal ( block . hash ( ) . toString ( 'hex' ) , genesisBlock . hash ( ) . toString ( 'hex' ) )
162
- st . end ( )
165
+ if ( block ) {
166
+ st . equal ( block . hash ( ) . toString ( 'hex' ) , genesisBlock . hash ( ) . toString ( 'hex' ) )
167
+ st . end ( )
168
+ } else {
169
+ st . fail ( 'block is not defined!' )
170
+ }
163
171
} )
164
172
} )
165
173
} )
@@ -370,7 +378,7 @@ test('blockchain test', t => {
370
378
} )
371
379
372
380
t . test ( 'should catch iterator func error' , async st => {
373
- const { blockchain, blocks , error } = await generateBlockchain ( 25 )
381
+ const { blockchain, error } = await generateBlockchain ( 25 )
374
382
st . error ( error , 'no error' )
375
383
blockchain . iterator (
376
384
'error' ,
@@ -585,9 +593,13 @@ test('blockchain test', t => {
585
593
if ( err ) {
586
594
return st . error ( err )
587
595
}
588
- st . equals ( head . hash ( ) . toString ( 'hex' ) , genesis . hash ( ) . toString ( 'hex' ) , 'should get head' )
589
- st . equals ( blockchain . _heads [ 'head0' ] . toString ( 'hex' ) , 'abcd' , 'should get state root heads' )
590
- st . end ( )
596
+ if ( genesis ) {
597
+ st . equals ( head . hash ( ) . toString ( 'hex' ) , genesis . hash ( ) . toString ( 'hex' ) , 'should get head' )
598
+ st . equals ( blockchain . _heads [ 'head0' ] . toString ( 'hex' ) , 'abcd' , 'should get state root heads' )
599
+ st . end ( )
600
+ } else {
601
+ st . fail ( )
602
+ }
591
603
} )
592
604
} )
593
605
} )
@@ -627,6 +639,9 @@ test('blockchain test', t => {
627
639
if ( err ) {
628
640
return st . error ( err )
629
641
}
642
+ if ( ! genesis ) {
643
+ return st . fail ( 'genesis not defined!' )
644
+ }
630
645
const blockchain = new Blockchain ( { db : db } )
631
646
async . series (
632
647
[
@@ -746,6 +761,9 @@ test('blockchain test', t => {
746
761
if ( err ) {
747
762
return st . error ( err )
748
763
}
764
+ if ( ! block ) {
765
+ return st . fail ( 'block not defined!' )
766
+ }
749
767
st . equals (
750
768
cachedHash . toString ( 'hex' ) ,
751
769
block . hash ( ) . toString ( 'hex' ) ,
@@ -854,6 +872,9 @@ test('blockchain test', t => {
854
872
if ( err ) {
855
873
return st . error ( err )
856
874
}
875
+ if ( ! getBlock ) {
876
+ return st . fail ( 'getBlock not defined!' )
877
+ }
857
878
t . equals (
858
879
getBlock . hash ( ) . toString ( 'hex' ) ,
859
880
block . hash ( ) . toString ( 'hex' ) ,
0 commit comments