Skip to content

Commit 22efdd8

Browse files
committed
add tests for EIP-7495: SSZ StableContainer
Implement test runner for new consensus-spec tests: - ethereum/consensus-specs#3777
1 parent c7bf6fb commit 22efdd8

File tree

4 files changed

+228
-34
lines changed

4 files changed

+228
-34
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
path = vendor/nim-ssz-serialization
185185
url = https://github.com/status-im/nim-ssz-serialization.git
186186
ignore = untracked
187-
branch = master
187+
branch = feat/eip-7495
188188
[submodule "vendor/nim-websock"]
189189
path = vendor/nim-websock
190190
url = https://github.com/status-im/nim-websock.git

AllTests-mainnet.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -431,20 +431,22 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
431431
OK: 253/253 Fail: 0/253 Skip: 0/253
432432
## EF - SSZ generic types
433433
```diff
434-
Testing basic_vector inputs - invalid Skip
435-
+ Testing basic_vector inputs - valid OK
436-
+ Testing bitlist inputs - invalid OK
437-
+ Testing bitlist inputs - valid OK
438-
Testing bitvector inputs - invalid Skip
439-
+ Testing bitvector inputs - valid OK
440-
+ Testing boolean inputs - invalid OK
441-
+ Testing boolean inputs - valid OK
442-
+ Testing containers inputs - invalid - skipping BitsStruct OK
443-
+ Testing containers inputs - valid - skipping BitsStruct OK
444-
+ Testing uints inputs - invalid OK
445-
+ Testing uints inputs - valid OK
446-
```
447-
OK: 10/12 Fail: 0/12 Skip: 2/12
434+
Testing basic_vector inputs - invalid Skip
435+
+ Testing basic_vector inputs - valid OK
436+
+ Testing bitlist inputs - invalid OK
437+
+ Testing bitlist inputs - valid OK
438+
Testing bitvector inputs - invalid Skip
439+
+ Testing bitvector inputs - valid OK
440+
+ Testing boolean inputs - invalid OK
441+
+ Testing boolean inputs - valid OK
442+
+ Testing containers inputs - invalid - skipping BitsStruct OK
443+
+ Testing containers inputs - valid - skipping BitsStruct OK
444+
+ Testing profiles inputs - valid OK
445+
+ Testing stablecontainers inputs - valid OK
446+
+ Testing uints inputs - invalid OK
447+
+ Testing uints inputs - valid OK
448+
```
449+
OK: 12/14 Fail: 0/14 Skip: 2/14
448450
## EIP-4881
449451
```diff
450452
+ deposit_cases OK
@@ -1030,4 +1032,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
10301032
OK: 9/9 Fail: 0/9 Skip: 0/9
10311033

10321034
---TOTAL---
1033-
OK: 687/692 Fail: 0/692 Skip: 5/692
1035+
OK: 689/694 Fail: 0/694 Skip: 5/694

tests/consensus_spec/test_fixture_ssz_generic_types.nim

Lines changed: 209 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,132 @@ type
8080
D: BitList[6]
8181
E: BitArray[8]
8282

83+
# https://github.com/wemeetagain/consensus-specs/blob/eip-7495/tests/generators/ssz_generic/ssz_stablecontainer.py
84+
SingleFieldTestStableStruct {.sszStableContainer: 4.} = object
85+
A: Opt[byte]
86+
87+
SmallTestStableStruct {.sszStableContainer: 4.} = object
88+
A: Opt[uint16]
89+
B: Opt[uint16]
90+
91+
FixedTestStableStruct {.sszStableContainer: 4.} = object
92+
A: Opt[uint8]
93+
B: Opt[uint64]
94+
C: Opt[uint32]
95+
96+
VarTestStableStruct {.sszStableContainer: 4.} = object
97+
A: Opt[uint16]
98+
B: Opt[List[uint16, 1024]]
99+
C: Opt[uint8]
100+
101+
ComplexTestStableStruct {.sszStableContainer: 8.} = object
102+
A: Opt[uint16]
103+
B: Opt[List[uint16, 128]]
104+
C: Opt[uint8]
105+
D: Opt[List[byte, 256]]
106+
E: Opt[VarTestStableStruct]
107+
F: Opt[array[4, FixedTestStableStruct]]
108+
G: Opt[array[2, VarTestStableStruct]]
109+
110+
BitsStableStruct {.sszStableContainer: 8.} = object
111+
A: Opt[BitList[5]]
112+
B: Opt[BitArray[2]]
113+
C: Opt[BitArray[1]]
114+
D: Opt[BitList[6]]
115+
E: Opt[BitArray[8]]
116+
117+
# https://github.com/wemeetagain/consensus-specs/blob/eip-7495/tests/generators/ssz_generic/ssz_profile.py
118+
SingleFieldTestProfile {.sszProfile: SingleFieldTestStableStruct.} = object
119+
A: byte
120+
121+
SmallTestProfile1 {.sszProfile: SmallTestStableStruct.} = object
122+
A: uint16
123+
B: uint16
124+
125+
SmallTestProfile2 {.sszProfile: SmallTestStableStruct.} = object
126+
A: uint16
127+
128+
SmallTestProfile3 {.sszProfile: SmallTestStableStruct.} = object
129+
B: uint16
130+
131+
FixedTestProfile1 {.sszProfile: FixedTestStableStruct.} = object
132+
A: uint8
133+
B: uint64
134+
C: uint32
135+
136+
FixedTestProfile2 {.sszProfile: FixedTestStableStruct.} = object
137+
A: uint8
138+
B: uint64
139+
140+
FixedTestProfile3 {.sszProfile: FixedTestStableStruct.} = object
141+
A: uint8
142+
C: uint32
143+
144+
FixedTestProfile4 {.sszProfile: FixedTestStableStruct.} = object
145+
C: uint32
146+
147+
VarTestProfile1 {.sszProfile: VarTestStableStruct.} = object
148+
A: uint16
149+
B: List[uint16, 1024]
150+
C: uint8
151+
152+
VarTestProfile2 {.sszProfile: VarTestStableStruct.} = object
153+
B: List[uint16, 1024]
154+
C: uint8
155+
156+
VarTestProfile3 {.sszProfile: VarTestStableStruct.} = object
157+
B: List[uint16, 1024]
158+
159+
ComplexTestProfile1 {.sszProfile: ComplexTestStableStruct.} = object
160+
A: uint16
161+
B: List[uint16, 128]
162+
C: uint8
163+
D: List[byte, 256]
164+
E: VarTestStableStruct
165+
F: array[4, FixedTestStableStruct]
166+
G: array[2, VarTestStableStruct]
167+
168+
ComplexTestProfile2 {.sszProfile: ComplexTestStableStruct.} = object
169+
A: uint16
170+
B: List[uint16, 128]
171+
C: uint8
172+
D: List[byte, 256]
173+
E: VarTestStableStruct
174+
175+
ComplexTestProfile3 {.sszProfile: ComplexTestStableStruct.} = object
176+
A: uint16
177+
C: uint8
178+
E: VarTestStableStruct
179+
G: array[2, VarTestStableStruct]
180+
181+
ComplexTestProfile4 {.sszProfile: ComplexTestStableStruct.} = object
182+
B: List[uint16, 128]
183+
D: List[byte, 256]
184+
F: array[4, FixedTestStableStruct]
185+
186+
ComplexTestProfile5 {.sszProfile: ComplexTestStableStruct.} = object
187+
E: VarTestStableStruct
188+
F: array[4, FixedTestStableStruct]
189+
G: array[2, VarTestStableStruct]
190+
191+
BitsProfile1 {.sszProfile: BitsStableStruct.} = object
192+
A: BitList[5]
193+
B: BitArray[2]
194+
C: BitArray[1]
195+
D: BitList[6]
196+
E: BitArray[8]
197+
198+
BitsProfile2 {.sszProfile: BitsStableStruct.} = object
199+
A: BitList[5]
200+
B: BitArray[2]
201+
C: BitArray[1]
202+
D: BitList[6]
203+
204+
BitsProfile3 {.sszProfile: BitsStableStruct.} = object
205+
A: BitList[5]
206+
D: BitList[6]
207+
E: BitArray[8]
208+
83209
# Type specific checks
84210
# ------------------------------------------------------------------------
85211

@@ -285,6 +411,71 @@ proc sszCheck(
285411
of "BitsStruct": checkBasic(BitsStruct, dir, expectedHash)
286412
else:
287413
raise newException(ValueError, "unknown container in test: " & sszSubType)
414+
of "profiles":
415+
var name: string
416+
let wasMatched = scanf(sszSubType, "$+_", name)
417+
doAssert wasMatched
418+
case name
419+
of "BitsProfile1":
420+
checkBasic(BitsProfile1, dir, expectedHash)
421+
of "BitsProfile2":
422+
checkBasic(BitsProfile2, dir, expectedHash)
423+
of "BitsProfile3":
424+
checkBasic(BitsProfile3, dir, expectedHash)
425+
of "ComplexTestProfile1":
426+
checkBasic(ComplexTestProfile1, dir, expectedHash)
427+
of "ComplexTestProfile2":
428+
checkBasic(ComplexTestProfile2, dir, expectedHash)
429+
of "ComplexTestProfile3":
430+
checkBasic(ComplexTestProfile3, dir, expectedHash)
431+
of "ComplexTestProfile4":
432+
checkBasic(ComplexTestProfile4, dir, expectedHash)
433+
of "ComplexTestProfile5":
434+
checkBasic(ComplexTestProfile5, dir, expectedHash)
435+
of "FixedTestProfile1":
436+
checkBasic(FixedTestProfile1, dir, expectedHash)
437+
of "FixedTestProfile2":
438+
checkBasic(FixedTestProfile2, dir, expectedHash)
439+
of "FixedTestProfile3":
440+
checkBasic(FixedTestProfile3, dir, expectedHash)
441+
of "FixedTestProfile4":
442+
checkBasic(FixedTestProfile4, dir, expectedHash)
443+
of "SingleFieldTestProfile":
444+
checkBasic(SingleFieldTestProfile, dir, expectedHash)
445+
of "SmallTestProfile1":
446+
checkBasic(SmallTestProfile1, dir, expectedHash)
447+
of "SmallTestProfile2":
448+
checkBasic(SmallTestProfile2, dir, expectedHash)
449+
of "SmallTestProfile3":
450+
checkBasic(SmallTestProfile3, dir, expectedHash)
451+
of "VarTestProfile1":
452+
checkBasic(VarTestProfile1, dir, expectedHash)
453+
of "VarTestProfile2":
454+
checkBasic(VarTestProfile2, dir, expectedHash)
455+
of "VarTestProfile3":
456+
checkBasic(VarTestProfile3, dir, expectedHash)
457+
else:
458+
raise newException(ValueError, "unknown profile in test: " & sszSubType)
459+
of "stablecontainers":
460+
var name: string
461+
let wasMatched = scanf(sszSubType, "$+_", name)
462+
doAssert wasMatched
463+
case name
464+
of "BitsStableStruct":
465+
checkBasic(BitsStableStruct, dir, expectedHash)
466+
of "ComplexTestStableStruct":
467+
checkBasic(ComplexTestStableStruct, dir, expectedHash)
468+
of "FixedTestStableStruct":
469+
checkBasic(FixedTestStableStruct, dir, expectedHash)
470+
of "SingleFieldTestStableStruct":
471+
checkBasic(SingleFieldTestStableStruct, dir, expectedHash)
472+
of "SmallTestStableStruct":
473+
checkBasic(SmallTestStableStruct, dir, expectedHash)
474+
of "VarTestStableStruct":
475+
checkBasic(VarTestStableStruct, dir, expectedHash)
476+
else:
477+
raise newException(ValueError,
478+
"unknown stablecontainer in test: " & sszSubType)
288479
else:
289480
raise newException(ValueError, "unknown ssz type in test: " & sszType)
290481

@@ -306,26 +497,27 @@ suite "EF - SSZ generic types":
306497
of "containers":
307498
skipped = " - skipping BitsStruct"
308499

309-
test &"Testing {sszType:12} inputs - valid" & skipped:
500+
test &"Testing {sszType:16} inputs - valid" & skipped:
310501
let path = SSZDir/sszType/"valid"
311502
for pathKind, sszSubType in walkDir(
312503
path, relative = true, checkDir = true):
313504
if pathKind != pcDir: continue
314505
sszCheck(path, sszType, sszSubType)
315506

316-
test &"Testing {sszType:12} inputs - invalid" & skipped:
317-
let path = SSZDir/sszType/"invalid"
318-
for pathKind, sszSubType in walkDir(
319-
path, relative = true, checkDir = true):
320-
if pathKind != pcDir: continue
321-
try:
322-
sszCheck(path, sszType, sszSubType)
323-
except SszError, UnconsumedInput:
324-
discard
325-
except TestSizeError as err:
326-
echo err.msg
327-
skip()
328-
except:
329-
checkpoint getStackTrace(getCurrentException())
330-
checkpoint getCurrentExceptionMsg()
331-
check false
507+
template invalidPath: untyped = SSZDir/sszType/"invalid"
508+
if os_ops.dirExists(invalidPath):
509+
test &"Testing {sszType:16} inputs - invalid" & skipped:
510+
for pathKind, sszSubType in walkDir(
511+
invalidPath, relative = true, checkDir = true):
512+
if pathKind != pcDir: continue
513+
try:
514+
sszCheck(invalidPath, sszType, sszSubType)
515+
except SszError, UnconsumedInput:
516+
discard
517+
except TestSizeError as err:
518+
echo err.msg
519+
skip()
520+
except:
521+
checkpoint getStackTrace(getCurrentException())
522+
checkpoint getCurrentExceptionMsg()
523+
check false

0 commit comments

Comments
 (0)