Skip to content

Commit c3124c3

Browse files
committed
refactor tests
1 parent 85921cd commit c3124c3

File tree

2 files changed

+92
-51
lines changed

2 files changed

+92
-51
lines changed

core/retry_test.go

Lines changed: 78 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ func TestWaitForTransactionReceipt(t *testing.T) {
170170
}
171171

172172
// Assert Call succeeds when Anvil running
173-
_, err = utils.WaitForTransactionReceiptRetryable(*client, *client, hash, retry.DefaultRetryConfig())
173+
receipt_function := utils.WaitForTransactionReceipt(*client, *client, hash, retry.DefaultRetryConfig())
174+
_, err = receipt_function()
174175
assert.NotNil(t, err, "Error Waiting for Transaction with Anvil Running: %s\n", err)
175176
if !strings.Contains(err.Error(), "not found") {
176177
t.Errorf("WaitForTransactionReceipt Emitted incorrect error: %s\n", err)
@@ -182,7 +183,8 @@ func TestWaitForTransactionReceipt(t *testing.T) {
182183
return
183184
}
184185

185-
_, err = utils.WaitForTransactionReceiptRetryable(*client, *client, hash, retry.DefaultRetryConfig())
186+
receipt_function = utils.WaitForTransactionReceipt(*client, *client, hash, retry.DefaultRetryConfig())
187+
_, err = receipt_function()
186188
assert.NotNil(t, err)
187189
if _, ok := err.(retry.PermanentError); ok {
188190
t.Errorf("WaitForTransactionReceipt Emitted non Transient error: %s\n", err)
@@ -198,7 +200,8 @@ func TestWaitForTransactionReceipt(t *testing.T) {
198200
t.Errorf("Error setting up Anvil: %s\n", err)
199201
}
200202

201-
_, err = utils.WaitForTransactionReceiptRetryable(*client, *client, hash, retry.DefaultRetryConfig())
203+
receipt_function = utils.WaitForTransactionReceipt(*client, *client, hash, retry.DefaultRetryConfig())
204+
_, err = receipt_function()
202205
assert.NotNil(t, err)
203206
if !strings.Contains(err.Error(), "not found") {
204207
t.Errorf("WaitForTransactionReceipt Emitted incorrect error: %s\n", err)
@@ -356,21 +359,23 @@ func TestSubscribeToNewTasksV3(t *testing.T) {
356359
t.Errorf("Error setting up Avs Service Bindings: %s\n", err)
357360
}
358361

359-
_, err = chainio.SubscribeToNewTasksV3Retryable(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
362+
sub_func := chainio.SubscribeToNewTasksV3(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
363+
_, err = sub_func()
360364
assert.Nil(t, err)
361365

362366
if err := cmd.Process.Kill(); err != nil {
363367
t.Errorf("Error killing process: %v\n", err)
364368
return
365369
}
366370

367-
_, err = chainio.SubscribeToNewTasksV3Retryable(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
371+
sub_func = chainio.SubscribeToNewTasksV3(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
372+
_, err = sub_func()
368373
assert.NotNil(t, err)
369374
if _, ok := err.(retry.PermanentError); ok {
370375
t.Errorf("SubscribeToNewTasksV3 Emitted non Transient error: %s\n", err)
371376
return
372377
}
373-
if !strings.Contains(err.Error(), "connect: connection refused") {
378+
if !strings.Contains(err.Error(), "connection reset") {
374379
t.Errorf("SubscribeToNewTasksV3 Emitted non Transient error: %s\n", err)
375380
return
376381
}
@@ -380,7 +385,8 @@ func TestSubscribeToNewTasksV3(t *testing.T) {
380385
t.Errorf("Error setting up Anvil: %s\n", err)
381386
}
382387

383-
_, err = chainio.SubscribeToNewTasksV3Retryable(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
388+
sub_func = chainio.SubscribeToNewTasksV3(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
389+
_, err = sub_func()
384390
assert.Nil(t, err)
385391

386392
if err := cmd.Process.Kill(); err != nil {
@@ -406,21 +412,24 @@ func TestSubscribeToNewTasksV2(t *testing.T) {
406412
t.Errorf("Error setting up Avs Service Bindings: %s\n", err)
407413
}
408414

409-
_, err = chainio.SubscribeToNewTasksV2Retryable(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
415+
sub_func := chainio.SubscribeToNewTasksV2(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
416+
_, err = sub_func()
410417
assert.Nil(t, err)
411418

412419
if err := cmd.Process.Kill(); err != nil {
413420
t.Errorf("Error killing process: %v\n", err)
414421
return
415422
}
416423

417-
_, err = chainio.SubscribeToNewTasksV2Retryable(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
424+
sub_func = chainio.SubscribeToNewTasksV2(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
425+
_, err = sub_func()
426+
418427
assert.NotNil(t, err)
419428
if _, ok := err.(retry.PermanentError); ok {
420429
t.Errorf("SubscribeToNewTasksV2 Emitted non Transient error: %s\n", err)
421430
return
422431
}
423-
if !strings.Contains(err.Error(), "connect: connection refused") {
432+
if !strings.Contains(err.Error(), "connection reset") {
424433
t.Errorf("SubscribeToNewTasksV2 Emitted non Transient error: %s\n", err)
425434
return
426435
}
@@ -430,7 +439,8 @@ func TestSubscribeToNewTasksV2(t *testing.T) {
430439
t.Errorf("Error setting up Anvil: %s\n", err)
431440
}
432441

433-
_, err = chainio.SubscribeToNewTasksV2Retryable(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
442+
sub_func = chainio.SubscribeToNewTasksV2(&bind.WatchOpts{}, s.ServiceManager, channel, nil)
443+
_, err = sub_func()
434444
assert.Nil(t, err)
435445

436446
if err := cmd.Process.Kill(); err != nil {
@@ -451,15 +461,17 @@ func TestBlockNumber(t *testing.T) {
451461
if err != nil {
452462
return
453463
}
454-
_, err = sub.BlockNumberRetryable(context.Background())
464+
block_func := chainio.BlockNumber(sub, context.Background())
465+
_, err = block_func()
455466
assert.Nil(t, err)
456467

457468
if err := cmd.Process.Kill(); err != nil {
458469
t.Errorf("Error killing process: %v\n", err)
459470
return
460471
}
461472

462-
_, err = sub.BlockNumberRetryable(context.Background())
473+
block_func = chainio.BlockNumber(sub, context.Background())
474+
_, err = block_func()
463475
assert.NotNil(t, err)
464476
if _, ok := err.(retry.PermanentError); ok {
465477
t.Errorf("BlockNumber Emitted non Transient error: %s\n", err)
@@ -475,7 +487,8 @@ func TestBlockNumber(t *testing.T) {
475487
t.Errorf("Error setting up Anvil: %s\n", err)
476488
}
477489

478-
_, err = sub.BlockNumberRetryable(context.Background())
490+
block_func = chainio.BlockNumber(sub, context.Background())
491+
_, err = block_func()
479492
assert.Nil(t, err)
480493

481494
if err := cmd.Process.Kill(); err != nil {
@@ -495,21 +508,23 @@ func TestFilterBatchV2(t *testing.T) {
495508
if err != nil {
496509
return
497510
}
498-
_, err = avsSubscriber.FilterBatchV2Retryable(&bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
511+
batch_func := chainio.FilterBatchV2(avsSubscriber, &bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
512+
_, err = batch_func()
499513
assert.Nil(t, err)
500514

501515
if err := cmd.Process.Kill(); err != nil {
502516
t.Errorf("Error killing process: %v\n", err)
503517
return
504518
}
505519

506-
_, err = avsSubscriber.FilterBatchV2Retryable(&bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
520+
batch_func = chainio.FilterBatchV2(avsSubscriber, &bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
521+
_, err = batch_func()
507522
assert.NotNil(t, err)
508523
if _, ok := err.(retry.PermanentError); ok {
509524
t.Errorf("FilterBatchV2 Emitted non Transient error: %s\n", err)
510525
return
511526
}
512-
if !strings.Contains(err.Error(), "connect: connection refused") {
527+
if !strings.Contains(err.Error(), "connection reset") {
513528
t.Errorf("FilterBatchV2 Emitted non Transient error: %s\n", err)
514529
return
515530
}
@@ -519,7 +534,8 @@ func TestFilterBatchV2(t *testing.T) {
519534
t.Errorf("Error setting up Anvil: %s\n", err)
520535
}
521536

522-
_, err = avsSubscriber.FilterBatchV2Retryable(&bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
537+
batch_func = chainio.FilterBatchV2(avsSubscriber, &bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
538+
_, err = batch_func()
523539
assert.Nil(t, err)
524540

525541
if err := cmd.Process.Kill(); err != nil {
@@ -539,21 +555,23 @@ func TestFilterBatchV3(t *testing.T) {
539555
if err != nil {
540556
return
541557
}
542-
_, err = avsSubscriber.FilterBatchV3Retryable(&bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
558+
batch_func := chainio.FilterBatchV3(avsSubscriber, &bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
559+
_, err = batch_func()
543560
assert.Nil(t, err)
544561

545562
if err := cmd.Process.Kill(); err != nil {
546563
t.Errorf("Error killing process: %v\n", err)
547564
return
548565
}
549566

550-
_, err = avsSubscriber.FilterBatchV3Retryable(&bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
567+
batch_func = chainio.FilterBatchV3(avsSubscriber, &bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
568+
_, err = batch_func()
551569
assert.NotNil(t, err)
552570
if _, ok := err.(retry.PermanentError); ok {
553571
t.Errorf("FilerBatchV3 Emitted non Transient error: %s\n", err)
554572
return
555573
}
556-
if !strings.Contains(err.Error(), "connect: connection refused") {
574+
if !strings.Contains(err.Error(), "connection reset") {
557575
t.Errorf("FilterBatchV3 Emitted non Transient error: %s\n", err)
558576
return
559577
}
@@ -563,7 +581,8 @@ func TestFilterBatchV3(t *testing.T) {
563581
t.Errorf("Error setting up Anvil: %s\n", err)
564582
}
565583

566-
_, err = avsSubscriber.FilterBatchV3Retryable(&bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
584+
batch_func = chainio.FilterBatchV3(avsSubscriber, &bind.FilterOpts{Start: 0, End: nil, Context: context.Background()}, nil)
585+
_, err = batch_func()
567586
assert.Nil(t, err)
568587

569588
if err := cmd.Process.Kill(); err != nil {
@@ -585,21 +604,23 @@ func TestBatchesStateSubscriber(t *testing.T) {
585604
}
586605

587606
zero_bytes := [32]byte{}
588-
_, err = avsSubscriber.BatchesStateRetryable(nil, zero_bytes)
607+
batch_state_func := chainio.BatchState(avsSubscriber, nil, zero_bytes)
608+
_, err = batch_state_func()
589609
assert.Nil(t, err)
590610

591611
if err := cmd.Process.Kill(); err != nil {
592612
t.Errorf("Error killing process: %v\n", err)
593613
return
594614
}
595615

596-
_, err = avsSubscriber.BatchesStateRetryable(nil, zero_bytes)
616+
batch_state_func = chainio.BatchState(avsSubscriber, nil, zero_bytes)
617+
_, err = batch_state_func()
597618
assert.NotNil(t, err)
598619
if _, ok := err.(retry.PermanentError); ok {
599620
t.Errorf("BatchesStateSubscriber Emitted non Transient error: %s\n", err)
600621
return
601622
}
602-
if !strings.Contains(err.Error(), "connect: connection refused") {
623+
if !strings.Contains(err.Error(), "connection reset") {
603624
t.Errorf("BatchesStateSubscriber Emitted non Transient error: %s\n", err)
604625
return
605626
}
@@ -609,7 +630,8 @@ func TestBatchesStateSubscriber(t *testing.T) {
609630
t.Errorf("Error setting up Anvil: %s\n", err)
610631
}
611632

612-
_, err = avsSubscriber.BatchesStateRetryable(nil, zero_bytes)
633+
batch_state_func = chainio.BatchState(avsSubscriber, nil, zero_bytes)
634+
_, err = batch_state_func()
613635
assert.Nil(t, err)
614636

615637
if err := cmd.Process.Kill(); err != nil {
@@ -631,15 +653,17 @@ func TestSubscribeNewHead(t *testing.T) {
631653
return
632654
}
633655

634-
_, err = avsSubscriber.SubscribeNewHeadRetryable(context.Background(), c)
656+
sub_func := chainio.SubscribeNewHead(avsSubscriber, context.Background(), c)
657+
_, err = sub_func()
635658
assert.Nil(t, err)
636659

637660
if err := cmd.Process.Kill(); err != nil {
638661
t.Errorf("Error killing process: %v\n", err)
639662
return
640663
}
641664

642-
_, err = avsSubscriber.SubscribeNewHeadRetryable(context.Background(), c)
665+
sub_func = chainio.SubscribeNewHead(avsSubscriber, context.Background(), c)
666+
_, err = sub_func()
643667
assert.NotNil(t, err)
644668
if _, ok := err.(retry.PermanentError); ok {
645669
t.Errorf("SubscribeNewHead Emitted non Transient error: %s\n", err)
@@ -655,7 +679,8 @@ func TestSubscribeNewHead(t *testing.T) {
655679
t.Errorf("Error setting up Anvil: %s\n", err)
656680
}
657681

658-
_, err = avsSubscriber.SubscribeNewHeadRetryable(context.Background(), c)
682+
sub_func = chainio.SubscribeNewHead(avsSubscriber, context.Background(), c)
683+
_, err = sub_func()
659684
assert.Nil(t, err)
660685

661686
if err := cmd.Process.Kill(); err != nil {
@@ -708,7 +733,8 @@ func TestRespondToTaskV2(t *testing.T) {
708733
zero_bytes := [32]byte{}
709734

710735
// NOTE: With zero bytes the tx reverts
711-
_, err = w.RespondToTaskV2Retryable(&txOpts, zero_bytes, aggregator_address, nonSignerStakesAndSignature)
736+
resp_func := chainio.RespondToTaskV2(w, &txOpts, zero_bytes, aggregator_address, nonSignerStakesAndSignature)
737+
_, err = resp_func()
712738
assert.NotNil(t, err)
713739
if !strings.Contains(err.Error(), "execution reverted") {
714740
t.Errorf("RespondToTaskV2 did not emit the expected message: %q doesn't contain %q", err.Error(), "execution reverted: custom error 0x2396d34e:")
@@ -718,7 +744,8 @@ func TestRespondToTaskV2(t *testing.T) {
718744
t.Errorf("Error killing process: %v\n", err)
719745
}
720746

721-
_, err = w.RespondToTaskV2Retryable(&txOpts, zero_bytes, aggregator_address, nonSignerStakesAndSignature)
747+
resp_func = chainio.RespondToTaskV2(w, &txOpts, zero_bytes, aggregator_address, nonSignerStakesAndSignature)
748+
_, err = resp_func()
722749
assert.NotNil(t, err)
723750
if _, ok := err.(*backoff.PermanentError); ok {
724751
t.Errorf("RespondToTaskV2 Emitted non-Transient error: %s\n", err)
@@ -733,7 +760,8 @@ func TestRespondToTaskV2(t *testing.T) {
733760
}
734761

735762
// NOTE: With zero bytes the tx reverts
736-
_, err = w.RespondToTaskV2Retryable(&txOpts, zero_bytes, aggregator_address, nonSignerStakesAndSignature)
763+
resp_func = chainio.RespondToTaskV2(w, &txOpts, zero_bytes, aggregator_address, nonSignerStakesAndSignature)
764+
_, err = resp_func()
737765
assert.NotNil(t, err)
738766
if !strings.Contains(err.Error(), "execution reverted") {
739767
t.Errorf("RespondToTaskV2 did not emit the expected message: %q doesn't contain %q", err.Error(), "execution reverted: custom error 0x2396d34e:")
@@ -761,15 +789,17 @@ func TestBatchesStateWriter(t *testing.T) {
761789
var bytes [32]byte
762790
num.FillBytes(bytes[:])
763791

764-
_, err = avsWriter.BatchesStateRetryable(&bind.CallOpts{}, bytes)
792+
state_func := chainio.BatchesState(avsWriter, &bind.CallOpts{}, bytes)
793+
_, err = state_func()
765794
assert.Nil(t, err)
766795

767796
if err := cmd.Process.Kill(); err != nil {
768797
t.Errorf("error killing process: %v\n", err)
769798
return
770799
}
771800

772-
_, err = avsWriter.BatchesStateRetryable(&bind.CallOpts{}, bytes)
801+
state_func = chainio.BatchesState(avsWriter, &bind.CallOpts{}, bytes)
802+
_, err = state_func()
773803
assert.NotNil(t, err)
774804
if _, ok := err.(retry.PermanentError); ok {
775805
t.Errorf("BatchesStateWriter Emitted non-Transient error: %s\n", err)
@@ -785,7 +815,8 @@ func TestBatchesStateWriter(t *testing.T) {
785815
t.Errorf("Error setting up Anvil: %s\n", err)
786816
}
787817

788-
_, err = avsWriter.BatchesStateRetryable(&bind.CallOpts{}, bytes)
818+
state_func = chainio.BatchesState(avsWriter, &bind.CallOpts{}, bytes)
819+
_, err = state_func()
789820
assert.Nil(t, err)
790821

791822
if err := cmd.Process.Kill(); err != nil {
@@ -808,15 +839,17 @@ func TestBalanceAt(t *testing.T) {
808839
aggregator_address := common.HexToAddress("0x0")
809840
blockHeight := big.NewInt(13)
810841

811-
_, err = avsWriter.BalanceAtRetryable(context.Background(), aggregator_address, blockHeight)
842+
balance_func := chainio.BalanceAt(avsWriter, context.Background(), aggregator_address, blockHeight)
843+
_, err = balance_func()
812844
assert.Nil(t, err)
813845

814846
if err := cmd.Process.Kill(); err != nil {
815847
t.Errorf("Error killing process: %v\n", err)
816848
return
817849
}
818850

819-
_, err = avsWriter.BalanceAtRetryable(context.Background(), aggregator_address, blockHeight)
851+
balance_func = chainio.BalanceAt(avsWriter, context.Background(), aggregator_address, blockHeight)
852+
_, err = balance_func()
820853
assert.NotNil(t, err)
821854
if _, ok := err.(retry.PermanentError); ok {
822855
t.Errorf("BalanceAt Emitted non-Transient error: %s\n", err)
@@ -832,7 +865,8 @@ func TestBalanceAt(t *testing.T) {
832865
t.Errorf("Error setting up Anvil: %s\n", err)
833866
}
834867

835-
_, err = avsWriter.BalanceAtRetryable(context.Background(), aggregator_address, blockHeight)
868+
balance_func = chainio.BalanceAt(avsWriter, context.Background(), aggregator_address, blockHeight)
869+
_, err = balance_func()
836870
assert.Nil(t, err)
837871

838872
if err := cmd.Process.Kill(); err != nil {
@@ -854,15 +888,17 @@ func TestBatchersBalances(t *testing.T) {
854888
}
855889
senderAddress := common.HexToAddress("0x0")
856890

857-
_, err = avsWriter.BatcherBalancesRetryable(&bind.CallOpts{}, senderAddress)
891+
batcher_func := chainio.BatcherBalances(avsWriter, &bind.CallOpts{}, senderAddress)
892+
_, err = batcher_func()
858893
assert.Nil(t, err)
859894

860895
if err := cmd.Process.Kill(); err != nil {
861896
t.Errorf("Error killing process: %v\n", err)
862897
return
863898
}
864899

865-
_, err = avsWriter.BatcherBalancesRetryable(&bind.CallOpts{}, senderAddress)
900+
batcher_func = chainio.BatcherBalances(avsWriter, &bind.CallOpts{}, senderAddress)
901+
_, err = batcher_func()
866902
assert.NotNil(t, err)
867903
if _, ok := err.(retry.PermanentError); ok {
868904
t.Errorf("BatchersBalances Emitted non-Transient error: %s\n", err)
@@ -878,7 +914,8 @@ func TestBatchersBalances(t *testing.T) {
878914
t.Errorf("Error setting up Anvil: %s\n", err)
879915
}
880916

881-
_, err = avsWriter.BatcherBalancesRetryable(&bind.CallOpts{}, senderAddress)
917+
batcher_func = chainio.BatcherBalances(avsWriter, &bind.CallOpts{}, senderAddress)
918+
_, err = batcher_func()
882919
assert.Nil(t, err)
883920

884921
if err := cmd.Process.Kill(); err != nil {

0 commit comments

Comments
 (0)