|
|
|
|
@@ -4,7 +4,7 @@ from typing import List
|
|
|
|
|
from eth2spec.utils.ssz.ssz_impl import signing_root
|
|
|
|
|
from eth2spec.utils.bls import bls_sign
|
|
|
|
|
|
|
|
|
|
from eth2spec.test.helpers.state import get_balance
|
|
|
|
|
from eth2spec.test.helpers.state import get_balance, state_transition_and_sign_block
|
|
|
|
|
# from eth2spec.test.helpers.transfers import get_valid_transfer
|
|
|
|
|
from eth2spec.test.helpers.block import build_empty_block_for_next_slot, sign_block
|
|
|
|
|
from eth2spec.test.helpers.keys import privkeys, pubkeys
|
|
|
|
|
@@ -16,6 +16,7 @@ from eth2spec.test.helpers.deposits import prepare_state_and_deposit
|
|
|
|
|
from eth2spec.test.context import spec_state_test, with_all_phases
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@with_all_phases
|
|
|
|
|
@spec_state_test
|
|
|
|
|
def test_empty_block_transition(spec, state):
|
|
|
|
|
@@ -25,9 +26,10 @@ def test_empty_block_transition(spec, state):
|
|
|
|
|
yield 'pre', state
|
|
|
|
|
|
|
|
|
|
block = build_empty_block_for_next_slot(spec, state, signed=True)
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
|
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
|
|
|
|
|
assert len(state.eth1_data_votes) == pre_eth1_votes + 1
|
|
|
|
|
@@ -44,9 +46,10 @@ def test_skipped_slots(spec, state):
|
|
|
|
|
block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
block.slot += 3
|
|
|
|
|
sign_block(spec, state, block)
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
|
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
|
|
|
|
|
assert state.slot == block.slot
|
|
|
|
|
@@ -64,9 +67,10 @@ def test_empty_epoch_transition(spec, state):
|
|
|
|
|
block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
block.slot += spec.SLOTS_PER_EPOCH
|
|
|
|
|
sign_block(spec, state, block)
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
|
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
|
|
|
|
|
assert state.slot == block.slot
|
|
|
|
|
@@ -84,9 +88,10 @@ def test_empty_epoch_transition(spec, state):
|
|
|
|
|
# block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
# block.slot += spec.SLOTS_PER_EPOCH * 5
|
|
|
|
|
# sign_block(spec, state, block, proposer_index=0)
|
|
|
|
|
# yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
|
|
|
|
|
# spec.state_transition(state, block)
|
|
|
|
|
# state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
# yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
# yield 'post', state
|
|
|
|
|
|
|
|
|
|
# assert state.slot == block.slot
|
|
|
|
|
@@ -113,9 +118,10 @@ def test_proposer_slashing(spec, state):
|
|
|
|
|
block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
block.body.proposer_slashings.append(proposer_slashing)
|
|
|
|
|
sign_block(spec, state, block)
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
|
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
|
|
|
|
|
# check if slashed
|
|
|
|
|
@@ -147,9 +153,10 @@ def test_attester_slashing(spec, state):
|
|
|
|
|
block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
block.body.attester_slashings.append(attester_slashing)
|
|
|
|
|
sign_block(spec, state, block)
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
|
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
|
|
|
|
|
slashed_validator = state.validator_registry[validator_index]
|
|
|
|
|
@@ -185,9 +192,9 @@ def test_deposit_in_block(spec, state):
|
|
|
|
|
block.body.deposits.append(deposit)
|
|
|
|
|
sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
|
|
|
|
|
assert len(state.validator_registry) == initial_registry_len + 1
|
|
|
|
|
@@ -213,9 +220,9 @@ def test_deposit_top_up(spec, state):
|
|
|
|
|
block.body.deposits.append(deposit)
|
|
|
|
|
sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
|
|
|
|
|
assert len(state.validator_registry) == initial_registry_len
|
|
|
|
|
@@ -238,7 +245,7 @@ def test_attestation(spec, state):
|
|
|
|
|
attestation_block.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
|
|
|
|
|
attestation_block.body.attestations.append(attestation)
|
|
|
|
|
sign_block(spec, state, attestation_block)
|
|
|
|
|
spec.state_transition(state, attestation_block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, attestation_block)
|
|
|
|
|
|
|
|
|
|
assert len(state.current_epoch_attestations) == pre_current_attestations_len + 1
|
|
|
|
|
|
|
|
|
|
@@ -248,7 +255,8 @@ def test_attestation(spec, state):
|
|
|
|
|
epoch_block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
epoch_block.slot += spec.SLOTS_PER_EPOCH
|
|
|
|
|
sign_block(spec, state, epoch_block)
|
|
|
|
|
spec.state_transition(state, epoch_block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, epoch_block)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [attestation_block, epoch_block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
@@ -287,7 +295,7 @@ def test_voluntary_exit(spec, state):
|
|
|
|
|
initiate_exit_block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
initiate_exit_block.body.voluntary_exits.append(voluntary_exit)
|
|
|
|
|
sign_block(spec, state, initiate_exit_block)
|
|
|
|
|
spec.state_transition(state, initiate_exit_block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, initiate_exit_block)
|
|
|
|
|
|
|
|
|
|
assert state.validator_registry[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH
|
|
|
|
|
|
|
|
|
|
@@ -295,7 +303,7 @@ def test_voluntary_exit(spec, state):
|
|
|
|
|
exit_block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
exit_block.slot += spec.SLOTS_PER_EPOCH
|
|
|
|
|
sign_block(spec, state, exit_block)
|
|
|
|
|
spec.state_transition(state, exit_block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, exit_block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [initiate_exit_block, exit_block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
@@ -326,9 +334,9 @@ def test_voluntary_exit(spec, state):
|
|
|
|
|
# block.body.transfers.append(transfer)
|
|
|
|
|
# sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
# yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
# state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
# spec.state_transition(state, block)
|
|
|
|
|
# yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
# yield 'post', state
|
|
|
|
|
|
|
|
|
|
# sender_balance = get_balance(state, sender_index)
|
|
|
|
|
@@ -354,7 +362,7 @@ def test_balance_driven_status_transitions(spec, state):
|
|
|
|
|
block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
block.slot += spec.SLOTS_PER_EPOCH
|
|
|
|
|
sign_block(spec, state, block)
|
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
@@ -371,7 +379,7 @@ def test_historical_batch(spec, state):
|
|
|
|
|
yield 'pre', state
|
|
|
|
|
|
|
|
|
|
block = build_empty_block_for_next_slot(spec, state, signed=True)
|
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
|
state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
yield 'post', state
|
|
|
|
|
@@ -392,7 +400,7 @@ def test_historical_batch(spec, state):
|
|
|
|
|
# blocks = []
|
|
|
|
|
# for _ in range(spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1):
|
|
|
|
|
# block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
# spec.state_transition(state, block)
|
|
|
|
|
# state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
# expected_votes += 1
|
|
|
|
|
# assert len(state.eth1_data_votes) == expected_votes
|
|
|
|
|
# blocks.append(block)
|
|
|
|
|
@@ -400,7 +408,7 @@ def test_historical_batch(spec, state):
|
|
|
|
|
# block = build_empty_block_for_next_slot(spec, state)
|
|
|
|
|
# blocks.append(block)
|
|
|
|
|
|
|
|
|
|
# spec.state_transition(state, block)
|
|
|
|
|
# state_transition_and_sign_block(spec, state, block)
|
|
|
|
|
|
|
|
|
|
# yield 'blocks', [block], List[spec.BeaconBlock]
|
|
|
|
|
# yield 'post', state
|
|
|
|
|
|