updating tests based on mikhail changes

This commit is contained in:
james-prysm 2024-07-08 23:15:03 -05:00
parent 093590ee11
commit 1a19d82bbc
2 changed files with 102 additions and 59 deletions

View File

@ -33,60 +33,7 @@ def test_apply_pending_deposit_add_validator_to_registry(spec, state):
@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_not_withdrawable_epoch_while_exiting(spec, state):
amount = 100
# validator exit epoch must be less than far future
state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1
state.validators[0].withdrawable_epoch = spec.FAR_FUTURE_EPOCH
deposit = spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials= state.validators[0].withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
)
assert spec.apply_pending_deposit(state,deposit) == False
@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_not_withdrawable_epoch_at_current_epoch_while_exiting(spec, state):
amount = 100
# validator exit epoch must be less than far future
state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1
state.validators[0].withdrawable_epoch = spec.get_current_epoch(state)
deposit = spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials= state.validators[0].withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
)
assert spec.apply_pending_deposit(state,deposit) == False
@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_withdrawable_epoch_while_exiting(spec, state):
amount = 100
state.slot = spec.SLOTS_PER_EPOCH * 2
# validator exit epoch must be less than far future
state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1
state.validators[0].withdrawable_epoch = 0
deposit = spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials= state.validators[0].withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
)
# reset the balance
state.balances[0] = 0
assert spec.apply_pending_deposit(state,deposit) == True
assert state.balances[0] == amount
@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_withdrawable_epoch_while_exited(spec, state):
def test_apply_pending_deposit_increases_balance(spec, state):
amount = 100
state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH
# signature doesn't matter here as it's interpreted as a top-up
@ -98,7 +45,8 @@ def test_apply_pending_deposit_withdrawable_epoch_while_exited(spec, state):
)
# reset the balance
state.balances[0] = 0
assert spec.apply_pending_deposit(state,deposit) == True
# run test
spec.apply_pending_deposit(state,deposit)
assert state.balances[0] == amount
@ -111,7 +59,41 @@ def test_apply_pending_deposit_switch_to_compounding(spec, state):
index = 0
withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + spec.hash(pubkeys[index])[1:]
compounding_credentials = spec.COMPOUNDING_WITHDRAWAL_PREFIX + spec.hash(pubkeys[index])[1:]
state.slot = spec.SLOTS_PER_EPOCH * 2
state.validators[index].withdrawal_credentials = withdrawal_credentials
# set validator to be exited by current epoch
state.validators[index].exit_epoch = spec.get_current_epoch(state) - 1
deposit_data = build_deposit_data(spec,
pubkeys[index],
privkeys[index],
amount,
compounding_credentials,
signed=True)
deposit = spec.PendingDeposit(
pubkey=pubkeys[index],
withdrawal_credentials= compounding_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
signature=deposit_data.signature,
)
state.balances[0] = 0
# run test
spec.apply_pending_deposit(state,deposit)
# validator balance should increase
assert state.balances[0] == amount
assert state.validators[0].withdrawal_credentials == compounding_credentials
@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_switch_to_compounding_while_validator_not_exited(spec, state):
amount = 100
# choose a value public key that's in the validator set
index = 0
withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + spec.hash(pubkeys[index])[1:]
compounding_credentials = spec.COMPOUNDING_WITHDRAWAL_PREFIX + spec.hash(pubkeys[index])[1:]
state.validators[index].withdrawal_credentials = withdrawal_credentials
# set validator to not be exited
state.validators[index].exit_epoch = spec.FAR_FUTURE_EPOCH
deposit_data = build_deposit_data(spec,
pubkeys[index],
@ -127,8 +109,10 @@ def test_apply_pending_deposit_switch_to_compounding(spec, state):
signature=deposit_data.signature,
)
state.balances[0] = 0
assert spec.apply_pending_deposit(state,deposit) == True
# validator count should increase by 1
# run test
spec.apply_pending_deposit(state,deposit)
# validator balance should increase
assert state.balances[0] == amount
assert state.validators[0].withdrawal_credentials == compounding_credentials
# make sure validator did not switch to compounding if not exited
assert state.validators[0].withdrawal_credentials == withdrawal_credentials

View File

@ -53,7 +53,7 @@ def test_pending_deposit_eth1_bridge_not_applied(spec, state):
@with_electra_and_later
@spec_state_test
def test_pending_deposit_deposit_not_finalized(spec, state):
def test_pending_deposit_not_finalized(spec, state):
amount = spec.MIN_ACTIVATION_BALANCE
# set slot to something not finalized
slot=spec.compute_start_slot_at_epoch(state.finalized_checkpoint.epoch+1)
@ -75,6 +75,65 @@ def test_pending_deposit_deposit_not_finalized(spec, state):
# deposit was postponed and not processed
assert len(state.pending_deposits) == 1
@with_electra_and_later
@spec_state_test
def test_pending_deposit_validator_withdrawn(spec, state):
amount = spec.MIN_ACTIVATION_BALANCE
withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + spec.hash(state.validators[0].pubkey)[1:]
state.slot = spec.SLOTS_PER_EPOCH * 2
state.validators[0].withdrawal_credentials = withdrawal_credentials
# set validator to be withdrawable by current epoch
state.validators[0].withdrawable_epoch = spec.get_current_epoch(state) - 1
state.pending_deposits.append(spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials=state.validators[0].withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
))
# set deposit_requests_start_index to something low so that we skip the bridge validation
state.deposit_requests_start_index = 0
print("deposit indexes",state.eth1_deposit_index,state.deposit_requests_start_index)
# set deposit_balance_to_consume to some initial amount to see its removal later on in the test
state.deposit_balance_to_consume = amount
# reset balance for assert
state.balances[0] = 0
yield from run_process_pending_deposits(spec, state)
# deposit_balance_to_consume was reset to 0
assert state.deposit_balance_to_consume == 0
# deposit was processed
assert state.pending_deposits == []
# balance increases because of withdraw
assert state.balances[0] == amount
@with_electra_and_later
@spec_state_test
def test_pending_deposit_validator_exiting_but_not_withdrawn(spec, state):
amount = spec.MIN_ACTIVATION_BALANCE
withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + spec.hash(state.validators[0].pubkey)[1:]
state.slot = spec.SLOTS_PER_EPOCH * 2
state.validators[0].withdrawal_credentials = withdrawal_credentials
# set validator to be withdrawable by current epoch
state.validators[0].exit_epoch = spec.get_current_epoch(state) - 1
state.validators[0].withdrawable_epoch = spec.FAR_FUTURE_EPOCH
state.pending_deposits.append(spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials=state.validators[0].withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
))
# set deposit_requests_start_index to something low so that we skip the bridge validation
state.deposit_requests_start_index = 0
print("deposit indexes",state.eth1_deposit_index,state.deposit_requests_start_index)
# set deposit_balance_to_consume to some initial amount to see its removal later on in the test
state.deposit_balance_to_consume = amount
yield from run_process_pending_deposits(spec, state)
# deposit_balance_to_consume was reset to 0
assert state.deposit_balance_to_consume == 0
# deposit was postponed and not processed
assert len(state.pending_deposits) == 1
@with_electra_and_later