Skip to content

Commit

Permalink
Revert "Implement shuffling test (pending typedesc and shuffling algo…
Browse files Browse the repository at this point in the history
… fix)"

This reverts commit ad9f643.
  • Loading branch information
mratsim committed May 9, 2019
1 parent ad9f643 commit 813cb6f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
30 changes: 0 additions & 30 deletions tests/official/test_fixture_shuffling.nim

This file was deleted.

6 changes: 3 additions & 3 deletions tests/official/test_fixture_state.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit 813cb6f

Please sign in to comment.