add tests for EIP-7495: SSZ StableContainer
Implement test runner for new consensus-spec tests: - https://github.com/ethereum/consensus-specs/pull/3777
This commit is contained in:
parent
c7bf6fb542
commit
22efdd85a5
|
@ -184,7 +184,7 @@
|
||||||
path = vendor/nim-ssz-serialization
|
path = vendor/nim-ssz-serialization
|
||||||
url = https://github.com/status-im/nim-ssz-serialization.git
|
url = https://github.com/status-im/nim-ssz-serialization.git
|
||||||
ignore = untracked
|
ignore = untracked
|
||||||
branch = master
|
branch = feat/eip-7495
|
||||||
[submodule "vendor/nim-websock"]
|
[submodule "vendor/nim-websock"]
|
||||||
path = vendor/nim-websock
|
path = vendor/nim-websock
|
||||||
url = https://github.com/status-im/nim-websock.git
|
url = https://github.com/status-im/nim-websock.git
|
||||||
|
|
|
@ -431,20 +431,22 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
|
||||||
OK: 253/253 Fail: 0/253 Skip: 0/253
|
OK: 253/253 Fail: 0/253 Skip: 0/253
|
||||||
## EF - SSZ generic types
|
## EF - SSZ generic types
|
||||||
```diff
|
```diff
|
||||||
Testing basic_vector inputs - invalid Skip
|
Testing basic_vector inputs - invalid Skip
|
||||||
+ Testing basic_vector inputs - valid OK
|
+ Testing basic_vector inputs - valid OK
|
||||||
+ Testing bitlist inputs - invalid OK
|
+ Testing bitlist inputs - invalid OK
|
||||||
+ Testing bitlist inputs - valid OK
|
+ Testing bitlist inputs - valid OK
|
||||||
Testing bitvector inputs - invalid Skip
|
Testing bitvector inputs - invalid Skip
|
||||||
+ Testing bitvector inputs - valid OK
|
+ Testing bitvector inputs - valid OK
|
||||||
+ Testing boolean inputs - invalid OK
|
+ Testing boolean inputs - invalid OK
|
||||||
+ Testing boolean inputs - valid OK
|
+ Testing boolean inputs - valid OK
|
||||||
+ Testing containers inputs - invalid - skipping BitsStruct OK
|
+ Testing containers inputs - invalid - skipping BitsStruct OK
|
||||||
+ Testing containers inputs - valid - skipping BitsStruct OK
|
+ Testing containers inputs - valid - skipping BitsStruct OK
|
||||||
+ Testing uints inputs - invalid OK
|
+ Testing profiles inputs - valid OK
|
||||||
+ Testing uints inputs - valid OK
|
+ Testing stablecontainers inputs - valid OK
|
||||||
|
+ Testing uints inputs - invalid OK
|
||||||
|
+ Testing uints inputs - valid OK
|
||||||
```
|
```
|
||||||
OK: 10/12 Fail: 0/12 Skip: 2/12
|
OK: 12/14 Fail: 0/14 Skip: 2/14
|
||||||
## EIP-4881
|
## EIP-4881
|
||||||
```diff
|
```diff
|
||||||
+ deposit_cases OK
|
+ deposit_cases OK
|
||||||
|
@ -1030,4 +1032,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
|
||||||
OK: 9/9 Fail: 0/9 Skip: 0/9
|
OK: 9/9 Fail: 0/9 Skip: 0/9
|
||||||
|
|
||||||
---TOTAL---
|
---TOTAL---
|
||||||
OK: 687/692 Fail: 0/692 Skip: 5/692
|
OK: 689/694 Fail: 0/694 Skip: 5/694
|
||||||
|
|
|
@ -80,6 +80,132 @@ type
|
||||||
D: BitList[6]
|
D: BitList[6]
|
||||||
E: BitArray[8]
|
E: BitArray[8]
|
||||||
|
|
||||||
|
# https://github.com/wemeetagain/consensus-specs/blob/eip-7495/tests/generators/ssz_generic/ssz_stablecontainer.py
|
||||||
|
SingleFieldTestStableStruct {.sszStableContainer: 4.} = object
|
||||||
|
A: Opt[byte]
|
||||||
|
|
||||||
|
SmallTestStableStruct {.sszStableContainer: 4.} = object
|
||||||
|
A: Opt[uint16]
|
||||||
|
B: Opt[uint16]
|
||||||
|
|
||||||
|
FixedTestStableStruct {.sszStableContainer: 4.} = object
|
||||||
|
A: Opt[uint8]
|
||||||
|
B: Opt[uint64]
|
||||||
|
C: Opt[uint32]
|
||||||
|
|
||||||
|
VarTestStableStruct {.sszStableContainer: 4.} = object
|
||||||
|
A: Opt[uint16]
|
||||||
|
B: Opt[List[uint16, 1024]]
|
||||||
|
C: Opt[uint8]
|
||||||
|
|
||||||
|
ComplexTestStableStruct {.sszStableContainer: 8.} = object
|
||||||
|
A: Opt[uint16]
|
||||||
|
B: Opt[List[uint16, 128]]
|
||||||
|
C: Opt[uint8]
|
||||||
|
D: Opt[List[byte, 256]]
|
||||||
|
E: Opt[VarTestStableStruct]
|
||||||
|
F: Opt[array[4, FixedTestStableStruct]]
|
||||||
|
G: Opt[array[2, VarTestStableStruct]]
|
||||||
|
|
||||||
|
BitsStableStruct {.sszStableContainer: 8.} = object
|
||||||
|
A: Opt[BitList[5]]
|
||||||
|
B: Opt[BitArray[2]]
|
||||||
|
C: Opt[BitArray[1]]
|
||||||
|
D: Opt[BitList[6]]
|
||||||
|
E: Opt[BitArray[8]]
|
||||||
|
|
||||||
|
# https://github.com/wemeetagain/consensus-specs/blob/eip-7495/tests/generators/ssz_generic/ssz_profile.py
|
||||||
|
SingleFieldTestProfile {.sszProfile: SingleFieldTestStableStruct.} = object
|
||||||
|
A: byte
|
||||||
|
|
||||||
|
SmallTestProfile1 {.sszProfile: SmallTestStableStruct.} = object
|
||||||
|
A: uint16
|
||||||
|
B: uint16
|
||||||
|
|
||||||
|
SmallTestProfile2 {.sszProfile: SmallTestStableStruct.} = object
|
||||||
|
A: uint16
|
||||||
|
|
||||||
|
SmallTestProfile3 {.sszProfile: SmallTestStableStruct.} = object
|
||||||
|
B: uint16
|
||||||
|
|
||||||
|
FixedTestProfile1 {.sszProfile: FixedTestStableStruct.} = object
|
||||||
|
A: uint8
|
||||||
|
B: uint64
|
||||||
|
C: uint32
|
||||||
|
|
||||||
|
FixedTestProfile2 {.sszProfile: FixedTestStableStruct.} = object
|
||||||
|
A: uint8
|
||||||
|
B: uint64
|
||||||
|
|
||||||
|
FixedTestProfile3 {.sszProfile: FixedTestStableStruct.} = object
|
||||||
|
A: uint8
|
||||||
|
C: uint32
|
||||||
|
|
||||||
|
FixedTestProfile4 {.sszProfile: FixedTestStableStruct.} = object
|
||||||
|
C: uint32
|
||||||
|
|
||||||
|
VarTestProfile1 {.sszProfile: VarTestStableStruct.} = object
|
||||||
|
A: uint16
|
||||||
|
B: List[uint16, 1024]
|
||||||
|
C: uint8
|
||||||
|
|
||||||
|
VarTestProfile2 {.sszProfile: VarTestStableStruct.} = object
|
||||||
|
B: List[uint16, 1024]
|
||||||
|
C: uint8
|
||||||
|
|
||||||
|
VarTestProfile3 {.sszProfile: VarTestStableStruct.} = object
|
||||||
|
B: List[uint16, 1024]
|
||||||
|
|
||||||
|
ComplexTestProfile1 {.sszProfile: ComplexTestStableStruct.} = object
|
||||||
|
A: uint16
|
||||||
|
B: List[uint16, 128]
|
||||||
|
C: uint8
|
||||||
|
D: List[byte, 256]
|
||||||
|
E: VarTestStableStruct
|
||||||
|
F: array[4, FixedTestStableStruct]
|
||||||
|
G: array[2, VarTestStableStruct]
|
||||||
|
|
||||||
|
ComplexTestProfile2 {.sszProfile: ComplexTestStableStruct.} = object
|
||||||
|
A: uint16
|
||||||
|
B: List[uint16, 128]
|
||||||
|
C: uint8
|
||||||
|
D: List[byte, 256]
|
||||||
|
E: VarTestStableStruct
|
||||||
|
|
||||||
|
ComplexTestProfile3 {.sszProfile: ComplexTestStableStruct.} = object
|
||||||
|
A: uint16
|
||||||
|
C: uint8
|
||||||
|
E: VarTestStableStruct
|
||||||
|
G: array[2, VarTestStableStruct]
|
||||||
|
|
||||||
|
ComplexTestProfile4 {.sszProfile: ComplexTestStableStruct.} = object
|
||||||
|
B: List[uint16, 128]
|
||||||
|
D: List[byte, 256]
|
||||||
|
F: array[4, FixedTestStableStruct]
|
||||||
|
|
||||||
|
ComplexTestProfile5 {.sszProfile: ComplexTestStableStruct.} = object
|
||||||
|
E: VarTestStableStruct
|
||||||
|
F: array[4, FixedTestStableStruct]
|
||||||
|
G: array[2, VarTestStableStruct]
|
||||||
|
|
||||||
|
BitsProfile1 {.sszProfile: BitsStableStruct.} = object
|
||||||
|
A: BitList[5]
|
||||||
|
B: BitArray[2]
|
||||||
|
C: BitArray[1]
|
||||||
|
D: BitList[6]
|
||||||
|
E: BitArray[8]
|
||||||
|
|
||||||
|
BitsProfile2 {.sszProfile: BitsStableStruct.} = object
|
||||||
|
A: BitList[5]
|
||||||
|
B: BitArray[2]
|
||||||
|
C: BitArray[1]
|
||||||
|
D: BitList[6]
|
||||||
|
|
||||||
|
BitsProfile3 {.sszProfile: BitsStableStruct.} = object
|
||||||
|
A: BitList[5]
|
||||||
|
D: BitList[6]
|
||||||
|
E: BitArray[8]
|
||||||
|
|
||||||
# Type specific checks
|
# Type specific checks
|
||||||
# ------------------------------------------------------------------------
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -285,6 +411,71 @@ proc sszCheck(
|
||||||
of "BitsStruct": checkBasic(BitsStruct, dir, expectedHash)
|
of "BitsStruct": checkBasic(BitsStruct, dir, expectedHash)
|
||||||
else:
|
else:
|
||||||
raise newException(ValueError, "unknown container in test: " & sszSubType)
|
raise newException(ValueError, "unknown container in test: " & sszSubType)
|
||||||
|
of "profiles":
|
||||||
|
var name: string
|
||||||
|
let wasMatched = scanf(sszSubType, "$+_", name)
|
||||||
|
doAssert wasMatched
|
||||||
|
case name
|
||||||
|
of "BitsProfile1":
|
||||||
|
checkBasic(BitsProfile1, dir, expectedHash)
|
||||||
|
of "BitsProfile2":
|
||||||
|
checkBasic(BitsProfile2, dir, expectedHash)
|
||||||
|
of "BitsProfile3":
|
||||||
|
checkBasic(BitsProfile3, dir, expectedHash)
|
||||||
|
of "ComplexTestProfile1":
|
||||||
|
checkBasic(ComplexTestProfile1, dir, expectedHash)
|
||||||
|
of "ComplexTestProfile2":
|
||||||
|
checkBasic(ComplexTestProfile2, dir, expectedHash)
|
||||||
|
of "ComplexTestProfile3":
|
||||||
|
checkBasic(ComplexTestProfile3, dir, expectedHash)
|
||||||
|
of "ComplexTestProfile4":
|
||||||
|
checkBasic(ComplexTestProfile4, dir, expectedHash)
|
||||||
|
of "ComplexTestProfile5":
|
||||||
|
checkBasic(ComplexTestProfile5, dir, expectedHash)
|
||||||
|
of "FixedTestProfile1":
|
||||||
|
checkBasic(FixedTestProfile1, dir, expectedHash)
|
||||||
|
of "FixedTestProfile2":
|
||||||
|
checkBasic(FixedTestProfile2, dir, expectedHash)
|
||||||
|
of "FixedTestProfile3":
|
||||||
|
checkBasic(FixedTestProfile3, dir, expectedHash)
|
||||||
|
of "FixedTestProfile4":
|
||||||
|
checkBasic(FixedTestProfile4, dir, expectedHash)
|
||||||
|
of "SingleFieldTestProfile":
|
||||||
|
checkBasic(SingleFieldTestProfile, dir, expectedHash)
|
||||||
|
of "SmallTestProfile1":
|
||||||
|
checkBasic(SmallTestProfile1, dir, expectedHash)
|
||||||
|
of "SmallTestProfile2":
|
||||||
|
checkBasic(SmallTestProfile2, dir, expectedHash)
|
||||||
|
of "SmallTestProfile3":
|
||||||
|
checkBasic(SmallTestProfile3, dir, expectedHash)
|
||||||
|
of "VarTestProfile1":
|
||||||
|
checkBasic(VarTestProfile1, dir, expectedHash)
|
||||||
|
of "VarTestProfile2":
|
||||||
|
checkBasic(VarTestProfile2, dir, expectedHash)
|
||||||
|
of "VarTestProfile3":
|
||||||
|
checkBasic(VarTestProfile3, dir, expectedHash)
|
||||||
|
else:
|
||||||
|
raise newException(ValueError, "unknown profile in test: " & sszSubType)
|
||||||
|
of "stablecontainers":
|
||||||
|
var name: string
|
||||||
|
let wasMatched = scanf(sszSubType, "$+_", name)
|
||||||
|
doAssert wasMatched
|
||||||
|
case name
|
||||||
|
of "BitsStableStruct":
|
||||||
|
checkBasic(BitsStableStruct, dir, expectedHash)
|
||||||
|
of "ComplexTestStableStruct":
|
||||||
|
checkBasic(ComplexTestStableStruct, dir, expectedHash)
|
||||||
|
of "FixedTestStableStruct":
|
||||||
|
checkBasic(FixedTestStableStruct, dir, expectedHash)
|
||||||
|
of "SingleFieldTestStableStruct":
|
||||||
|
checkBasic(SingleFieldTestStableStruct, dir, expectedHash)
|
||||||
|
of "SmallTestStableStruct":
|
||||||
|
checkBasic(SmallTestStableStruct, dir, expectedHash)
|
||||||
|
of "VarTestStableStruct":
|
||||||
|
checkBasic(VarTestStableStruct, dir, expectedHash)
|
||||||
|
else:
|
||||||
|
raise newException(ValueError,
|
||||||
|
"unknown stablecontainer in test: " & sszSubType)
|
||||||
else:
|
else:
|
||||||
raise newException(ValueError, "unknown ssz type in test: " & sszType)
|
raise newException(ValueError, "unknown ssz type in test: " & sszType)
|
||||||
|
|
||||||
|
@ -306,26 +497,27 @@ suite "EF - SSZ generic types":
|
||||||
of "containers":
|
of "containers":
|
||||||
skipped = " - skipping BitsStruct"
|
skipped = " - skipping BitsStruct"
|
||||||
|
|
||||||
test &"Testing {sszType:12} inputs - valid" & skipped:
|
test &"Testing {sszType:16} inputs - valid" & skipped:
|
||||||
let path = SSZDir/sszType/"valid"
|
let path = SSZDir/sszType/"valid"
|
||||||
for pathKind, sszSubType in walkDir(
|
for pathKind, sszSubType in walkDir(
|
||||||
path, relative = true, checkDir = true):
|
path, relative = true, checkDir = true):
|
||||||
if pathKind != pcDir: continue
|
if pathKind != pcDir: continue
|
||||||
sszCheck(path, sszType, sszSubType)
|
sszCheck(path, sszType, sszSubType)
|
||||||
|
|
||||||
test &"Testing {sszType:12} inputs - invalid" & skipped:
|
template invalidPath: untyped = SSZDir/sszType/"invalid"
|
||||||
let path = SSZDir/sszType/"invalid"
|
if os_ops.dirExists(invalidPath):
|
||||||
for pathKind, sszSubType in walkDir(
|
test &"Testing {sszType:16} inputs - invalid" & skipped:
|
||||||
path, relative = true, checkDir = true):
|
for pathKind, sszSubType in walkDir(
|
||||||
if pathKind != pcDir: continue
|
invalidPath, relative = true, checkDir = true):
|
||||||
try:
|
if pathKind != pcDir: continue
|
||||||
sszCheck(path, sszType, sszSubType)
|
try:
|
||||||
except SszError, UnconsumedInput:
|
sszCheck(invalidPath, sszType, sszSubType)
|
||||||
discard
|
except SszError, UnconsumedInput:
|
||||||
except TestSizeError as err:
|
discard
|
||||||
echo err.msg
|
except TestSizeError as err:
|
||||||
skip()
|
echo err.msg
|
||||||
except:
|
skip()
|
||||||
checkpoint getStackTrace(getCurrentException())
|
except:
|
||||||
checkpoint getCurrentExceptionMsg()
|
checkpoint getStackTrace(getCurrentException())
|
||||||
check false
|
checkpoint getCurrentExceptionMsg()
|
||||||
|
check false
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 248f2bdca2d65ff920920c72b764d0622d522596
|
Subproject commit 695d1c9dbec4fa0f746a15df259a19fed49e075e
|
Loading…
Reference in New Issue