Skip to content

Commit

Permalink
Update test_incorrect_not_enough_consolidation_churn_available and …
Browse files Browse the repository at this point in the history
…add assertions to test cases
  • Loading branch information
hwwhww committed Jun 24, 2024
1 parent 00b7468 commit 5c68abc
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ def test_incorrect_source_equals_target(spec, state):
target_pubkey=state.validators[source_index].pubkey,
)

# Check the the return condition
assert consolidation.source_pubkey == consolidation.target_pubkey

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand Down Expand Up @@ -454,6 +457,9 @@ def test_incorrect_exceed_pending_consolidations_limit(spec, state):
)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)

# Check the the return condition
assert len(state.pending_consolidations) == spec.PENDING_CONSOLIDATIONS_LIMIT

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand All @@ -463,7 +469,6 @@ def test_incorrect_exceed_pending_consolidations_limit(spec, state):
@spec_state_test
@single_phase
def test_incorrect_not_enough_consolidation_churn_available(spec, state):
state.validators = state.validators[0:2]
state.pending_consolidations = [
spec.PendingConsolidation(source_index=0, target_index=1)
]
Expand All @@ -481,7 +486,12 @@ def test_incorrect_not_enough_consolidation_churn_available(spec, state):
source_pubkey=state.validators[source_index].pubkey,
target_pubkey=state.validators[target_index].pubkey,
)

set_eth1_withdrawal_credential_with_balance(spec, state, target_index)

# Check the the return condition
assert spec.get_consolidation_churn_limit(state) <= spec.MIN_ACTIVATION_BALANCE

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand Down Expand Up @@ -514,6 +524,9 @@ def test_incorrect_exited_source(spec, state):
# exit source
spec.initiate_validator_exit(state, source_index)

# Check the the return condition
assert state.validators[source_index].exit_epoch != spec.FAR_FUTURE_EPOCH

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand Down Expand Up @@ -544,6 +557,10 @@ def test_incorrect_exited_target(spec, state):
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
# exit target
spec.initiate_validator_exit(state, 1)

# Check the the return condition
assert state.validators[target_index].exit_epoch != spec.FAR_FUTURE_EPOCH

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand Down Expand Up @@ -576,6 +593,9 @@ def test_incorrect_inactive_source(spec, state):
# set source validator as not yet activated
state.validators[source_index].activation_epoch = spec.FAR_FUTURE_EPOCH

# Check the the return condition
assert not spec.is_active_validator(state.validators[source_index], current_epoch)

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand Down Expand Up @@ -607,6 +627,10 @@ def test_incorrect_inactive_target(spec, state):

# set target validator as not yet activated
state.validators[1].activation_epoch = spec.FAR_FUTURE_EPOCH

# Check the the return condition
assert not spec.is_active_validator(state.validators[target_index], current_epoch)

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand All @@ -633,6 +657,10 @@ def test_incorrect_no_source_execution_withdrawal_credential(spec, state):
target_pubkey=state.validators[target_index].pubkey,
)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)

# Check the the return condition
assert not spec.has_execution_withdrawal_credential(state.validators[source_index])

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand Down Expand Up @@ -661,6 +689,10 @@ def test_incorrect_no_target_execution_withdrawal_credential(spec, state):
source_pubkey=state.validators[source_index].pubkey,
target_pubkey=state.validators[target_index].pubkey,
)

# Check the the return condition
assert not spec.has_execution_withdrawal_credential(state.validators[target_index])

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand Down Expand Up @@ -691,6 +723,9 @@ def test_incorrect_incorrect_source_address(spec, state):
)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)

# Check the the return condition
assert not state.validators[source_index].withdrawal_credentials[12:] == consolidation.source_address

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand Down Expand Up @@ -721,6 +756,9 @@ def test_incorrect_unknown_source_pubkey(spec, state):
)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)

# Check the the return condition
assert not state.validators[source_index].pubkey == consolidation.source_pubkey

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand Down Expand Up @@ -751,6 +789,9 @@ def test_incorrect_unknown_target_pubkey(spec, state):
)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)

# Check the the return condition
assert not state.validators[target_index].pubkey == consolidation.target_pubkey

yield from run_consolidation_processing(
spec, state, consolidation, success=False
)
Expand All @@ -762,7 +803,7 @@ def run_consolidation_processing(spec, state, consolidation, success=True):
- pre-state ('pre')
- consolidation_request ('consolidation_request')
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError``
If ``success == False``, ``process_consolidation_request`` would be interruped without any state change.
"""

if success:
Expand Down

0 comments on commit 5c68abc

Please sign in to comment.