Skip to content

Commit

Permalink
Merge pull request ethereum#3203 from ethereum/btec-previous-fork-ver…
Browse files Browse the repository at this point in the history
…sion

Add `BLSToExecutionChange` `test_invalid_previous_fork_version` test case
  • Loading branch information
djrtwo authored Jan 12, 2023
2 parents 71d66af + a2099da commit 5123119
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,25 @@ def test_invalid_bad_signature(spec, state):
signed_address_change.signature = spec.BLSSignature(b'\x42' * 96)

yield from run_bls_to_execution_change_processing(spec, state, signed_address_change, valid=False)


@with_capella_and_later
@spec_state_test
@always_bls
def test_current_fork_version(spec, state):
"""
It should be identical to the `test_success` test case.
It is just for comparing with `test_invalid_previous_fork_version`.
"""
signed_address_change = get_signed_address_change(spec, state, fork_version=state.fork.current_version)

yield from run_bls_to_execution_change_processing(spec, state, signed_address_change)


@with_capella_and_later
@spec_state_test
@always_bls
def test_invalid_previous_fork_version(spec, state):
signed_address_change = get_signed_address_change(spec, state, fork_version=state.fork.previous_version)

yield from run_bls_to_execution_change_processing(spec, state, signed_address_change, valid=False)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from eth2spec.test.helpers.keys import pubkeys, privkeys, pubkey_to_privkey


def get_signed_address_change(spec, state, validator_index=None, withdrawal_pubkey=None, to_execution_address=None):
def get_signed_address_change(spec, state, validator_index=None, withdrawal_pubkey=None, to_execution_address=None,
fork_version=None):
if validator_index is None:
validator_index = 0

Expand All @@ -16,7 +17,11 @@ def get_signed_address_change(spec, state, validator_index=None, withdrawal_pubk
if to_execution_address is None:
to_execution_address = b'\x42' * 20

domain = spec.get_domain(state, spec.DOMAIN_BLS_TO_EXECUTION_CHANGE)
if fork_version is None:
domain = spec.get_domain(state, spec.DOMAIN_BLS_TO_EXECUTION_CHANGE)
else:
domain = spec.compute_domain(spec.DOMAIN_BLS_TO_EXECUTION_CHANGE, fork_version, state.genesis_validators_root)

address_change = spec.BLSToExecutionChange(
validator_index=validator_index,
from_bls_pubkey=withdrawal_pubkey,
Expand Down

0 comments on commit 5123119

Please sign in to comment.