Revert "Implement shuffling test (pending typedesc and shuffling algo fix)"

This reverts commit ad9f643873.
This commit is contained in:
Mamy André-Ratsimbazafy 2019-05-09 12:06:45 +02:00
parent ad9f643873
commit 813cb6fbb8
No known key found for this signature in database
GPG Key ID: 7B88AD1FE79492E1
3 changed files with 8 additions and 74 deletions

View File

@ -12,15 +12,14 @@ export nimcrypto.toHex
type
# TODO: use ref object to avoid allocating
# so much on the stack - pending https://github.com/status-im/nim-json-serialization/issues/3
StateTests* = object
StateTest* = object
title*: string
summary*: string
test_suite*: string
fork*: string
test_cases*: seq[StateTestCase]
test_cases*: seq[TestCase]
TestConstants* = object
# TODO - 0.5.1 constants
SHARD_COUNT*: int
TARGET_COMMITTEE_SIZE*: int
MAX_BALANCE_CHURN_QUOTIENT*: int
@ -67,7 +66,7 @@ type
DOMAIN_VOLUNTARY_EXIT*: SignatureDomain
DOMAIN_TRANSFER*: SignatureDomain
StateTestCase* = object
TestCase* = object
name*: string
config*: TestConstants
verify_signatures*: bool
@ -75,23 +74,6 @@ type
blocks*: seq[BeaconBlock]
expected_state*: BeaconState
ShufflingTests* = object
title*: string
summary*: string
forks_timeline*: string
forks*: seq[string]
config*: string
runner*: string
handler*: string
test_cases*: seq[ShufflingTestCase]
ShufflingTestCase* = object
seed*: Eth2Digest
count*: uint64
shuffled*: seq[ValidatorIndex]
Tests* = StateTests or ShufflingTests
# #######################
# Default init
proc default*(T: typedesc): T = discard
@ -107,27 +89,9 @@ proc readValue*[N: static int](r: var JsonReader, a: var array[N, byte]) {.inlin
# if so export that to nim-eth
hexToByteArray(r.readValue(string), a)
proc readValue*(r: var JsonReader, a: var ValidatorIndex) {.inline.} =
a = r.readValue(uint32)
# TODO: cannot pass a typedesc
# proc parseTests*(jsonPath: string, T: typedesc[Tests]): T =
# # TODO: due to generic early symbol resolution
# # we cannot use a generic proc
# # Otherwise we get:
# # "Error: undeclared identifier: 'ReaderType'"
# # Templates, even untyped don't work
# try:
# result = Json.loadFile(jsonPath, T)
# except SerializationError as err:
# writeStackTrace()
# stderr.write "Json load issue for file \"", jsonPath, "\"\n"
# stderr.write err.formatMsg(jsonPath), "\n"
# quit 1
proc parseTests*(jsonPath: string): ShufflingTests =
proc parseStateTests*(jsonPath: string): StateTest =
try:
result = Json.loadFile(jsonPath, ShufflingTests)
result = Json.loadFile(jsonPath, StateTest)
except SerializationError as err:
writeStackTrace()
stderr.write "Json load issue for file \"", jsonPath, "\"\n"

View File

@ -1,30 +0,0 @@
# beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://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 libs
ospaths, strutils, json, unittest,
# Third parties
# Beacon chain internals
../../beacon_chain/spec/validator,
# Test utilities
./fixtures_utils
const TestFolder = currentSourcePath.rsplit(DirSep, 1)[0]
const TestsPath = "fixtures" / "json_tests" / "shuffling" / "core" / "shuffling_full.json"
var shufflingTests: ShufflingTests
suite "Official - Shuffling tests":
test "Parsing the official shuffling tests":
shufflingTests = parseTests(TestFolder / TestsPath)
test "Shuffling a sequence of N validators":
for t in shufflingTests.test_cases:
let implResult = get_shuffled_seq(t.seed, t.count)
check: implResult == t.shuffled

View File

@ -14,17 +14,17 @@ import
../../beacon_chain/spec/[datatypes, crypto, digest, beaconstate],
../../beacon_chain/[ssz, state_transition],
# Test utilities
./fixtures_utils
./state_test_utils
const TestFolder = currentSourcePath.rsplit(DirSep, 1)[0]
const TestsPath = "fixtures" / "json_tests" / "state" / "sanity-check_default-config_100-vals.json"
var stateTests: StateTests
var stateTests: StateTest
suite "Official - State tests": # Initializing a beacon state from the deposits
# Source: https://github.com/ethereum/eth2.0-specs/blob/2baa242ac004b0475604c4c4ef4315e14f56c5c7/tests/phase0/test_sanity.py#L55-L460
test "Parsing the official state tests into Nimbus beacon types":
stateTests = parseTests(TestFolder / TestsPath, StateTests) # TODO pending typedesc fix in fixture_utils.nim
stateTests = parseStateTests(TestFolder / TestsPath)
doAssert $stateTests.test_cases[0].name == "test_empty_block_transition"
test "[For information - Non-blocking] Block root signing":