adding run_process_pending_deposits to deposit request tests to properly test changes

This commit is contained in:
james-prysm 2024-08-06 14:10:23 -05:00
parent 337726cbae
commit 56fe31031c
2 changed files with 85 additions and 0 deletions

View File

@ -6,6 +6,12 @@ from eth2spec.test.helpers.deposits import (
)
from eth2spec.test.helpers.state import next_epoch_via_block
from eth2spec.test.helpers.withdrawals import set_validator_fully_withdrawable
from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with
def run_process_pending_deposits(spec, state):
yield from run_epoch_processing_with(
spec, state, 'process_pending_deposits')
@with_electra_and_later
@ -18,6 +24,7 @@ def test_new_deposit_under_max(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, signed=True)
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@ -30,6 +37,7 @@ def test_new_deposit_max(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, signed=True)
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@ -42,6 +50,7 @@ def test_new_deposit_over_max(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, signed=True)
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@ -64,6 +73,7 @@ def test_new_deposit_eth1_withdrawal_credentials(spec, state):
)
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@ -85,6 +95,7 @@ def test_new_deposit_non_versioned_withdrawal_credentials(spec, state):
)
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@ -177,6 +188,7 @@ def test_incorrect_sig_top_up(spec, state):
# invalid signatures, in top-ups, are allowed!
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@ -194,6 +206,7 @@ def test_incorrect_withdrawal_credentials_top_up(spec, state):
# inconsistent withdrawal credentials, in top-ups, are allowed!
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@ -208,6 +221,7 @@ def test_key_validate_invalid_subgroup(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, pubkey=pubkey, signed=True)
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@ -224,6 +238,7 @@ def test_key_validate_invalid_decompression(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, pubkey=pubkey, signed=True)
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later

View File

@ -1,6 +1,7 @@
from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with
from eth2spec.test.context import (
spec_state_test,
always_bls,
with_electra_and_later,
)
from eth2spec.test.helpers.deposits import (
@ -801,3 +802,72 @@ def test_processing_deposit_of_withdrawable_validator_not_churned(spec, state):
build_pending_deposit_top_up(spec, state,
validator_index=1, amount=amount)
]
@with_electra_and_later
@spec_state_test
@always_bls
def test_correct_sig_but_forked_state(spec, state):
amount = spec.MAX_EFFECTIVE_BALANCE
# deposits will always be valid, regardless of the current fork
state.fork.current_version = spec.Version('0x1234abcd')
index = 0
withdrawal_credentials = (
spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX +
spec.hash(pubkeys[index])[1:]
)
wc = withdrawal_credentials
pd = build_pending_deposit(spec, 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_key_validate_invalid_subgroup(spec, state):
amount = spec.MAX_EFFECTIVE_BALANCE
# All-zero pubkey would not pass `bls.KeyValidate`, but `process_deposit` would not throw exception.
pubkey = b'\x00' * 48
index = 0
withdrawal_credentials = (
spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX +
spec.hash(pubkey)[1:]
)
wc = withdrawal_credentials
pd = build_pending_deposit(spec, index,
amount=amount,
withdrawal_credentials=wc,
pubkey=pubkey,
signed=True)
state.pending_deposits.append(pd)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@spec_state_test
def test_key_validate_invalid_decompression(spec, state):
amount = spec.MAX_EFFECTIVE_BALANCE
# `deserialization_fails_infinity_with_true_b_flag` BLS G1 deserialization test case.
# This pubkey would not pass `bls.KeyValidate`, but `process_deposit` would not throw exception.
pubkey_hex = 'c01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
pubkey = bytes.fromhex(pubkey_hex)
index = 0
withdrawal_credentials = (
spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX +
spec.hash(pubkey)[1:]
)
wc = withdrawal_credentials
pd = build_pending_deposit(spec, index,
amount=amount,
withdrawal_credentials=wc,
pubkey=pubkey,
signed=True)
state.pending_deposits.append(pd)
yield from run_process_pending_deposits(spec, state)