2018-11-23 22:44:43 +00:00
|
|
|
# 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
|
2018-11-27 23:10:09 +00:00
|
|
|
math,unittest, sequtils,
|
2018-11-28 19:49:03 +00:00
|
|
|
../beacon_chain/spec/[datatypes, digest, validator]
|
2018-11-23 22:44:43 +00:00
|
|
|
|
2018-12-06 02:07:04 +00:00
|
|
|
func sumCommittees(v: openArray[seq[ShardCommittee]]): int =
|
2018-11-23 22:44:43 +00:00
|
|
|
for x in v:
|
|
|
|
for y in x:
|
|
|
|
inc result, y.committee.len
|
|
|
|
|
|
|
|
suite "Validators":
|
|
|
|
## For now just test that we can compile and execute block processing with mock data.
|
2018-11-26 15:44:49 +00:00
|
|
|
## https://github.com/status-im/nim-beacon-chain/issues/1
|
|
|
|
## https://github.com/sigp/lighthouse/blob/ba548e49a52687a655c61b443b6835d79c6d4236/beacon_chain/validator_shuffling/src/shuffle.rs
|
2018-11-23 22:44:43 +00:00
|
|
|
test "Smoke validator shuffling":
|
|
|
|
let
|
|
|
|
validators = repeat(
|
|
|
|
ValidatorRecord(
|
|
|
|
status: ACTIVE
|
2018-11-29 05:23:40 +00:00
|
|
|
), 32*1024)
|
2018-11-23 22:44:43 +00:00
|
|
|
|
2018-11-29 22:11:05 +00:00
|
|
|
# TODO the shuffling looks really odd, probably buggy
|
2019-01-16 10:21:06 +00:00
|
|
|
let s = get_shuffling(Eth2Digest(), validators, 0)
|
2018-11-23 22:44:43 +00:00
|
|
|
check:
|
2018-12-03 17:46:22 +00:00
|
|
|
s.len == EPOCH_LENGTH
|
2018-11-29 05:23:40 +00:00
|
|
|
# 32k validators means 2 shards validated per slot - the aim is to get
|
|
|
|
# TARGET_COMMITTEE_SIZE validators in each shard and there are
|
2018-12-03 17:46:22 +00:00
|
|
|
# EPOCH_LENGTH slots which each will crosslink a different shard
|
|
|
|
s[0].len == 32 * 1024 div (TARGET_COMMITTEE_SIZE * EPOCH_LENGTH)
|
2018-11-23 22:44:43 +00:00
|
|
|
sumCommittees(s) == validators.len() # all validators accounted for
|