packages.valory.skills.abstract_round_abci.tests.test_behaviours
Test the behaviours.py module of the skill.
test_skill_public_id
def test_skill_public_id() -> None
Test skill module public ID
RoundA Objects
class RoundA(AbstractRound)
Round A.
end_block
def end_block() -> Optional[Tuple[BaseSynchronizedData, EventType]]
End block.
check_payload
def check_payload(payload: BaseTxPayload) -> None
Check payload.
process_payload
def process_payload(payload: BaseTxPayload) -> None
Process payload.
RoundB Objects
class RoundB(AbstractRound)
Round B.
end_block
def end_block() -> Optional[Tuple[BaseSynchronizedData, EventType]]
End block.
check_payload
def check_payload(payload: BaseTxPayload) -> None
Check payload.
process_payload
def process_payload(payload: BaseTxPayload) -> None
Process payload.
ConcreteBackgroundRound Objects
class ConcreteBackgroundRound(AbstractRound)
Concrete Background Round.
end_block
def end_block() -> Optional[Tuple[BaseSynchronizedData, EventType]]
End block.
check_payload
def check_payload(payload: BaseTxPayload) -> None
Check payload.
process_payload
def process_payload(payload: BaseTxPayload) -> None
Process payload.
BehaviourA Objects
class BehaviourA(BaseBehaviour)
Dummy behaviour.
__init__
def __init__(*args: Any, **kwargs: Any) -> None
Initialize behaviour.
setup
def setup() -> None
Setup behaviour.
async_act
def async_act() -> Generator
Dummy act method.
BehaviourB Objects
class BehaviourB(BaseBehaviour)
Dummy behaviour.
async_act
def async_act() -> Generator
Dummy act method.
BehaviourC Objects
class BehaviourC(BaseBehaviour, ABC)
Dummy behaviour.
test_auto_behaviour_id
def test_auto_behaviour_id() -> None
Test that the 'auto_behaviour_id()' method works as expected.
ConcreteBackgroundBehaviour Objects
class ConcreteBackgroundBehaviour(BaseBehaviour)
Dummy behaviour.
async_act
def async_act() -> Generator
Dummy act method.
ConcreteAbciApp Objects
class ConcreteAbciApp(AbciApp)
Concrete ABCI App.
ConcreteRoundBehaviour Objects
class ConcreteRoundBehaviour(AbstractRoundBehaviour)
Concrete round behaviour.
behaviours
type: ignore
background_behaviours_cls
type: ignore
TestAbstractRoundBehaviour Objects
class TestAbstractRoundBehaviour()
Test 'AbstractRoundBehaviour' class.
setup_method
def setup_method() -> None
Set up the tests.
test_setup
@pytest.mark.parametrize("use_termination", (True, False))
def test_setup(use_termination: bool) -> None
Test 'setup' method.
test_setup_pending_offences_included_when_slashing_enabled
def test_setup_pending_offences_included_when_slashing_enabled() -> None
Test that PendingOffencesBehaviour is included when use_slashing=True.
test_teardown
def test_teardown() -> None
Test 'teardown' method.
test_current_behaviour_return_none
def test_current_behaviour_return_none() -> None
Test 'current_behaviour' property return None.
test_act_current_behaviour_name_is_none
def test_act_current_behaviour_name_is_none() -> None
Test 'act' with current behaviour None.
test_check_matching_round_consistency_no_behaviour
@pytest.mark.parametrize(
"no_round, error",
(
(
True,
"Behaviour 'behaviour_without_round' specifies unknown 'unknown' as a matching round. "
"Please make sure that the round is implemented and belongs to the FSM. "
"If 'behaviour_without_round' is a background behaviour, please make sure that it is set correctly, "
"by overriding the corresponding attribute of the chained skill's behaviour.",
),
(False, "round round_1 is not a matching round of any behaviour"),
),
)
def test_check_matching_round_consistency_no_behaviour(no_round: bool,
error: str) -> None
Test classmethod '_check_matching_round_consistency', when no behaviour or round is specified.
test_check_matching_round_consistency
def test_check_matching_round_consistency() -> None
Test classmethod '_check_matching_round_consistency', negative case.
test_check_matching_round_consistency_with_bg_rounds
@pytest.mark.parametrize("behaviour_cls", (set(), {MagicMock()}))
def test_check_matching_round_consistency_with_bg_rounds(
behaviour_cls: set) -> None
Test classmethod '_check_matching_round_consistency' when a background behaviour class is set.
test_get_behaviour_id_to_behaviour_mapping_negative
def test_get_behaviour_id_to_behaviour_mapping_negative() -> None
Test classmethod '_get_behaviour_id_to_behaviour_mapping', negative case.
test_get_round_to_behaviour_mapping_two_behaviours_same_round
def test_get_round_to_behaviour_mapping_two_behaviours_same_round() -> None
Test classmethod '_get_round_to_behaviour_mapping' when two different behaviours point to the same round.
test_get_round_to_behaviour_mapping_with_final_rounds
def test_get_round_to_behaviour_mapping_with_final_rounds() -> None
Test classmethod '_get_round_to_behaviour_mapping' with final rounds.
test_check_behaviour_id_uniqueness_negative
def test_check_behaviour_id_uniqueness_negative() -> None
Test metaclass method '_check_consistency', negative case.
test_check_consistency_two_behaviours_same_round
def test_check_consistency_two_behaviours_same_round() -> None
Test metaclass method '_check_consistency' when two different behaviours point to the same round.
test_check_initial_behaviour_in_set_of_behaviours_negative_case
def test_check_initial_behaviour_in_set_of_behaviours_negative_case() -> None
Test classmethod '_check_initial_behaviour_in_set_of_behaviours' when initial behaviour is NOT in the set.
test_act_no_round_change
def test_act_no_round_change() -> None
Test the 'act' method of the behaviour, with no round change.
test_act_behaviour_setup
def test_act_behaviour_setup() -> None
Test the 'act' method of the FSM behaviour triggers setup() of the behaviour.
test_act_with_round_change
def test_act_with_round_change() -> None
Test the 'act' method of the behaviour, with round change.
test_act_with_round_change_after_current_behaviour_is_none
def test_act_with_round_change_after_current_behaviour_is_none() -> None
Test the 'act' method of the behaviour, with round change, after cur behaviour is none.
test_termination_behaviour_acting
@mock.patch.object(
AbstractRoundBehaviour,
"_process_current_round",
)
@mock.patch.object(
TmManager,
"tm_communication_unhealthy",
new_callable=mock.PropertyMock,
return_value=False,
)
@mock.patch.object(
TmManager,
"is_acting",
new_callable=mock.PropertyMock,
return_value=False,
)
@pytest.mark.parametrize("expected_termination_acting", (True, False))
def test_termination_behaviour_acting(
_: mock._patch, __: mock._patch, ___: mock._patch,
expected_termination_acting: bool) -> None
Test if the termination background behaviour is acting only when it should.
test_try_fix_call
@mock.patch.object(
AbstractRoundBehaviour,
"_process_current_round",
)
@pytest.mark.parametrize(
("mock_tm_communication_unhealthy", "mock_is_acting", "expected_fix"),
[
(True, True, True),
(False, True, True),
(True, False, True),
(False, False, False),
],
)
def test_try_fix_call(_: mock._patch, mock_tm_communication_unhealthy: bool,
mock_is_acting: bool, expected_fix: bool) -> None
Test that try_fix is called when necessary.
test_meta_round_behaviour_when_instance_not_subclass_of_abstract_round_behaviour
def test_meta_round_behaviour_when_instance_not_subclass_of_abstract_round_behaviour(
) -> (None)
Test instantiation of meta class when instance not a subclass of abstract round behaviour.
test_abstract_round_behaviour_instantiation_without_attributes_raises_error
def test_abstract_round_behaviour_instantiation_without_attributes_raises_error(
) -> (None)
Test that definition of concrete subclass of AbstractRoundBehavior without attributes raises error.
test_abstract_round_behaviour_matching_rounds_not_covered
def test_abstract_round_behaviour_matching_rounds_not_covered() -> None
Test that definition of concrete subclass of AbstractRoundBehavior when matching round not covered.
test_self_loops_in_abci_app_reinstantiate_behaviour
@mock.patch.object(
BaseBehaviour,
"tm_communication_unhealthy",
new_callable=mock.PropertyMock,
return_value=False,
)
def test_self_loops_in_abci_app_reinstantiate_behaviour(
_: mock._patch) -> None
Test that a self-loop transition in the AbciApp will trigger a transition in the round behaviour.
LongRunningBehaviour Objects
class LongRunningBehaviour(BaseBehaviour)
A behaviour that runs forevever.
async_act
def async_act() -> Generator
An act method that simply cycles forever.
test_reset_should_be_performed_when_tm_unhealthy
def test_reset_should_be_performed_when_tm_unhealthy() -> None
Test that hard reset is performed while a behaviour is running, and tendermint communication is unhealthy.
TestPendingOffencesBehaviour Objects
class TestPendingOffencesBehaviour()
Tests for PendingOffencesBehaviour.
setup_class
@classmethod
def setup_class(cls) -> None
Setup the test class.
test_pending_offences_act
@pytest.mark.skipif(
platform.system() == "Windows",
reason="`timegm` behaves differently on Windows. "
"As a result, the generation of `last_transition_timestamp` is invalid.",
)
@given(
offence=st.builds(
PendingOffense,
accused_agent_address=st.text(),
round_count=st.integers(min_value=0),
offense_type=st.sampled_from(OffenseType),
last_transition_timestamp=st.floats(
min_value=timegm(datetime(1971, 1, 1).utctimetuple()),
max_value=timegm(datetime(8000, 1, 1).utctimetuple()) - 2000,
),
time_to_live=st.floats(min_value=1, max_value=2000),
),
wait_ticks=st.integers(min_value=0, max_value=1000),
expired=st.booleans(),
)
def test_pending_offences_act(offence: PendingOffense, wait_ticks: int,
expired: bool) -> None
Test PendingOffencesBehaviour.