mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-08 08:45:57 +00:00
adding 3 more tests
This commit is contained in:
parent
336c6f1510
commit
3593a0cb34
@ -101,6 +101,45 @@ def test_apply_pending_deposit_switch_to_compounding(spec, state):
|
||||
assert current_credentials == compounding_credentials
|
||||
|
||||
|
||||
@with_electra_and_later
|
||||
@spec_state_test
|
||||
def test_apply_pending_deposit_switch_to_compounding_has_bls(spec, state):
|
||||
amount = 100
|
||||
|
||||
# choose a value public key that's in the validator set
|
||||
index = 0
|
||||
compounding_credentials = (
|
||||
spec.COMPOUNDING_WITHDRAWAL_PREFIX +
|
||||
spec.hash(pubkeys[index])[1:]
|
||||
)
|
||||
# advance the state
|
||||
next_epoch_via_block(spec, state)
|
||||
bls_credentials = state.validators[index].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[index] = 0
|
||||
# run test
|
||||
spec.apply_pending_deposit(state, deposit)
|
||||
# validator balance should increase
|
||||
assert state.balances[index] == amount
|
||||
current_credentials = state.validators[index].withdrawal_credentials
|
||||
# does not switch to compounding
|
||||
assert current_credentials == bls_credentials
|
||||
|
||||
|
||||
@with_electra_and_later
|
||||
@spec_state_test
|
||||
def test_apply_pending_deposit_switch_to_compounding_invalid_sig(spec, state):
|
||||
|
@ -393,6 +393,71 @@ def test_pending_deposit_balance_equal_churn_with_compounding(spec, state):
|
||||
assert current_credentials == withdrawal_credentials
|
||||
|
||||
|
||||
@with_electra_and_later
|
||||
@spec_state_test
|
||||
def test_top_up__zero_balance(spec, state):
|
||||
validator_index = 0
|
||||
amount = spec.MAX_EFFECTIVE_BALANCE // 4
|
||||
|
||||
initial_balance = 0
|
||||
initial_effective_balance = 0
|
||||
state.balances[validator_index] = initial_balance
|
||||
val = state.validators[validator_index]
|
||||
val.effective_balance = initial_effective_balance
|
||||
wc = val.withdrawal_credentials
|
||||
pd = build_pending_deposit(spec, validator_index,
|
||||
amount=amount,
|
||||
withdrawal_credentials=wc,
|
||||
signed=True)
|
||||
state.pending_deposits.append(pd)
|
||||
|
||||
yield from run_process_pending_deposits(spec, state)
|
||||
|
||||
deposits_len = len(state.pending_deposits)
|
||||
assert state.pending_deposits[deposits_len - 1].amount == amount
|
||||
# unchanged effective balance
|
||||
assert val.effective_balance == initial_effective_balance
|
||||
|
||||
|
||||
@with_electra_and_later
|
||||
@spec_state_test
|
||||
def test_incorrect_sig_top_up(spec, state):
|
||||
validator_index = 0
|
||||
amount = spec.MAX_EFFECTIVE_BALANCE // 4
|
||||
|
||||
val = state.validators[validator_index]
|
||||
wc = val.withdrawal_credentials
|
||||
pd = build_pending_deposit(spec, validator_index,
|
||||
amount=amount,
|
||||
withdrawal_credentials=wc,
|
||||
signed=False)
|
||||
state.pending_deposits.append(pd)
|
||||
|
||||
yield from run_process_pending_deposits(spec, state)
|
||||
|
||||
|
||||
@with_electra_and_later
|
||||
@spec_state_test
|
||||
def test_incorrect_withdrawal_credentials_top_up(spec, state):
|
||||
validator_index = 0
|
||||
amount = spec.MAX_EFFECTIVE_BALANCE // 4
|
||||
|
||||
initial_balance = 0
|
||||
initial_effective_balance = 0
|
||||
state.balances[validator_index] = initial_balance
|
||||
val = state.validators[validator_index]
|
||||
val.effective_balance = initial_effective_balance
|
||||
wc = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(b"junk")[1:]
|
||||
|
||||
pd = build_pending_deposit(spec, validator_index,
|
||||
amount=amount,
|
||||
withdrawal_credentials=wc,
|
||||
signed=True)
|
||||
state.pending_deposits.append(pd)
|
||||
|
||||
yield from run_process_pending_deposits(spec, state)
|
||||
|
||||
|
||||
@with_electra_and_later
|
||||
@spec_state_test
|
||||
def test_pending_deposit_balance_above_churn(spec, state):
|
||||
@ -416,6 +481,49 @@ def test_pending_deposit_balance_above_churn(spec, state):
|
||||
]
|
||||
|
||||
|
||||
@with_electra_and_later
|
||||
@spec_state_test
|
||||
def test_top_up__max_effective_balance(spec, state):
|
||||
validator_index = 0
|
||||
amount = spec.MAX_EFFECTIVE_BALANCE // 4
|
||||
wc = state.validators[validator_index].withdrawal_credentials
|
||||
pd = build_pending_deposit(spec, validator_index,
|
||||
amount=amount,
|
||||
withdrawal_credentials=wc,
|
||||
signed=True)
|
||||
state.pending_deposits.append(pd)
|
||||
|
||||
state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE
|
||||
state.validators[validator_index].effective_balance = spec.MAX_EFFECTIVE_BALANCE
|
||||
|
||||
yield from run_process_pending_deposits(spec, state)
|
||||
|
||||
assert state.validators[validator_index].effective_balance == spec.MAX_EFFECTIVE_BALANCE
|
||||
|
||||
|
||||
@with_electra_and_later
|
||||
@spec_state_test
|
||||
def test_top_up__less_effective_balance(spec, state):
|
||||
validator_index = 0
|
||||
amount = spec.MAX_EFFECTIVE_BALANCE // 4
|
||||
wc = state.validators[validator_index].withdrawal_credentials
|
||||
pd = build_pending_deposit(spec, validator_index,
|
||||
amount=amount,
|
||||
withdrawal_credentials=wc,
|
||||
signed=True)
|
||||
state.pending_deposits.append(pd)
|
||||
|
||||
initial_balance = spec.MAX_EFFECTIVE_BALANCE - 1000
|
||||
initial_effective_balance = spec.MAX_EFFECTIVE_BALANCE - spec.EFFECTIVE_BALANCE_INCREMENT
|
||||
state.balances[validator_index] = initial_balance
|
||||
state.validators[validator_index].effective_balance = initial_effective_balance
|
||||
|
||||
yield from run_process_pending_deposits(spec, state)
|
||||
|
||||
# unchanged effective balance
|
||||
assert state.validators[validator_index].effective_balance == initial_effective_balance
|
||||
|
||||
|
||||
@with_electra_and_later
|
||||
@spec_state_test
|
||||
def test_pending_deposit_preexisting_churn(spec, state):
|
||||
|
Loading…
x
Reference in New Issue
Block a user