Skip to content

Commit 391c836

Browse files
committed
test: add blobindexer tests for validateSpec method
1 parent ed92d0e commit 391c836

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

backend/pkg/blobindexer/blobindexer_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package blobindexer
22

33
import (
4+
"fmt"
45
"math"
56
"testing"
67
"time"
@@ -509,6 +510,95 @@ func TestGetLastIndexedFinalizedSlot(t *testing.T) {
509510
}
510511
}
511512

513+
func TestValidateSpec(t *testing.T) {
514+
tests := []struct {
515+
name string
516+
spec *constypes.StandardSpecResponse
517+
configDepositID uint64
518+
expectedError error
519+
}{
520+
{
521+
name: "valid spec",
522+
spec: &constypes.StandardSpecResponse{
523+
Data: constypes.StandardSpec{
524+
DenebForkEpoch: uint64Ptr(4),
525+
MinEpochsForBlobSidecarsRequests: uint64Ptr(2),
526+
DepositNetworkID: 1,
527+
},
528+
},
529+
configDepositID: 1,
530+
expectedError: nil,
531+
},
532+
{
533+
name: "missing DenebForkEpoch value",
534+
spec: &constypes.StandardSpecResponse{
535+
Data: constypes.StandardSpec{
536+
DenebForkEpoch: nil,
537+
MinEpochsForBlobSidecarsRequests: uint64Ptr(2),
538+
DepositNetworkID: 1,
539+
},
540+
},
541+
configDepositID: 1,
542+
expectedError: fmt.Errorf("DENEB_FORK_EPOCH not set in spec"),
543+
},
544+
{
545+
name: "missing MinEpochsForBlobSidecarsRequests value",
546+
spec: &constypes.StandardSpecResponse{
547+
Data: constypes.StandardSpec{
548+
DenebForkEpoch: uint64Ptr(4),
549+
MinEpochsForBlobSidecarsRequests: nil,
550+
DepositNetworkID: 1,
551+
},
552+
},
553+
configDepositID: 1,
554+
expectedError: fmt.Errorf("MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS not set in spec"),
555+
},
556+
{
557+
name: "DepositNetworkID mismatch",
558+
spec: &constypes.StandardSpecResponse{
559+
Data: constypes.StandardSpec{
560+
DenebForkEpoch: uint64Ptr(4),
561+
MinEpochsForBlobSidecarsRequests: uint64Ptr(2),
562+
DepositNetworkID: 1,
563+
},
564+
},
565+
configDepositID: 2,
566+
expectedError: fmt.Errorf("config.DepositNetworkId mismatch: 2 != 1"),
567+
},
568+
{
569+
name: "all fields missing",
570+
spec: &constypes.StandardSpecResponse{
571+
Data: constypes.StandardSpec{
572+
DenebForkEpoch: nil,
573+
MinEpochsForBlobSidecarsRequests: nil,
574+
DepositNetworkID: 0,
575+
},
576+
},
577+
configDepositID: 1,
578+
expectedError: fmt.Errorf("DENEB_FORK_EPOCH not set in spec"),
579+
},
580+
}
581+
582+
for _, tt := range tests {
583+
t.Run(tt.name, func(t *testing.T) {
584+
utils.Config = &types.Config{
585+
Chain: types.Chain{
586+
ClConfig: types.ClChainConfig{
587+
DepositNetworkID: tt.configDepositID,
588+
},
589+
},
590+
}
591+
err := validateSpec(tt.spec)
592+
593+
if (err == nil && tt.expectedError != nil) || (err != nil && tt.expectedError == nil) {
594+
t.Errorf("got error %v, want %v", err, tt.expectedError)
595+
} else if err != nil && tt.expectedError != nil && err.Error() != tt.expectedError.Error() {
596+
t.Errorf("got error %v, want %v", err, tt.expectedError)
597+
}
598+
})
599+
}
600+
}
601+
512602
// unit64Ptr returns a pointer to a uint64
513603
func uint64Ptr(i uint64) *uint64 {
514604
return &i

0 commit comments

Comments
 (0)