From 3593a0cb3451a3c60ae37092594d4ef07207fa93 Mon Sep 17 00:00:00 2001 From: james-prysm Date: Mon, 5 Aug 2024 16:38:51 -0500 Subject: [PATCH] adding 3 more tests --- .../test_apply_pending_deposit.py | 39 +++++++ .../test_process_pending_deposits.py | 108 ++++++++++++++++++ 2 files changed, 147 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_apply_pending_deposit.py b/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_apply_pending_deposit.py index 0cf9cd3a9..3b8588ecc 100644 --- a/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_apply_pending_deposit.py +++ b/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_apply_pending_deposit.py @@ -101,6 +101,45 @@ def test_apply_pending_deposit_switch_to_compounding(spec, state): assert current_credentials == compounding_credentials +@with_electra_and_later +@spec_state_test +def test_apply_pending_deposit_switch_to_compounding_has_bls(spec, state): + amount = 100 + + # choose a value public key that's in the validator set + index = 0 + compounding_credentials = ( + spec.COMPOUNDING_WITHDRAWAL_PREFIX + + spec.hash(pubkeys[index])[1:] + ) + # advance the state + next_epoch_via_block(spec, state) + bls_credentials = state.validators[index].withdrawal_credentials + # set validator to be exited by current epoch + state.validators[index].exit_epoch = spec.get_current_epoch(state) - 1 + deposit_data = build_deposit_data(spec, + pubkeys[index], + privkeys[index], + amount, + compounding_credentials, + signed=True) + deposit = spec.PendingDeposit( + pubkey=pubkeys[index], + withdrawal_credentials=compounding_credentials, + amount=amount, + slot=spec.GENESIS_SLOT, + signature=deposit_data.signature, + ) + state.balances[index] = 0 + # run test + spec.apply_pending_deposit(state, deposit) + # validator balance should increase + assert state.balances[index] == amount + current_credentials = state.validators[index].withdrawal_credentials + # does not switch to compounding + assert current_credentials == bls_credentials + + @with_electra_and_later @spec_state_test def test_apply_pending_deposit_switch_to_compounding_invalid_sig(spec, state): 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 05e8de00b..5babd66c8 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 @@ -393,6 +393,71 @@ def test_pending_deposit_balance_equal_churn_with_compounding(spec, state): assert current_credentials == withdrawal_credentials +@with_electra_and_later +@spec_state_test +def test_top_up__zero_balance(spec, state): + validator_index = 0 + amount = spec.MAX_EFFECTIVE_BALANCE // 4 + + initial_balance = 0 + initial_effective_balance = 0 + state.balances[validator_index] = initial_balance + val = state.validators[validator_index] + val.effective_balance = initial_effective_balance + wc = val.withdrawal_credentials + pd = build_pending_deposit(spec, validator_index, + amount=amount, + withdrawal_credentials=wc, + signed=True) + state.pending_deposits.append(pd) + + yield from run_process_pending_deposits(spec, state) + + deposits_len = len(state.pending_deposits) + assert state.pending_deposits[deposits_len - 1].amount == amount + # unchanged effective balance + assert val.effective_balance == initial_effective_balance + + +@with_electra_and_later +@spec_state_test +def test_incorrect_sig_top_up(spec, state): + validator_index = 0 + amount = spec.MAX_EFFECTIVE_BALANCE // 4 + + val = state.validators[validator_index] + wc = val.withdrawal_credentials + pd = build_pending_deposit(spec, validator_index, + amount=amount, + withdrawal_credentials=wc, + signed=False) + state.pending_deposits.append(pd) + + yield from run_process_pending_deposits(spec, state) + + +@with_electra_and_later +@spec_state_test +def test_incorrect_withdrawal_credentials_top_up(spec, state): + validator_index = 0 + amount = spec.MAX_EFFECTIVE_BALANCE // 4 + + initial_balance = 0 + initial_effective_balance = 0 + state.balances[validator_index] = initial_balance + val = state.validators[validator_index] + val.effective_balance = initial_effective_balance + wc = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(b"junk")[1:] + + pd = build_pending_deposit(spec, validator_index, + amount=amount, + withdrawal_credentials=wc, + signed=True) + state.pending_deposits.append(pd) + + yield from run_process_pending_deposits(spec, state) + + @with_electra_and_later @spec_state_test def test_pending_deposit_balance_above_churn(spec, state): @@ -416,6 +481,49 @@ def test_pending_deposit_balance_above_churn(spec, state): ] +@with_electra_and_later +@spec_state_test +def test_top_up__max_effective_balance(spec, state): + validator_index = 0 + amount = spec.MAX_EFFECTIVE_BALANCE // 4 + wc = state.validators[validator_index].withdrawal_credentials + pd = build_pending_deposit(spec, validator_index, + amount=amount, + withdrawal_credentials=wc, + signed=True) + state.pending_deposits.append(pd) + + state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE + state.validators[validator_index].effective_balance = spec.MAX_EFFECTIVE_BALANCE + + yield from run_process_pending_deposits(spec, state) + + assert state.validators[validator_index].effective_balance == spec.MAX_EFFECTIVE_BALANCE + + +@with_electra_and_later +@spec_state_test +def test_top_up__less_effective_balance(spec, state): + validator_index = 0 + amount = spec.MAX_EFFECTIVE_BALANCE // 4 + wc = state.validators[validator_index].withdrawal_credentials + pd = build_pending_deposit(spec, validator_index, + amount=amount, + withdrawal_credentials=wc, + signed=True) + state.pending_deposits.append(pd) + + initial_balance = spec.MAX_EFFECTIVE_BALANCE - 1000 + initial_effective_balance = spec.MAX_EFFECTIVE_BALANCE - spec.EFFECTIVE_BALANCE_INCREMENT + state.balances[validator_index] = initial_balance + state.validators[validator_index].effective_balance = initial_effective_balance + + yield from run_process_pending_deposits(spec, state) + + # unchanged effective balance + assert state.validators[validator_index].effective_balance == initial_effective_balance + + @with_electra_and_later @spec_state_test def test_pending_deposit_preexisting_churn(spec, state):