1
+ {.used .}
2
+
1
3
import
2
4
unittest2,
3
- stew/ byteutils,
4
- ../ beacon_chain/ spec/ [forks, helpers],
5
- ../ beacon_chain/ spec/ datatypes/ [phase0, altair, bellatrix]
6
-
7
- {.used .}
5
+ ../ beacon_chain/ spec/ forks
8
6
9
7
template testHashedBeaconState (T: type , s: Slot ) =
10
- let
11
- state = (ref T)()
8
+ let state = (ref T)()
12
9
state[].slot = s
13
10
let
14
11
bytes = SSZ .encode (state[])
@@ -20,11 +17,8 @@ template testHashedBeaconState(T: type, s: Slot) =
20
17
forked.kind == T.toFork ()
21
18
22
19
template testTrustedSignedBeaconBlock (T: type , s: Slot ) =
23
- let
24
- blck = (ref T)()
25
-
20
+ let blck = (ref T)()
26
21
blck[].message.slot = s
27
-
28
22
let
29
23
bytes = SSZ .encode (blck[])
30
24
forked = (ref ForkedSignedBeaconBlock )()
@@ -38,40 +32,84 @@ suite "Type helpers":
38
32
test " BeaconBlockType" :
39
33
check:
40
34
BeaconBlockType (ConsensusFork .Phase0 ) is phase0.BeaconBlock
35
+ BeaconBlockType (ConsensusFork .Altair ) is altair.BeaconBlock
41
36
BeaconBlockType (ConsensusFork .Bellatrix ) is bellatrix.BeaconBlock
37
+ BeaconBlockType (ConsensusFork .Capella ) is capella.BeaconBlock
38
+ BeaconBlockType (ConsensusFork .Deneb ) is deneb.BeaconBlock
39
+ BeaconBlockBodyType (ConsensusFork .Phase0 ) is phase0.BeaconBlockBody
42
40
BeaconBlockBodyType (ConsensusFork .Altair ) is altair.BeaconBlockBody
43
41
BeaconBlockBodyType (ConsensusFork .Bellatrix ) is bellatrix.BeaconBlockBody
42
+ BeaconBlockBodyType (ConsensusFork .Capella ) is capella.BeaconBlockBody
43
+ BeaconBlockBodyType (ConsensusFork .Deneb ) is deneb.BeaconBlockBody
44
44
45
45
suite " Forked SSZ readers" :
46
- var
47
- cfg = defaultRuntimeConfig
48
-
49
- cfg.ALTAIR_FORK_EPOCH = Epoch (1 )
50
- cfg.BELLATRIX_FORK_EPOCH = Epoch (2 )
46
+ let cfg = block :
47
+ var cfg = defaultRuntimeConfig
48
+ cfg.ALTAIR_FORK_EPOCH = Epoch (1 )
49
+ cfg.BELLATRIX_FORK_EPOCH = Epoch (2 )
50
+ cfg.CAPELLA_FORK_EPOCH = Epoch (3 )
51
+ cfg.DENEB_FORK_EPOCH = Epoch (4 )
52
+ cfg
51
53
52
54
test " load phase0 state" :
53
- testHashedBeaconState (phase0.BeaconState , 0 .Slot )
55
+ testHashedBeaconState (phase0.BeaconState , 0 .Slot )
54
56
55
57
expect (SszError ):
56
- testHashedBeaconState (altair.BeaconState , 0 .Slot )
58
+ testHashedBeaconState (altair.BeaconState , 0 .Slot )
57
59
expect (SszError ):
58
60
testHashedBeaconState (bellatrix.BeaconState , 0 .Slot )
61
+ expect (SszError ):
62
+ testHashedBeaconState (capella.BeaconState , 0 .Slot )
63
+ expect (SszError ):
64
+ testHashedBeaconState (deneb.BeaconState , 0 .Slot )
59
65
60
66
test " load altair state" :
61
- testHashedBeaconState (altair.BeaconState , cfg.ALTAIR_FORK_EPOCH .start_slot)
67
+ testHashedBeaconState (altair.BeaconState , cfg.ALTAIR_FORK_EPOCH .start_slot)
62
68
63
69
expect (SszError ):
64
- testHashedBeaconState (phase0.BeaconState , cfg.ALTAIR_FORK_EPOCH .start_slot)
70
+ testHashedBeaconState (phase0.BeaconState , cfg.ALTAIR_FORK_EPOCH .start_slot)
65
71
expect (SszError ):
66
72
testHashedBeaconState (bellatrix.BeaconState , cfg.ALTAIR_FORK_EPOCH .start_slot)
73
+ expect (SszError ):
74
+ testHashedBeaconState (capella.BeaconState , cfg.ALTAIR_FORK_EPOCH .start_slot)
75
+ expect (SszError ):
76
+ testHashedBeaconState (deneb.BeaconState , cfg.ALTAIR_FORK_EPOCH .start_slot)
67
77
68
78
test " load bellatrix state" :
69
- testHashedBeaconState (bellatrix.BeaconState , cfg.BELLATRIX_FORK_EPOCH .start_slot)
79
+ testHashedBeaconState (bellatrix.BeaconState , cfg.BELLATRIX_FORK_EPOCH .start_slot)
80
+
81
+ expect (SszError ):
82
+ testHashedBeaconState (phase0.BeaconState , cfg.BELLATRIX_FORK_EPOCH .start_slot)
83
+ expect (SszError ):
84
+ testHashedBeaconState (altair.BeaconState , cfg.BELLATRIX_FORK_EPOCH .start_slot)
85
+ expect (SszError ):
86
+ testHashedBeaconState (capella.BeaconState , cfg.BELLATRIX_FORK_EPOCH .start_slot)
87
+ expect (SszError ):
88
+ testHashedBeaconState (deneb.BeaconState , cfg.BELLATRIX_FORK_EPOCH .start_slot)
89
+
90
+ test " load capella state" :
91
+ testHashedBeaconState (capella.BeaconState , cfg.CAPELLA_FORK_EPOCH .start_slot)
70
92
71
93
expect (SszError ):
72
- testHashedBeaconState (phase0.BeaconState , cfg.BELLATRIX_FORK_EPOCH .start_slot)
94
+ testHashedBeaconState (phase0.BeaconState , cfg.CAPELLA_FORK_EPOCH .start_slot)
73
95
expect (SszError ):
74
- testHashedBeaconState (altair.BeaconState , cfg.BELLATRIX_FORK_EPOCH .start_slot)
96
+ testHashedBeaconState (altair.BeaconState , cfg.CAPELLA_FORK_EPOCH .start_slot)
97
+ expect (SszError ):
98
+ testHashedBeaconState (bellatrix.BeaconState , cfg.CAPELLA_FORK_EPOCH .start_slot)
99
+ expect (SszError ):
100
+ testHashedBeaconState (deneb.BeaconState , cfg.CAPELLA_FORK_EPOCH .start_slot)
101
+
102
+ test " load deneb state" :
103
+ testHashedBeaconState (deneb.BeaconState , cfg.DENEB_FORK_EPOCH .start_slot)
104
+
105
+ expect (SszError ):
106
+ testHashedBeaconState (phase0.BeaconState , cfg.DENEB_FORK_EPOCH .start_slot)
107
+ expect (SszError ):
108
+ testHashedBeaconState (altair.BeaconState , cfg.DENEB_FORK_EPOCH .start_slot)
109
+ expect (SszError ):
110
+ testHashedBeaconState (bellatrix.BeaconState , cfg.DENEB_FORK_EPOCH .start_slot)
111
+ expect (SszError ):
112
+ testHashedBeaconState (capella.BeaconState , cfg.DENEB_FORK_EPOCH .start_slot)
75
113
76
114
test " should raise on unknown data" :
77
115
let
@@ -80,32 +118,82 @@ suite "Forked SSZ readers":
80
118
discard newClone (readSszForkedHashedBeaconState (cfg, bytes))
81
119
82
120
test " load phase0 block" :
83
- testTrustedSignedBeaconBlock (phase0.TrustedSignedBeaconBlock , 0 .Slot )
121
+ testTrustedSignedBeaconBlock (phase0.TrustedSignedBeaconBlock , 0 .Slot )
84
122
expect (SszError ):
85
- testTrustedSignedBeaconBlock (altair.TrustedSignedBeaconBlock , 0 .Slot )
123
+ testTrustedSignedBeaconBlock (altair.TrustedSignedBeaconBlock , 0 .Slot )
86
124
expect (SszError ):
87
125
testTrustedSignedBeaconBlock (bellatrix.TrustedSignedBeaconBlock , 0 .Slot )
126
+ expect (SszError ):
127
+ testTrustedSignedBeaconBlock (capella.TrustedSignedBeaconBlock , 0 .Slot )
128
+ expect (SszError ):
129
+ testTrustedSignedBeaconBlock (deneb.TrustedSignedBeaconBlock , 0 .Slot )
88
130
89
131
test " load altair block" :
90
132
testTrustedSignedBeaconBlock (
91
- altair.TrustedSignedBeaconBlock , cfg.ALTAIR_FORK_EPOCH .start_slot)
133
+ altair.TrustedSignedBeaconBlock , cfg.ALTAIR_FORK_EPOCH .start_slot)
92
134
expect (SszError ):
93
135
testTrustedSignedBeaconBlock (
94
- phase0.TrustedSignedBeaconBlock , cfg.ALTAIR_FORK_EPOCH .start_slot)
136
+ phase0.TrustedSignedBeaconBlock , cfg.ALTAIR_FORK_EPOCH .start_slot)
95
137
expect (SszError ):
96
138
testTrustedSignedBeaconBlock (
97
139
bellatrix.TrustedSignedBeaconBlock , cfg.ALTAIR_FORK_EPOCH .start_slot)
140
+ expect (SszError ):
141
+ testTrustedSignedBeaconBlock (
142
+ capella.TrustedSignedBeaconBlock , cfg.ALTAIR_FORK_EPOCH .start_slot)
143
+ expect (SszError ):
144
+ testTrustedSignedBeaconBlock (
145
+ deneb.TrustedSignedBeaconBlock , cfg.ALTAIR_FORK_EPOCH .start_slot)
98
146
99
147
test " load bellatrix block" :
100
148
testTrustedSignedBeaconBlock (
101
149
bellatrix.TrustedSignedBeaconBlock , cfg.BELLATRIX_FORK_EPOCH .start_slot)
102
150
103
151
expect (SszError ):
104
152
testTrustedSignedBeaconBlock (
105
- phase0.TrustedSignedBeaconBlock , cfg.BELLATRIX_FORK_EPOCH .start_slot)
153
+ phase0.TrustedSignedBeaconBlock , cfg.BELLATRIX_FORK_EPOCH .start_slot)
154
+ expect (SszError ):
155
+ testTrustedSignedBeaconBlock (
156
+ altair.TrustedSignedBeaconBlock , cfg.BELLATRIX_FORK_EPOCH .start_slot)
157
+ expect (SszError ):
158
+ testTrustedSignedBeaconBlock (
159
+ capella.TrustedSignedBeaconBlock , cfg.BELLATRIX_FORK_EPOCH .start_slot)
160
+ expect (SszError ):
161
+ testTrustedSignedBeaconBlock (
162
+ deneb.TrustedSignedBeaconBlock , cfg.BELLATRIX_FORK_EPOCH .start_slot)
163
+
164
+ test " load capella block" :
165
+ testTrustedSignedBeaconBlock (
166
+ capella.TrustedSignedBeaconBlock , cfg.CAPELLA_FORK_EPOCH .start_slot)
167
+
168
+ expect (SszError ):
169
+ testTrustedSignedBeaconBlock (
170
+ phase0.TrustedSignedBeaconBlock , cfg.CAPELLA_FORK_EPOCH .start_slot)
171
+ expect (SszError ):
172
+ testTrustedSignedBeaconBlock (
173
+ altair.TrustedSignedBeaconBlock , cfg.CAPELLA_FORK_EPOCH .start_slot)
174
+ expect (SszError ):
175
+ testTrustedSignedBeaconBlock (
176
+ bellatrix.TrustedSignedBeaconBlock , cfg.CAPELLA_FORK_EPOCH .start_slot)
177
+ expect (SszError ):
178
+ testTrustedSignedBeaconBlock (
179
+ deneb.TrustedSignedBeaconBlock , cfg.CAPELLA_FORK_EPOCH .start_slot)
180
+
181
+ test " load deneb block" :
182
+ testTrustedSignedBeaconBlock (
183
+ deneb.TrustedSignedBeaconBlock , cfg.DENEB_FORK_EPOCH .start_slot)
184
+
185
+ expect (SszError ):
186
+ testTrustedSignedBeaconBlock (
187
+ phase0.TrustedSignedBeaconBlock , cfg.DENEB_FORK_EPOCH .start_slot)
188
+ expect (SszError ):
189
+ testTrustedSignedBeaconBlock (
190
+ altair.TrustedSignedBeaconBlock , cfg.DENEB_FORK_EPOCH .start_slot)
191
+ expect (SszError ):
192
+ testTrustedSignedBeaconBlock (
193
+ bellatrix.TrustedSignedBeaconBlock , cfg.DENEB_FORK_EPOCH .start_slot)
106
194
expect (SszError ):
107
195
testTrustedSignedBeaconBlock (
108
- altair .TrustedSignedBeaconBlock , cfg.BELLATRIX_FORK_EPOCH .start_slot)
196
+ capella .TrustedSignedBeaconBlock , cfg.DENEB_FORK_EPOCH .start_slot)
109
197
110
198
test " should raise on unknown data" :
111
199
let
0 commit comments