remove ssz stint support (#1046)

This commit is contained in:
Jacek Sieka 2020-05-20 19:05:22 +02:00 committed by GitHub
parent b9817867f5
commit a38eddcaac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 95 deletions

View File

@ -4,8 +4,9 @@ import
options as stdOptions, net as stdNet,
# Status libs
stew/[varints, base58, bitseqs, results], stew/shims/[macros, tables],
stint, faststreams/[inputs, outputs, buffers], snappy, snappy/framing,
stew/[varints, base58, bitseqs, endians2, results],
stew/shims/[macros, tables],
faststreams/[inputs, outputs, buffers], snappy, snappy/framing,
json_serialization, json_serialization/std/[net, options],
chronos, chronicles, metrics,
# TODO: create simpler to use libp2p modules that use re-exports

View File

@ -14,7 +14,7 @@
import
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,
faststreams/[inputs, outputs, buffers],
serialization, serialization/testing/tracing,
@ -44,7 +44,7 @@ type
SszWriter* = object
stream: OutputStream
BasicType = byte|char|bool|SomeUnsignedInt|StUint
BasicType = byte|char|bool|SomeUnsignedInt
SszChunksMerkleizer = object
combinedChunks: StackArray[Eth2Digest]
@ -105,7 +105,7 @@ proc writeFixedSized(s: var (OutputStream|WriteCursor), x: auto) {.raises: [Defe
s.write x
elif x is bool|char:
s.write byte(ord(x))
elif x is SomeUnsignedInt|StUint:
elif x is SomeUnsignedInt:
when cpuEndian == bigEndian:
s.write toBytesLE(x)
else:
@ -418,7 +418,7 @@ template merkleizeFields(totalElements: int, body: untyped): Eth2Digest =
getFinalHash(merkleizer)
template writeBytesLE(chunk: var array[bytesPerChunk, byte], atParam: int,
val: SomeUnsignedInt|StUint) =
val: SomeUnsignedInt) =
let at = atParam
chunk[at ..< at + sizeof(val)] = toBytesLE(val)
@ -448,7 +448,7 @@ func chunkedHashTreeRootForBasicTypes[T](merkleizer: var SszChunksMerkleizer,
else:
static:
assert T is SomeUnsignedInt|StUInt
assert T is SomeUnsignedInt
assert bytesPerChunk mod sizeof(Т) == 0
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
elif T is bool|char:
result.data[0] = byte(x)
elif T is SomeUnsignedInt|StUint:
elif T is SomeUnsignedInt:
when cpuEndian == bigEndian:
result.data[0..<sizeof(x)] = toBytesLE(x)
else:

View File

@ -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()

View File

@ -10,7 +10,7 @@ import
os, unittest, strutils, streams, strformat,
macros, sets,
# Status libraries
stint, stew/bitseqs,
stew/bitseqs,
# Third-party
yaml,
# Beacon chain internals

View File

@ -10,7 +10,7 @@ import
os, unittest, strutils, streams, strformat, strscans,
macros, typetraits,
# Status libraries
faststreams, stint, stew/bitseqs, ../testutil,
faststreams, stew/bitseqs, ../testutil,
# Third-party
yaml,
# Beacon chain internals

View File

@ -1,7 +1,7 @@
{.used.}
import
unittest, stint, ./testutil,
unittest, ./testutil,
../beacon_chain/spec/[datatypes, network]
suiteReport "Honest validator":

View File

@ -9,7 +9,7 @@
import
unittest, options, json_serialization,
stint, nimcrypto, eth/common, serialization/testing/generic_suite,
nimcrypto, eth/common, serialization/testing/generic_suite,
./testutil,
../beacon_chain/spec/[datatypes, digest],
../beacon_chain/ssz, ../beacon_chain/ssz/[navigator, dynamic_navigator]
@ -20,7 +20,6 @@ type
Simple = object
flag: bool
# count: StUint[256]
# ignored {.dontSerialize.}: string
# data: array[256, bool]