mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-20 15:38:55 +00:00
fix fully withdrawal tests
This commit is contained in:
parent
d513f5cf17
commit
f5dab5b666
@ -117,9 +117,9 @@ class ExecutionPayload(Container):
|
||||
parent_hash: Hash32
|
||||
fee_recipient: ExecutionAddress # 'beneficiary' in the yellow paper
|
||||
state_root: Bytes32
|
||||
receipt_root: Bytes32 # 'receipts root' in the yellow paper
|
||||
receipts_root: Bytes32
|
||||
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
|
||||
random: Bytes32 # 'difficulty' in the yellow paper
|
||||
prev_randao: Bytes32 # 'difficulty' in the yellow paper
|
||||
block_number: uint64 # 'number' in the yellow paper
|
||||
gas_limit: uint64
|
||||
gas_used: uint64
|
||||
@ -140,9 +140,9 @@ class ExecutionPayloadHeader(Container):
|
||||
parent_hash: Hash32
|
||||
fee_recipient: ExecutionAddress
|
||||
state_root: Bytes32
|
||||
receipt_root: Bytes32
|
||||
receipts_root: Bytes32
|
||||
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
|
||||
random: Bytes32
|
||||
prev_randao: Bytes32
|
||||
block_number: uint64
|
||||
gas_limit: uint64
|
||||
gas_used: uint64
|
||||
@ -165,7 +165,7 @@ followed by an SSZ encoding of the `WithdrawalTransaction` container comprising
|
||||
```python
|
||||
class WithdrawalTransaction(Container):
|
||||
address: ExecutionAddress
|
||||
value: Gwei
|
||||
amount: Gwei
|
||||
```
|
||||
|
||||
## Helpers
|
||||
@ -188,12 +188,12 @@ def withdraw(state: BeaconState, index: ValidatorIndex, amount: Gwei) -> None:
|
||||
|
||||
### Predicates
|
||||
|
||||
#### `is_withdrawable_validator`
|
||||
#### `is_fully_withdrawable_validator`
|
||||
|
||||
```python
|
||||
def is_withdrawable_validator(validator: Validator, epoch: Epoch) -> bool:
|
||||
def is_fully_withdrawable_validator(validator: Validator, epoch: Epoch) -> bool:
|
||||
"""
|
||||
Check if ``validator`` is withdrawable.
|
||||
Check if ``validator`` is fully withdrawable.
|
||||
"""
|
||||
is_eth1_withdrawal_prefix = validator.withdrawal_credentials[0:1] == ETH1_ADDRESS_WITHDRAWAL_PREFIX
|
||||
return is_eth1_withdrawal_prefix and validator.withdrawable_epoch <= epoch < validator.withdrawn_epoch
|
||||
@ -228,7 +228,7 @@ def process_epoch(state: BeaconState) -> None:
|
||||
def process_full_withdrawals(state: BeaconState) -> None:
|
||||
current_epoch = get_current_epoch(state)
|
||||
for index, validator in enumerate(state.validators):
|
||||
if is_withdrawable_validator(validator, current_epoch):
|
||||
if is_fully_withdrawable_validator(validator, current_epoch):
|
||||
# TODO, consider the zero-balance case
|
||||
withdraw(state, ValidatorIndex(index), state.balances[index])
|
||||
validator.withdrawn_epoch = current_epoch
|
||||
@ -297,6 +297,6 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe
|
||||
base_fee_per_gas=payload.base_fee_per_gas,
|
||||
block_hash=payload.block_hash,
|
||||
transactions_root=hash_tree_root(payload.transactions),
|
||||
withdrawal_transactions=hash_tree_root(payload.withdrawal_transactions),
|
||||
withdrawal_transactions_root=hash_tree_root(payload.withdrawal_transactions),
|
||||
)
|
||||
```
|
||||
|
@ -13,31 +13,34 @@ def set_validator_withdrawable(spec, state, index, withdrawable_epoch=None):
|
||||
validator.withdrawable_epoch = withdrawable_epoch
|
||||
validator.withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + validator.withdrawal_credentials[1:]
|
||||
|
||||
assert spec.is_withdrawable_validator(validator, withdrawable_epoch)
|
||||
assert spec.is_fully_withdrawable_validator(validator, withdrawable_epoch)
|
||||
|
||||
|
||||
def run_process_withdrawals(spec, state, num_expected_withdrawals=None):
|
||||
def run_process_full_withdrawals(spec, state, num_expected_withdrawals=None):
|
||||
pre_withdrawal_receipts = state.withdrawal_receipts
|
||||
to_be_withdrawn_indices = [
|
||||
index for index, validator in enumerate(state.validators)
|
||||
if spec.is_withdrawable_validator(validator, spec.get_current_epoch(state))
|
||||
if spec.is_fully_withdrawable_validator(validator, spec.get_current_epoch(state))
|
||||
]
|
||||
|
||||
if num_expected_withdrawals is not None:
|
||||
assert len(to_be_withdrawn_indices) == num_expected_withdrawals
|
||||
|
||||
yield from run_epoch_processing_with(spec, state, 'process_withdrawals')
|
||||
yield from run_epoch_processing_with(spec, state, 'process_full_withdrawals')
|
||||
|
||||
for index in to_be_withdrawn_indices:
|
||||
validator = state.validators[index]
|
||||
assert validator.withdrawn_epoch == spec.get_current_epoch(state)
|
||||
assert state.balances[index] == 0
|
||||
|
||||
assert len(state.withdrawal_receipts) == len(pre_withdrawal_receipts) + num_expected_withdrawals
|
||||
|
||||
|
||||
@with_capella_and_later
|
||||
@spec_state_test
|
||||
def test_no_withdrawals(spec, state):
|
||||
pre_validators = state.validators.copy()
|
||||
yield from run_process_withdrawals(spec, state, 0)
|
||||
yield from run_process_full_withdrawals(spec, state, 0)
|
||||
|
||||
assert pre_validators == state.validators
|
||||
|
||||
@ -51,7 +54,7 @@ def test_no_withdrawals_but_some_next_epoch(spec, state):
|
||||
for index in range(3):
|
||||
set_validator_withdrawable(spec, state, index, current_epoch + 1)
|
||||
|
||||
yield from run_process_withdrawals(spec, state, 0)
|
||||
yield from run_process_full_withdrawals(spec, state, 0)
|
||||
|
||||
|
||||
@with_capella_and_later
|
||||
@ -60,7 +63,7 @@ def test_single_withdrawal(spec, state):
|
||||
# Make one validator withdrawable
|
||||
set_validator_withdrawable(spec, state, 0)
|
||||
|
||||
yield from run_process_withdrawals(spec, state, 1)
|
||||
yield from run_process_full_withdrawals(spec, state, 1)
|
||||
|
||||
|
||||
@with_capella_and_later
|
||||
@ -70,7 +73,7 @@ def test_multi_withdrawal(spec, state):
|
||||
for index in range(3):
|
||||
set_validator_withdrawable(spec, state, index)
|
||||
|
||||
yield from run_process_withdrawals(spec, state, 3)
|
||||
yield from run_process_full_withdrawals(spec, state, 3)
|
||||
|
||||
|
||||
@with_capella_and_later
|
||||
@ -80,4 +83,4 @@ def test_all_withdrawal(spec, state):
|
||||
for index in range(len(state.validators)):
|
||||
set_validator_withdrawable(spec, state, index)
|
||||
|
||||
yield from run_process_withdrawals(spec, state, len(state.validators))
|
||||
yield from run_process_full_withdrawals(spec, state, len(state.validators))
|
Loading…
x
Reference in New Issue
Block a user