Eth1 data test
This commit is contained in:
parent
d587c4fe61
commit
b133dedeaf
|
@ -5,7 +5,7 @@ from eth2spec.utils.bls import bls_sign
|
||||||
|
|
||||||
from eth2spec.test.helpers.state import get_balance, state_transition_and_sign_block
|
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.transfers import get_valid_transfer
|
||||||
from eth2spec.test.helpers.block import build_empty_block_for_next_slot, sign_block
|
from eth2spec.test.helpers.block import build_empty_block_for_next_slot, build_empty_block, sign_block
|
||||||
from eth2spec.test.helpers.keys import privkeys, pubkeys
|
from eth2spec.test.helpers.keys import privkeys, pubkeys
|
||||||
from eth2spec.test.helpers.attester_slashings import get_valid_attester_slashing
|
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.proposer_slashings import get_valid_proposer_slashing
|
||||||
|
@ -172,8 +172,6 @@ def test_attester_slashing(spec, state):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO update functions below to be like above, i.e. with @spec_state_test and yielding data to put into the test vector
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_deposit_in_block(spec, state):
|
def test_deposit_in_block(spec, state):
|
||||||
|
@ -386,29 +384,43 @@ def test_historical_batch(spec, state):
|
||||||
assert len(state.historical_roots) == pre_historical_roots_len + 1
|
assert len(state.historical_roots) == pre_historical_roots_len + 1
|
||||||
|
|
||||||
|
|
||||||
# @with_all_phases
|
@with_all_phases
|
||||||
# @spec_state_test
|
@spec_state_test
|
||||||
# def test_eth1_data_votes(spec, state):
|
def test_eth1_data_votes_success(spec, state):
|
||||||
# yield 'pre', 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
|
||||||
|
|
||||||
# expected_votes = 0
|
offset_block = build_empty_block(spec, state, slot=spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1)
|
||||||
# assert len(state.eth1_data_votes) == expected_votes
|
state_transition_and_sign_block(spec, state, offset_block)
|
||||||
|
yield 'pre', state
|
||||||
|
|
||||||
# blocks = []
|
a = b'\xaa' * 32
|
||||||
# for _ in range(spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1):
|
b = b'\xbb' * 32
|
||||||
# block = build_empty_block_for_next_slot(spec, state)
|
c = b'\xcc' * 32
|
||||||
# state_transition_and_sign_block(spec, state, block)
|
|
||||||
# expected_votes += 1
|
|
||||||
# assert len(state.eth1_data_votes) == expected_votes
|
|
||||||
# blocks.append(block)
|
|
||||||
|
|
||||||
# block = build_empty_block_for_next_slot(spec, state)
|
blocks = []
|
||||||
# blocks.append(block)
|
|
||||||
|
|
||||||
# state_transition_and_sign_block(spec, state, block)
|
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
|
||||||
|
state_transition_and_sign_block(spec, state, block)
|
||||||
|
blocks.append(block)
|
||||||
|
|
||||||
# yield 'blocks', [block]
|
assert len(state.eth1_data_votes) == spec.SLOTS_PER_ETH1_VOTING_PERIOD
|
||||||
# yield 'post', state
|
assert state.eth1_data.block_hash == a
|
||||||
|
|
||||||
# assert state.slot % spec.SLOTS_PER_ETH1_VOTING_PERIOD == 0
|
# transition to next eth1 voting period
|
||||||
# assert len(state.eth1_data_votes) == 1
|
block = build_empty_block_for_next_slot(spec, state)
|
||||||
|
block.body.eth1_data.block_hash = c
|
||||||
|
state_transition_and_sign_block(spec, state, block)
|
||||||
|
blocks.append(block)
|
||||||
|
|
||||||
|
yield 'blocks', blocks
|
||||||
|
yield 'post', state
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue