diff --git a/tests/factory/no_registry.py b/tests/factory/no_registry.py index 140fdf44b..6e23eb701 100644 --- a/tests/factory/no_registry.py +++ b/tests/factory/no_registry.py @@ -1,5 +1,6 @@ import random from itertools import count +from typing import Any from faker import Faker from pydantic_factories import Use @@ -10,7 +11,6 @@ from tests.factory.web3_factory import Web3Factory from src.web3py.extensions.lido_validators import StakingModule, LidoValidator, NodeOperator - faker = Faker() @@ -47,6 +47,12 @@ class LidoValidatorFactory(Web3Factory): index: str = Use(lambda x: str(next(x)), count(1)) balance: str = Use(lambda x: str(x), random.randrange(1, 10**9)) + @classmethod + def build_with_activation_epoch_bound(cls, max_value: int, **kwargs: Any): + return cls.build( + validator=ValidatorStateFactory.build(activation_epoch=str(faker.pyint(max_value=max_value - 1))), **kwargs + ) + class NodeOperatorFactory(Web3Factory): __model__ = NodeOperator diff --git a/tests/modules/ejector/test_iterator_v2.py b/tests/modules/ejector/test_iterator_v2.py index 57fd087cb..877538841 100644 --- a/tests/modules/ejector/test_iterator_v2.py +++ b/tests/modules/ejector/test_iterator_v2.py @@ -6,7 +6,11 @@ from src.services.exit_order_v2.iterator import ValidatorExitIteratorV2, NodeOperatorStats, StakingModuleStats from src.web3py.extensions.lido_validators import NodeOperatorLimitMode from tests.factory.blockstamp import ReferenceBlockStampFactory -from tests.factory.no_registry import NodeOperatorFactory, StakingModuleFactory, LidoValidatorFactory +from tests.factory.no_registry import ( + NodeOperatorFactory, + StakingModuleFactory, + LidoValidatorFactory, +) from tests.factory.web3_factory import Web3Factory @@ -95,12 +99,14 @@ def test_eject_validator(iterator): ) no_1 = NodeOperatorFactory.build( + id=1, staking_module=sk_1, total_deposited_validators=3, target_validators_count=1, is_target_limit_active=NodeOperatorLimitMode.FORCE, ) no_2 = NodeOperatorFactory.build( + id=2, staking_module=sk_1, total_deposited_validators=2, is_target_limit_active=NodeOperatorLimitMode.SOFT, @@ -122,12 +128,19 @@ def test_eject_validator(iterator): iterator.w3.lido_validators.get_lido_validators_by_node_operators = Mock( return_value={ - (1, 1): [LidoValidatorFactory.build(), LidoValidatorFactory.build(), LidoValidatorFactory.build()], - (1, 2): [LidoValidatorFactory.build(), LidoValidatorFactory.build()], + (1, 1): [ + LidoValidatorFactory.build_with_activation_epoch_bound(iterator.blockstamp.ref_epoch), + LidoValidatorFactory.build_with_activation_epoch_bound(iterator.blockstamp.ref_epoch), + LidoValidatorFactory.build_with_activation_epoch_bound(iterator.blockstamp.ref_epoch), + ], + (1, 2): [ + LidoValidatorFactory.build_with_activation_epoch_bound(iterator.blockstamp.ref_epoch), + LidoValidatorFactory.build_with_activation_epoch_bound(iterator.blockstamp.ref_epoch), + ], (2, 1): [ - LidoValidatorFactory.build(index='8'), - LidoValidatorFactory.build(index='7'), - LidoValidatorFactory.build(index='6'), + LidoValidatorFactory.build_with_activation_epoch_bound(iterator.blockstamp.ref_epoch, index='8'), + LidoValidatorFactory.build_with_activation_epoch_bound(iterator.blockstamp.ref_epoch, index='7'), + LidoValidatorFactory.build_with_activation_epoch_bound(iterator.blockstamp.ref_epoch, index='6'), ], } )