Skip to content

Commit ea0c27d

Browse files
committed
Add test_min_empty_validator_index
1 parent 3fc6b4c commit ea0c27d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/beacon/test_deposit_helpers.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
get_domain,
1818
)
1919
from eth.beacon.deposit_helpers import (
20+
min_empty_validator_index,
2021
process_deposit,
2122
validate_proof_of_possession,
2223
)
2324
from eth.beacon.types.states import BeaconState
2425
from eth.beacon.types.deposit_input import DepositInput
26+
from eth.beacon.types.validator_records import ValidatorRecord
2527

2628

2729
def sign_proof_of_possession(deposit_input, privkey, domain):
@@ -37,6 +39,41 @@ def make_deposit_input(pubkey, withdrawal_credentials, randao_commitment):
3739
)
3840

3941

42+
@pytest.mark.parametrize(
43+
"balance,"
44+
"latest_status_change_slot,"
45+
"zero_balance_validator_ttl,"
46+
"current_slot,"
47+
"expected",
48+
(
49+
(0, 1, 1, 2, 0),
50+
(1, 1, 1, 2, None), # not (balance == 0)
51+
(0, 1, 1, 1, None), # not (validator.latest_status_change_slot + zero_balance_validator_ttl <= current_slot) # noqa: E501
52+
),
53+
)
54+
def test_min_empty_validator_index(sample_validator_record_params,
55+
balance,
56+
latest_status_change_slot,
57+
zero_balance_validator_ttl,
58+
current_slot,
59+
expected):
60+
validators = [
61+
ValidatorRecord(**sample_validator_record_params).copy(
62+
balance=balance,
63+
latest_status_change_slot=latest_status_change_slot,
64+
)
65+
for _ in range(10)
66+
]
67+
68+
result = min_empty_validator_index(
69+
validators=validators,
70+
current_slot=current_slot,
71+
zero_balance_validator_ttl=zero_balance_validator_ttl,
72+
)
73+
74+
assert result == expected
75+
76+
4077
@pytest.mark.parametrize(
4178
"expected",
4279
(

0 commit comments

Comments
 (0)