Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions tests/consensus_spec/test_fixture_ssz_generic_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import
strutils, streams, strformat, strscans,
macros, typetraits],
# Status libraries
faststreams, snappy, stint, ../testutil,
faststreams, serialization/case_objects, snappy, stint, ../testutil,
# Third-party
yaml,
# Beacon chain internals
Expand Down Expand Up @@ -127,6 +127,32 @@ type
G: List[ProgressiveSingleFieldContainerTestStruct, 10]
H: seq[ProgressiveVarTestStruct]

SelectorA {.pure.} = enum
a = 1
CompatibleUnionA {.allowDiscriminatorsWithoutZero.} = object
case selector: SelectorA
of SelectorA.a: aData: ProgressiveSingleFieldContainerTestStruct

SelectorBC {.pure.} = enum
b = 2
c = 3
CompatibleUnionBC {.allowDiscriminatorsWithoutZero.} = object
case selector: SelectorBC
of SelectorBC.b: bData: ProgressiveSingleListContainerTestStruct
of SelectorBC.c: cData: ProgressiveVarTestStruct

SelectorABCA {.pure.} = enum
a1 = 1
b = 2
c = 3
a4 = 4
CompatibleUnionABCA {.allowDiscriminatorsWithoutZero.} = object
case selector: SelectorABCA
of SelectorABCA.a1, SelectorABCA.a4:
aData: ProgressiveSingleFieldContainerTestStruct
of SelectorABCA.b: bData: ProgressiveSingleListContainerTestStruct
of SelectorABCA.c: cData: ProgressiveVarTestStruct

# Type specific checks
# ------------------------------------------------------------------------

Expand All @@ -153,7 +179,7 @@ proc checkProgressiveList(
var typeIdent: string
let wasMatched =
try:
scanf(sszSubType, "proglist_$+", typeIdent)
scanf(sszSubType, "proglist_$+_", typeIdent)
except ValueError:
false # Parsed `size` is out of range
doAssert wasMatched
Expand All @@ -173,6 +199,8 @@ proc checkProgressiveList(
checkBasic(seq[UInt128], dir, expectedHash)
of "uint256":
checkBasic(seq[UInt256], dir, expectedHash)
else:
raise newException(ValueError, "unknown ssz type in test: " & sszSubType)

macro testVector(typeIdent: string, size: int): untyped =
# find the compile-time type to test
Expand Down Expand Up @@ -363,6 +391,17 @@ proc sszCheck(dir, sszType, sszSubType: string)
of "basic_vector": checkVector(sszSubType, dir, expectedHash)
of "bitvector": checkBitVector(sszSubType, dir, expectedHash)
of "bitlist": checkBitList(sszSubType, dir, expectedHash)
of "compatible_unions":
var name: string
let wasMatched = scanf(sszSubType, "$+_", name)
doAssert wasMatched
case name
of "CompatibleUnionA": checkBasic(CompatibleUnionA, dir, expectedHash)
of "CompatibleUnionBC": checkBasic(CompatibleUnionBC, dir, expectedHash)
of "CompatibleUnionABCA": checkBasic(CompatibleUnionABCA, dir, expectedHash)
else:
raise newException(ValueError,
"unknown compatible union in test: " & sszSubType)
of "containers":
var name: string
let wasMatched = scanf(sszSubType, "$+_", name)
Expand Down
Loading