Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add deposit+bls_change test #3264

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

@with_capella_and_later
@spec_state_test
def test_success_bls_change(spec, state):
def test_bls_change(spec, state):
index = 0
signed_address_change = get_signed_address_change(spec, state, validator_index=index)
pre_credentials = state.validators[index].withdrawal_credentials
Expand All @@ -60,7 +60,46 @@ def test_success_bls_change(spec, state):

@with_capella_and_later
@spec_state_test
def test_success_exit_and_bls_change(spec, state):
def test_deposit_and_bls_change(spec, state):
initial_registry_len = len(state.validators)
initial_balances_len = len(state.balances)

validator_index = len(state.validators)
amount = spec.MAX_EFFECTIVE_BALANCE
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)

signed_address_change = get_signed_address_change(
spec, state,
validator_index=validator_index,
withdrawal_pubkey=deposit.data.pubkey, # Deposit helper defaults to use pubkey as withdrawal credential
)

deposit_credentials = deposit.data.withdrawal_credentials
assert deposit_credentials[:1] == spec.BLS_WITHDRAWAL_PREFIX

yield 'pre', state

block = build_empty_block_for_next_slot(spec, state)
block.body.deposits.append(deposit)
block.body.bls_to_execution_changes.append(signed_address_change)

signed_block = state_transition_and_sign_block(spec, state, block)

yield 'blocks', [signed_block]
yield 'post', state

assert len(state.validators) == initial_registry_len + 1
assert len(state.balances) == initial_balances_len + 1
validator_credentials = state.validators[validator_index].withdrawal_credentials
assert deposit_credentials != validator_credentials
assert validator_credentials[:1] == spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX
assert validator_credentials[1:12] == b'\x00' * 11
assert validator_credentials[12:] == signed_address_change.message.to_execution_address


@with_capella_and_later
@spec_state_test
def test_exit_and_bls_change(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH

Expand Down