2020-09-24 17:05:49 +00:00
|
|
|
# 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.}
|
|
|
|
|
2021-09-17 00:13:52 +00:00
|
|
|
import chronicles, chronos
|
2021-09-27 14:22:58 +00:00
|
|
|
import eth/keys
|
2021-10-18 16:37:27 +00:00
|
|
|
import ../beacon_chain/spec/[datatypes/base, forks, presets]
|
2021-11-25 12:20:36 +00:00
|
|
|
import ../beacon_chain/consensus_object_pools/[
|
|
|
|
block_quarantine, blockchain_dag, exit_pool]
|
2021-04-28 16:41:02 +00:00
|
|
|
import "."/[testutil, testdbutil]
|
2020-09-24 17:05:49 +00:00
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
suite "Exit pool testing suite":
|
2020-09-24 17:05:49 +00:00
|
|
|
setup:
|
2021-10-18 16:37:27 +00:00
|
|
|
let
|
|
|
|
dag = init(
|
|
|
|
ChainDAGRef, defaultRuntimeConfig, makeTestDB(SLOTS_PER_EPOCH * 3), {})
|
|
|
|
pool = newClone(ExitPool.init(dag))
|
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
test "addExitMessage/getProposerSlashingMessage":
|
2020-09-24 17:05:49 +00:00
|
|
|
for i in 0'u64 .. MAX_PROPOSER_SLASHINGS + 5:
|
|
|
|
for j in 0'u64 .. i:
|
2021-11-05 15:39:47 +00:00
|
|
|
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)
|
2021-10-18 16:37:27 +00:00
|
|
|
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
|
2020-09-24 17:05:49 +00:00
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
test "addExitMessage/getAttesterSlashingMessage":
|
2020-09-24 17:05:49 +00:00
|
|
|
for i in 0'u64 .. MAX_ATTESTER_SLASHINGS + 5:
|
|
|
|
for j in 0'u64 .. i:
|
2021-11-05 15:39:47 +00:00
|
|
|
let msg = AttesterSlashing(
|
2020-10-07 16:57:21 +00:00
|
|
|
attestation_1: IndexedAttestation(attesting_indices:
|
2021-10-18 16:37:27 +00:00
|
|
|
List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE](@[j])),
|
2020-10-07 16:57:21 +00:00
|
|
|
attestation_2: IndexedAttestation(attesting_indices:
|
2021-11-05 15:39:47 +00:00
|
|
|
List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE](@[j])))
|
|
|
|
|
|
|
|
if i == 0:
|
|
|
|
check not pool[].isSeen(msg)
|
|
|
|
|
|
|
|
pool[].addMessage(msg)
|
|
|
|
check: pool[].isSeen(msg)
|
2021-10-18 16:37:27 +00:00
|
|
|
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
|
2020-09-24 17:05:49 +00:00
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
test "addExitMessage/getVoluntaryExitMessage":
|
2020-09-24 17:05:49 +00:00
|
|
|
for i in 0'u64 .. MAX_VOLUNTARY_EXITS + 5:
|
|
|
|
for j in 0'u64 .. i:
|
2021-11-05 15:39:47 +00:00
|
|
|
let msg = SignedVoluntaryExit(message: VoluntaryExit(validator_index: j))
|
|
|
|
|
|
|
|
if i == 0:
|
|
|
|
check not pool[].isSeen(msg)
|
|
|
|
|
|
|
|
pool[].addMessage(msg)
|
|
|
|
check: pool[].isSeen(msg)
|
2021-10-18 16:37:27 +00:00
|
|
|
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
|