Skip to content

Commit

Permalink
adding run_process_pending_deposits to deposit request tests to prope…
Browse files Browse the repository at this point in the history
…rly test changes
  • Loading branch information
james-prysm committed Aug 6, 2024
1 parent 337726c commit 56fe310
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
)
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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)

0 comments on commit 56fe310

Please sign in to comment.