adding fork version tests

This commit is contained in:
james-prysm 2024-08-06 14:36:20 -05:00
parent 56fe31031c
commit c5db6dfcfb
2 changed files with 74 additions and 4 deletions

View File

@ -871,3 +871,68 @@ def test_key_validate_invalid_decompression(spec, state):
signed=True)
state.pending_deposits.append(pd)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@spec_state_test
@always_bls
def test_apply_pending_deposit_with_previous_fork_version(spec, state):
# Since deposits are valid across forks, the domain is always set with `GENESIS_FORK_VERSION`.
assert state.fork.previous_version != state.fork.current_version
amount = spec.MAX_EFFECTIVE_BALANCE
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,
fork_version=state.fork.previous_version,
signed=True)
state.pending_deposits.append(pd)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@spec_state_test
@always_bls
def test_apply_pending_deposit_with_genesis_fork_version(spec, state):
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version)
assert state.fork.previous_version != state.fork.current_version
amount = spec.MAX_EFFECTIVE_BALANCE
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,
fork_version=spec.GENESIS_FORK_VERSION,
signed=True)
state.pending_deposits.append(pd)
yield from run_process_pending_deposits(spec, state)
@with_electra_and_later
@spec_state_test
@always_bls
def test_apply_pending_deposit_with_bad_fork_version(spec, state):
amount = spec.MAX_EFFECTIVE_BALANCE
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,
fork_version=spec.Version('0xAaBbCcDd'),
signed=True)
state.pending_deposits.append(pd)
yield from run_process_pending_deposits(spec, state)

View File

@ -23,23 +23,26 @@ def mock_deposit(spec, state, index):
assert not spec.is_active_validator(state.validators[index], spec.get_current_epoch(state))
def build_deposit_data(spec, pubkey, privkey, amount, withdrawal_credentials, signed=False):
def build_deposit_data(spec, pubkey, privkey, amount, withdrawal_credentials, fork_version, signed=False):
deposit_data = spec.DepositData(
pubkey=pubkey,
withdrawal_credentials=withdrawal_credentials,
amount=amount,
)
if signed:
sign_deposit_data(spec, deposit_data, privkey)
sign_deposit_data(spec, deposit_data, privkey, fork_version)
return deposit_data
def sign_deposit_data(spec, deposit_data, privkey):
def sign_deposit_data(spec, deposit_data, privkey, fork_version):
deposit_message = spec.DepositMessage(
pubkey=deposit_data.pubkey,
withdrawal_credentials=deposit_data.withdrawal_credentials,
amount=deposit_data.amount)
domain = spec.compute_domain(spec.DOMAIN_DEPOSIT)
if fork_version is not None:
domain = spec.compute_domain(domain_type=spec.DOMAIN_DEPOSIT, fork_version=fork_version)
else:
domain = spec.compute_domain(spec.DOMAIN_DEPOSIT)
signing_root = spec.compute_signing_root(deposit_message, domain)
deposit_data.signature = bls.Sign(privkey, signing_root)
@ -241,6 +244,7 @@ def build_pending_deposit(spec, validator_index, amount,
pubkey=None,
privkey=None,
withdrawal_credentials=None,
fork_version=None,
slot=None,
signed=False):
if index is None:
@ -267,6 +271,7 @@ def build_pending_deposit(spec, validator_index, amount,
privkeys[index],
amount,
withdrawal_credentials,
fork_version,
signed=True)
pending_deposit.signature = deposit_data.signature
return pending_deposit