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,
|
2019-01-22 22:36:31 +00:00
|
|
|
../beacon_chain/spec/[helpers, datatypes, digest, validator]
|
2018-11-23 22:44:43 +00:00
|
|
|
|
2019-01-29 04:15:00 +00:00
|
|
|
func sumCommittees(v: openArray[seq[ValidatorIndex]], reqCommitteeLen: int): int =
|
2018-11-23 22:44:43 +00:00
|
|
|
for x in v:
|
2019-01-23 18:16:16 +00:00
|
|
|
## This only holds when num_validators is divisible by
|
2019-02-20 01:33:58 +00:00
|
|
|
## SLOTS_PER_EPOCH * get_committee_count_per_slot(len(validators))
|
2019-01-23 18:16:16 +00:00
|
|
|
## as, in general, not all committees can be equally sized.
|
2019-01-22 22:36:31 +00:00
|
|
|
assert x.len == reqCommitteeLen
|
|
|
|
inc result, x.len
|
2018-11-23 22:44:43 +00:00
|
|
|
|
|
|
|
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
|
2019-01-22 22:36:31 +00:00
|
|
|
num_validators = 32*1024
|
2018-11-23 22:44:43 +00:00
|
|
|
validators = repeat(
|
2019-01-17 18:27:11 +00:00
|
|
|
Validator(
|
2019-01-29 03:22:22 +00:00
|
|
|
exit_epoch: FAR_FUTURE_EPOCH
|
2019-01-22 22:36:31 +00:00
|
|
|
), num_validators)
|
|
|
|
s = get_shuffling(Eth2Digest(), validators, 0)
|
2019-01-29 03:22:22 +00:00
|
|
|
committees = get_epoch_committee_count(len(validators)).int
|
2018-11-23 22:44:43 +00:00
|
|
|
check:
|
2019-01-22 22:36:31 +00:00
|
|
|
s.len == committees
|
2019-02-20 01:33:58 +00:00
|
|
|
# 32k validators: SLOTS_PER_EPOCH slots * committee_count_per_slot =
|
2019-01-29 03:22:22 +00:00
|
|
|
# get_epoch_committee_count committees.
|
2019-01-22 22:36:31 +00:00
|
|
|
sumCommittees(s, num_validators div committees) == validators.len() # all validators accounted for
|