enable uint128 / uint256 SSZ serialization tests (#2960)
So far, SSZ tests for `uint128` and `uint256` integers were disabled due to "compile-time issues". The code has been adjusted to support those additional test vectors, and the corresponding tests have been enabled.
This commit is contained in:
parent
35a4f5b957
commit
55c2553193
|
@ -325,6 +325,8 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
+ Overlong SSZ.decode: HashList[system.uint64, 32] OK
|
+ Overlong SSZ.decode: HashList[system.uint64, 32] OK
|
||||||
+ Overlong SSZ.decode: List[system.uint64, 32] OK
|
+ Overlong SSZ.decode: List[system.uint64, 32] OK
|
||||||
Overlong SSZ.decode: Simple Skip
|
Overlong SSZ.decode: Simple Skip
|
||||||
|
Overlong SSZ.decode: UInt128 Skip
|
||||||
|
Overlong SSZ.decode: UInt256 Skip
|
||||||
Overlong SSZ.decode: array[0..31, byte] Skip
|
Overlong SSZ.decode: array[0..31, byte] Skip
|
||||||
Overlong SSZ.decode: bool Skip
|
Overlong SSZ.decode: bool Skip
|
||||||
Overlong SSZ.decode: limb_t Skip
|
Overlong SSZ.decode: limb_t Skip
|
||||||
|
@ -337,6 +339,8 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
+ Overlong readSszBytes: HashList[system.uint64, 32] OK
|
+ Overlong readSszBytes: HashList[system.uint64, 32] OK
|
||||||
+ Overlong readSszBytes: List[system.uint64, 32] OK
|
+ Overlong readSszBytes: List[system.uint64, 32] OK
|
||||||
Overlong readSszBytes: Simple Skip
|
Overlong readSszBytes: Simple Skip
|
||||||
|
+ Overlong readSszBytes: UInt128 OK
|
||||||
|
+ Overlong readSszBytes: UInt256 OK
|
||||||
+ Overlong readSszBytes: array[0..31, byte] OK
|
+ Overlong readSszBytes: array[0..31, byte] OK
|
||||||
+ Overlong readSszBytes: bool OK
|
+ Overlong readSszBytes: bool OK
|
||||||
+ Overlong readSszBytes: limb_t OK
|
+ Overlong readSszBytes: limb_t OK
|
||||||
|
@ -349,6 +353,8 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
+ Underlong SSZ.decode: HashList[system.uint64, 32] OK
|
+ Underlong SSZ.decode: HashList[system.uint64, 32] OK
|
||||||
+ Underlong SSZ.decode: List[system.uint64, 32] OK
|
+ Underlong SSZ.decode: List[system.uint64, 32] OK
|
||||||
+ Underlong SSZ.decode: Simple OK
|
+ Underlong SSZ.decode: Simple OK
|
||||||
|
+ Underlong SSZ.decode: UInt128 OK
|
||||||
|
+ Underlong SSZ.decode: UInt256 OK
|
||||||
+ Underlong SSZ.decode: array[0..31, byte] OK
|
+ Underlong SSZ.decode: array[0..31, byte] OK
|
||||||
+ Underlong SSZ.decode: bool OK
|
+ Underlong SSZ.decode: bool OK
|
||||||
+ Underlong SSZ.decode: limb_t OK
|
+ Underlong SSZ.decode: limb_t OK
|
||||||
|
@ -361,6 +367,8 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
+ Underlong readSszBytes: HashList[system.uint64, 32] OK
|
+ Underlong readSszBytes: HashList[system.uint64, 32] OK
|
||||||
+ Underlong readSszBytes: List[system.uint64, 32] OK
|
+ Underlong readSszBytes: List[system.uint64, 32] OK
|
||||||
+ Underlong readSszBytes: Simple OK
|
+ Underlong readSszBytes: Simple OK
|
||||||
|
+ Underlong readSszBytes: UInt128 OK
|
||||||
|
+ Underlong readSszBytes: UInt256 OK
|
||||||
+ Underlong readSszBytes: array[0..31, byte] OK
|
+ Underlong readSszBytes: array[0..31, byte] OK
|
||||||
+ Underlong readSszBytes: bool OK
|
+ Underlong readSszBytes: bool OK
|
||||||
+ Underlong readSszBytes: limb_t OK
|
+ Underlong readSszBytes: limb_t OK
|
||||||
|
@ -368,7 +376,7 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
+ Underlong readSszBytes: uint32 OK
|
+ Underlong readSszBytes: uint32 OK
|
||||||
+ Underlong readSszBytes: uint8 OK
|
+ Underlong readSszBytes: uint8 OK
|
||||||
```
|
```
|
||||||
OK: 36/48 Fail: 0/48 Skip: 12/48
|
OK: 42/56 Fail: 0/56 Skip: 14/56
|
||||||
|
|
||||||
---TOTAL---
|
---TOTAL---
|
||||||
OK: 201/213 Fail: 0/213 Skip: 12/213
|
OK: 207/221 Fail: 0/221 Skip: 14/221
|
||||||
|
|
|
@ -2,8 +2,8 @@ FixtureSSZGeneric-mainnet
|
||||||
===
|
===
|
||||||
## Ethereum Foundation - SSZ generic types
|
## Ethereum Foundation - SSZ generic types
|
||||||
```diff
|
```diff
|
||||||
Testing basic_vector inputs - invalid - skipping Vector[uint128, N] and Vector[uint256, N] Skip
|
Testing basic_vector inputs - invalid Skip
|
||||||
+ Testing basic_vector inputs - valid - skipping Vector[uint128, N] and Vector[uint256, N] 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
|
||||||
|
@ -12,8 +12,8 @@ FixtureSSZGeneric-mainnet
|
||||||
+ 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 - skipping uint128 and uint256 OK
|
+ Testing uints inputs - invalid OK
|
||||||
+ Testing uints inputs - valid - skipping uint128 and uint256 OK
|
+ Testing uints inputs - valid OK
|
||||||
```
|
```
|
||||||
OK: 10/12 Fail: 0/12 Skip: 2/12
|
OK: 10/12 Fail: 0/12 Skip: 2/12
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,13 @@ import stew/[results, base10, byteutils, endians2], presto/common,
|
||||||
libp2p/peerid, serialization,
|
libp2p/peerid, serialization,
|
||||||
json_serialization, json_serialization/std/[options, net],
|
json_serialization, json_serialization/std/[options, net],
|
||||||
nimcrypto/utils as ncrutils
|
nimcrypto/utils as ncrutils
|
||||||
import ".."/[forks, ssz_codec], ".."/datatypes/[phase0, altair, merge],
|
import ".."/[eth2_ssz_serialization, forks],
|
||||||
".."/eth2_ssz_serialization,
|
".."/datatypes/[phase0, altair, merge],
|
||||||
".."/".."/ssz/[ssz_serialization, codec, types],
|
|
||||||
"."/rest_types
|
"."/rest_types
|
||||||
|
|
||||||
export
|
export
|
||||||
results, peerid, common, serialization, json_serialization, options, net,
|
results, peerid, common, serialization, json_serialization, options, net,
|
||||||
rest_types, ssz_codec, ssz_serialization, codec, types
|
eth2_ssz_serialization, rest_types
|
||||||
|
|
||||||
Json.createFlavor RestJson
|
Json.createFlavor RestJson
|
||||||
|
|
||||||
|
|
|
@ -413,7 +413,7 @@ template merkleizeFields(totalElements: static Limit, body: untyped): Eth2Digest
|
||||||
getFinalHash(merkleizer)
|
getFinalHash(merkleizer)
|
||||||
|
|
||||||
template writeBytesLE(chunk: var array[bytesPerChunk, byte], atParam: int,
|
template writeBytesLE(chunk: var array[bytesPerChunk, byte], atParam: int,
|
||||||
val: SomeUnsignedInt) =
|
val: UintN) =
|
||||||
let at = atParam
|
let at = atParam
|
||||||
chunk[at ..< at + sizeof(val)] = toBytesLE(val)
|
chunk[at ..< at + sizeof(val)] = toBytesLE(val)
|
||||||
|
|
||||||
|
@ -528,7 +528,7 @@ func maxChunksCount(T: type, maxLen: Limit): Limit =
|
||||||
func hashTreeRootAux[T](x: T): Eth2Digest =
|
func hashTreeRootAux[T](x: T): Eth2Digest =
|
||||||
when T is bool|char:
|
when T is bool|char:
|
||||||
result.data[0] = byte(x)
|
result.data[0] = byte(x)
|
||||||
elif T is SomeUnsignedInt:
|
elif T is UintN:
|
||||||
when cpuEndian == bigEndian:
|
when cpuEndian == bigEndian:
|
||||||
result.data[0..<sizeof(x)] = toBytesLE(x)
|
result.data[0..<sizeof(x)] = toBytesLE(x)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -9,20 +9,20 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[tables, typetraits, strformat],
|
std/[tables, typetraits, strformat],
|
||||||
stew/shims/macros, stew/[byteutils, bitops2, objects],
|
stew/shims/macros, stew/[byteutils, bitops2, objects], stint,
|
||||||
serialization/[object_serialization, errors],
|
serialization/[object_serialization, errors],
|
||||||
json_serialization,
|
json_serialization,
|
||||||
"."/[bitseqs],
|
"."/[bitseqs],
|
||||||
../spec/digest
|
../spec/digest
|
||||||
|
|
||||||
export bitseqs, json_serialization
|
export stint, bitseqs, json_serialization
|
||||||
|
|
||||||
const
|
const
|
||||||
offsetSize* = 4
|
offsetSize* = 4
|
||||||
bytesPerChunk* = 32
|
bytesPerChunk* = 32
|
||||||
|
|
||||||
type
|
type
|
||||||
UintN* = SomeUnsignedInt
|
UintN* = SomeUnsignedInt|UInt128|UInt256
|
||||||
BasicType* = bool|UintN
|
BasicType* = bool|UintN
|
||||||
|
|
||||||
Limit* = int64
|
Limit* = int64
|
||||||
|
|
|
@ -10,7 +10,7 @@ import
|
||||||
os, strutils, streams, strformat, strscans,
|
os, strutils, streams, strformat, strscans,
|
||||||
macros, typetraits,
|
macros, typetraits,
|
||||||
# Status libraries
|
# Status libraries
|
||||||
faststreams, snappy, ../testutil,
|
faststreams, snappy, stint, ../testutil,
|
||||||
# Third-party
|
# Third-party
|
||||||
yaml,
|
yaml,
|
||||||
# Beacon chain internals
|
# Beacon chain internals
|
||||||
|
@ -101,7 +101,7 @@ macro testVector(typeIdent: string, size: int): untyped =
|
||||||
# sizes: 1, 2, 3, 4, 5, 8, 16, 31, 512, 513
|
# sizes: 1, 2, 3, 4, 5, 8, 16, 31, 512, 513
|
||||||
#
|
#
|
||||||
# We allocate in a ref array to not run out of stack space
|
# We allocate in a ref array to not run out of stack space
|
||||||
let types = ["bool", "uint8", "uint16", "uint32", "uint64"] # "uint128", "uint256"]
|
let types = ["bool", "uint8", "uint16", "uint32", "uint64", "uint128", "uint256"]
|
||||||
let sizes = [1, 2, 3, 4, 5, 8, 16, 31, 512, 513]
|
let sizes = [1, 2, 3, 4, 5, 8, 16, 31, 512, 513]
|
||||||
|
|
||||||
var dispatcher = nnkIfStmt.newTree()
|
var dispatcher = nnkIfStmt.newTree()
|
||||||
|
@ -111,7 +111,11 @@ macro testVector(typeIdent: string, size: int): untyped =
|
||||||
for s in sizes:
|
for s in sizes:
|
||||||
# if size == s // elif size == s
|
# if size == s // elif size == s
|
||||||
let T = nnkBracketExpr.newTree(
|
let T = nnkBracketExpr.newTree(
|
||||||
ident"array", newLit(s), ident(t)
|
ident"array", newLit(s),
|
||||||
|
case t
|
||||||
|
of "uint128": ident("UInt128")
|
||||||
|
of "uint256": ident("UInt256")
|
||||||
|
else: ident(t)
|
||||||
)
|
)
|
||||||
var testStmt = quote do:
|
var testStmt = quote do:
|
||||||
checkBasic(`T`, dir, expectedHash)
|
checkBasic(`T`, dir, expectedHash)
|
||||||
|
@ -128,11 +132,9 @@ macro testVector(typeIdent: string, size: int): untyped =
|
||||||
sizeDispatch
|
sizeDispatch
|
||||||
)
|
)
|
||||||
dispatcher.add nnkElse.newTree quote do:
|
dispatcher.add nnkElse.newTree quote do:
|
||||||
# TODO: support uint128 and uint256
|
raise newException(ValueError,
|
||||||
if `typeIdent` != "uint128" and `typeIdent` != "uint256":
|
"Unsupported **type** in type/size combination: array[" &
|
||||||
raise newException(ValueError,
|
$`size` & ", " & `typeIdent` & ']')
|
||||||
"Unsupported **type** in type/size combination: array[" &
|
|
||||||
$`size` & ", " & `typeIdent` & ']')
|
|
||||||
|
|
||||||
result = dispatcher
|
result = dispatcher
|
||||||
# echo result.toStrLit() # view the generated code
|
# echo result.toStrLit() # view the generated code
|
||||||
|
@ -204,16 +206,12 @@ proc sszCheck(baseDir, sszType, sszSubType: string) =
|
||||||
let wasMatched = scanf(sszSubType, "uint_$i", bitsize)
|
let wasMatched = scanf(sszSubType, "uint_$i", bitsize)
|
||||||
doAssert wasMatched
|
doAssert wasMatched
|
||||||
case bitsize
|
case bitsize
|
||||||
of 8: checkBasic(uint8, dir, expectedHash)
|
of 8: checkBasic(uint8, dir, expectedHash)
|
||||||
of 16: checkBasic(uint16, dir, expectedHash)
|
of 16: checkBasic(uint16, dir, expectedHash)
|
||||||
of 32: checkBasic(uint32, dir, expectedHash)
|
of 32: checkBasic(uint32, dir, expectedHash)
|
||||||
of 64: checkBasic(uint64, dir, expectedHash)
|
of 64: checkBasic(uint64, dir, expectedHash)
|
||||||
of 128:
|
of 128: checkBasic(UInt128, dir, expectedHash)
|
||||||
# Compile-time issues
|
of 256: checkBasic(UInt256, dir, expectedHash)
|
||||||
discard # checkBasic(Stuint[128], dir, expectedHash)
|
|
||||||
of 256:
|
|
||||||
# Compile-time issues
|
|
||||||
discard # checkBasic(Stuint[256], dir, expectedHash)
|
|
||||||
else:
|
else:
|
||||||
raise newException(ValueError, "unknown uint in test: " & sszSubType)
|
raise newException(ValueError, "unknown uint in test: " & sszSubType)
|
||||||
of "basic_vector": checkVector(sszSubType, dir, expectedHash)
|
of "basic_vector": checkVector(sszSubType, dir, expectedHash)
|
||||||
|
@ -252,10 +250,6 @@ suite "Ethereum Foundation - SSZ generic types":
|
||||||
|
|
||||||
var skipped: string
|
var skipped: string
|
||||||
case sszType
|
case sszType
|
||||||
of "uints":
|
|
||||||
skipped = " - skipping uint128 and uint256"
|
|
||||||
of "basic_vector":
|
|
||||||
skipped = " - skipping Vector[uint128, N] and Vector[uint256, N]"
|
|
||||||
of "containers":
|
of "containers":
|
||||||
skipped = " - skipping BitsStruct"
|
skipped = " - skipping BitsStruct"
|
||||||
|
|
||||||
|
|
|
@ -343,6 +343,8 @@ suite "underlong values":
|
||||||
testit(default(uint16))
|
testit(default(uint16))
|
||||||
testit(default(uint32))
|
testit(default(uint32))
|
||||||
testit(default(uint64))
|
testit(default(uint64))
|
||||||
|
testit(default(UInt128))
|
||||||
|
testit(default(UInt256))
|
||||||
testit(default(array[32, uint8]))
|
testit(default(array[32, uint8]))
|
||||||
testit(default(HashArray[32, uint8]))
|
testit(default(HashArray[32, uint8]))
|
||||||
testit(List[uint64, 32].init(@[42'u64]))
|
testit(List[uint64, 32].init(@[42'u64]))
|
||||||
|
|
Loading…
Reference in New Issue