update registry tests to return the blocks that transiiton the pre_state to post_state
This commit is contained in:
parent
70cd3d2253
commit
f76ade93d8
|
@ -224,7 +224,7 @@ Up to `MAX_ATTESTATIONS` aggregate attestations can be included in the `block`.
|
||||||
|
|
||||||
##### Deposits
|
##### Deposits
|
||||||
|
|
||||||
If there are any unprocessed deposits for the existing `state.latest_eth1_data` (i.e. `state.latest_eth1_data.deposit_count > state.deposit_index`), then pending deposits _must_ be added to the block. The expected number of deposits is exactly `min(MAX_DEPOSITS, latest_eth1_data.deposit_count - state.deposit_index)`. These [`deposits`](../core/0_beacon-chain.md#deposit) are constructed from the `Deposit` logs from the [Eth1.0 deposit contract](../core/0_deposit-contract.md) and must be processed in sequential order. The deposits included in the `block` must satisfy the verification conditions found in [deposits processing](../core/0_beacon-chain.md#deposits).
|
If there are any unprocessed deposits for the existing `state.latest_eth1_data` (i.e. `state.latest_eth1_data.deposit_count > state.deposit_index`), then pending deposits _must_ be added to the block. The expected number of deposits is exactly `min(MAX_DEPOSITS, latest_eth1_data.deposit_count - state.deposit_index)`. These [`deposits`](../core/0_beacon-chain.md#deposit) are constructed from the `Deposit` logs from the [Eth1.0 deposit contract](../core/0_deposit-contract) and must be processed in sequential order. The deposits included in the `block` must satisfy the verification conditions found in [deposits processing](../core/0_beacon-chain.md#deposits).
|
||||||
|
|
||||||
The `proof` for each deposit must be constructed against the deposit root contained in `state.latest_eth1_data` rather than the deposit root at the time the deposit was initially logged from the 1.0 chain. This entails storing a full deposit merkle tree locally and computing updated proofs against the `latest_eth1_data.deposit_root` as needed. See [`minimal_merkle.py`](https://github.com/ethereum/research/blob/master/spec_pythonizer/utils/merkle_minimal.py) for a sample implementation.
|
The `proof` for each deposit must be constructed against the deposit root contained in `state.latest_eth1_data` rather than the deposit root at the time the deposit was initially logged from the 1.0 chain. This entails storing a full deposit merkle tree locally and computing updated proofs against the `latest_eth1_data.deposit_root` as needed. See [`minimal_merkle.py`](https://github.com/ethereum/research/blob/master/spec_pythonizer/utils/merkle_minimal.py) for a sample implementation.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
import eth2spec.phase0.spec as spec
|
import eth2spec.phase0.spec as spec
|
||||||
|
|
||||||
from eth2spec.phase0.spec import (
|
from eth2spec.phase0.spec import (
|
||||||
|
@ -10,6 +12,9 @@ from tests.helpers import (
|
||||||
next_epoch,
|
next_epoch,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# mark entire file as 'state'
|
||||||
|
pytestmark = pytest.mark.state
|
||||||
|
|
||||||
|
|
||||||
def test_activation(state):
|
def test_activation(state):
|
||||||
index = 0
|
index = 0
|
||||||
|
@ -23,8 +28,10 @@ def test_activation(state):
|
||||||
|
|
||||||
pre_state = deepcopy(state)
|
pre_state = deepcopy(state)
|
||||||
|
|
||||||
|
blocks = []
|
||||||
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1):
|
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1):
|
||||||
next_epoch(state)
|
block = next_epoch(state)
|
||||||
|
blocks.append(block)
|
||||||
|
|
||||||
assert state.validator_registry[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH
|
assert state.validator_registry[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
assert state.validator_registry[index].activation_epoch != spec.FAR_FUTURE_EPOCH
|
assert state.validator_registry[index].activation_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
|
@ -33,7 +40,7 @@ def test_activation(state):
|
||||||
get_current_epoch(state),
|
get_current_epoch(state),
|
||||||
)
|
)
|
||||||
|
|
||||||
return pre_state, state
|
return pre_state, blocks, state
|
||||||
|
|
||||||
|
|
||||||
def test_ejection(state):
|
def test_ejection(state):
|
||||||
|
@ -46,8 +53,10 @@ def test_ejection(state):
|
||||||
|
|
||||||
pre_state = deepcopy(state)
|
pre_state = deepcopy(state)
|
||||||
|
|
||||||
|
blocks = []
|
||||||
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1):
|
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1):
|
||||||
next_epoch(state)
|
block = next_epoch(state)
|
||||||
|
blocks.append(block)
|
||||||
|
|
||||||
assert state.validator_registry[index].exit_epoch != spec.FAR_FUTURE_EPOCH
|
assert state.validator_registry[index].exit_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
assert not is_active_validator(
|
assert not is_active_validator(
|
||||||
|
@ -55,4 +64,4 @@ def test_ejection(state):
|
||||||
get_current_epoch(state),
|
get_current_epoch(state),
|
||||||
)
|
)
|
||||||
|
|
||||||
return pre_state, state
|
return pre_state, blocks, state
|
||||||
|
|
|
@ -402,11 +402,21 @@ def add_attestation_to_state(state, attestation, slot):
|
||||||
|
|
||||||
|
|
||||||
def next_slot(state):
|
def next_slot(state):
|
||||||
|
"""
|
||||||
|
Transition to the next slot via an empty block.
|
||||||
|
Return the empty block that triggered the transition.
|
||||||
|
"""
|
||||||
block = build_empty_block_for_next_slot(state)
|
block = build_empty_block_for_next_slot(state)
|
||||||
state_transition(state, block)
|
state_transition(state, block)
|
||||||
|
return block
|
||||||
|
|
||||||
|
|
||||||
def next_epoch(state):
|
def next_epoch(state):
|
||||||
|
"""
|
||||||
|
Transition to the start slot of the next epoch via an empty block.
|
||||||
|
Return the empty block that triggered the transition.
|
||||||
|
"""
|
||||||
block = build_empty_block_for_next_slot(state)
|
block = build_empty_block_for_next_slot(state)
|
||||||
block.slot += spec.SLOTS_PER_EPOCH - (state.slot % spec.SLOTS_PER_EPOCH)
|
block.slot += spec.SLOTS_PER_EPOCH - (state.slot % spec.SLOTS_PER_EPOCH)
|
||||||
state_transition(state, block)
|
state_transition(state, block)
|
||||||
|
return block
|
||||||
|
|
Loading…
Reference in New Issue