From c4b359e589298982d1191539cdf03cd49c12e01f Mon Sep 17 00:00:00 2001 From: Ravleen-Solulab Date: Tue, 10 Sep 2024 18:29:02 +0530 Subject: [PATCH] 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: