Skip to content

Commit ba8c092

Browse files
committed
Add more checks to electra fork transition tests
1 parent 96b1d31 commit ba8c092

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

specs/electra/fork.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ an irregular state change is made to upgrade to Electra.
7272
```python
7373
def upgrade_to_electra(pre: deneb.BeaconState) -> BeaconState:
7474
epoch = deneb.get_current_epoch(pre)
75-
latest_execution_payload_header = pre.latest_execution_payload_header
7675

7776
exit_epochs = [v.exit_epoch for v in pre.validators if v.exit_epoch != FAR_FUTURE_EPOCH]
7877
if not exit_epochs:
@@ -119,7 +118,7 @@ def upgrade_to_electra(pre: deneb.BeaconState) -> BeaconState:
119118
current_sync_committee=pre.current_sync_committee,
120119
next_sync_committee=pre.next_sync_committee,
121120
# Execution-layer
122-
latest_execution_payload_header=latest_execution_payload_header, # [Modified in Electra:EIP6110:EIP7002]
121+
latest_execution_payload_header=pre.latest_execution_payload_header,
123122
# Withdrawals
124123
next_withdrawal_index=pre.next_withdrawal_index,
125124
next_withdrawal_validator_index=pre.next_withdrawal_validator_index,

tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,41 @@ def test_fork_random_large_validator_set(spec, phases, state):
8787
@with_state
8888
@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS)
8989
def test_fork_pre_activation(spec, phases, state):
90+
index = 0
9091
post_spec = phases[ELECTRA]
91-
state.validators[0].activation_epoch = spec.FAR_FUTURE_EPOCH
92+
state.validators[index].activation_epoch = spec.FAR_FUTURE_EPOCH
9293
post_state = yield from run_fork_test(post_spec, state)
9394

94-
assert len(post_state.pending_deposits) > 0
95+
validator = post_state.validators[index]
96+
assert post_state.balances[index] == 0
97+
assert validator.effective_balance == 0
98+
assert validator.activation_eligibility_epoch == spec.FAR_FUTURE_EPOCH
99+
assert post_state.pending_deposits == [post_spec.PendingDeposit(
100+
pubkey=validator.pubkey,
101+
withdrawal_credentials=validator.withdrawal_credentials,
102+
amount=state.balances[index],
103+
signature=spec.bls.G2_POINT_AT_INFINITY,
104+
slot=spec.GENESIS_SLOT,
105+
)]
95106

96107

97108
@with_phases(phases=[DENEB], other_phases=[ELECTRA])
98109
@spec_test
99110
@with_state
100111
@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS)
101112
def test_fork_has_compounding_withdrawal_credential(spec, phases, state):
113+
index = 0
102114
post_spec = phases[ELECTRA]
103-
validator = state.validators[0]
104-
state.balances[0] = post_spec.MIN_ACTIVATION_BALANCE + 1
115+
validator = state.validators[index]
116+
state.balances[index] = post_spec.MIN_ACTIVATION_BALANCE + 1
105117
validator.withdrawal_credentials = post_spec.COMPOUNDING_WITHDRAWAL_PREFIX + validator.withdrawal_credentials[1:]
106118
post_state = yield from run_fork_test(post_spec, state)
107119

108-
assert len(post_state.pending_deposits) > 0
120+
assert post_state.balances[index] == post_spec.MIN_ACTIVATION_BALANCE
121+
assert post_state.pending_deposits == [post_spec.PendingDeposit(
122+
pubkey=validator.pubkey,
123+
withdrawal_credentials=validator.withdrawal_credentials,
124+
amount=state.balances[index] - post_spec.MIN_ACTIVATION_BALANCE,
125+
signature=spec.bls.G2_POINT_AT_INFINITY,
126+
slot=spec.GENESIS_SLOT,
127+
)]

tests/core/pyspec/eth2spec/test/helpers/electra/fork.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_fork_test(post_spec, pre_state):
5454
stable_validator_fields = [
5555
'pubkey', 'withdrawal_credentials',
5656
'slashed',
57-
'exit_epoch', 'withdrawable_epoch',
57+
'activation_epoch', 'exit_epoch', 'withdrawable_epoch',
5858
]
5959
for field in stable_validator_fields:
6060
assert getattr(pre_validator, field) == getattr(post_validator, field)

0 commit comments

Comments
 (0)