Add a test case from staking-deposit-cli

This commit is contained in:
Hsiao-Wei Wang 2023-01-11 00:23:19 +08:00
parent 427a6e809f
commit 64f609af18
No known key found for this signature in database
GPG Key ID: AE3D6B174F971DE4
1 changed files with 36 additions and 2 deletions

View File

@ -1,7 +1,14 @@
from eth2spec.test.helpers.keys import pubkeys
from eth2spec.test.helpers.bls_to_execution_changes import get_signed_address_change
from eth2spec.test.context import spec_state_test, expect_assertion_error, with_capella_and_later, always_bls
from eth2spec.test.helpers.constants import CAPELLA, MAINNET
from eth2spec.test.context import (
always_bls,
expect_assertion_error,
spec_state_test,
with_capella_and_later,
with_presets,
with_phases,
)
def run_bls_to_execution_change_processing(spec, state, signed_address_change, valid=True):
@ -208,3 +215,30 @@ def test_invalid_genesis_validators_root(spec, state):
signed_address_change = get_signed_address_change(spec, state, genesis_validators_root=b'\x99' * 32)
yield from run_bls_to_execution_change_processing(spec, state, signed_address_change, valid=False)
@with_phases([CAPELLA])
@with_presets([MAINNET], reason="use mainnet fork version")
@spec_state_test
@always_bls
def test_valid_signature_from_staking_deposit_cli(spec, state):
validator_index = 1
from_bls_pubkey = bytes.fromhex('86248e64705987236ec3c41f6a81d96f98e7b85e842a1d71405b216fa75a9917512f3c94c85779a9729c927ea2aa9ed1') # noqa: E501
to_execution_address = bytes.fromhex('3434343434343434343434343434343434343434')
signature = bytes.fromhex('b9611626f18632086b6e05e161b1cb1f686ca0e920d12a2d7430e230e336d96b381099d1fda198949b727830088d70eb039e30ea213908a34a1d0d81b0c4c8fd23f38475f36c45ff98dd0906874387183d7583c60ad7bd1744a41ea68b5dfcb2') # noqa: E501
# Use mainnet `genesis_validators_root`
state.genesis_validators_root = bytes.fromhex('4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95')
state.validators[1].withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(from_bls_pubkey)[1:]
address_change = spec.BLSToExecutionChange(
validator_index=validator_index,
from_bls_pubkey=from_bls_pubkey,
to_execution_address=to_execution_address,
)
signed_address_change = spec.SignedBLSToExecutionChange(
message=address_change,
signature=signature,
)
yield from run_bls_to_execution_change_processing(spec, state, signed_address_change)