remove ssz stint support (#1046)
This commit is contained in:
parent
b9817867f5
commit
a38eddcaac
|
@ -4,8 +4,9 @@ import
|
||||||
options as stdOptions, net as stdNet,
|
options as stdOptions, net as stdNet,
|
||||||
|
|
||||||
# Status libs
|
# Status libs
|
||||||
stew/[varints, base58, bitseqs, results], stew/shims/[macros, tables],
|
stew/[varints, base58, bitseqs, endians2, results],
|
||||||
stint, faststreams/[inputs, outputs, buffers], snappy, snappy/framing,
|
stew/shims/[macros, tables],
|
||||||
|
faststreams/[inputs, outputs, buffers], snappy, snappy/framing,
|
||||||
json_serialization, json_serialization/std/[net, options],
|
json_serialization, json_serialization/std/[net, options],
|
||||||
chronos, chronicles, metrics,
|
chronos, chronicles, metrics,
|
||||||
# TODO: create simpler to use libp2p modules that use re-exports
|
# TODO: create simpler to use libp2p modules that use re-exports
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
options, algorithm, options, strformat, typetraits,
|
options, algorithm, options, strformat, typetraits,
|
||||||
stint, stew/[bitops2, bitseqs, objects, varints, ptrops],
|
stew/[bitops2, bitseqs, endians2, objects, varints, ptrops],
|
||||||
stew/ranges/[ptr_arith, stackarrays], stew/shims/macros,
|
stew/ranges/[ptr_arith, stackarrays], stew/shims/macros,
|
||||||
faststreams/[inputs, outputs, buffers],
|
faststreams/[inputs, outputs, buffers],
|
||||||
serialization, serialization/testing/tracing,
|
serialization, serialization/testing/tracing,
|
||||||
|
@ -44,7 +44,7 @@ type
|
||||||
SszWriter* = object
|
SszWriter* = object
|
||||||
stream: OutputStream
|
stream: OutputStream
|
||||||
|
|
||||||
BasicType = byte|char|bool|SomeUnsignedInt|StUint
|
BasicType = byte|char|bool|SomeUnsignedInt
|
||||||
|
|
||||||
SszChunksMerkleizer = object
|
SszChunksMerkleizer = object
|
||||||
combinedChunks: StackArray[Eth2Digest]
|
combinedChunks: StackArray[Eth2Digest]
|
||||||
|
@ -105,7 +105,7 @@ proc writeFixedSized(s: var (OutputStream|WriteCursor), x: auto) {.raises: [Defe
|
||||||
s.write x
|
s.write x
|
||||||
elif x is bool|char:
|
elif x is bool|char:
|
||||||
s.write byte(ord(x))
|
s.write byte(ord(x))
|
||||||
elif x is SomeUnsignedInt|StUint:
|
elif x is SomeUnsignedInt:
|
||||||
when cpuEndian == bigEndian:
|
when cpuEndian == bigEndian:
|
||||||
s.write toBytesLE(x)
|
s.write toBytesLE(x)
|
||||||
else:
|
else:
|
||||||
|
@ -418,7 +418,7 @@ template merkleizeFields(totalElements: int, 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|StUint) =
|
val: SomeUnsignedInt) =
|
||||||
let at = atParam
|
let at = atParam
|
||||||
chunk[at ..< at + sizeof(val)] = toBytesLE(val)
|
chunk[at ..< at + sizeof(val)] = toBytesLE(val)
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ func chunkedHashTreeRootForBasicTypes[T](merkleizer: var SszChunksMerkleizer,
|
||||||
|
|
||||||
else:
|
else:
|
||||||
static:
|
static:
|
||||||
assert T is SomeUnsignedInt|StUInt
|
assert T is SomeUnsignedInt
|
||||||
assert bytesPerChunk mod sizeof(Т) == 0
|
assert bytesPerChunk mod sizeof(Т) == 0
|
||||||
|
|
||||||
const valuesPerChunk = bytesPerChunk div sizeof(Т)
|
const valuesPerChunk = bytesPerChunk div sizeof(Т)
|
||||||
|
@ -539,7 +539,7 @@ func hashTreeRootAux[T](x: T): Eth2Digest =
|
||||||
unsupported T # Blocks are identified by htr(BeaconBlock) so we avoid these
|
unsupported T # Blocks are identified by htr(BeaconBlock) so we avoid these
|
||||||
elif T is bool|char:
|
elif T is bool|char:
|
||||||
result.data[0] = byte(x)
|
result.data[0] = byte(x)
|
||||||
elif T is SomeUnsignedInt|StUint:
|
elif T is SomeUnsignedInt:
|
||||||
when cpuEndian == bigEndian:
|
when cpuEndian == bigEndian:
|
||||||
result.data[0..<sizeof(x)] = toBytesLE(x)
|
result.data[0..<sizeof(x)] = toBytesLE(x)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
# beacon_chain
|
|
||||||
# Copyright (c) 2018-Present Status Research & Development GmbH
|
|
||||||
# Licensed and distributed under either of
|
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
||||||
|
|
||||||
import
|
|
||||||
# Standard library
|
|
||||||
os, unittest, strutils, streams,
|
|
||||||
# Status libraries
|
|
||||||
stint, stew/bitseqs,
|
|
||||||
# Third-party
|
|
||||||
yaml,
|
|
||||||
# Beacon chain internals
|
|
||||||
../../beacon_chain/spec/[datatypes, digest, crypto],
|
|
||||||
../../beacon_chain/ssz
|
|
||||||
|
|
||||||
# Config
|
|
||||||
# ---------------------------------------------
|
|
||||||
|
|
||||||
const
|
|
||||||
FixturesDir = currentSourcePath.rsplit(DirSep, 1)[0] / ".." / "official"/"fixtures"
|
|
||||||
SSZDir = FixturesDir/"tests-v0.9.1"/const_preset/"phase0"/"ssz_static"
|
|
||||||
UnitTestDir = SSZDir/"Validator"/"ssz_zero"/"case_0"
|
|
||||||
|
|
||||||
type
|
|
||||||
SSZHashTreeRoot = object
|
|
||||||
# The test files have the values at the "root"
|
|
||||||
# so we **must** use "root" as a field name
|
|
||||||
root: string
|
|
||||||
# Some have a signing_root field
|
|
||||||
signing_root: string
|
|
||||||
|
|
||||||
# Make signing root optional
|
|
||||||
setDefaultValue(SSZHashTreeRoot, signing_root, "")
|
|
||||||
|
|
||||||
# Parsing + Test
|
|
||||||
# ---------------------------------------------
|
|
||||||
|
|
||||||
type Skip = enum
|
|
||||||
SkipNone
|
|
||||||
SkipHashTreeRoot
|
|
||||||
SkipSigningRoot
|
|
||||||
|
|
||||||
proc checkSSZ(T: typedesc, dir: string, expectedHash: SSZHashTreeRoot, skip = SkipNone) =
|
|
||||||
# Deserialize into a ref object to not fill Nim stack
|
|
||||||
var deserialized: ref T
|
|
||||||
new deserialized
|
|
||||||
deserialized[] = SSZ.loadFile(dir/"serialized.ssz", T)
|
|
||||||
|
|
||||||
echo "\n\nObject: ", T
|
|
||||||
echo "---------------------------------------"
|
|
||||||
echo deserialized[]
|
|
||||||
|
|
||||||
if not(skip == SkipHashTreeRoot):
|
|
||||||
check: expectedHash.root == "0x" & toLowerASCII($deserialized.hashTreeRoot())
|
|
||||||
if expectedHash.signing_root != "" and not(skip == SkipSigningRoot):
|
|
||||||
check: expectedHash.signing_root == "0x" & toLowerASCII($deserialized[].signingRoot())
|
|
||||||
|
|
||||||
proc loadExpectedHashTreeRoot(dir: string): SSZHashTreeRoot =
|
|
||||||
var s = openFileStream(dir/"roots.yaml")
|
|
||||||
yaml.load(s, result)
|
|
||||||
s.close()
|
|
||||||
|
|
||||||
# Manual checks
|
|
||||||
# ---------------------------------------------
|
|
||||||
|
|
||||||
# Compile with -d:ssz_testing for consensus objects
|
|
||||||
# as they are always an Opaque Blob even if they might seem like a valid BLS signature
|
|
||||||
|
|
||||||
echo "Current preset: ", const_preset
|
|
||||||
|
|
||||||
let hash = loadExpectedHashTreeRoot(UnitTestDir)
|
|
||||||
checkSSZ(Validator, UnitTestDir, hash)
|
|
||||||
|
|
||||||
echo "\n\n"
|
|
||||||
var deserialized: ref Validator
|
|
||||||
new deserialized
|
|
||||||
deserialized[] = SSZ.loadFile(UnitTestDir/"serialized.ssz", Validator)
|
|
||||||
|
|
||||||
echo deserialized[].hashTreeRoot()
|
|
|
@ -10,7 +10,7 @@ import
|
||||||
os, unittest, strutils, streams, strformat,
|
os, unittest, strutils, streams, strformat,
|
||||||
macros, sets,
|
macros, sets,
|
||||||
# Status libraries
|
# Status libraries
|
||||||
stint, stew/bitseqs,
|
stew/bitseqs,
|
||||||
# Third-party
|
# Third-party
|
||||||
yaml,
|
yaml,
|
||||||
# Beacon chain internals
|
# Beacon chain internals
|
||||||
|
|
|
@ -10,7 +10,7 @@ import
|
||||||
os, unittest, strutils, streams, strformat, strscans,
|
os, unittest, strutils, streams, strformat, strscans,
|
||||||
macros, typetraits,
|
macros, typetraits,
|
||||||
# Status libraries
|
# Status libraries
|
||||||
faststreams, stint, stew/bitseqs, ../testutil,
|
faststreams, stew/bitseqs, ../testutil,
|
||||||
# Third-party
|
# Third-party
|
||||||
yaml,
|
yaml,
|
||||||
# Beacon chain internals
|
# Beacon chain internals
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
unittest, stint, ./testutil,
|
unittest, ./testutil,
|
||||||
../beacon_chain/spec/[datatypes, network]
|
../beacon_chain/spec/[datatypes, network]
|
||||||
|
|
||||||
suiteReport "Honest validator":
|
suiteReport "Honest validator":
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
unittest, options, json_serialization,
|
unittest, options, json_serialization,
|
||||||
stint, nimcrypto, eth/common, serialization/testing/generic_suite,
|
nimcrypto, eth/common, serialization/testing/generic_suite,
|
||||||
./testutil,
|
./testutil,
|
||||||
../beacon_chain/spec/[datatypes, digest],
|
../beacon_chain/spec/[datatypes, digest],
|
||||||
../beacon_chain/ssz, ../beacon_chain/ssz/[navigator, dynamic_navigator]
|
../beacon_chain/ssz, ../beacon_chain/ssz/[navigator, dynamic_navigator]
|
||||||
|
@ -20,7 +20,6 @@ type
|
||||||
|
|
||||||
Simple = object
|
Simple = object
|
||||||
flag: bool
|
flag: bool
|
||||||
# count: StUint[256]
|
|
||||||
# ignored {.dontSerialize.}: string
|
# ignored {.dontSerialize.}: string
|
||||||
# data: array[256, bool]
|
# data: array[256, bool]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue