-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathglobal_test.go
More file actions
74 lines (60 loc) · 1.68 KB
/
global_test.go
File metadata and controls
74 lines (60 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package dynssz
import (
"reflect"
"testing"
)
// Test SetGlobalSpecs function
func TestSetGlobalSpecs(t *testing.T) {
// Reset global state after test
defer func() {
SetGlobalSpecs(nil)
}()
t.Run("SetGlobalSpecs creates new DynSsz with specs", func(t *testing.T) {
specs := map[string]any{
"MAX_VALIDATORS": float64(65536),
"MAX_COMMITTEES": float64(64),
}
SetGlobalSpecs(specs)
ds := GetGlobalDynSsz()
if ds == nil {
t.Fatal("expected GetGlobalDynSsz to return non-nil")
}
// Verify specs are available by testing with a type that uses them
type TestStruct struct {
Data []byte `ssz-max:"100" dynssz-max:"MAX_VALIDATORS"`
}
desc, err := ds.GetTypeCache().GetTypeDescriptor(reflect.TypeOf(TestStruct{}), nil, nil, nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if desc.ContainerDesc == nil || len(desc.ContainerDesc.Fields) == 0 {
t.Fatal("expected container with fields")
}
field := desc.ContainerDesc.Fields[0]
if field.Type.Limit != 65536 {
t.Errorf("expected Limit 65536 from specs, got %d", field.Type.Limit)
}
})
t.Run("SetGlobalSpecs replaces existing DynSsz", func(t *testing.T) {
specs1 := map[string]any{
"TEST_VALUE": float64(100),
}
SetGlobalSpecs(specs1)
ds1 := GetGlobalDynSsz()
specs2 := map[string]any{
"TEST_VALUE": float64(200),
}
SetGlobalSpecs(specs2)
ds2 := GetGlobalDynSsz()
if ds1 == ds2 {
t.Error("expected SetGlobalSpecs to create a new DynSsz instance")
}
})
t.Run("SetGlobalSpecs with nil specs", func(t *testing.T) {
SetGlobalSpecs(nil)
ds := GetGlobalDynSsz()
if ds == nil {
t.Fatal("expected GetGlobalDynSsz to return non-nil even with nil specs")
}
})
}