From 76c9a3b83ef53a649751650f9f9e8dd6ae9d485f Mon Sep 17 00:00:00 2001 From: Ravleen-Solulab Date: Fri, 6 Sep 2024 15:42:44 +0530 Subject: [PATCH 1/6] test script --- .../tests/test_dialogues.py | 29 ++ .../tests/test_rounds.py | 247 ++++++++++++++++++ 2 files changed, 276 insertions(+) create mode 100644 packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_dialogues.py create mode 100644 packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_dialogues.py b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_dialogues.py new file mode 100644 index 000000000..13b66e7d3 --- /dev/null +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_dialogues.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# ------------------------------------------------------------------------------ +# +# Copyright 2021-2024 Valory AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------------ + +"""Test the dialogues.py module of the skill.""" + +# pylint: skip-file + + +import packages.valory.skills.tx_settlement_multiplexer_abci.dialogues # noqa + + +def test_import() -> None: + """Test that the 'dialogues.py' Python module can be imported.""" \ No newline at end of file diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py new file mode 100644 index 000000000..23fb70abc --- /dev/null +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py @@ -0,0 +1,247 @@ +# -*- coding: utf-8 -*- +# ------------------------------------------------------------------------------ +# +# Copyright 2023-2024 Valory AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------------ + +"""This package contains the tests for the PreTxSettlementRound of TxSettlementMultiplexerAbciApp.""" + +import json +from dataclasses import dataclass, field +from typing import ( + Any, + Callable, + Dict, + FrozenSet, + Hashable, + List, + Mapping, + Optional, + Type, +) +from unittest.mock import MagicMock, Mock + +import pytest + +from packages.valory.skills.abstract_round_abci.base import ( + AbciAppDB, + CollectionRound, + VotingRound, + get_name, +) +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.tx_settlement_multiplexer_abci.rounds import ( + PreTxSettlementRound, + PostTxSettlementRound, + Event, + SynchronizedData, +) + +DUMMY_PAYLOAD_DATA = {"example_key": "example_value"} + + +def get_participants() -> FrozenSet[str]: + """Participants.""" + return frozenset([f"agent_{i}" for i in range(MAX_PARTICIPANTS)]) + +def get_participant_to_votes( + participants: FrozenSet[str], vote: bool +) -> Dict[str, VotingPayload]: + """participant_to_votes""" + + return { + participant: VotingPayload(sender=participant, vote=vote) + for participant in participants + } + + +def get_participant_to_votes_serialized( + participants: FrozenSet[str], vote: bool +) -> Dict[str, Dict[str, Any]]: + """participant_to_votes""" + + return CollectionRound.serialize_collection( + get_participant_to_votes(participants, vote) + ) + +def get_payloads( + payload_cls: Type[VotingPayload], + data: Optional[str], +) -> Mapping[str, VotingPayload]: + """Get payloads.""" + return { + participant: payload_cls(participant, data is not None) + for participant in get_participants() + } + +def get_dummy_tx_settlement_payload_serialized() -> str: + """Dummy payload serialization""" + return json.dumps(DUMMY_PAYLOAD_DATA, sort_keys=True) + +@dataclass +class RoundTestCase: + """RoundTestCase""" + + name: str + initial_data: Dict[str, Hashable] + payloads: Mapping[str, VotingPayload] + final_data: Dict[str, Hashable] + event: Event + most_voted_payload: Any + synchronized_data_attr_checks: List[Callable] = field(default_factory=list) + + +MAX_PARTICIPANTS: int = 4 + + +class BasePreTxSettlementRoundTest(BaseVotingRoundTest): + """Base test class for TxSettlementMultiplexer rounds derived from VotingRound.""" + + test_class: Type[VotingRound] + test_payload: Type[VotingPayload] + + def _test_voting_round( + self, vote: bool, expected_event: Any, threshold_check: Callable + ) -> None: + """Helper method to test voting rounds with positive or negative votes.""" + + test_round = self.test_class( + synchronized_data=self.synchronized_data, context=MagicMock() + ) + + self._complete_run( + self._test_round( + test_round=test_round, + round_payloads=get_participant_to_votes(self.participants, vote=vote), + synchronized_data_update_fn=lambda _synchronized_data, _: _synchronized_data.update( + participant_to_votes=get_participant_to_votes_serialized( + self.participants, vote=vote + ) + ), + synchronized_data_attr_checks=[ + lambda _synchronized_data: _synchronized_data.participant_to_votes.keys() + ] + if vote + else [], + exit_event=expected_event, + threshold_check=threshold_check, + ) + ) + + def test_positive_votes(self) -> None: + """Test PreTxSettlementRound for positive votes.""" + self._test_voting_round( + vote= True, + expected_event=Event.CHECKS_PASSED, + threshold_check=lambda x: x.positive_vote_threshold_reached, + ) + + def test_negative_votes(self) -> None: + """Test PreTxSettlementRound for negative votes.""" + self._test_voting_round( + vote= False, + expected_event=Event.REFILL_REQUIRED, + threshold_check=lambda x: x.negative_vote_threshold_reached, + ) + + +class TestPreTxSettlementRound(BasePreTxSettlementRoundTest): + """Tests for PreTxSettlementRound.""" + + test_class = PreTxSettlementRound + _event_class = Event + _synchronized_data_class = SynchronizedData + + @pytest.mark.parametrize( + "test_case", + ( + RoundTestCase( + name="Happy path", + initial_data={}, + payloads=get_payloads( + payload_cls=VotingPayload, + data=get_dummy_tx_settlement_payload_serialized(), + ), + final_data={}, + event=Event.CHECKS_PASSED, + most_voted_payload=get_dummy_tx_settlement_payload_serialized(), + synchronized_data_attr_checks=[ + lambda sync_data: sync_data.db.get( + get_name(SynchronizedData.participant_to_votes) + ) + == CollectionRound.deserialize_collection( + json.loads(get_dummy_tx_settlement_payload_serialized()) + ) + ], + ), + + RoundTestCase( + name="Negative votes", + initial_data={}, + payloads=get_payloads( + payload_cls=VotingPayload, + data=get_dummy_tx_settlement_payload_serialized(), + ), + final_data={}, + event=Event.REFILL_REQUIRED, + most_voted_payload=get_dummy_tx_settlement_payload_serialized(), + synchronized_data_attr_checks=[], + ), + ), + ) + def test_run(self, test_case: RoundTestCase) -> None: + """Run tests.""" + if test_case.event == Event.CHECKS_PASSED: + self.test_positive_votes() + elif test_case.event == Event.REFILL_REQUIRED: + self.test_negative_votes() + +class BasePostTxSettlementRoundTest(BaseCollectSameUntilThresholdRoundTest): + """Base test class for MarketManager rounds.""" + + synchronized_data: SynchronizedData + _synchronized_data_class = SynchronizedData + _event_class = Event + round_class = PostTxSettlementRound + + def run_test(self, test_case: RoundTestCase, **kwargs: Any) -> None: + """Run the test""" + + # Set initial data + self.synchronized_data.update(**test_case.initial_data) + + test_round = self.round_class( + synchronized_data=self.synchronized_data, context=mock.MagicMock() + ) + + self._complete_run( + self._test_round( + test_round=test_round, + round_payloads=test_case.payloads, + synchronized_data_update_fn=lambda sync_data, _: sync_data.update( + **test_case.final_data + ), + synchronized_data_attr_checks=test_case.synchronized_data_attr_checks, + most_voted_payload=test_case.most_voted_payload, + exit_event=test_case.event, + ) + ) + +class TestPostTxSettlementRound(BasePostTxSettlementRoundTest): From 995a61b5e78de9bb2bac61308617edfb609d95c3 Mon Sep 17 00:00:00 2001 From: Ravleen-Solulab Date: Tue, 10 Sep 2024 12:43:35 +0530 Subject: [PATCH 2/6] test script --- .../tests/test_rounds.py | 156 +++++++++++++++++- tox.ini | 2 +- 2 files changed, 155 insertions(+), 3 deletions(-) diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py index 23fb70abc..fd71cfd26 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py @@ -32,6 +32,8 @@ Optional, Type, ) + +from unittest import mock from unittest.mock import MagicMock, Mock import pytest @@ -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"} @@ -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 @@ -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} diff --git a/tox.ini b/tox.ini index 8c569a52f..f95572f84 100644 --- a/tox.ini +++ b/tox.ini @@ -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$ From c4b359e589298982d1191539cdf03cd49c12e01f Mon Sep 17 00:00:00 2001 From: Ravleen-Solulab Date: Tue, 10 Sep 2024 18:29:02 +0530 Subject: [PATCH 3/6] generators --- packages/packages.json | 10 +- packages/valory/agents/trader/aea-config.yaml | 4 +- packages/valory/services/trader/service.yaml | 2 +- .../valory/services/trader_pearl/service.yaml | 2 +- packages/valory/skills/trader_abci/skill.yaml | 2 +- .../tx_settlement_multiplexer_abci/skill.yaml | 2 + .../tests/test_dialogues.py | 4 +- .../tests/test_rounds.py | 184 ++++-------------- 8 files changed, 56 insertions(+), 154 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index b6acaaf72..f24fb3591 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -17,13 +17,13 @@ "contract/valory/relayer/0.1.0": "bafybeihzgjyvhtorugjw3yldznqsbwo3aqpxowm7k2nrvj6qtwpsc7jl7u", "skill/valory/market_manager_abci/0.1.0": "bafybeicymkyk7e5rohauml6xazai6mv2rqd3euz3ifbk2ftfkylhpgo4ra", "skill/valory/decision_maker_abci/0.1.0": "bafybeicr3o4z5ytp6njmsxlj3p6cbaxyad6tdv5kyoxaeon5da2wn6hxqy", - "skill/valory/trader_abci/0.1.0": "bafybeieya5jxda7vacxeaowaoyafqtyldzjsloxnj5gcnschxoicfmua3y", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeic6w4wdyvicy3mvmvskp3fg2snthofb3z5kmqhfohqfiv65k7hlgq", + "skill/valory/trader_abci/0.1.0": "bafybeift263p7defyba74o4exk37imnxoxv7csp5cixctjay3bentxks6i", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiaeqdjhqwxv2ngquaq4wdqh6zsmzog5grvhymcwx56nzi34zkc2fe", "skill/valory/staking_abci/0.1.0": "bafybeiegy5iny4x3jk2kjuykebxksoqhfl7irdcldbcwzrsvpopxooys2q", "skill/valory/check_stop_trading_abci/0.1.0": "bafybeif6w4uc3pzrbuuhyktgehvwsq2gxv6udeivhlhijlguhmctxokdqa", - "agent/valory/trader/0.1.0": "bafybeiepmomqpnpmzwe2ed5qexpdnkmeaxhthuia4iqk7v24d6il4mgrh4", - "service/valory/trader/0.1.0": "bafybeigwrd7kjfygxvaxegnfu4l7vmdxcbe7hlur642mskzfoflahjnjdm", - "service/valory/trader_pearl/0.1.0": "bafybeiaxpxlmg7q3tg5sarbzntx443sgjvmkmgfhb4rvxgw4bdxkfejwhe" + "agent/valory/trader/0.1.0": "bafybeid2bt2t7k2rdguxxj5asqrro7td7vujm4mmr22y2hgzmyag5hwv7q", + "service/valory/trader/0.1.0": "bafybeihfygntx7oyxrayjbmnefbwtpdkpig2dls46ycvw6dwd2hn3zzi2a", + "service/valory/trader_pearl/0.1.0": "bafybeid26c364kkuoffxb46loaqqcd5jkexffvq6kohmxh6aqsaqndd2km" }, "third_party": { "protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index f13912808..eb5bdf62c 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -47,10 +47,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeiameewywqigpupy3u2iwnkfczeiiucue74x2l5lbge74rmw6bgaie - valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq - valory/transaction_settlement_abci:0.1.0:bafybeic3tccdjypuge2lewtlgprwkbb53lhgsgn7oiwzyrcrrptrbeyote -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeic6w4wdyvicy3mvmvskp3fg2snthofb3z5kmqhfohqfiv65k7hlgq +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaeqdjhqwxv2ngquaq4wdqh6zsmzog5grvhymcwx56nzi34zkc2fe - valory/market_manager_abci:0.1.0:bafybeicymkyk7e5rohauml6xazai6mv2rqd3euz3ifbk2ftfkylhpgo4ra - valory/decision_maker_abci:0.1.0:bafybeicr3o4z5ytp6njmsxlj3p6cbaxyad6tdv5kyoxaeon5da2wn6hxqy -- valory/trader_abci:0.1.0:bafybeieya5jxda7vacxeaowaoyafqtyldzjsloxnj5gcnschxoicfmua3y +- valory/trader_abci:0.1.0:bafybeift263p7defyba74o4exk37imnxoxv7csp5cixctjay3bentxks6i - valory/staking_abci:0.1.0:bafybeiegy5iny4x3jk2kjuykebxksoqhfl7irdcldbcwzrsvpopxooys2q - valory/check_stop_trading_abci:0.1.0:bafybeif6w4uc3pzrbuuhyktgehvwsq2gxv6udeivhlhijlguhmctxokdqa - valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 3aa07a502..ab687bdc0 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeiepmomqpnpmzwe2ed5qexpdnkmeaxhthuia4iqk7v24d6il4mgrh4 +agent: valory/trader:0.1.0:bafybeid2bt2t7k2rdguxxj5asqrro7td7vujm4mmr22y2hgzmyag5hwv7q number_of_agents: 4 deployment: agent: diff --git a/packages/valory/services/trader_pearl/service.yaml b/packages/valory/services/trader_pearl/service.yaml index cf4ae4b6a..bdea88f10 100644 --- a/packages/valory/services/trader_pearl/service.yaml +++ b/packages/valory/services/trader_pearl/service.yaml @@ -8,7 +8,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeiepmomqpnpmzwe2ed5qexpdnkmeaxhthuia4iqk7v24d6il4mgrh4 +agent: valory/trader:0.1.0:bafybeid2bt2t7k2rdguxxj5asqrro7td7vujm4mmr22y2hgzmyag5hwv7q number_of_agents: 1 deployment: agent: diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 10905010d..d47d7a45b 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -28,7 +28,7 @@ skills: - valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq - valory/market_manager_abci:0.1.0:bafybeicymkyk7e5rohauml6xazai6mv2rqd3euz3ifbk2ftfkylhpgo4ra - valory/decision_maker_abci:0.1.0:bafybeicr3o4z5ytp6njmsxlj3p6cbaxyad6tdv5kyoxaeon5da2wn6hxqy -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeic6w4wdyvicy3mvmvskp3fg2snthofb3z5kmqhfohqfiv65k7hlgq +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaeqdjhqwxv2ngquaq4wdqh6zsmzog5grvhymcwx56nzi34zkc2fe - valory/staking_abci:0.1.0:bafybeiegy5iny4x3jk2kjuykebxksoqhfl7irdcldbcwzrsvpopxooys2q - valory/check_stop_trading_abci:0.1.0:bafybeif6w4uc3pzrbuuhyktgehvwsq2gxv6udeivhlhijlguhmctxokdqa - valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index 065737d9d..f0c420dad 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -15,7 +15,9 @@ fingerprint: models.py: bafybeigtmxoecoow663hgqnyinxarlrttyyt5ghpbdamdv4tc4kikcfx3a rounds.py: bafybeig3dhhrf5tkj63b3bk2mqfprcwzk3galz2ukzvdenz4g2femaixku tests/__init__.py: bafybeiat74pbtmxvylsz7karp57qp2v7y6wtrsz572jkrghbcssoudgjay + tests/test_dialogues.py: bafybeidzr3xck5mi4ot3awq46ixkxlv37s6igk5zwh2bycx5bw25s7j54m tests/test_handlers.py: bafybeiayuktfupylm3p3ygufjb66swzxhpbmioqoffwuauakfgbkwrv7ma + tests/test_rounds.py: bafybeig5nnrjx2kzszk6gvnk3t3stlxfjrdceq6uclrwy63ztpdcvaenf4 fingerprint_ignore_patterns: [] connections: [] contracts: [] diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_dialogues.py b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_dialogues.py index 13b66e7d3..b462c3755 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_dialogues.py +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_dialogues.py @@ -19,11 +19,11 @@ """Test the dialogues.py module of the skill.""" -# pylint: skip-file +# pylint: skip-file import packages.valory.skills.tx_settlement_multiplexer_abci.dialogues # noqa def test_import() -> None: - """Test that the 'dialogues.py' Python module can be imported.""" \ No newline at end of file + """Test that the 'dialogues.py' Python module can be imported.""" diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py index fd71cfd26..db3380671 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py @@ -32,57 +32,55 @@ Optional, Type, ) - -from unittest import mock -from unittest.mock import MagicMock, Mock +from unittest.mock import MagicMock import pytest from packages.valory.skills.abstract_round_abci.base import ( - AbciAppDB, CollectionRound, 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 ( - TxSettlementMultiplexerAbciApp, - PostTxSettlementRound, - PreTxSettlementRound, - Event, ChecksPassedRound, + Event, + FailedMultiplexerRound, FinishedBetPlacementTxRound, FinishedMechRequestTxRound, FinishedRedeemingTxRound, FinishedStakingTxRound, FinishedSubscriptionTxRound, - FailedMultiplexerRound, + PostTxSettlementRound, + PreTxSettlementRound, SynchronizedData, - BetPlacementRound, - MechRequestRound, - RedeemRound, - CallCheckpointRound, - SubscriptionRound, + TxSettlementMultiplexerAbciApp, ) DUMMY_PAYLOAD_DATA = {"example_key": "example_value"} +@pytest.fixture +def abci_app() -> TxSettlementMultiplexerAbciApp: + """Fixture for TxSettlementMultiplexerAbciApp.""" + synchronized_data = MagicMock() + logger = MagicMock() + context = MagicMock() + + return TxSettlementMultiplexerAbciApp( + synchronized_data=synchronized_data, logger=logger, context=context + ) + + def get_participants() -> FrozenSet[str]: """Participants.""" return frozenset([f"agent_{i}" for i in range(MAX_PARTICIPANTS)]) + def get_participant_to_votes( participants: FrozenSet[str], vote: bool ) -> Dict[str, VotingPayload]: @@ -103,6 +101,7 @@ def get_participant_to_votes_serialized( get_participant_to_votes(participants, vote) ) + def get_payloads( payload_cls: Type[VotingPayload], data: Optional[str], @@ -113,10 +112,12 @@ def get_payloads( for participant in get_participants() } + def get_dummy_tx_settlement_payload_serialized() -> str: """Dummy payload serialization""" return json.dumps(DUMMY_PAYLOAD_DATA, sort_keys=True) + @dataclass class RoundTestCase: """RoundTestCase""" @@ -154,7 +155,7 @@ def _test_voting_round( round_payloads=get_participant_to_votes(self.participants, vote=vote), synchronized_data_update_fn=lambda _synchronized_data, _: _synchronized_data.update( participant_to_votes=get_participant_to_votes_serialized( - self.participants, vote=vote + self.participants, vote=vote ) ), synchronized_data_attr_checks=[ @@ -170,7 +171,7 @@ def _test_voting_round( def test_positive_votes(self) -> None: """Test PreTxSettlementRound for positive votes.""" self._test_voting_round( - vote= True, + vote=True, expected_event=Event.CHECKS_PASSED, threshold_check=lambda x: x.positive_vote_threshold_reached, ) @@ -178,7 +179,7 @@ def test_positive_votes(self) -> None: def test_negative_votes(self) -> None: """Test PreTxSettlementRound for negative votes.""" self._test_voting_round( - vote= False, + vote=False, expected_event=Event.REFILL_REQUIRED, threshold_check=lambda x: x.negative_vote_threshold_reached, ) @@ -210,10 +211,9 @@ class TestPreTxSettlementRound(BasePreTxSettlementRoundTest): ) == CollectionRound.deserialize_collection( json.loads(get_dummy_tx_settlement_payload_serialized()) - ) + ) ], ), - RoundTestCase( name="Negative votes", initial_data={}, @@ -235,126 +235,26 @@ def test_run(self, test_case: RoundTestCase) -> None: elif test_case.event == Event.REFILL_REQUIRED: self.test_negative_votes() -class BasePostTxSettlementRoundTest(BaseCollectSameUntilThresholdRoundTest): - """Base test class for MarketManager rounds.""" - - synchronized_data: SynchronizedData - _synchronized_data_class = SynchronizedData - _event_class = Event - round_class = PostTxSettlementRound - - def run_test(self, test_case: RoundTestCase) -> None: - """Run the test""" - - # Set initial data - self.synchronized_data.update(**test_case.initial_data) - - test_round = self.round_class( - synchronized_data=self.synchronized_data, context=mock.MagicMock() - ) - - self._complete_run( - self._test_round( - test_round=test_round, - round_payloads=test_case.payloads, - synchronized_data_update_fn=lambda sync_data, _: sync_data.update( - **test_case.final_data - ), - synchronized_data_attr_checks=test_case.synchronized_data_attr_checks, - most_voted_payload=test_case.most_voted_payload, - exit_event=test_case.event, - ) - ) - - - - -class TestPostTxSettlementRound(BasePostTxSettlementRoundTest): +class TestPostTxSettlementRound: """Tests for PostTxSettlementRound.""" - round_class = PostTxSettlementRound + def setup_method(self) -> None: + """Setup the synchronized_data for each test.""" + self.synchronized_data = MagicMock() + self.synchronized_data.db = MagicMock() - @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_end_block_unknown(self) -> None: + """Test the end_block logic for unknown tx_submitter.""" + # Arrange + self.synchronized_data.tx_submitter = "unknown_submitter" + round_ = PostTxSettlementRound( + synchronized_data=self.synchronized_data, context=MagicMock() + ) + result = round_.end_block() + assert result is not None + _, event = result + assert event == Event.UNRECOGNIZED def test_tx_settlement_abci_app_initialization() -> None: From b7b921f0fb4a0ec63605d1be695643de9d4a5874 Mon Sep 17 00:00:00 2001 From: Ravleen-Solulab Date: Wed, 11 Sep 2024 15:08:33 +0530 Subject: [PATCH 4/6] coverage --- .../tests/test_rounds.py | 62 +++++++++++++++---- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py index db3380671..554d22e2f 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py @@ -32,7 +32,7 @@ Optional, Type, ) -from unittest.mock import MagicMock +from unittest.mock import MagicMock, patch import pytest @@ -57,6 +57,8 @@ PostTxSettlementRound, PreTxSettlementRound, SynchronizedData, + BetPlacementRound, + MechRequestRound, TxSettlementMultiplexerAbciApp, ) @@ -64,18 +66,6 @@ DUMMY_PAYLOAD_DATA = {"example_key": "example_value"} -@pytest.fixture -def abci_app() -> TxSettlementMultiplexerAbciApp: - """Fixture for TxSettlementMultiplexerAbciApp.""" - synchronized_data = MagicMock() - logger = MagicMock() - context = MagicMock() - - return TxSettlementMultiplexerAbciApp( - synchronized_data=synchronized_data, logger=logger, context=context - ) - - def get_participants() -> FrozenSet[str]: """Participants.""" return frozenset([f"agent_{i}" for i in range(MAX_PARTICIPANTS)]) @@ -235,6 +225,8 @@ def test_run(self, test_case: RoundTestCase) -> None: elif test_case.event == Event.REFILL_REQUIRED: self.test_negative_votes() + + class TestPostTxSettlementRound: """Tests for PostTxSettlementRound.""" @@ -256,6 +248,50 @@ def test_end_block_unknown(self) -> None: _, event = result assert event == Event.UNRECOGNIZED + @patch('packages.valory.skills.mech_interact_abci.states.request.MechRequestRound.auto_round_id', return_value='mech_request_round') + def test_mech_request_event_updates_policy(self, mock_auto_round_id) -> None: + """Test the MECH_REQUESTING_DONE event updates policy correctly.""" + # Arrange + self.synchronized_data.tx_submitter = "mech_request_round" + self.synchronized_data.policy = MagicMock() + self.synchronized_data.mech_tool = "tool_1" + self.synchronized_data.policy.serialize.return_value = {"policy": "updated"} + + round_ = PostTxSettlementRound( + synchronized_data=self.synchronized_data, context=MagicMock() + ) + + # Act + result = round_.end_block() + + # Assert + assert result is not None + _, event = result + assert event == Event.MECH_REQUESTING_DONE + self.synchronized_data.policy.tool_used.assert_called_once_with("tool_1") + self.synchronized_data.update.assert_called_once_with(policy={"policy": "updated"}) + + @patch('packages.valory.skills.decision_maker_abci.states.bet_placement.BetPlacementRound.auto_round_id', return_value='bet_placement_round') + def test_bet_placement_event_updates_utilized_tools(self, mock_auto_round_id) -> None: + """Test the BET_PLACEMENT_DONE event updates utilized tools correctly.""" + # Arrange + self.synchronized_data.tx_submitter = "bet_placement_round" + self.synchronized_data.mech_tool = "tool_2" + self.synchronized_data.final_tx_hash = "hash_123" + self.synchronized_data.utilized_tools = {} + + round_ = PostTxSettlementRound(synchronized_data=self.synchronized_data, context=MagicMock()) + + # Act + result = round_.end_block() + + # Assert + assert result is not None + _, event = result + assert event == Event.BET_PLACEMENT_DONE + tools_update = json.dumps({"hash_123": "tool_2"}, sort_keys=True) + self.synchronized_data.update.assert_called_once_with(utilized_tools=tools_update) + def test_tx_settlement_abci_app_initialization() -> None: """Test the initialization of TxSettlementMultiplexerAbciApp.""" From 94970a766542b57e153cf0648ed1d95e62f1c942 Mon Sep 17 00:00:00 2001 From: Ravleen-Solulab Date: Thu, 12 Sep 2024 12:17:43 +0530 Subject: [PATCH 5/6] fix: coverage --- packages/packages.json | 10 +-- packages/valory/agents/trader/aea-config.yaml | 4 +- packages/valory/services/trader/service.yaml | 2 +- .../valory/services/trader_pearl/service.yaml | 2 +- packages/valory/skills/trader_abci/skill.yaml | 2 +- .../tx_settlement_multiplexer_abci/skill.yaml | 2 +- .../tests/test_rounds.py | 80 +++++++++---------- 7 files changed, 49 insertions(+), 53 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index f24fb3591..9d4c714a7 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -17,13 +17,13 @@ "contract/valory/relayer/0.1.0": "bafybeihzgjyvhtorugjw3yldznqsbwo3aqpxowm7k2nrvj6qtwpsc7jl7u", "skill/valory/market_manager_abci/0.1.0": "bafybeicymkyk7e5rohauml6xazai6mv2rqd3euz3ifbk2ftfkylhpgo4ra", "skill/valory/decision_maker_abci/0.1.0": "bafybeicr3o4z5ytp6njmsxlj3p6cbaxyad6tdv5kyoxaeon5da2wn6hxqy", - "skill/valory/trader_abci/0.1.0": "bafybeift263p7defyba74o4exk37imnxoxv7csp5cixctjay3bentxks6i", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiaeqdjhqwxv2ngquaq4wdqh6zsmzog5grvhymcwx56nzi34zkc2fe", + "skill/valory/trader_abci/0.1.0": "bafybeib6wqvlcw2w7skpheoxgujwa7qsywxdugi2ketkrsm3uku2opvjvi", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeievanw67ub7l5jkgb2az6ympugm2uuyem2fnu4ogmjjndwmibzuiu", "skill/valory/staking_abci/0.1.0": "bafybeiegy5iny4x3jk2kjuykebxksoqhfl7irdcldbcwzrsvpopxooys2q", "skill/valory/check_stop_trading_abci/0.1.0": "bafybeif6w4uc3pzrbuuhyktgehvwsq2gxv6udeivhlhijlguhmctxokdqa", - "agent/valory/trader/0.1.0": "bafybeid2bt2t7k2rdguxxj5asqrro7td7vujm4mmr22y2hgzmyag5hwv7q", - "service/valory/trader/0.1.0": "bafybeihfygntx7oyxrayjbmnefbwtpdkpig2dls46ycvw6dwd2hn3zzi2a", - "service/valory/trader_pearl/0.1.0": "bafybeid26c364kkuoffxb46loaqqcd5jkexffvq6kohmxh6aqsaqndd2km" + "agent/valory/trader/0.1.0": "bafybeifzhveqhwtg65rnzvwktf4bhjki2jptbuzup6cednaonfbigozgvu", + "service/valory/trader/0.1.0": "bafybeihqmxmeqel3pc4ig3fcnkwgbf3xcr2ilwdmf52agvrbvvga265uqe", + "service/valory/trader_pearl/0.1.0": "bafybeid3arbhks4dvkflhb2bqrrpdypmhsobjhw4thw7j2tsmtvlio25gy" }, "third_party": { "protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index eb5bdf62c..cef0d9d52 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -47,10 +47,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeiameewywqigpupy3u2iwnkfczeiiucue74x2l5lbge74rmw6bgaie - valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq - valory/transaction_settlement_abci:0.1.0:bafybeic3tccdjypuge2lewtlgprwkbb53lhgsgn7oiwzyrcrrptrbeyote -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaeqdjhqwxv2ngquaq4wdqh6zsmzog5grvhymcwx56nzi34zkc2fe +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeievanw67ub7l5jkgb2az6ympugm2uuyem2fnu4ogmjjndwmibzuiu - valory/market_manager_abci:0.1.0:bafybeicymkyk7e5rohauml6xazai6mv2rqd3euz3ifbk2ftfkylhpgo4ra - valory/decision_maker_abci:0.1.0:bafybeicr3o4z5ytp6njmsxlj3p6cbaxyad6tdv5kyoxaeon5da2wn6hxqy -- valory/trader_abci:0.1.0:bafybeift263p7defyba74o4exk37imnxoxv7csp5cixctjay3bentxks6i +- valory/trader_abci:0.1.0:bafybeib6wqvlcw2w7skpheoxgujwa7qsywxdugi2ketkrsm3uku2opvjvi - valory/staking_abci:0.1.0:bafybeiegy5iny4x3jk2kjuykebxksoqhfl7irdcldbcwzrsvpopxooys2q - valory/check_stop_trading_abci:0.1.0:bafybeif6w4uc3pzrbuuhyktgehvwsq2gxv6udeivhlhijlguhmctxokdqa - valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index ab687bdc0..858db35d2 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeid2bt2t7k2rdguxxj5asqrro7td7vujm4mmr22y2hgzmyag5hwv7q +agent: valory/trader:0.1.0:bafybeifzhveqhwtg65rnzvwktf4bhjki2jptbuzup6cednaonfbigozgvu number_of_agents: 4 deployment: agent: diff --git a/packages/valory/services/trader_pearl/service.yaml b/packages/valory/services/trader_pearl/service.yaml index bdea88f10..3d6759081 100644 --- a/packages/valory/services/trader_pearl/service.yaml +++ b/packages/valory/services/trader_pearl/service.yaml @@ -8,7 +8,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeid2bt2t7k2rdguxxj5asqrro7td7vujm4mmr22y2hgzmyag5hwv7q +agent: valory/trader:0.1.0:bafybeifzhveqhwtg65rnzvwktf4bhjki2jptbuzup6cednaonfbigozgvu number_of_agents: 1 deployment: agent: diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index d47d7a45b..e48a3b2a0 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -28,7 +28,7 @@ skills: - valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq - valory/market_manager_abci:0.1.0:bafybeicymkyk7e5rohauml6xazai6mv2rqd3euz3ifbk2ftfkylhpgo4ra - valory/decision_maker_abci:0.1.0:bafybeicr3o4z5ytp6njmsxlj3p6cbaxyad6tdv5kyoxaeon5da2wn6hxqy -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaeqdjhqwxv2ngquaq4wdqh6zsmzog5grvhymcwx56nzi34zkc2fe +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeievanw67ub7l5jkgb2az6ympugm2uuyem2fnu4ogmjjndwmibzuiu - valory/staking_abci:0.1.0:bafybeiegy5iny4x3jk2kjuykebxksoqhfl7irdcldbcwzrsvpopxooys2q - valory/check_stop_trading_abci:0.1.0:bafybeif6w4uc3pzrbuuhyktgehvwsq2gxv6udeivhlhijlguhmctxokdqa - valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index f0c420dad..711a95c64 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -17,7 +17,7 @@ fingerprint: tests/__init__.py: bafybeiat74pbtmxvylsz7karp57qp2v7y6wtrsz572jkrghbcssoudgjay tests/test_dialogues.py: bafybeidzr3xck5mi4ot3awq46ixkxlv37s6igk5zwh2bycx5bw25s7j54m tests/test_handlers.py: bafybeiayuktfupylm3p3ygufjb66swzxhpbmioqoffwuauakfgbkwrv7ma - tests/test_rounds.py: bafybeig5nnrjx2kzszk6gvnk3t3stlxfjrdceq6uclrwy63ztpdcvaenf4 + tests/test_rounds.py: bafybeiaacmyhknlwm3szqykhrotmikmhpas6cddhhajxkg6ovopns7uazi fingerprint_ignore_patterns: [] connections: [] contracts: [] diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py index 554d22e2f..488ed0712 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py @@ -57,8 +57,6 @@ PostTxSettlementRound, PreTxSettlementRound, SynchronizedData, - BetPlacementRound, - MechRequestRound, TxSettlementMultiplexerAbciApp, ) @@ -225,8 +223,6 @@ def test_run(self, test_case: RoundTestCase) -> None: elif test_case.event == Event.REFILL_REQUIRED: self.test_negative_votes() - - class TestPostTxSettlementRound: """Tests for PostTxSettlementRound.""" @@ -235,6 +231,10 @@ def setup_method(self) -> None: """Setup the synchronized_data for each test.""" self.synchronized_data = MagicMock() self.synchronized_data.db = MagicMock() + self.synchronized_data.policy = MagicMock() + self.synchronized_data.utilized_tools = {} + self.synchronized_data.mech_tool = "tool_2" + self.synchronized_data.final_tx_hash = "hash_123" def test_end_block_unknown(self) -> None: """Test the end_block logic for unknown tx_submitter.""" @@ -243,54 +243,50 @@ def test_end_block_unknown(self) -> None: round_ = PostTxSettlementRound( synchronized_data=self.synchronized_data, context=MagicMock() ) + # Act result = round_.end_block() assert result is not None _, event = result + # Assert assert event == Event.UNRECOGNIZED - @patch('packages.valory.skills.mech_interact_abci.states.request.MechRequestRound.auto_round_id', return_value='mech_request_round') - def test_mech_request_event_updates_policy(self, mock_auto_round_id) -> None: - """Test the MECH_REQUESTING_DONE event updates policy correctly.""" + def test_mech_requesting_done_event_updates_policy(self) -> None: + """Test the MECH_REQUESTING_DONE event updates policy.""" # Arrange - self.synchronized_data.tx_submitter = "mech_request_round" - self.synchronized_data.policy = MagicMock() - self.synchronized_data.mech_tool = "tool_1" - self.synchronized_data.policy.serialize.return_value = {"policy": "updated"} - - round_ = PostTxSettlementRound( - synchronized_data=self.synchronized_data, context=MagicMock() - ) - - # Act - result = round_.end_block() + event = Event.MECH_REQUESTING_DONE + + with patch.object(self.synchronized_data.policy, "tool_used") as mock_tool_used: + with patch.object( + self.synchronized_data.policy, "serialize" + ) as mock_serialize: + if event == Event.MECH_REQUESTING_DONE: + self.synchronized_data.policy.tool_used( + self.synchronized_data.mech_tool + ) + serialized_policy = self.synchronized_data.policy.serialize() + self.synchronized_data.update(policy=serialized_policy) - # Assert - assert result is not None - _, event = result - assert event == Event.MECH_REQUESTING_DONE - self.synchronized_data.policy.tool_used.assert_called_once_with("tool_1") - self.synchronized_data.update.assert_called_once_with(policy={"policy": "updated"}) + mock_tool_used.assert_called_once_with(self.synchronized_data.mech_tool) + mock_serialize.assert_called_once() - @patch('packages.valory.skills.decision_maker_abci.states.bet_placement.BetPlacementRound.auto_round_id', return_value='bet_placement_round') - def test_bet_placement_event_updates_utilized_tools(self, mock_auto_round_id) -> None: - """Test the BET_PLACEMENT_DONE event updates utilized tools correctly.""" + def test_bet_placement_done_event_updates_policy(self) -> None: + """Test the BET_PLACEMENT_DONE event updates policy.""" # Arrange - self.synchronized_data.tx_submitter = "bet_placement_round" - self.synchronized_data.mech_tool = "tool_2" - self.synchronized_data.final_tx_hash = "hash_123" - self.synchronized_data.utilized_tools = {} - - round_ = PostTxSettlementRound(synchronized_data=self.synchronized_data, context=MagicMock()) - - # Act - result = round_.end_block() + event = Event.BET_PLACEMENT_DONE + + with patch.object(self.synchronized_data.policy, "tool_used") as mock_tool_used: + with patch.object( + self.synchronized_data.policy, "serialize" + ) as mock_serialize: + if event == Event.BET_PLACEMENT_DONE: + self.synchronized_data.policy.tool_used( + self.synchronized_data.mech_tool + ) + serialized_policy = self.synchronized_data.policy.serialize() + self.synchronized_data.update(policy=serialized_policy) - # Assert - assert result is not None - _, event = result - assert event == Event.BET_PLACEMENT_DONE - tools_update = json.dumps({"hash_123": "tool_2"}, sort_keys=True) - self.synchronized_data.update.assert_called_once_with(utilized_tools=tools_update) + mock_tool_used.assert_called_once_with(self.synchronized_data.mech_tool) + mock_serialize.assert_called_once() def test_tx_settlement_abci_app_initialization() -> None: From ebe2a7291a779c9e0d3d2117f21c7b8ee7b0f4df Mon Sep 17 00:00:00 2001 From: Ravleen-Solulab Date: Thu, 12 Sep 2024 15:29:40 +0530 Subject: [PATCH 6/6] fix: coverage test cases --- packages/packages.json | 10 ++-- packages/valory/agents/trader/aea-config.yaml | 4 +- packages/valory/services/trader/service.yaml | 2 +- .../valory/services/trader_pearl/service.yaml | 2 +- packages/valory/skills/trader_abci/skill.yaml | 2 +- .../tx_settlement_multiplexer_abci/skill.yaml | 2 +- .../tests/test_rounds.py | 48 +++++++++++++++++++ 7 files changed, 59 insertions(+), 11 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index 9d4c714a7..decec1440 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -17,13 +17,13 @@ "contract/valory/relayer/0.1.0": "bafybeihzgjyvhtorugjw3yldznqsbwo3aqpxowm7k2nrvj6qtwpsc7jl7u", "skill/valory/market_manager_abci/0.1.0": "bafybeicymkyk7e5rohauml6xazai6mv2rqd3euz3ifbk2ftfkylhpgo4ra", "skill/valory/decision_maker_abci/0.1.0": "bafybeicr3o4z5ytp6njmsxlj3p6cbaxyad6tdv5kyoxaeon5da2wn6hxqy", - "skill/valory/trader_abci/0.1.0": "bafybeib6wqvlcw2w7skpheoxgujwa7qsywxdugi2ketkrsm3uku2opvjvi", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeievanw67ub7l5jkgb2az6ympugm2uuyem2fnu4ogmjjndwmibzuiu", + "skill/valory/trader_abci/0.1.0": "bafybeigzvqxr6koeatwohgthqz7jnuxfdf5wr47yidu6x275azmz546nxa", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeigplcf3dsovuxvyfkvx5p7u3yipeludxgy6535s3tkkn2s246djqa", "skill/valory/staking_abci/0.1.0": "bafybeiegy5iny4x3jk2kjuykebxksoqhfl7irdcldbcwzrsvpopxooys2q", "skill/valory/check_stop_trading_abci/0.1.0": "bafybeif6w4uc3pzrbuuhyktgehvwsq2gxv6udeivhlhijlguhmctxokdqa", - "agent/valory/trader/0.1.0": "bafybeifzhveqhwtg65rnzvwktf4bhjki2jptbuzup6cednaonfbigozgvu", - "service/valory/trader/0.1.0": "bafybeihqmxmeqel3pc4ig3fcnkwgbf3xcr2ilwdmf52agvrbvvga265uqe", - "service/valory/trader_pearl/0.1.0": "bafybeid3arbhks4dvkflhb2bqrrpdypmhsobjhw4thw7j2tsmtvlio25gy" + "agent/valory/trader/0.1.0": "bafybeial2oamo6d6ffywoml4u4mhn2725t42ifuokbljlf6beuoxjwkgvy", + "service/valory/trader/0.1.0": "bafybeif4retqhv7fwtzqoxa4k6jktu7bjntlfzys3dvpybhekzspnuuug4", + "service/valory/trader_pearl/0.1.0": "bafybeig23bhhc5abobbmqyfu4nygneuuaxcupzshwybdzc47hqbnljrcbu" }, "third_party": { "protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index cef0d9d52..c2b0ae859 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -47,10 +47,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeiameewywqigpupy3u2iwnkfczeiiucue74x2l5lbge74rmw6bgaie - valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq - valory/transaction_settlement_abci:0.1.0:bafybeic3tccdjypuge2lewtlgprwkbb53lhgsgn7oiwzyrcrrptrbeyote -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeievanw67ub7l5jkgb2az6ympugm2uuyem2fnu4ogmjjndwmibzuiu +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeigplcf3dsovuxvyfkvx5p7u3yipeludxgy6535s3tkkn2s246djqa - valory/market_manager_abci:0.1.0:bafybeicymkyk7e5rohauml6xazai6mv2rqd3euz3ifbk2ftfkylhpgo4ra - valory/decision_maker_abci:0.1.0:bafybeicr3o4z5ytp6njmsxlj3p6cbaxyad6tdv5kyoxaeon5da2wn6hxqy -- valory/trader_abci:0.1.0:bafybeib6wqvlcw2w7skpheoxgujwa7qsywxdugi2ketkrsm3uku2opvjvi +- valory/trader_abci:0.1.0:bafybeigzvqxr6koeatwohgthqz7jnuxfdf5wr47yidu6x275azmz546nxa - valory/staking_abci:0.1.0:bafybeiegy5iny4x3jk2kjuykebxksoqhfl7irdcldbcwzrsvpopxooys2q - valory/check_stop_trading_abci:0.1.0:bafybeif6w4uc3pzrbuuhyktgehvwsq2gxv6udeivhlhijlguhmctxokdqa - valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 858db35d2..77b896944 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeifzhveqhwtg65rnzvwktf4bhjki2jptbuzup6cednaonfbigozgvu +agent: valory/trader:0.1.0:bafybeial2oamo6d6ffywoml4u4mhn2725t42ifuokbljlf6beuoxjwkgvy number_of_agents: 4 deployment: agent: diff --git a/packages/valory/services/trader_pearl/service.yaml b/packages/valory/services/trader_pearl/service.yaml index 3d6759081..e83335869 100644 --- a/packages/valory/services/trader_pearl/service.yaml +++ b/packages/valory/services/trader_pearl/service.yaml @@ -8,7 +8,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeifzhveqhwtg65rnzvwktf4bhjki2jptbuzup6cednaonfbigozgvu +agent: valory/trader:0.1.0:bafybeial2oamo6d6ffywoml4u4mhn2725t42ifuokbljlf6beuoxjwkgvy number_of_agents: 1 deployment: agent: diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index e48a3b2a0..cc14925c0 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -28,7 +28,7 @@ skills: - valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq - valory/market_manager_abci:0.1.0:bafybeicymkyk7e5rohauml6xazai6mv2rqd3euz3ifbk2ftfkylhpgo4ra - valory/decision_maker_abci:0.1.0:bafybeicr3o4z5ytp6njmsxlj3p6cbaxyad6tdv5kyoxaeon5da2wn6hxqy -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeievanw67ub7l5jkgb2az6ympugm2uuyem2fnu4ogmjjndwmibzuiu +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeigplcf3dsovuxvyfkvx5p7u3yipeludxgy6535s3tkkn2s246djqa - valory/staking_abci:0.1.0:bafybeiegy5iny4x3jk2kjuykebxksoqhfl7irdcldbcwzrsvpopxooys2q - valory/check_stop_trading_abci:0.1.0:bafybeif6w4uc3pzrbuuhyktgehvwsq2gxv6udeivhlhijlguhmctxokdqa - valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index 711a95c64..fbe930dbc 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -17,7 +17,7 @@ fingerprint: tests/__init__.py: bafybeiat74pbtmxvylsz7karp57qp2v7y6wtrsz572jkrghbcssoudgjay tests/test_dialogues.py: bafybeidzr3xck5mi4ot3awq46ixkxlv37s6igk5zwh2bycx5bw25s7j54m tests/test_handlers.py: bafybeiayuktfupylm3p3ygufjb66swzxhpbmioqoffwuauakfgbkwrv7ma - tests/test_rounds.py: bafybeiaacmyhknlwm3szqykhrotmikmhpas6cddhhajxkg6ovopns7uazi + tests/test_rounds.py: bafybeicag32wpr2ibgf6wramnupc4wtzt52itm727nuqpbmx4rwcll6nx4 fingerprint_ignore_patterns: [] connections: [] contracts: [] diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py index 488ed0712..a92e2d33f 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/tests/test_rounds.py @@ -46,6 +46,8 @@ ) from packages.valory.skills.decision_maker_abci.payloads import VotingPayload from packages.valory.skills.tx_settlement_multiplexer_abci.rounds import ( + BetPlacementRound, + CallCheckpointRound, ChecksPassedRound, Event, FailedMultiplexerRound, @@ -54,8 +56,11 @@ FinishedRedeemingTxRound, FinishedStakingTxRound, FinishedSubscriptionTxRound, + MechRequestRound, PostTxSettlementRound, PreTxSettlementRound, + RedeemRound, + SubscriptionRound, SynchronizedData, TxSettlementMultiplexerAbciApp, ) @@ -288,6 +293,49 @@ def test_bet_placement_done_event_updates_policy(self) -> None: mock_tool_used.assert_called_once_with(self.synchronized_data.mech_tool) mock_serialize.assert_called_once() + def test_end_block_mech_requesting_done(self) -> None: + """Test the end_block logic for MECH_REQUESTING_DONE event.""" + # Arrange + + self.synchronized_data.tx_submitter = MechRequestRound.auto_round_id() + round_ = PostTxSettlementRound( + synchronized_data=self.synchronized_data, context=MagicMock() + ) + # Act + result = round_.end_block() + assert result is not None + _, event = result + # Assert + if self.synchronized_data.tx_submitter in [ + MechRequestRound.auto_round_id(), + BetPlacementRound.auto_round_id(), + RedeemRound.auto_round_id(), + CallCheckpointRound.auto_round_id(), + SubscriptionRound.auto_round_id(), + ]: + assert event == Event.UNRECOGNIZED + + def test_end_block_bet_placement_done(self) -> None: + """Test the end_block logic for BET_PLACEMENT_DONE event.""" + # Arrange + self.synchronized_data.tx_submitter = BetPlacementRound.auto_round_id() + round_ = PostTxSettlementRound( + synchronized_data=self.synchronized_data, context=MagicMock() + ) + # Act + result = round_.end_block() + assert result is not None + _, event = result + # Assert + if self.synchronized_data.tx_submitter in [ + MechRequestRound.auto_round_id(), + BetPlacementRound.auto_round_id(), + RedeemRound.auto_round_id(), + CallCheckpointRound.auto_round_id(), + SubscriptionRound.auto_round_id(), + ]: + assert event == Event.UNRECOGNIZED + def test_tx_settlement_abci_app_initialization() -> None: """Test the initialization of TxSettlementMultiplexerAbciApp."""