diff --git a/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_deposits.py b/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_deposits.py index 25352a05a..33eeca52c 100644 --- a/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_deposits.py +++ b/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_deposits.py @@ -11,6 +11,71 @@ from eth2spec.test.helpers.deposits import ( def run_process_pending_deposits(spec, state): yield from run_epoch_processing_with(spec, state, 'process_pending_deposits') +@with_electra_and_later +@spec_state_test +def test_pending_deposit_over_max(spec, state): + # pick an amount that adds to less than churn limit + amount = 100 + overmax = spec.MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING + 1 + for i in range(overmax): + state.pending_deposits.append(spec.PendingDeposit( + pubkey=state.validators[i].pubkey, + withdrawal_credentials=state.validators[i].withdrawal_credentials, + amount=amount, + slot=spec.GENESIS_SLOT, + )) + assert len(state.pending_deposits) == overmax,"pending deposits is not over max" + yield from run_process_pending_deposits(spec, state) + # the remaining deposit over MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING should remain in pending_deposits + assert len(state.pending_deposits) == 1 + +@with_electra_and_later +@spec_state_test +def test_pending_deposit_eth1_bridge_not_applied(spec, state): + amount = spec.MIN_ACTIVATION_BALANCE + # deposit is not finalized yet, so it is postponed + state.pending_deposits.append(spec.PendingDeposit( + pubkey=state.validators[0].pubkey, + withdrawal_credentials=state.validators[0].withdrawal_credentials, + amount=amount, + slot=1, + )) + # set deposit_requests_start_index to something high so that deposit is not processed + state.deposit_requests_start_index = 100000000000000000 + # set deposit_balance_to_consume to some initial amount to see its removal later on in the test + state.deposit_balance_to_consume = amount + yield from run_process_pending_deposits(spec, state) + # deposit_balance_to_consume was reset to 0 + assert state.deposit_balance_to_consume == 0 + # deposit was postponed and not processed + assert len(state.pending_deposits) == 1 + + +@with_electra_and_later +@spec_state_test +def test_pending_deposit_deposit_not_finalized(spec, state): + amount = spec.MIN_ACTIVATION_BALANCE + # set slot to something not finalized + slot=spec.compute_start_slot_at_epoch(state.finalized_checkpoint.epoch+1) + # deposit is not finalized yet, so it is postponed + state.pending_deposits.append(spec.PendingDeposit( + pubkey=state.validators[0].pubkey, + withdrawal_credentials=state.validators[0].withdrawal_credentials, + amount=amount, + slot=slot, + )) + # set deposit_requests_start_index to something low so that we skip the bridge validation + state.deposit_requests_start_index = 0 + print("deposit indexes",state.eth1_deposit_index,state.deposit_requests_start_index) + # set deposit_balance_to_consume to some initial amount to see its removal later on in the test + state.deposit_balance_to_consume = amount + yield from run_process_pending_deposits(spec, state) + # deposit_balance_to_consume was reset to 0 + assert state.deposit_balance_to_consume == 0 + # deposit was postponed and not processed + assert len(state.pending_deposits) == 1 + + @with_electra_and_later @spec_state_test @@ -280,41 +345,3 @@ def test_processing_deposit_of_withdrawable_validator_does_not_get_churned(spec, assert state.deposit_balance_to_consume == spec.get_activation_exit_churn_limit(state) assert state.pending_deposits == [build_pending_deposit_top_up(spec, state, validator_index=1, amount=amount)] -@with_electra_and_later -@spec_state_test -def test_pending_deposit_over_max(spec, state): - # pick an amount that adds to less than churn limit - amount = 100 - overmax = spec.MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING + 1 - for i in range(overmax): - state.pending_deposits.append(spec.PendingDeposit( - pubkey=state.validators[i].pubkey, - withdrawal_credentials=state.validators[i].withdrawal_credentials, - amount=amount, - slot=state.slot - )) - - assert len(state.pending_deposits) == overmax,"pending deposits is not over max" - yield from run_process_pending_deposits(spec, state) - # the remaining deposit over MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING should remain in pending_deposits - assert len(state.pending_deposits) == 1 - -@with_electra_and_later -@spec_state_test -def test_pending_deposit_deposit_not_finalized(spec, state): - amount = spec.MIN_ACTIVATION_BALANCE - slot=spec.compute_start_slot_at_epoch(state.finalized_checkpoint.epoch) - # deposit is not finalized yet, so it is postponed - state.pending_deposits.append(spec.PendingDeposit( - pubkey=state.validators[0].pubkey, - withdrawal_credentials=state.validators[0].withdrawal_credentials, - amount=amount, - slot=slot, - )) - # set deposit_balance_to_consume to some initial amount to see its removal later on in the test - state.deposit_balance_to_consume = amount - yield from run_process_pending_deposits(spec, state) - # deposit_balance_to_consume was reset to 0 - assert state.deposit_balance_to_consume == 0 - # deposit was postponed and not processed - assert len(state.pending_deposits) == 1