Skip to content

Commit

Permalink
test script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravleen-Solulab committed Sep 10, 2024
1 parent 6741162 commit 995a61b
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
Optional,
Type,
)

from unittest import mock
from unittest.mock import MagicMock, Mock

import pytest
Expand All @@ -42,18 +44,38 @@
VotingRound,
get_name,
)
from packages.valory.skills.mech_interact_abci.states.request import MechRequestRound
from packages.valory.skills.abstract_round_abci.test_tools.rounds import (
BaseVotingRoundTest,
BaseCollectSameUntilThresholdRoundTest,
)
from packages.valory.skills.decision_maker_abci.payloads import VotingPayload

from packages.valory.skills.decision_maker_abci.states.bet_placement import (
BetPlacementRound,
)

from packages.valory.skills.tx_settlement_multiplexer_abci.rounds import (
PreTxSettlementRound,
TxSettlementMultiplexerAbciApp,
PostTxSettlementRound,
PreTxSettlementRound,
Event,
ChecksPassedRound,
FinishedBetPlacementTxRound,
FinishedMechRequestTxRound,
FinishedRedeemingTxRound,
FinishedStakingTxRound,
FinishedSubscriptionTxRound,
FailedMultiplexerRound,
SynchronizedData,
BetPlacementRound,
MechRequestRound,
RedeemRound,
CallCheckpointRound,
SubscriptionRound,
)


DUMMY_PAYLOAD_DATA = {"example_key": "example_value"}


Expand Down Expand Up @@ -221,7 +243,7 @@ class BasePostTxSettlementRoundTest(BaseCollectSameUntilThresholdRoundTest):
_event_class = Event
round_class = PostTxSettlementRound

def run_test(self, test_case: RoundTestCase, **kwargs: Any) -> None:
def run_test(self, test_case: RoundTestCase) -> None:
"""Run the test"""

# Set initial data
Expand All @@ -244,4 +266,134 @@ def run_test(self, test_case: RoundTestCase, **kwargs: Any) -> None:
)
)





class TestPostTxSettlementRound(BasePostTxSettlementRoundTest):
"""Tests for PostTxSettlementRound."""

round_class = PostTxSettlementRound

@pytest.mark.parametrize(
"test_case",
[
RoundTestCase(
name="Mech Requesting Done",
initial_data={"tx_submitter": MechRequestRound.auto_round_id()},
payloads={},
final_data={},
event=Event.MECH_REQUESTING_DONE,
most_voted_payload="mech_tool",
synchronized_data_attr_checks=[
lambda synchronized_data: synchronized_data.tx_submitter
== MechRequestRound.auto_round_id(),
],
),
RoundTestCase(
name="Bet Placement Done",
initial_data={"tx_submitter": BetPlacementRound.auto_round_id()},
payloads={},
final_data={},
event=Event.BET_PLACEMENT_DONE,
most_voted_payload="mech_tool",
synchronized_data_attr_checks=[
lambda synchronized_data: synchronized_data.tx_submitter
== BetPlacementRound.auto_round_id(),
],
),
RoundTestCase(
name="Redeeming Done",
initial_data={"tx_submitter": RedeemRound.auto_round_id()},
payloads={},
final_data={},
event=Event.REDEEMING_DONE,
most_voted_payload="mech_tool",
synchronized_data_attr_checks=[
lambda synchronized_data: synchronized_data.tx_submitter
== RedeemRound.auto_round_id(),
],
),
RoundTestCase(
name="Staking Done",
initial_data={"tx_submitter": CallCheckpointRound.auto_round_id()},
payloads={},
final_data={},
event=Event.STAKING_DONE,
most_voted_payload="mech_tool",
synchronized_data_attr_checks=[
lambda synchronized_data: synchronized_data.tx_submitter
== CallCheckpointRound.auto_round_id(),
],
),
RoundTestCase(
name="Subscription Done",
initial_data={"tx_submitter": SubscriptionRound.auto_round_id()},
payloads={},
final_data={},
event=Event.SUBSCRIPTION_DONE,
most_voted_payload="mech_tool",
synchronized_data_attr_checks=[
lambda synchronized_data: synchronized_data.tx_submitter
== SubscriptionRound.auto_round_id(),
],
),
RoundTestCase(
name="Unknown Submitter",
initial_data={"tx_submitter": "unknown_submitter"},
payloads={},
final_data={},
event=Event.UNRECOGNIZED,
most_voted_payload=None,
synchronized_data_attr_checks=[
lambda synchronized_data: synchronized_data.tx_submitter
== "unknown_submitter",
],
),
],
)
def test_run(self, test_case: RoundTestCase) -> None:
"""Run the test."""
self.run_test(test_case)


def test_tx_settlement_abci_app_initialization() -> None:
"""Test the initialization of TxSettlementMultiplexerAbciApp."""
abci_app = TxSettlementMultiplexerAbciApp(
synchronized_data=MagicMock(), logger=MagicMock(), context=MagicMock()
)
assert abci_app.initial_round_cls is PreTxSettlementRound
assert abci_app.final_states == {
ChecksPassedRound,
FinishedMechRequestTxRound,
FinishedBetPlacementTxRound,
FinishedRedeemingTxRound,
FinishedStakingTxRound,
FinishedSubscriptionTxRound,
FailedMultiplexerRound,
}
assert abci_app.transition_function == {
PreTxSettlementRound: {
Event.CHECKS_PASSED: ChecksPassedRound,
Event.REFILL_REQUIRED: PreTxSettlementRound,
Event.NO_MAJORITY: PreTxSettlementRound,
Event.ROUND_TIMEOUT: PreTxSettlementRound,
},
PostTxSettlementRound: {
Event.MECH_REQUESTING_DONE: FinishedMechRequestTxRound,
Event.BET_PLACEMENT_DONE: FinishedBetPlacementTxRound,
Event.REDEEMING_DONE: FinishedRedeemingTxRound,
Event.STAKING_DONE: FinishedStakingTxRound,
Event.SUBSCRIPTION_DONE: FinishedSubscriptionTxRound,
Event.ROUND_TIMEOUT: PostTxSettlementRound,
Event.UNRECOGNIZED: FailedMultiplexerRound,
},
ChecksPassedRound: {},
FinishedMechRequestTxRound: {},
FinishedBetPlacementTxRound: {},
FinishedRedeemingTxRound: {},
FinishedStakingTxRound: {},
FinishedSubscriptionTxRound: {},
FailedMultiplexerRound: {},
}
assert abci_app.event_to_timeout == {Event.ROUND_TIMEOUT: 30.0}
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ commands =
pytest -rfE {env:SKILLS_PATHS}/check_stop_trading_abci/tests --cov={env:SKILLS_PATHS}/check_stop_trading_abci --cov-report=xml --cov-report=term --cov-report=term-missing --cov-config=.coveragerc {posargs}
pytest -rfE {env:SKILLS_PATHS}/market_manager_abci/tests --cov={env:SKILLS_PATHS}/market_manager_abci --cov-report=xml --cov-report=term --cov-report=term-missing --cov-config=.coveragerc {posargs}
pytest -rfE {env:SKILLS_PATHS}/staking_abci/tests --cov={env:SKILLS_PATHS}/staking_abci --cov-report=xml --cov-report=term --cov-report=term-missing --cov-config=.coveragerc {posargs}

pytest -rfE {env:SKILLS_PATHS}/tx_settlement_multiplexer_abci/tests --cov={env:SKILLS_PATHS}/tx_settlement_multiplexer_abci --cov-report=xml --cov-report=term --cov-report=term-missing --cov-config=.coveragerc {posargs}
[testenv:py3.8-linux]
basepython = python3.8
platform=^linux$
Expand Down

0 comments on commit 995a61b

Please sign in to comment.