|
| 1 | +from eth2spec.test.helpers.deposits import mock_deposit |
| 2 | +from eth2spec.test.helpers.state import next_epoch |
| 3 | +from eth2spec.test.context import spec_state_test, with_electra_and_later |
| 4 | +from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with |
| 5 | +from eth2spec.test.helpers.withdrawals import ( |
| 6 | + set_eth1_withdrawal_credential_with_balance, |
| 7 | + set_compounding_withdrawal_credential_with_balance |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +def run_test_activation_queue_eligibility(spec, state, validator_index, balance): |
| 12 | + # move past first two irregular epochs wrt finality |
| 13 | + next_epoch(spec, state) |
| 14 | + next_epoch(spec, state) |
| 15 | + |
| 16 | + state.balances[validator_index] = balance |
| 17 | + state.validators[validator_index].effective_balance = balance |
| 18 | + |
| 19 | + # ready for entrance into activation queue |
| 20 | + mock_deposit(spec, state, validator_index) |
| 21 | + |
| 22 | + yield from run_epoch_processing_with(spec, state, 'process_registry_updates') |
| 23 | + |
| 24 | + # validator moved into activation queue if eligible |
| 25 | + validator = state.validators[validator_index] |
| 26 | + if validator.effective_balance < spec.MIN_ACTIVATION_BALANCE: |
| 27 | + assert validator.activation_eligibility_epoch == spec.FAR_FUTURE_EPOCH |
| 28 | + else: |
| 29 | + assert validator.activation_eligibility_epoch < spec.FAR_FUTURE_EPOCH |
| 30 | + |
| 31 | + |
| 32 | +@with_electra_and_later |
| 33 | +@spec_state_test |
| 34 | +def test_activation_queue_eligibility__less_than_min_activation_balance(spec, state): |
| 35 | + # move past first two irregular epochs wrt finality |
| 36 | + next_epoch(spec, state) |
| 37 | + next_epoch(spec, state) |
| 38 | + |
| 39 | + index = 3 |
| 40 | + balance = spec.MIN_ACTIVATION_BALANCE - spec.EFFECTIVE_BALANCE_INCREMENT |
| 41 | + yield from run_test_activation_queue_eligibility(spec, state, index, balance) |
| 42 | + |
| 43 | + |
| 44 | +@with_electra_and_later |
| 45 | +@spec_state_test |
| 46 | +def test_activation_queue_eligibility__min_activation_balance(spec, state): |
| 47 | + # move past first two irregular epochs wrt finality |
| 48 | + next_epoch(spec, state) |
| 49 | + next_epoch(spec, state) |
| 50 | + |
| 51 | + index = 5 |
| 52 | + balance = spec.MIN_ACTIVATION_BALANCE |
| 53 | + yield from run_test_activation_queue_eligibility(spec, state, index, balance) |
| 54 | + |
| 55 | + |
| 56 | +@with_electra_and_later |
| 57 | +@spec_state_test |
| 58 | +def test_activation_queue_eligibility__min_activation_balance_eth1_creds(spec, state): |
| 59 | + # move past first two irregular epochs wrt finality |
| 60 | + next_epoch(spec, state) |
| 61 | + next_epoch(spec, state) |
| 62 | + |
| 63 | + index = 7 |
| 64 | + balance = spec.MIN_ACTIVATION_BALANCE |
| 65 | + set_eth1_withdrawal_credential_with_balance(spec, state, index) |
| 66 | + yield from run_test_activation_queue_eligibility(spec, state, index, balance) |
| 67 | + |
| 68 | + |
| 69 | +@with_electra_and_later |
| 70 | +@spec_state_test |
| 71 | +def test_activation_queue_eligibility__min_activation_balance_compounding_creds(spec, state): |
| 72 | + # move past first two irregular epochs wrt finality |
| 73 | + next_epoch(spec, state) |
| 74 | + next_epoch(spec, state) |
| 75 | + |
| 76 | + index = 11 |
| 77 | + balance = spec.MIN_ACTIVATION_BALANCE |
| 78 | + set_compounding_withdrawal_credential_with_balance(spec, state, index) |
| 79 | + yield from run_test_activation_queue_eligibility(spec, state, index, balance) |
| 80 | + |
| 81 | + |
| 82 | +@with_electra_and_later |
| 83 | +@spec_state_test |
| 84 | +def test_activation_queue_eligibility__greater_than_min_activation_balance(spec, state): |
| 85 | + # move past first two irregular epochs wrt finality |
| 86 | + next_epoch(spec, state) |
| 87 | + next_epoch(spec, state) |
| 88 | + |
| 89 | + index = 13 |
| 90 | + balance = spec.MIN_ACTIVATION_BALANCE + spec.EFFECTIVE_BALANCE_INCREMENT |
| 91 | + set_compounding_withdrawal_credential_with_balance(spec, state, index) |
| 92 | + yield from run_test_activation_queue_eligibility(spec, state, index, balance) |
0 commit comments