Skip to content

Commit ceb24d3

Browse files
authored
test forks.nim capella and deneb block/state ssz serialization (#4772)
1 parent 0d051b3 commit ceb24d3

File tree

2 files changed

+123
-31
lines changed

2 files changed

+123
-31
lines changed

AllTests-mainnet.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,15 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
223223
+ load altair state OK
224224
+ load bellatrix block OK
225225
+ load bellatrix state OK
226+
+ load capella block OK
227+
+ load capella state OK
228+
+ load deneb block OK
229+
+ load deneb state OK
226230
+ load phase0 block OK
227231
+ load phase0 state OK
228232
+ should raise on unknown data OK
229233
```
230-
OK: 7/7 Fail: 0/7 Skip: 0/7
234+
OK: 11/11 Fail: 0/11 Skip: 0/11
231235
## Gas limit management [Beacon Node] [Preset: mainnet]
232236
```diff
233237
+ Configuring the gas limit [Beacon Node] [Preset: mainnet] OK
@@ -636,4 +640,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
636640
OK: 9/9 Fail: 0/9 Skip: 0/9
637641

638642
---TOTAL---
639-
OK: 353/358 Fail: 0/358 Skip: 5/358
643+
OK: 357/362 Fail: 0/362 Skip: 5/362

tests/test_forks.nim

Lines changed: 117 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1+
{.used.}
2+
13
import
24
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
86

97
template testHashedBeaconState(T: type, s: Slot) =
10-
let
11-
state = (ref T)()
8+
let state = (ref T)()
129
state[].slot = s
1310
let
1411
bytes = SSZ.encode(state[])
@@ -20,11 +17,8 @@ template testHashedBeaconState(T: type, s: Slot) =
2017
forked.kind == T.toFork()
2118

2219
template testTrustedSignedBeaconBlock(T: type, s: Slot) =
23-
let
24-
blck = (ref T)()
25-
20+
let blck = (ref T)()
2621
blck[].message.slot = s
27-
2822
let
2923
bytes = SSZ.encode(blck[])
3024
forked = (ref ForkedSignedBeaconBlock)()
@@ -38,40 +32,84 @@ suite "Type helpers":
3832
test "BeaconBlockType":
3933
check:
4034
BeaconBlockType(ConsensusFork.Phase0) is phase0.BeaconBlock
35+
BeaconBlockType(ConsensusFork.Altair) is altair.BeaconBlock
4136
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
4240
BeaconBlockBodyType(ConsensusFork.Altair) is altair.BeaconBlockBody
4341
BeaconBlockBodyType(ConsensusFork.Bellatrix) is bellatrix.BeaconBlockBody
42+
BeaconBlockBodyType(ConsensusFork.Capella) is capella.BeaconBlockBody
43+
BeaconBlockBodyType(ConsensusFork.Deneb) is deneb.BeaconBlockBody
4444

4545
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
5153

5254
test "load phase0 state":
53-
testHashedBeaconState(phase0.BeaconState, 0.Slot)
55+
testHashedBeaconState(phase0.BeaconState, 0.Slot)
5456

5557
expect(SszError):
56-
testHashedBeaconState(altair.BeaconState, 0.Slot)
58+
testHashedBeaconState(altair.BeaconState, 0.Slot)
5759
expect(SszError):
5860
testHashedBeaconState(bellatrix.BeaconState, 0.Slot)
61+
expect(SszError):
62+
testHashedBeaconState(capella.BeaconState, 0.Slot)
63+
expect(SszError):
64+
testHashedBeaconState(deneb.BeaconState, 0.Slot)
5965

6066
test "load altair state":
61-
testHashedBeaconState(altair.BeaconState, cfg.ALTAIR_FORK_EPOCH.start_slot)
67+
testHashedBeaconState(altair.BeaconState, cfg.ALTAIR_FORK_EPOCH.start_slot)
6268

6369
expect(SszError):
64-
testHashedBeaconState(phase0.BeaconState, cfg.ALTAIR_FORK_EPOCH.start_slot)
70+
testHashedBeaconState(phase0.BeaconState, cfg.ALTAIR_FORK_EPOCH.start_slot)
6571
expect(SszError):
6672
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)
6777

6878
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)
7092

7193
expect(SszError):
72-
testHashedBeaconState(phase0.BeaconState, cfg.BELLATRIX_FORK_EPOCH.start_slot)
94+
testHashedBeaconState(phase0.BeaconState, cfg.CAPELLA_FORK_EPOCH.start_slot)
7395
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)
75113

76114
test "should raise on unknown data":
77115
let
@@ -80,32 +118,82 @@ suite "Forked SSZ readers":
80118
discard newClone(readSszForkedHashedBeaconState(cfg, bytes))
81119

82120
test "load phase0 block":
83-
testTrustedSignedBeaconBlock(phase0.TrustedSignedBeaconBlock, 0.Slot)
121+
testTrustedSignedBeaconBlock(phase0.TrustedSignedBeaconBlock, 0.Slot)
84122
expect(SszError):
85-
testTrustedSignedBeaconBlock(altair.TrustedSignedBeaconBlock, 0.Slot)
123+
testTrustedSignedBeaconBlock(altair.TrustedSignedBeaconBlock, 0.Slot)
86124
expect(SszError):
87125
testTrustedSignedBeaconBlock(bellatrix.TrustedSignedBeaconBlock, 0.Slot)
126+
expect(SszError):
127+
testTrustedSignedBeaconBlock(capella.TrustedSignedBeaconBlock, 0.Slot)
128+
expect(SszError):
129+
testTrustedSignedBeaconBlock(deneb.TrustedSignedBeaconBlock, 0.Slot)
88130

89131
test "load altair block":
90132
testTrustedSignedBeaconBlock(
91-
altair.TrustedSignedBeaconBlock, cfg.ALTAIR_FORK_EPOCH.start_slot)
133+
altair.TrustedSignedBeaconBlock, cfg.ALTAIR_FORK_EPOCH.start_slot)
92134
expect(SszError):
93135
testTrustedSignedBeaconBlock(
94-
phase0.TrustedSignedBeaconBlock, cfg.ALTAIR_FORK_EPOCH.start_slot)
136+
phase0.TrustedSignedBeaconBlock, cfg.ALTAIR_FORK_EPOCH.start_slot)
95137
expect(SszError):
96138
testTrustedSignedBeaconBlock(
97139
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)
98146

99147
test "load bellatrix block":
100148
testTrustedSignedBeaconBlock(
101149
bellatrix.TrustedSignedBeaconBlock, cfg.BELLATRIX_FORK_EPOCH.start_slot)
102150

103151
expect(SszError):
104152
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)
106194
expect(SszError):
107195
testTrustedSignedBeaconBlock(
108-
altair.TrustedSignedBeaconBlock, cfg.BELLATRIX_FORK_EPOCH.start_slot)
196+
capella.TrustedSignedBeaconBlock, cfg.DENEB_FORK_EPOCH.start_slot)
109197

110198
test "should raise on unknown data":
111199
let

0 commit comments

Comments
 (0)