nimbus-eth2/tests/official/test_fixture_shuffling.nim
Mamy Ratsimbazafy 0926ebf8fe [Tests] SSZ unsigned integer + test suite genericity (#284)
* Generics over tests (https://github.com/status-im/nim-serialization/issues/4, https://github.com/status-im/nim-serialization/issues/5, https://github.com/nim-lang/Nim/issues/11225)

* Skeleton of SSZ uint tests

* Check all primitive uint types

* Add deserialization test. "wrong length" skipped due to https://github.com/status-im/nim-beacon-chain/issues/280

* Move test types to their specific test files

* Stint also sometimes throws an AssertionError for invalid ranges

* Add debug path for Access denied issue in Appveyor 64-bit (https://ci.appveyor.com/project/nimbus/nim-beacon-chain/builds/25278666/job/fs8q0bcluvj2gdor#L866)

* indent the Appveyor debug info
2019-06-17 09:29:23 +00:00

40 lines
1.4 KiB
Nim

# 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 library
ospaths, strutils, unittest,
# Beacon chain internals
../../beacon_chain/spec/[datatypes, validator, digest],
# Test utilities
../testutil,
./fixtures_utils
type
Shuffling* = object
seed*: Eth2Digest
count*: uint64
shuffled*: seq[ValidatorIndex]
const TestFolder = currentSourcePath.rsplit(DirSep, 1)[0]
when const_preset == "mainnet":
const TestsPath = "fixtures" / "json_tests" / "shuffling" / "core" / "shuffling_full.json"
elif const_preset == "minimal":
const TestsPath = "fixtures" / "json_tests" / "shuffling" / "core" / "shuffling_minimal.json"
var shufflingTests: Tests[Shuffling]
suite "Official - Shuffling tests [Preset: " & preset():
test "Parsing the official shuffling tests [Preset: " & preset():
shufflingTests = parseTests(TestFolder / TestsPath, Shuffling)
test "Shuffling a sequence of N validators" & preset():
for t in shufflingTests.test_cases:
let implResult = get_shuffled_seq(t.seed, t.count)
check: implResult == t.shuffled