2019-02-19 23:35:02 +00:00
|
|
|
# beacon_chain
|
|
|
|
# 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
|
|
|
|
options, sequtils, unittest,
|
|
|
|
./testutil,
|
|
|
|
../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator],
|
2019-03-12 15:03:14 +00:00
|
|
|
../beacon_chain/[beacon_node_types, attestation_pool, block_pool, extras, state_transition, ssz]
|
2019-02-19 23:35:02 +00:00
|
|
|
|
|
|
|
suite "Attestation pool processing":
|
|
|
|
## For now just test that we can compile and execute block processing with
|
|
|
|
## mock data.
|
|
|
|
|
2019-02-28 21:21:29 +00:00
|
|
|
# Genesis state with minimal number of deposits
|
2019-03-13 22:59:20 +00:00
|
|
|
let
|
2019-02-28 21:21:29 +00:00
|
|
|
genState = get_genesis_beacon_state(
|
|
|
|
makeInitialDeposits(flags = {skipValidation}), 0, Eth1Data(),
|
|
|
|
{skipValidation})
|
|
|
|
genBlock = get_initial_beacon_block(genState)
|
|
|
|
|
2019-02-19 23:35:02 +00:00
|
|
|
test "Can add and retrieve simple attestation":
|
|
|
|
var
|
2019-03-13 22:59:20 +00:00
|
|
|
blockPool = BlockPool.init(makeTestDB(genState, genBlock))
|
2019-02-28 21:21:29 +00:00
|
|
|
pool = AttestationPool.init(blockPool)
|
|
|
|
state = blockPool.loadTailState()
|
2019-02-19 23:35:02 +00:00
|
|
|
# Slot 0 is a finalized slot - won't be making attestations for it..
|
2019-03-27 01:32:35 +00:00
|
|
|
advanceState(state.data)
|
2019-02-19 23:35:02 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
# Create an attestation for slot 1 signed by the only attester we have!
|
2019-02-28 21:21:29 +00:00
|
|
|
crosslink_committees =
|
2019-05-04 14:10:45 +00:00
|
|
|
get_crosslink_committees_at_slot(state.data.data, state.data.data.slot)
|
2019-02-19 23:35:02 +00:00
|
|
|
attestation = makeAttestation(
|
2019-05-04 14:10:45 +00:00
|
|
|
state.data.data, state.blck.root, crosslink_committees[0].committee[0])
|
2019-02-19 23:35:02 +00:00
|
|
|
|
2019-05-04 14:10:45 +00:00
|
|
|
pool.add(state.data.data, attestation)
|
2019-02-19 23:35:02 +00:00
|
|
|
|
|
|
|
let attestations = pool.getAttestationsForBlock(
|
2019-05-04 14:10:45 +00:00
|
|
|
state.data.data, state.data.data.slot + MIN_ATTESTATION_INCLUSION_DELAY)
|
2019-02-19 23:35:02 +00:00
|
|
|
|
2019-03-28 19:15:09 +00:00
|
|
|
# TODO test needs fixing for new attestation validation
|
|
|
|
# check:
|
|
|
|
# attestations.len == 1
|
2019-02-21 04:42:17 +00:00
|
|
|
|
|
|
|
test "Attestations may arrive in any order":
|
|
|
|
var
|
2019-03-13 22:59:20 +00:00
|
|
|
blockPool = BlockPool.init(makeTestDB(genState, genBlock))
|
2019-02-28 21:21:29 +00:00
|
|
|
pool = AttestationPool.init(blockPool)
|
|
|
|
state = blockPool.loadTailState()
|
2019-02-21 04:42:17 +00:00
|
|
|
# Slot 0 is a finalized slot - won't be making attestations for it..
|
2019-03-27 01:32:35 +00:00
|
|
|
advanceState(state.data)
|
2019-02-21 04:42:17 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
# Create an attestation for slot 1 signed by the only attester we have!
|
2019-02-28 21:21:29 +00:00
|
|
|
crosslink_committees1 =
|
2019-05-04 14:10:45 +00:00
|
|
|
get_crosslink_committees_at_slot(state.data.data, state.data.data.slot)
|
2019-02-21 04:42:17 +00:00
|
|
|
attestation1 = makeAttestation(
|
2019-05-04 14:10:45 +00:00
|
|
|
state.data.data, state.blck.root, crosslink_committees1[0].committee[0])
|
2019-02-21 04:42:17 +00:00
|
|
|
|
2019-03-27 01:32:35 +00:00
|
|
|
advanceState(state.data)
|
2019-02-21 04:42:17 +00:00
|
|
|
|
|
|
|
let
|
2019-02-28 21:21:29 +00:00
|
|
|
crosslink_committees2 =
|
2019-05-04 14:10:45 +00:00
|
|
|
get_crosslink_committees_at_slot(state.data.data, state.data.data.slot)
|
2019-02-21 04:42:17 +00:00
|
|
|
attestation2 = makeAttestation(
|
2019-05-04 14:10:45 +00:00
|
|
|
state.data.data, state.blck.root, crosslink_committees2[0].committee[0])
|
2019-02-21 04:42:17 +00:00
|
|
|
|
|
|
|
# test reverse order
|
2019-05-04 14:10:45 +00:00
|
|
|
pool.add(state.data.data, attestation2)
|
|
|
|
pool.add(state.data.data, attestation1)
|
2019-02-21 04:42:17 +00:00
|
|
|
|
|
|
|
let attestations = pool.getAttestationsForBlock(
|
2019-05-04 14:10:45 +00:00
|
|
|
state.data.data, state.data.data.slot + MIN_ATTESTATION_INCLUSION_DELAY)
|
2019-02-21 04:42:17 +00:00
|
|
|
|
2019-03-28 19:15:09 +00:00
|
|
|
# TODO test needs fixing for new attestation validation
|
|
|
|
# check:
|
|
|
|
# attestations.len == 1
|