80
80
D: BitList [6 ]
81
81
E: BitArray [8 ]
82
82
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
+
83
209
# Type specific checks
84
210
# ------------------------------------------------------------------------
85
211
@@ -285,6 +411,71 @@ proc sszCheck(
285
411
of " BitsStruct" : checkBasic (BitsStruct , dir, expectedHash)
286
412
else :
287
413
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)
288
479
else :
289
480
raise newException (ValueError , " unknown ssz type in test: " & sszType)
290
481
@@ -306,26 +497,27 @@ suite "EF - SSZ generic types":
306
497
of " containers" :
307
498
skipped = " - skipping BitsStruct"
308
499
309
- test & " Testing { sszType:12 } inputs - valid " & skipped:
500
+ test & " Testing { sszType:16 } inputs - valid " & skipped:
310
501
let path = SSZDir / sszType/ " valid"
311
502
for pathKind, sszSubType in walkDir (
312
503
path, relative = true , checkDir = true ):
313
504
if pathKind != pcDir: continue
314
505
sszCheck (path, sszType, sszSubType)
315
506
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