From 813cb6fbb8cdbb768a894c35173c3adc1e5d6c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mamy=20Andr=C3=A9-Ratsimbazafy?= Date: Thu, 9 May 2019 12:06:45 +0200 Subject: [PATCH] Revert "Implement shuffling test (pending typedesc and shuffling algo fix)" This reverts commit ad9f64387302513c7a8ac43d97e3ad04201d5e7d. --- ...ixtures_utils.nim => state_test_utils.nim} | 46 ++----------------- tests/official/test_fixture_shuffling.nim | 30 ------------ tests/official/test_fixture_state.nim | 6 +-- 3 files changed, 8 insertions(+), 74 deletions(-) rename tests/official/{fixtures_utils.nim => state_test_utils.nim} (75%) delete mode 100644 tests/official/test_fixture_shuffling.nim diff --git a/tests/official/fixtures_utils.nim b/tests/official/state_test_utils.nim similarity index 75% rename from tests/official/fixtures_utils.nim rename to tests/official/state_test_utils.nim index a14e34f5a..bac339e81 100644 --- a/tests/official/fixtures_utils.nim +++ b/tests/official/state_test_utils.nim @@ -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,30 +66,13 @@ type DOMAIN_VOLUNTARY_EXIT*: SignatureDomain DOMAIN_TRANSFER*: SignatureDomain - StateTestCase* = object + TestCase* = object name*: string config*: TestConstants verify_signatures*: bool initial_state*: BeaconState 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 @@ -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" diff --git a/tests/official/test_fixture_shuffling.nim b/tests/official/test_fixture_shuffling.nim deleted file mode 100644 index cdfab8565..000000000 --- a/tests/official/test_fixture_shuffling.nim +++ /dev/null @@ -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 \ No newline at end of file diff --git a/tests/official/test_fixture_state.nim b/tests/official/test_fixture_state.nim index f5429773b..bc4aeeb40 100644 --- a/tests/official/test_fixture_state.nim +++ b/tests/official/test_fixture_state.nim @@ -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":