From 919f8da515e0d755997a8dd70662226bbab3ccc9 Mon Sep 17 00:00:00 2001 From: hweawer Date: Wed, 18 Sep 2024 13:48:55 +0200 Subject: [PATCH] Move generation to the model --- tests/factory/no_registry.py | 8 +++++++- tests/modules/ejector/test_iterator_v2.py | 21 ++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) 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 5847b9fb7..6260f5ec3 100644 --- a/tests/modules/ejector/test_iterator_v2.py +++ b/tests/modules/ejector/test_iterator_v2.py @@ -130,26 +130,21 @@ def test_eject_validator(iterator): ] ) - def generate_validator_state_with_activation_epoch_bound(): - return ValidatorStateFactory.build( - activation_epoch=str(faker.pyint(max_value=iterator.blockstamp.ref_epoch - 1)) - ) - iterator.w3.lido_validators.get_lido_validators_by_node_operators = Mock( return_value={ (1, 1): [ - LidoValidatorFactory.build(validator=generate_validator_state_with_activation_epoch_bound()), - LidoValidatorFactory.build(validator=generate_validator_state_with_activation_epoch_bound()), - LidoValidatorFactory.build(validator=generate_validator_state_with_activation_epoch_bound()), + 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(validator=generate_validator_state_with_activation_epoch_bound()), - LidoValidatorFactory.build(validator=generate_validator_state_with_activation_epoch_bound()), + 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', validator=generate_validator_state_with_activation_epoch_bound()), - LidoValidatorFactory.build(index='7', validator=generate_validator_state_with_activation_epoch_bound()), - LidoValidatorFactory.build(index='6', validator=generate_validator_state_with_activation_epoch_bound()), + 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'), ], } )