mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 06:16:25 +00:00
a223d62b07
Renames and cleanups split out from the validator monitoring branch, so as to reduce conflict area vs other PR:s * add constants for expected message timing * name validators after the messages they validate, mostly, to make grepping easier * unify field naming of EpochInfo across forks to make cross-fork code easier
76 lines
2.8 KiB
Nim
76 lines
2.8 KiB
Nim
# beacon_chain
|
|
# Copyright (c) 2020 Status Research & Development GmbH
|
|
# Licensed and distributed under either of
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
{.used.}
|
|
|
|
import chronicles, chronos
|
|
import eth/keys
|
|
import ../beacon_chain/spec/[datatypes/base, forks, presets]
|
|
import ../beacon_chain/consensus_object_pools/[
|
|
block_quarantine, blockchain_dag, exit_pool]
|
|
import "."/[testutil, testdbutil]
|
|
|
|
suite "Exit pool testing suite":
|
|
setup:
|
|
let
|
|
dag = init(
|
|
ChainDAGRef, defaultRuntimeConfig, makeTestDB(SLOTS_PER_EPOCH * 3), {})
|
|
pool = newClone(ExitPool.init(dag))
|
|
|
|
test "addExitMessage/getProposerSlashingMessage":
|
|
for i in 0'u64 .. MAX_PROPOSER_SLASHINGS + 5:
|
|
for j in 0'u64 .. i:
|
|
let msg = ProposerSlashing(signed_header_1: SignedBeaconBlockHeader(
|
|
message: BeaconBlockHeader(proposer_index: j)))
|
|
|
|
if i == 0:
|
|
check not pool[].isSeen(msg)
|
|
|
|
pool[].addMessage(msg)
|
|
check: pool[].isSeen(msg)
|
|
withState(dag.headState.data):
|
|
check:
|
|
pool[].getBeaconBlockExits(state.data).proposer_slashings.lenu64 ==
|
|
min(i + 1, MAX_PROPOSER_SLASHINGS)
|
|
pool[].getBeaconBlockExits(state.data).proposer_slashings.len == 0
|
|
|
|
test "addExitMessage/getAttesterSlashingMessage":
|
|
for i in 0'u64 .. MAX_ATTESTER_SLASHINGS + 5:
|
|
for j in 0'u64 .. i:
|
|
let msg = AttesterSlashing(
|
|
attestation_1: IndexedAttestation(attesting_indices:
|
|
List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE](@[j])),
|
|
attestation_2: IndexedAttestation(attesting_indices:
|
|
List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE](@[j])))
|
|
|
|
if i == 0:
|
|
check not pool[].isSeen(msg)
|
|
|
|
pool[].addMessage(msg)
|
|
check: pool[].isSeen(msg)
|
|
withState(dag.headState.data):
|
|
check:
|
|
pool[].getBeaconBlockExits(state.data).attester_slashings.lenu64 ==
|
|
min(i + 1, MAX_ATTESTER_SLASHINGS)
|
|
pool[].getBeaconBlockExits(state.data).attester_slashings.len == 0
|
|
|
|
test "addExitMessage/getVoluntaryExitMessage":
|
|
for i in 0'u64 .. MAX_VOLUNTARY_EXITS + 5:
|
|
for j in 0'u64 .. i:
|
|
let msg = SignedVoluntaryExit(message: VoluntaryExit(validator_index: j))
|
|
|
|
if i == 0:
|
|
check not pool[].isSeen(msg)
|
|
|
|
pool[].addMessage(msg)
|
|
check: pool[].isSeen(msg)
|
|
withState(dag.headState.data):
|
|
check:
|
|
pool[].getBeaconBlockExits(state.data).voluntary_exits.lenu64 ==
|
|
min(i + 1, MAX_VOLUNTARY_EXITS)
|
|
pool[].getBeaconBlockExits(state.data).voluntary_exits.len == 0
|