Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test #518

Merged
merged 8 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tests/factory/no_registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
from itertools import count
from typing import Any

from faker import Faker
from pydantic_factories import Use
Expand All @@ -10,7 +11,6 @@
from tests.factory.web3_factory import Web3Factory
from src.web3py.extensions.lido_validators import StakingModule, LidoValidator, NodeOperator


faker = Faker()


Expand Down Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions tests/modules/ejector/test_iterator_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand All @@ -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'),
],
}
)
Expand Down
Loading