Skip to content

packages.valory.skills.abstract_round_abci.tests.test_common

Test the common.py module of the skill.

test_random_selection

def test_random_selection() -> None

Test 'random_selection'

DummyRandomnessBehaviour Objects

class DummyRandomnessBehaviour(RandomnessBehaviour)

Dummy randomness behaviour.

DummySelectKeeperBehaviour Objects

class DummySelectKeeperBehaviour(SelectKeeperBehaviour)

Dummy select keeper behaviour.

BaseDummyBehaviour Objects

class BaseDummyBehaviour()

A Base dummy behaviour class.

setup_class

@classmethod
def setup_class(cls) -> None

Setup the test class.

dummy_generator

def dummy_generator(
    return_value: ReturnValueType
) -> Callable[[Any, Any], Generator[None, None, ReturnValueType]]

A method that returns a dummy generator which yields nothing once and then returns the given return_value.

last_iteration

def last_iteration(gen: Generator) -> None

Perform a generator iteration and ensure that it is the last one.

TestRandomnessBehaviour Objects

class TestRandomnessBehaviour(BaseDummyBehaviour)

Test RandomnessBehaviour.

setup_class

@classmethod
def setup_class(cls) -> None

Setup the test class.

test_failsafe_randomness

@pytest.mark.parametrize(
    "return_value, expected_hash",
    (
        (MagicMock(performative=LedgerApiMessage.Performative.ERROR), None),
        (MagicMock(state=MagicMock(body={"hash_key_is_not_in_body": ""})),
         None),
        (
            MagicMock(state=MagicMock(body={"hash": "test_randomness"})),
            {
                "randomness":
                "d067b86fa5235e7e5225e8328e8faac5c279cbf57131d647e4da0a70df6d3d7b",
                "round": 0,
            },
        ),
    ),
)
def test_failsafe_randomness(return_value: MagicMock,
                             expected_hash: Optional[str]) -> None

Test failsafe_randomness.

test_get_randomness_from_api

@pytest.mark.parametrize("randomness_response", ("test", None))
@pytest.mark.parametrize("verified", (True, False))
def test_get_randomness_from_api(randomness_response: Optional[str],
                                 verified: bool) -> None

Test get_randomness_from_api.

test_async_act

@pytest.mark.parametrize(
    "retries_exceeded, failsafe_succeeds",
    # (False, False) is not tested, because it does not make sense
    ((True, False), (True, True), (False, True)),
)
@pytest.mark.parametrize(
    "observation",
    (
        None,
        {},
        {
            "randomness":
            "d067b86fa5235e7e5225e8328e8faac5c279cbf57131d647e4da0a70df6d3d7b",
            "round": 0,
        },
    ),
)
def test_async_act(retries_exceeded: bool, failsafe_succeeds: bool,
                   observation: Optional[Dict[str, Union[str, int]]]) -> None

Test async_act.

test_clean_up

def test_clean_up() -> None

Test clean_up.

teardown_method

def teardown_method() -> None

Teardown run after each test method.

TestSelectKeeperBehaviour Objects

class TestSelectKeeperBehaviour(BaseDummyBehaviour)

Tests for SelectKeeperBehaviour.

setup_class

@classmethod
def setup_class(cls) -> None

Setup the test class.

test_select_keeper

@mock.patch.object(random, "shuffle", lambda do_not_shuffle: do_not_shuffle)
@pytest.mark.parametrize(
    "participants, blacklisted_keepers, most_voted_keeper_address, expected_keeper",
    (
        (
            frozenset((f"test_p{i}" for i in range(4))),
            set(),
            "test_p0",
            "test_p1",
        ),
        (
            frozenset((f"test_p{i}" for i in range(4))),
            set(),
            "test_p1",
            "test_p2",
        ),
        (
            frozenset((f"test_p{i}" for i in range(4))),
            set(),
            "test_p2",
            "test_p3",
        ),
        (
            frozenset((f"test_p{i}" for i in range(4))),
            set(),
            "test_p3",
            "test_p0",
        ),
        (
            frozenset((f"test_p{i}" for i in range(4))),
            {f"test_p{i}"
             for i in range(1)},
            "test_p1",
            "test_p2",
        ),
        (
            frozenset((f"test_p{i}" for i in range(4))),
            {f"test_p{i}"
             for i in range(4)},
            "",
            "",
        ),
    ),
)
def test_select_keeper(participants: FrozenSet[str],
                       blacklisted_keepers: Set[str],
                       most_voted_keeper_address: str,
                       expected_keeper: str) -> None

Test _select_keeper.

test_async_act

def test_async_act() -> None

Test async_act.