2019-05-10 08:14:01 +00:00
|
|
|
# beacon_chain
|
2019-09-03 03:12:09 +00:00
|
|
|
# Copyright (c) 2018-Present Status Research & Development GmbH
|
2019-05-10 08:14:01 +00:00
|
|
|
# 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.
|
|
|
|
|
2019-11-14 10:47:55 +00:00
|
|
|
{.used.}
|
|
|
|
|
2019-05-10 08:14:01 +00:00
|
|
|
import
|
2019-05-27 12:48:13 +00:00
|
|
|
# Standard library
|
2019-10-02 09:08:21 +00:00
|
|
|
os, unittest, sequtils,
|
2019-05-10 08:14:01 +00:00
|
|
|
# Beacon chain internals
|
2019-06-17 09:29:23 +00:00
|
|
|
../../beacon_chain/spec/[datatypes, validator, digest],
|
2019-05-10 08:14:01 +00:00
|
|
|
# Test utilities
|
2019-05-27 12:48:13 +00:00
|
|
|
../testutil,
|
2019-09-03 03:12:09 +00:00
|
|
|
./fixtures_utils
|
2019-05-10 08:14:01 +00:00
|
|
|
|
2019-06-17 09:29:23 +00:00
|
|
|
type
|
|
|
|
Shuffling* = object
|
|
|
|
seed*: Eth2Digest
|
|
|
|
count*: uint64
|
2019-10-02 09:08:21 +00:00
|
|
|
mapping*: seq[uint64]
|
2019-06-17 09:29:23 +00:00
|
|
|
|
2019-09-03 03:12:09 +00:00
|
|
|
const ShufflingDir = JsonTestsDir/const_preset/"phase0"/"shuffling"/"core"/"shuffle"
|
2019-05-10 08:14:01 +00:00
|
|
|
|
2019-05-27 12:48:13 +00:00
|
|
|
suite "Official - Shuffling tests [Preset: " & preset():
|
|
|
|
test "Shuffling a sequence of N validators" & preset():
|
2019-09-03 03:12:09 +00:00
|
|
|
for file in walkDirRec(ShufflingDir):
|
|
|
|
let t = parseTest(file, Json, Shuffling)
|
2019-05-10 08:14:01 +00:00
|
|
|
let implResult = get_shuffled_seq(t.seed, t.count)
|
2019-10-02 09:08:21 +00:00
|
|
|
check: implResult == mapIt(t.mapping, it.ValidatorIndex)
|