@@ -167,6 +167,8 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
167
167
warpMessagePredicateBytes := predicate .PackPredicate (warpMessage .Bytes ())
168
168
getVerifiedWarpMsg , err := PackGetVerifiedWarpMessage (0 )
169
169
require .NoError (t , err )
170
+ noFailures := set .NewBits ().Bytes ()
171
+ require .Len (t , noFailures , 0 )
170
172
171
173
tests := map [string ]testutils.PrecompileTest {
172
174
"get message success" : {
@@ -176,7 +178,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
176
178
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessagePredicateBytes })
177
179
},
178
180
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
179
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
181
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
180
182
},
181
183
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessagePredicateBytes )),
182
184
ReadOnly : false ,
@@ -199,16 +201,14 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
199
201
Caller : callerAddr ,
200
202
InputFn : func (t testing.TB ) []byte {
201
203
input , err := PackGetVerifiedWarpMessage (1 )
202
- if err != nil {
203
- t .Fatal (err )
204
- }
204
+ require .NoError (t , err )
205
205
return input
206
206
},
207
207
BeforeHook : func (t testing.TB , state contract.StateDB ) {
208
208
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessagePredicateBytes })
209
209
},
210
210
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
211
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits (). Bytes () )
211
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
212
212
},
213
213
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
214
214
ReadOnly : false ,
@@ -224,16 +224,14 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
224
224
Caller : callerAddr ,
225
225
InputFn : func (t testing.TB ) []byte {
226
226
input , err := PackGetVerifiedWarpMessage (1 )
227
- if err != nil {
228
- t .Fatal (err )
229
- }
227
+ require .NoError (t , err )
230
228
return input
231
229
},
232
230
BeforeHook : func (t testing.TB , state contract.StateDB ) {
233
231
state .SetPredicateStorageSlots (ContractAddress , [][]byte {{}, warpMessagePredicateBytes })
234
232
},
235
233
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
236
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set .NewBits (1 ).Bytes ())
234
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set .NewBits (0 ).Bytes ())
237
235
},
238
236
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessagePredicateBytes )),
239
237
ReadOnly : false ,
@@ -252,11 +250,34 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
252
250
return res
253
251
}(),
254
252
},
253
+ "get message failure non-zero index" : {
254
+ Caller : callerAddr ,
255
+ InputFn : func (t testing.TB ) []byte {
256
+ input , err := PackGetVerifiedWarpMessage (1 )
257
+ require .NoError (t , err )
258
+ return input
259
+ },
260
+ BeforeHook : func (t testing.TB , state contract.StateDB ) {
261
+ state .SetPredicateStorageSlots (ContractAddress , [][]byte {{}, warpMessagePredicateBytes })
262
+ },
263
+ SetupBlockContext : func (mbc * contract.MockBlockContext ) {
264
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set .NewBits (0 , 1 ).Bytes ())
265
+ },
266
+ SuppliedGas : GetVerifiedWarpMessageBaseCost ,
267
+ ReadOnly : false ,
268
+ ExpectedRes : func () []byte {
269
+ res , err := PackGetVerifiedWarpMessageOutput (GetVerifiedWarpMessageOutput {Valid : false })
270
+ if err != nil {
271
+ panic (err )
272
+ }
273
+ return res
274
+ }(),
275
+ },
255
276
"get non-existent message" : {
256
277
Caller : callerAddr ,
257
278
InputFn : func (t testing.TB ) []byte { return getVerifiedWarpMsg },
258
279
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
259
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits (). Bytes () )
280
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
260
281
},
261
282
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
262
283
ReadOnly : false ,
@@ -275,7 +296,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
275
296
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessagePredicateBytes })
276
297
},
277
298
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
278
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
299
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
279
300
},
280
301
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessagePredicateBytes )),
281
302
ReadOnly : true ,
@@ -298,7 +319,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
298
319
Caller : callerAddr ,
299
320
InputFn : func (t testing.TB ) []byte { return getVerifiedWarpMsg },
300
321
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
301
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits (). Bytes () )
322
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
302
323
},
303
324
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
304
325
ReadOnly : true ,
@@ -327,7 +348,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
327
348
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessagePredicateBytes })
328
349
},
329
350
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
330
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
351
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
331
352
},
332
353
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessagePredicateBytes )) - 1 ,
333
354
ReadOnly : false ,
@@ -340,7 +361,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
340
361
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessage .Bytes ()})
341
362
},
342
363
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
343
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
364
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
344
365
},
345
366
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessage .Bytes ())),
346
367
ReadOnly : false ,
@@ -353,7 +374,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
353
374
state .SetPredicateStorageSlots (ContractAddress , [][]byte {predicate .PackPredicate ([]byte {1 , 2 , 3 })})
354
375
},
355
376
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
356
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
377
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
357
378
},
358
379
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (32 ),
359
380
ReadOnly : false ,
@@ -371,7 +392,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
371
392
state .SetPredicateStorageSlots (ContractAddress , [][]byte {predicate .PackPredicate (warpMessage .Bytes ())})
372
393
},
373
394
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
374
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
395
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
375
396
},
376
397
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (160 ),
377
398
ReadOnly : false ,
@@ -390,9 +411,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
390
411
Caller : callerAddr ,
391
412
InputFn : func (t testing.TB ) []byte {
392
413
res , err := PackGetVerifiedWarpMessage (math .MaxInt32 + 1 )
393
- if err != nil {
394
- t .Fatal (err )
395
- }
414
+ require .NoError (t , err )
396
415
return res
397
416
},
398
417
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
@@ -403,9 +422,7 @@ func TestGetVerifiedWarpMessage(t *testing.T) {
403
422
Caller : callerAddr ,
404
423
InputFn : func (t testing.TB ) []byte {
405
424
res , err := PackGetVerifiedWarpMessage (1 )
406
- if err != nil {
407
- t .Fatal (err )
408
- }
425
+ require .NoError (t , err )
409
426
return res [:len (res )- 2 ]
410
427
},
411
428
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
@@ -431,6 +448,8 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
431
448
warpMessagePredicateBytes := predicate .PackPredicate (warpMessage .Bytes ())
432
449
getVerifiedWarpBlockHash , err := PackGetVerifiedWarpBlockHash (0 )
433
450
require .NoError (t , err )
451
+ noFailures := set .NewBits ().Bytes ()
452
+ require .Len (t , noFailures , 0 )
434
453
435
454
tests := map [string ]testutils.PrecompileTest {
436
455
"get message success" : {
@@ -440,7 +459,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
440
459
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessagePredicateBytes })
441
460
},
442
461
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
443
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
462
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
444
463
},
445
464
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessagePredicateBytes )),
446
465
ReadOnly : false ,
@@ -462,16 +481,14 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
462
481
Caller : callerAddr ,
463
482
InputFn : func (t testing.TB ) []byte {
464
483
input , err := PackGetVerifiedWarpBlockHash (1 )
465
- if err != nil {
466
- t .Fatal (err )
467
- }
484
+ require .NoError (t , err )
468
485
return input
469
486
},
470
487
BeforeHook : func (t testing.TB , state contract.StateDB ) {
471
488
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessagePredicateBytes })
472
489
},
473
490
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
474
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits (). Bytes () )
491
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
475
492
},
476
493
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
477
494
ReadOnly : false ,
@@ -487,16 +504,14 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
487
504
Caller : callerAddr ,
488
505
InputFn : func (t testing.TB ) []byte {
489
506
input , err := PackGetVerifiedWarpBlockHash (1 )
490
- if err != nil {
491
- t .Fatal (err )
492
- }
507
+ require .NoError (t , err )
493
508
return input
494
509
},
495
510
BeforeHook : func (t testing.TB , state contract.StateDB ) {
496
511
state .SetPredicateStorageSlots (ContractAddress , [][]byte {{}, warpMessagePredicateBytes })
497
512
},
498
513
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
499
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set .NewBits (1 ).Bytes ())
514
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set .NewBits (0 ).Bytes ())
500
515
},
501
516
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessagePredicateBytes )),
502
517
ReadOnly : false ,
@@ -514,11 +529,34 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
514
529
return res
515
530
}(),
516
531
},
532
+ "get message failure non-zero index" : {
533
+ Caller : callerAddr ,
534
+ InputFn : func (t testing.TB ) []byte {
535
+ input , err := PackGetVerifiedWarpBlockHash (1 )
536
+ require .NoError (t , err )
537
+ return input
538
+ },
539
+ BeforeHook : func (t testing.TB , state contract.StateDB ) {
540
+ state .SetPredicateStorageSlots (ContractAddress , [][]byte {{}, warpMessagePredicateBytes })
541
+ },
542
+ SetupBlockContext : func (mbc * contract.MockBlockContext ) {
543
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set .NewBits (0 , 1 ).Bytes ())
544
+ },
545
+ SuppliedGas : GetVerifiedWarpMessageBaseCost ,
546
+ ReadOnly : false ,
547
+ ExpectedRes : func () []byte {
548
+ res , err := PackGetVerifiedWarpBlockHashOutput (GetVerifiedWarpBlockHashOutput {Valid : false })
549
+ if err != nil {
550
+ panic (err )
551
+ }
552
+ return res
553
+ }(),
554
+ },
517
555
"get non-existent message" : {
518
556
Caller : callerAddr ,
519
557
InputFn : func (t testing.TB ) []byte { return getVerifiedWarpBlockHash },
520
558
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
521
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits (). Bytes () )
559
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
522
560
},
523
561
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
524
562
ReadOnly : false ,
@@ -537,7 +575,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
537
575
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessagePredicateBytes })
538
576
},
539
577
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
540
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
578
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
541
579
},
542
580
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessagePredicateBytes )),
543
581
ReadOnly : true ,
@@ -559,7 +597,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
559
597
Caller : callerAddr ,
560
598
InputFn : func (t testing.TB ) []byte { return getVerifiedWarpBlockHash },
561
599
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
562
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits (). Bytes () )
600
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
563
601
},
564
602
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
565
603
ReadOnly : true ,
@@ -588,7 +626,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
588
626
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessagePredicateBytes })
589
627
},
590
628
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
591
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
629
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
592
630
},
593
631
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessagePredicateBytes )) - 1 ,
594
632
ReadOnly : false ,
@@ -601,7 +639,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
601
639
state .SetPredicateStorageSlots (ContractAddress , [][]byte {warpMessage .Bytes ()})
602
640
},
603
641
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
604
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
642
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
605
643
},
606
644
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (len (warpMessage .Bytes ())),
607
645
ReadOnly : false ,
@@ -614,7 +652,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
614
652
state .SetPredicateStorageSlots (ContractAddress , [][]byte {predicate .PackPredicate ([]byte {1 , 2 , 3 })})
615
653
},
616
654
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
617
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
655
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
618
656
},
619
657
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (32 ),
620
658
ReadOnly : false ,
@@ -632,7 +670,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
632
670
state .SetPredicateStorageSlots (ContractAddress , [][]byte {predicate .PackPredicate (warpMessage .Bytes ())})
633
671
},
634
672
SetupBlockContext : func (mbc * contract.MockBlockContext ) {
635
- mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (set . NewBits ( 0 ). Bytes () )
673
+ mbc .EXPECT ().GetPredicateResults (common.Hash {}, ContractAddress ).Return (noFailures )
636
674
},
637
675
SuppliedGas : GetVerifiedWarpMessageBaseCost + GasCostPerWarpMessageBytes * uint64 (160 ),
638
676
ReadOnly : false ,
@@ -651,9 +689,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
651
689
Caller : callerAddr ,
652
690
InputFn : func (t testing.TB ) []byte {
653
691
res , err := PackGetVerifiedWarpBlockHash (math .MaxInt32 + 1 )
654
- if err != nil {
655
- t .Fatal (err )
656
- }
692
+ require .NoError (t , err )
657
693
return res
658
694
},
659
695
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
@@ -664,9 +700,7 @@ func TestGetVerifiedWarpBlockHash(t *testing.T) {
664
700
Caller : callerAddr ,
665
701
InputFn : func (t testing.TB ) []byte {
666
702
res , err := PackGetVerifiedWarpBlockHash (1 )
667
- if err != nil {
668
- t .Fatal (err )
669
- }
703
+ require .NoError (t , err )
670
704
return res [:len (res )- 2 ]
671
705
},
672
706
SuppliedGas : GetVerifiedWarpMessageBaseCost ,
0 commit comments