nimbus-eth2/tests/test_exit_pool.nim

61 lines
2.7 KiB
Nim
Raw Normal View History

# 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:
pool.proposer_slashings.addExitMessage(
ProposerSlashing(signed_header_1: SignedBeaconBlockHeader(
message: BeaconBlockHeader(proposer_index: j))), MAX_PROPOSER_SLASHINGS)
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:
pool.attester_slashings.addExitMessage(
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]))),
MAX_ATTESTER_SLASHINGS)
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:
pool.voluntary_exits.addExitMessage(
SignedVoluntaryExit(message: VoluntaryExit(validator_index: j)), MAX_VOLUNTARY_EXITS)
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