eth2.0-specs/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py

502 lines
16 KiB
Python
Raw Normal View History

2019-03-18 18:51:52 +00:00
from copy import deepcopy
2019-06-05 13:29:26 +00:00
from eth2spec.utils.ssz.ssz_impl import signing_root
2019-05-30 20:57:18 +00:00
from eth2spec.utils.bls import bls_sign
2019-03-18 18:51:52 +00:00
from eth2spec.test.helpers.state import get_balance, state_transition_and_sign_block
2019-06-26 20:11:40 +00:00
from eth2spec.test.helpers.block import build_empty_block_for_next_slot, build_empty_block, sign_block
2019-05-23 21:32:21 +00:00
from eth2spec.test.helpers.keys import privkeys, pubkeys
from eth2spec.test.helpers.attester_slashings import get_valid_attester_slashing
from eth2spec.test.helpers.proposer_slashings import get_valid_proposer_slashing
from eth2spec.test.helpers.attestations import get_valid_attestation
from eth2spec.test.helpers.deposits import prepare_state_and_deposit
from eth2spec.test.context import spec_state_test, with_all_phases, expect_assertion_error
@with_all_phases
@spec_state_test
def test_prev_slot_block_transition(spec, state):
# Go to clean slot
spec.process_slots(state, state.slot + 1)
# Make a block for it
block = build_empty_block(spec, state, slot=state.slot, signed=True)
# Transition to next slot, above block will not be invalid on top of new state.
spec.process_slots(state, state.slot + 1)
yield 'pre', state
expect_assertion_error(lambda: state_transition_and_sign_block(spec, state, block))
yield 'blocks', [block]
yield 'post', None
@with_all_phases
@spec_state_test
def test_same_slot_block_transition(spec, state):
# Same slot on top of pre-state, but move out of slot 0 first.
spec.process_slots(state, state.slot + 1)
block = build_empty_block(spec, state, slot=state.slot, signed=True)
yield 'pre', state
state_transition_and_sign_block(spec, state, block)
yield 'blocks', [block]
yield 'post', state
2019-03-18 18:51:52 +00:00
2019-05-06 15:43:02 +00:00
2019-06-06 21:30:40 +00:00
@with_all_phases
2019-05-06 15:43:02 +00:00
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_empty_block_transition(spec, state):
2019-05-06 15:43:02 +00:00
pre_slot = state.slot
pre_eth1_votes = len(state.eth1_data_votes)
yield 'pre', state
2019-03-18 18:51:52 +00:00
2019-05-30 20:57:18 +00:00
block = build_empty_block_for_next_slot(spec, state, signed=True)
2019-03-18 18:51:52 +00:00
state_transition_and_sign_block(spec, state, block)
yield 'blocks', [block]
2019-05-06 15:43:02 +00:00
yield 'post', state
2019-03-18 18:51:52 +00:00
2019-05-06 15:43:02 +00:00
assert len(state.eth1_data_votes) == pre_eth1_votes + 1
2019-05-30 20:57:18 +00:00
assert spec.get_block_root_at_slot(state, pre_slot) == block.parent_root
2019-06-30 15:10:22 +00:00
assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.Hash()
2019-03-18 18:51:52 +00:00
2019-06-26 22:43:50 +00:00
@with_all_phases
@spec_state_test
def test_invalid_state_root(spec, state):
yield 'pre', state
block = build_empty_block_for_next_slot(spec, state)
block.state_root = b"\xaa" * 32
sign_block(spec, state, block)
expect_assertion_error(
lambda: spec.state_transition(state, block, validate_state_root=True))
yield 'blocks', [block]
yield 'post', None
2019-06-06 21:30:40 +00:00
@with_all_phases
2019-05-06 15:43:02 +00:00
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_skipped_slots(spec, state):
2019-05-06 15:43:02 +00:00
pre_slot = state.slot
yield 'pre', state
2019-03-18 18:51:52 +00:00
2019-05-30 20:57:18 +00:00
block = build_empty_block_for_next_slot(spec, state)
2019-05-06 15:43:02 +00:00
block.slot += 3
2019-05-30 20:57:18 +00:00
sign_block(spec, state, block)
2019-03-18 18:51:52 +00:00
state_transition_and_sign_block(spec, state, block)
yield 'blocks', [block]
2019-05-06 15:43:02 +00:00
yield 'post', state
2019-03-18 18:51:52 +00:00
2019-05-06 15:43:02 +00:00
assert state.slot == block.slot
2019-06-30 15:10:22 +00:00
assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.Hash()
2019-05-06 15:43:02 +00:00
for slot in range(pre_slot, state.slot):
2019-05-30 20:57:18 +00:00
assert spec.get_block_root_at_slot(state, slot) == block.parent_root
2019-03-18 18:51:52 +00:00
2019-06-06 21:30:40 +00:00
@with_all_phases
2019-05-06 15:43:02 +00:00
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_empty_epoch_transition(spec, state):
2019-05-06 15:43:02 +00:00
pre_slot = state.slot
yield 'pre', state
2019-03-18 18:51:52 +00:00
2019-05-30 20:57:18 +00:00
block = build_empty_block_for_next_slot(spec, state)
2019-05-06 15:43:02 +00:00
block.slot += spec.SLOTS_PER_EPOCH
2019-05-30 20:57:18 +00:00
sign_block(spec, state, block)
2019-03-18 18:51:52 +00:00
state_transition_and_sign_block(spec, state, block)
yield 'blocks', [block]
2019-05-06 15:43:02 +00:00
yield 'post', state
2019-03-18 18:51:52 +00:00
2019-05-06 15:43:02 +00:00
assert state.slot == block.slot
for slot in range(pre_slot, state.slot):
2019-05-30 20:57:18 +00:00
assert spec.get_block_root_at_slot(state, slot) == block.parent_root
2019-03-18 18:51:52 +00:00
@with_all_phases
@spec_state_test
def test_empty_epoch_transition_not_finalizing(spec, state):
# Don't run for non-minimal configs, it takes very long, and the effect
2019-06-29 19:39:10 +00:00
# of calling finalization/justification is just the same as with the minimal configuration.
if spec.SLOTS_PER_EPOCH > 8:
return
# copy for later balance lookups.
pre_balances = list(state.balances)
yield 'pre', state
spec.process_slots(state, state.slot + (spec.SLOTS_PER_EPOCH * 5))
block = build_empty_block_for_next_slot(spec, state, signed=True)
state_transition_and_sign_block(spec, state, block)
yield 'blocks', [block]
yield 'post', state
assert state.slot == block.slot
assert state.finalized_checkpoint.epoch < spec.get_current_epoch(state) - 4
for index in range(len(state.validators)):
assert state.balances[index] < pre_balances[index]
2019-03-18 18:51:52 +00:00
2019-06-06 21:30:40 +00:00
@with_all_phases
2019-05-06 15:43:02 +00:00
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_proposer_slashing(spec, state):
2019-05-06 15:43:02 +00:00
# copy for later balance lookups.
pre_state = deepcopy(state)
2019-05-30 20:57:18 +00:00
proposer_slashing = get_valid_proposer_slashing(spec, state, signed_1=True, signed_2=True)
2019-03-21 23:08:54 +00:00
validator_index = proposer_slashing.proposer_index
2019-03-18 18:51:52 +00:00
2019-06-09 19:41:21 +00:00
assert not state.validators[validator_index].slashed
2019-05-06 15:43:02 +00:00
yield 'pre', state
2019-03-18 18:51:52 +00:00
#
# Add to state via block transition
#
2019-05-30 20:57:18 +00:00
block = build_empty_block_for_next_slot(spec, state)
2019-03-18 18:51:52 +00:00
block.body.proposer_slashings.append(proposer_slashing)
2019-05-30 20:57:18 +00:00
sign_block(spec, state, block)
2019-03-18 18:51:52 +00:00
state_transition_and_sign_block(spec, state, block)
yield 'blocks', [block]
2019-05-06 15:43:02 +00:00
yield 'post', state
2019-03-18 18:51:52 +00:00
2019-05-06 15:43:02 +00:00
# check if slashed
2019-06-09 19:41:21 +00:00
slashed_validator = state.validators[validator_index]
2019-03-18 18:51:52 +00:00
assert slashed_validator.slashed
assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH
assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH
# lost whistleblower reward
2019-05-06 15:43:02 +00:00
assert get_balance(state, validator_index) < get_balance(pre_state, validator_index)
2019-03-18 18:51:52 +00:00
2019-06-06 21:30:40 +00:00
@with_all_phases
2019-05-06 15:43:02 +00:00
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_attester_slashing(spec, state):
2019-05-06 15:43:02 +00:00
# copy for later balance lookups.
pre_state = deepcopy(state)
2019-05-30 20:57:18 +00:00
attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True)
2019-11-02 03:02:53 +00:00
validator_index = attester_slashing.attestation_1.attesting_indices[0]
2019-06-09 19:41:21 +00:00
assert not state.validators[validator_index].slashed
2019-05-06 15:43:02 +00:00
yield 'pre', state
#
# Add to state via block transition
#
2019-05-30 20:57:18 +00:00
block = build_empty_block_for_next_slot(spec, state)
block.body.attester_slashings.append(attester_slashing)
2019-05-30 20:57:18 +00:00
sign_block(spec, state, block)
state_transition_and_sign_block(spec, state, block)
yield 'blocks', [block]
2019-05-06 15:43:02 +00:00
yield 'post', state
2019-06-09 19:41:21 +00:00
slashed_validator = state.validators[validator_index]
assert slashed_validator.slashed
assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH
assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH
# lost whistleblower reward
2019-05-06 15:43:02 +00:00
assert get_balance(state, validator_index) < get_balance(pre_state, validator_index)
2019-06-30 17:42:24 +00:00
proposer_index = spec.get_beacon_proposer_index(state)
2019-04-03 00:04:12 +00:00
# gained whistleblower reward
assert (
2019-05-06 15:43:02 +00:00
get_balance(state, proposer_index) >
get_balance(pre_state, proposer_index)
2019-04-03 00:04:12 +00:00
)
2019-06-22 00:37:20 +00:00
@with_all_phases
@spec_state_test
def test_expected_deposit_in_block(spec, state):
# Make the state expect a deposit, then don't provide it.
state.eth1_data.deposit_count += 1
yield 'pre', state
block = build_empty_block_for_next_slot(spec, state)
sign_block(spec, state, block)
bad = False
try:
state_transition_and_sign_block(spec, state, block)
bad = True
except AssertionError:
pass
if bad:
raise AssertionError("expected deposit was not enforced")
yield 'blocks', [block]
yield 'post', None
2019-06-06 21:30:40 +00:00
@with_all_phases
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_deposit_in_block(spec, state):
2019-06-09 19:41:21 +00:00
initial_registry_len = len(state.validators)
initial_balances_len = len(state.balances)
2019-06-09 19:41:21 +00:00
validator_index = len(state.validators)
amount = spec.MAX_EFFECTIVE_BALANCE
2019-05-30 20:57:18 +00:00
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
yield 'pre', state
2019-03-18 18:51:52 +00:00
2019-05-30 20:57:18 +00:00
block = build_empty_block_for_next_slot(spec, state)
2019-03-18 18:51:52 +00:00
block.body.deposits.append(deposit)
2019-05-30 20:57:18 +00:00
sign_block(spec, state, block)
2019-03-18 18:51:52 +00:00
state_transition_and_sign_block(spec, state, block)
2019-03-18 18:51:52 +00:00
yield 'blocks', [block]
yield 'post', state
2019-03-18 18:51:52 +00:00
2019-06-09 19:41:21 +00:00
assert len(state.validators) == initial_registry_len + 1
assert len(state.balances) == initial_balances_len + 1
assert get_balance(state, validator_index) == spec.MAX_EFFECTIVE_BALANCE
2019-06-09 19:41:21 +00:00
assert state.validators[validator_index].pubkey == pubkeys[validator_index]
2019-03-18 18:51:52 +00:00
2019-06-06 21:30:40 +00:00
@with_all_phases
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_deposit_top_up(spec, state):
2019-03-18 18:51:52 +00:00
validator_index = 0
2019-04-16 06:16:13 +00:00
amount = spec.MAX_EFFECTIVE_BALANCE // 4
2019-05-30 20:57:18 +00:00
deposit = prepare_state_and_deposit(spec, state, validator_index, amount)
2019-06-09 19:41:21 +00:00
initial_registry_len = len(state.validators)
initial_balances_len = len(state.balances)
validator_pre_balance = get_balance(state, validator_index)
2019-03-18 18:51:52 +00:00
yield 'pre', state
2019-05-30 20:57:18 +00:00
block = build_empty_block_for_next_slot(spec, state)
2019-03-18 18:51:52 +00:00
block.body.deposits.append(deposit)
2019-05-30 20:57:18 +00:00
sign_block(spec, state, block)
2019-03-18 18:51:52 +00:00
state_transition_and_sign_block(spec, state, block)
yield 'blocks', [block]
yield 'post', state
2019-03-18 18:51:52 +00:00
2019-06-09 19:41:21 +00:00
assert len(state.validators) == initial_registry_len
assert len(state.balances) == initial_balances_len
assert get_balance(state, validator_index) == validator_pre_balance + amount
2019-03-18 18:51:52 +00:00
2019-06-06 21:30:40 +00:00
@with_all_phases
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_attestation(spec, state):
2019-04-20 05:17:33 +00:00
state.slot = spec.SLOTS_PER_EPOCH
yield 'pre', state
2019-05-30 20:57:18 +00:00
attestation = get_valid_attestation(spec, state, signed=True)
2019-03-18 18:51:52 +00:00
# Add to state via block transition
pre_current_attestations_len = len(state.current_epoch_attestations)
2019-05-30 20:57:18 +00:00
attestation_block = build_empty_block_for_next_slot(spec, state)
2019-03-18 18:51:52 +00:00
attestation_block.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
attestation_block.body.attestations.append(attestation)
2019-05-30 20:57:18 +00:00
sign_block(spec, state, attestation_block)
state_transition_and_sign_block(spec, state, attestation_block)
2019-03-18 18:51:52 +00:00
assert len(state.current_epoch_attestations) == pre_current_attestations_len + 1
2019-03-18 18:51:52 +00:00
# Epoch transition should move to previous_epoch_attestations
pre_current_attestations_root = spec.hash_tree_root(state.current_epoch_attestations)
2019-03-18 18:51:52 +00:00
2019-05-30 20:57:18 +00:00
epoch_block = build_empty_block_for_next_slot(spec, state)
2019-03-18 18:51:52 +00:00
epoch_block.slot += spec.SLOTS_PER_EPOCH
2019-05-30 20:57:18 +00:00
sign_block(spec, state, epoch_block)
state_transition_and_sign_block(spec, state, epoch_block)
yield 'blocks', [attestation_block, epoch_block]
yield 'post', state
2019-03-18 18:51:52 +00:00
assert len(state.current_epoch_attestations) == 0
assert spec.hash_tree_root(state.previous_epoch_attestations) == pre_current_attestations_root
2019-03-18 18:51:52 +00:00
2019-06-06 21:30:40 +00:00
@with_all_phases
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_voluntary_exit(spec, state):
validator_index = spec.get_active_validator_indices(
state,
2019-05-30 20:57:18 +00:00
spec.get_current_epoch(state)
)[-1]
2019-03-18 18:51:52 +00:00
# move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow for exit
state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
2019-03-18 18:51:52 +00:00
yield 'pre', state
2019-03-18 18:51:52 +00:00
2019-05-30 20:57:18 +00:00
voluntary_exit = spec.VoluntaryExit(
epoch=spec.get_current_epoch(state),
2019-03-18 18:51:52 +00:00
validator_index=validator_index,
)
2019-05-20 17:38:18 +00:00
voluntary_exit.signature = bls_sign(
2019-04-08 01:51:13 +00:00
message_hash=signing_root(voluntary_exit),
2019-03-18 18:51:52 +00:00
privkey=privkeys[validator_index],
2019-05-30 20:57:18 +00:00
domain=spec.get_domain(
state=state,
2019-03-18 18:51:52 +00:00
domain_type=spec.DOMAIN_VOLUNTARY_EXIT,
)
)
# Add to state via block transition
2019-05-30 20:57:18 +00:00
initiate_exit_block = build_empty_block_for_next_slot(spec, state)
2019-03-18 18:51:52 +00:00
initiate_exit_block.body.voluntary_exits.append(voluntary_exit)
2019-05-30 20:57:18 +00:00
sign_block(spec, state, initiate_exit_block)
state_transition_and_sign_block(spec, state, initiate_exit_block)
2019-03-18 18:51:52 +00:00
2019-06-09 19:41:21 +00:00
assert state.validators[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH
2019-03-18 18:51:52 +00:00
# Process within epoch transition
2019-05-30 20:57:18 +00:00
exit_block = build_empty_block_for_next_slot(spec, state)
2019-03-18 18:51:52 +00:00
exit_block.slot += spec.SLOTS_PER_EPOCH
2019-05-30 20:57:18 +00:00
sign_block(spec, state, exit_block)
state_transition_and_sign_block(spec, state, exit_block)
2019-03-18 18:51:52 +00:00
yield 'blocks', [initiate_exit_block, exit_block]
yield 'post', state
2019-03-18 18:51:52 +00:00
2019-06-09 19:41:21 +00:00
assert state.validators[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH
2019-03-18 18:51:52 +00:00
2019-06-06 21:30:40 +00:00
@with_all_phases
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_balance_driven_status_transitions(spec, state):
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[-1]
2019-03-18 18:51:52 +00:00
2019-06-09 19:41:21 +00:00
assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH
2019-03-18 18:51:52 +00:00
# set validator balance to below ejection threshold
2019-06-09 19:41:21 +00:00
state.validators[validator_index].effective_balance = spec.EJECTION_BALANCE
2019-03-18 18:51:52 +00:00
yield 'pre', state
2019-03-18 18:51:52 +00:00
# trigger epoch transition
2019-05-30 20:57:18 +00:00
block = build_empty_block_for_next_slot(spec, state)
2019-03-18 18:51:52 +00:00
block.slot += spec.SLOTS_PER_EPOCH
2019-05-30 20:57:18 +00:00
sign_block(spec, state, block)
state_transition_and_sign_block(spec, state, block)
2019-03-18 18:51:52 +00:00
yield 'blocks', [block]
yield 'post', state
2019-03-18 18:51:52 +00:00
2019-06-09 19:41:21 +00:00
assert state.validators[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH
2019-03-18 18:51:52 +00:00
2019-06-06 21:30:40 +00:00
@with_all_phases
@spec_state_test
2019-05-30 20:57:18 +00:00
def test_historical_batch(spec, state):
state.slot += spec.SLOTS_PER_HISTORICAL_ROOT - (state.slot % spec.SLOTS_PER_HISTORICAL_ROOT) - 1
pre_historical_roots_len = len(state.historical_roots)
2019-03-18 18:51:52 +00:00
yield 'pre', state
2019-03-18 18:51:52 +00:00
2019-05-30 20:57:18 +00:00
block = build_empty_block_for_next_slot(spec, state, signed=True)
2019-06-21 23:46:26 +00:00
sign_block(spec, state, block)
state_transition_and_sign_block(spec, state, block)
2019-03-18 18:51:52 +00:00
yield 'blocks', [block]
yield 'post', state
2019-03-18 18:51:52 +00:00
assert state.slot == block.slot
2019-05-30 20:57:18 +00:00
assert spec.get_current_epoch(state) % (spec.SLOTS_PER_HISTORICAL_ROOT // spec.SLOTS_PER_EPOCH) == 0
assert len(state.historical_roots) == pre_historical_roots_len + 1
2019-06-26 20:11:40 +00:00
@with_all_phases
@spec_state_test
2019-06-21 23:23:37 +00:00
def test_eth1_data_votes_consensus(spec, state):
2019-06-26 20:11:40 +00:00
# Don't run when it will take very, very long to simulate. Minimal configuration suffices.
if spec.SLOTS_PER_ETH1_VOTING_PERIOD > 16:
return
2019-06-04 14:14:14 +00:00
2019-06-26 20:11:40 +00:00
offset_block = build_empty_block(spec, state, slot=spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1)
2019-06-21 23:46:26 +00:00
sign_block(spec, state, offset_block)
2019-06-26 20:11:40 +00:00
state_transition_and_sign_block(spec, state, offset_block)
yield 'pre', state
2019-06-04 14:14:14 +00:00
2019-06-26 20:11:40 +00:00
a = b'\xaa' * 32
b = b'\xbb' * 32
c = b'\xcc' * 32
2019-06-04 14:14:14 +00:00
2019-06-26 20:11:40 +00:00
blocks = []
2019-06-04 14:14:14 +00:00
2019-06-26 20:11:40 +00:00
for i in range(0, spec.SLOTS_PER_ETH1_VOTING_PERIOD):
block = build_empty_block_for_next_slot(spec, state)
# wait for over 50% for A, then start voting B
block.body.eth1_data.block_hash = b if i * 2 > spec.SLOTS_PER_ETH1_VOTING_PERIOD else a
2019-06-21 23:46:26 +00:00
sign_block(spec, state, block)
2019-06-26 20:11:40 +00:00
state_transition_and_sign_block(spec, state, block)
blocks.append(block)
2019-06-04 14:14:14 +00:00
2019-06-26 20:11:40 +00:00
assert len(state.eth1_data_votes) == spec.SLOTS_PER_ETH1_VOTING_PERIOD
assert state.eth1_data.block_hash == a
# transition to next eth1 voting period
block = build_empty_block_for_next_slot(spec, state)
block.body.eth1_data.block_hash = c
2019-06-21 23:46:26 +00:00
sign_block(spec, state, block)
2019-06-26 20:11:40 +00:00
state_transition_and_sign_block(spec, state, block)
blocks.append(block)
yield 'blocks', blocks
yield 'post', state
2019-06-04 14:14:14 +00:00
2019-06-26 20:11:40 +00:00
assert state.eth1_data.block_hash == a
assert state.slot % spec.SLOTS_PER_ETH1_VOTING_PERIOD == 0
assert len(state.eth1_data_votes) == 1
assert state.eth1_data_votes[0].block_hash == c
2019-06-21 23:23:37 +00:00
@with_all_phases
@spec_state_test
def test_eth1_data_votes_no_consensus(spec, state):
# Don't run when it will take very, very long to simulate. Minimal configuration suffices.
if spec.SLOTS_PER_ETH1_VOTING_PERIOD > 16:
return
pre_eth1_hash = state.eth1_data.block_hash
2019-06-21 23:23:37 +00:00
offset_block = build_empty_block(spec, state, slot=spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1)
2019-06-21 23:46:26 +00:00
sign_block(spec, state, offset_block)
2019-06-21 23:23:37 +00:00
state_transition_and_sign_block(spec, state, offset_block)
yield 'pre', state
a = b'\xaa' * 32
b = b'\xbb' * 32
blocks = []
for i in range(0, spec.SLOTS_PER_ETH1_VOTING_PERIOD):
block = build_empty_block_for_next_slot(spec, state)
# wait for precisely 50% for A, then start voting B for other 50%
block.body.eth1_data.block_hash = b if i * 2 >= spec.SLOTS_PER_ETH1_VOTING_PERIOD else a
2019-06-21 23:46:26 +00:00
sign_block(spec, state, block)
2019-06-21 23:23:37 +00:00
state_transition_and_sign_block(spec, state, block)
blocks.append(block)
assert len(state.eth1_data_votes) == spec.SLOTS_PER_ETH1_VOTING_PERIOD
assert state.eth1_data.block_hash == pre_eth1_hash
2019-06-21 23:23:37 +00:00
yield 'blocks', blocks
yield 'post', state