Skip to content

Commit

Permalink
Move generation to the model
Browse files Browse the repository at this point in the history
  • Loading branch information
hweawer committed Sep 18, 2024
1 parent 87ee53f commit 919f8da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
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
21 changes: 8 additions & 13 deletions tests/modules/ejector/test_iterator_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
}
)
Expand Down

0 comments on commit 919f8da

Please sign in to comment.