Skip to content

Commit 112924c

Browse files
committed
fix EIP-7251 tests
1 parent 4f6a623 commit 112924c

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

tests/core/pyspec/eth2spec/test/eip7251/block_processing/test_process_consolidation.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,12 @@ def test_basic_consolidation_with_compounding_credential(spec, state):
106106
def test_consolidation_churn_limit_balance(spec, state):
107107
# This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn
108108
consolidation_churn_limit = spec.get_consolidation_churn_limit(state)
109-
# Set the consolidation balance to consume equal to churn limit
110-
state.consolidation_balance_to_consume = consolidation_churn_limit
111109
current_epoch = spec.get_current_epoch(state)
112110

113111
source_index = spec.get_active_validator_indices(state, current_epoch)[0]
114-
# Set source balance to consolidation churn limit
115-
state.balances[source_index] = consolidation_churn_limit
112+
source_validator = state.validators[source_index]
113+
source_validator.effective_balance = consolidation_churn_limit
114+
updated_consolidation_churn_limit = spec.get_consolidation_churn_limit(state)
116115
target_index = spec.get_active_validator_indices(state, current_epoch)[1]
117116
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
118117
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
@@ -131,7 +130,7 @@ def test_consolidation_churn_limit_balance(spec, state):
131130

132131
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
133132
# Check consolidation churn is decremented correctly
134-
assert state.consolidation_balance_to_consume == 0
133+
assert state.consolidation_balance_to_consume == updated_consolidation_churn_limit - consolidation_churn_limit
135134
# Check exit epoch
136135
assert state.validators[0].exit_epoch == expected_exit_epoch
137136

@@ -145,13 +144,11 @@ def test_consolidation_churn_limit_balance(spec, state):
145144
def test_consolidation_balance_larger_than_churn_limit(spec, state):
146145
# This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn
147146
consolidation_churn_limit = spec.get_consolidation_churn_limit(state)
148-
# Set the consolidation balance to consume equal to churn limit
149-
state.consolidation_balance_to_consume = consolidation_churn_limit
150147
current_epoch = spec.get_current_epoch(state)
151148

152149
source_index = spec.get_active_validator_indices(state, current_epoch)[0]
153150
# Set source balance higher than consolidation churn limit
154-
state.balances[source_index] = consolidation_churn_limit + 1
151+
state.validators[source_index].effective_balance = 2 * consolidation_churn_limit
155152
target_index = spec.get_active_validator_indices(state, current_epoch)[1]
156153
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
157154
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
@@ -160,6 +157,10 @@ def test_consolidation_balance_larger_than_churn_limit(spec, state):
160157
set_compounding_withdrawal_credential(spec, state, source_index)
161158
set_compounding_withdrawal_credential(spec, state, target_index)
162159

160+
new_churn_limit = spec.get_consolidation_churn_limit(state)
161+
remainder = state.validators[source_index].effective_balance % new_churn_limit
162+
expected_balance = new_churn_limit - remainder
163+
163164
signed_consolidation = sign_consolidation(spec, state,
164165
spec.Consolidation(
165166
epoch=current_epoch,
@@ -170,7 +171,7 @@ def test_consolidation_balance_larger_than_churn_limit(spec, state):
170171

171172
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) + 1
172173
# Check consolidation churn is decremented correctly
173-
assert state.consolidation_balance_to_consume == consolidation_churn_limit - 1
174+
assert state.consolidation_balance_to_consume == expected_balance
174175
# Check exit epoch
175176
assert state.validators[0].exit_epoch == expected_exit_epoch
176177

@@ -181,11 +182,9 @@ def test_consolidation_balance_larger_than_churn_limit(spec, state):
181182
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
182183
@spec_test
183184
@single_phase
184-
def test_consolidation_balance_twice_the_churn_limit(spec, state):
185+
def test_consolidation_balance_through_two_churn_epochs(spec, state):
185186
# This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn
186187
consolidation_churn_limit = spec.get_consolidation_churn_limit(state)
187-
# Set the consolidation balance to consume equal to churn limit
188-
state.consolidation_balance_to_consume = consolidation_churn_limit
189188
current_epoch = spec.get_current_epoch(state)
190189

191190
source_index = spec.get_active_validator_indices(state, current_epoch)[0]
@@ -198,7 +197,11 @@ def test_consolidation_balance_twice_the_churn_limit(spec, state):
198197
set_compounding_withdrawal_credential(spec, state, target_index)
199198

200199
# Set source balance higher than consolidation churn limit
201-
state.balances[source_index] = 2 * consolidation_churn_limit
200+
state.validators[source_index].effective_balance = 3 * consolidation_churn_limit
201+
202+
new_churn_limit = spec.get_consolidation_churn_limit(state)
203+
remainder = state.validators[source_index].effective_balance % new_churn_limit
204+
expected_balance = new_churn_limit - remainder
202205

203206
signed_consolidation = sign_consolidation(spec, state,
204207
spec.Consolidation(
@@ -212,7 +215,7 @@ def test_consolidation_balance_twice_the_churn_limit(spec, state):
212215
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) + 2
213216
assert state.validators[0].exit_epoch == expected_exit_epoch
214217
# since the earliest exit epoch moves to a new one, consolidation balance is back to full
215-
assert state.consolidation_balance_to_consume == consolidation_churn_limit
218+
assert state.consolidation_balance_to_consume == expected_balance
216219

217220

218221
@with_eip7251_and_later

tests/core/pyspec/eth2spec/test/helpers/genesis.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def create_genesis_state(spec, validator_balances, activation_threshold):
153153
state.deposit_balance_to_consume = 0
154154
state.exit_balance_to_consume = 0
155155
state.earliest_exit_epoch = spec.GENESIS_EPOCH
156+
state.consolidation_balance_to_consume = 0
157+
state.earliest_consolidation_epoch = 0
156158
state.pending_balance_deposits = []
157159
state.pending_partial_withdrawals = []
160+
state.pending_consolidations = []
158161

159162
return state

0 commit comments

Comments
 (0)