From 803e0ccc10ebc1a6a38224f1f3aacbc7f787e6ab Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 4 Jun 2024 17:47:42 +0300 Subject: [PATCH 1/4] test: add test for wei to native conversion --- .../decision_maker_abci/tests/behaviours/test_base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py b/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py index 3d8949b9b..4d798a71a 100644 --- a/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py +++ b/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py @@ -33,7 +33,7 @@ ) from packages.valory.skills.decision_maker_abci.behaviours.base import ( BET_AMOUNT_FIELD, - remove_fraction_wei, + remove_fraction_wei, DecisionMakerBaseBehaviour ) from packages.valory.skills.decision_maker_abci.behaviours.blacklisting import ( BlacklistingBehaviour, @@ -180,6 +180,13 @@ def test_execute_strategy( res = behaviour.execute_strategy(*args, **kwargs) assert res == expected_result + @given(st.integers()) + def test_wei_to_native(self, wei: int) -> None: + """Test the `wei_to_native` method.""" + result = DecisionMakerBaseBehaviour.wei_to_native(wei) + assert isinstance(result, float) + assert result == wei / 10**18 + @pytest.mark.parametrize( "mocked_result, expected_result", ( From 1b544b3b890beaf287399edaedea5abaa1b08874 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 4 Jun 2024 17:48:13 +0300 Subject: [PATCH 2/4] test: add test for `collateral_amount_info` --- .../tests/behaviours/test_base.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py b/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py index 4d798a71a..4d6c38ab6 100644 --- a/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py +++ b/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py @@ -22,6 +22,7 @@ import re from pathlib import Path from typing import Any, Dict, Optional, Tuple, cast +from unittest import mock import pytest from hypothesis import given, settings @@ -33,7 +34,7 @@ ) from packages.valory.skills.decision_maker_abci.behaviours.base import ( BET_AMOUNT_FIELD, - remove_fraction_wei, DecisionMakerBaseBehaviour + remove_fraction_wei, DecisionMakerBaseBehaviour, WXDAI, ) from packages.valory.skills.decision_maker_abci.behaviours.blacklisting import ( BlacklistingBehaviour, @@ -187,6 +188,25 @@ def test_wei_to_native(self, wei: int) -> None: assert isinstance(result, float) assert result == wei / 10**18 + @given(st.integers(), st.booleans(), st.booleans()) + def test_collateral_amount_info(self, amount: int, benchmarking_mode_enabled: bool, is_wxdai: bool) -> None: + """Test the `collateral_amount_info` method.""" + # use `BlacklistingBehaviour` because it overrides the `DecisionMakerBaseBehaviour`. + self.ffw(BlacklistingBehaviour, {"sampled_bet_index": 0}) + behaviour = cast(BlacklistingBehaviour, self.behaviour.current_behaviour) + assert behaviour.behaviour_id == BlacklistingBehaviour.auto_behaviour_id() + + behaviour.benchmarking_mode.enabled = benchmarking_mode_enabled + with mock.patch.object(behaviour, "read_bets"): + collateral_token = WXDAI if is_wxdai else "unknown" + behaviour.bets = [(mock.MagicMock(collateralToken=collateral_token))] + result = behaviour._collateral_amount_info(amount) + + if benchmarking_mode_enabled or is_wxdai: + assert result == f"{behaviour.wei_to_native(amount)} wxDAI" + else: + assert result == f"{amount} WEI of the collateral token with address {collateral_token}" + @pytest.mark.parametrize( "mocked_result, expected_result", ( From 3e2bcef2aaedf7b1578c6787d098bf3299594a53 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 5 Jun 2024 17:10:31 +0300 Subject: [PATCH 3/4] test: add test for `_mock_balance_check` --- .../tests/behaviours/test_base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py b/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py index 4d6c38ab6..2e7f55060 100644 --- a/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py +++ b/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py @@ -207,6 +207,22 @@ def test_collateral_amount_info(self, amount: int, benchmarking_mode_enabled: bo else: assert result == f"{amount} WEI of the collateral token with address {collateral_token}" + @given(st.integers(), st.integers()) + def test_mock_balance_check(self, collateral_balance: int, native_balance: int) -> None: + """Test the `_mock_balance_check` method.""" + # use `BlacklistingBehaviour` because it overrides the `DecisionMakerBaseBehaviour`. + self.ffw(BlacklistingBehaviour) + behaviour = cast(BlacklistingBehaviour, self.behaviour.current_behaviour) + assert behaviour.behaviour_id == BlacklistingBehaviour.auto_behaviour_id() + + behaviour.benchmarking_mode.collateral_balance = collateral_balance + behaviour.benchmarking_mode.native_balance = native_balance + with mock.patch.object(behaviour, "_report_balance") as mock_report_balance: + behaviour._mock_balance_check() + mock_report_balance.assert_called_once() + assert behaviour.token_balance == collateral_balance + assert behaviour.wallet_balance == native_balance + @pytest.mark.parametrize( "mocked_result, expected_result", ( From 23e4fcc95a143e53f96ab45e9d08139c1325271b Mon Sep 17 00:00:00 2001 From: Adamantios Date: Fri, 21 Jun 2024 11:11:47 +0300 Subject: [PATCH 4/4] chore: run generators --- packages/packages.json | 12 ++++++------ packages/valory/agents/trader/aea-config.yaml | 6 +++--- packages/valory/services/trader/service.yaml | 2 +- .../services/trader_omen_gnosis/service.yaml | 2 +- .../skills/decision_maker_abci/skill.yaml | 2 +- .../tests/behaviours/test_base.py | 17 +++++++++++++---- packages/valory/skills/trader_abci/skill.yaml | 4 ++-- .../tx_settlement_multiplexer_abci/skill.yaml | 2 +- 8 files changed, 28 insertions(+), 19 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index d3a1be454..eb70dec31 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -16,14 +16,14 @@ "contract/valory/staking_token/0.1.0": "bafybeig4fl35dn7d5gnprux2nwsqbirm7zkiujz3xvrwcjuktz6hkq4as4", "contract/valory/relayer/0.1.0": "bafybeiaabvxim4blp5fxb6qjlzjivtvkme3fk24h5jte7w6vr6rsx72j6u", "skill/valory/market_manager_abci/0.1.0": "bafybeicbvxvjkoksbknujaid5hx7krjlgm6barcjcwo33tdccanrcp674a", - "skill/valory/decision_maker_abci/0.1.0": "bafybeibt44wsyruovefpezbuean5rnzccd44zwge2xsddpbp6fevphu2ui", - "skill/valory/trader_abci/0.1.0": "bafybeig6zcnrmosil45k3crl2le5mxx5gnnsvktjh3oil3a2xigl76gr7m", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiddh2iqcn355syeqalmq2hdpczfcx6wijnvtpfie5gi6hasprstii", + "skill/valory/decision_maker_abci/0.1.0": "bafybeigianh43fjwufi5bv4n4cjsa5nuv5cihuq5db6xyya347d4brxd2m", + "skill/valory/trader_abci/0.1.0": "bafybeigxsa4uvssmhghokwscwca7flu7eiqr6aq5me4wn2v22od6lxmotm", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiaj4us7tbtc2ctpofnrk6fkk7uekcjx65y5wbcwwfbgzeoccyy62e", "skill/valory/staking_abci/0.1.0": "bafybeidubhfvlf6x627t4wetc6ran5sb4pttjphyhv6vefp2a4kcuca2be", "skill/valory/check_stop_trading_abci/0.1.0": "bafybeie6vnp4oovs3k6qnqjcjcjiok6u2uu4dkyd5gqibu77zxpcmztbnq", - "agent/valory/trader/0.1.0": "bafybeihii7hnxv5pbrb25f5suh5eye62qnjlcy5oq2kpjchxppwwm62mre", - "service/valory/trader/0.1.0": "bafybeidzuea526pcth73sftqxjebhq47s6vo5dhmxzlryyl7lh3etj7gpe", - "service/valory/trader_omen_gnosis/0.1.0": "bafybeid2bg4ypzwqrd3etfwmwlvopyh2muuflbgp3ji6nzz2lzbmmytgty" + "agent/valory/trader/0.1.0": "bafybeih6wqj5vwkeaq4wbmelcrudbrqcemtqj245usk5nyuvq3z7yxvko4", + "service/valory/trader/0.1.0": "bafybeihcywq4yn52ui7adjm3xzgnshcn2i7qhhjkyp5yuejiqhrbv3tqge", + "service/valory/trader_omen_gnosis/0.1.0": "bafybeib6zffgo76wln3rnwhnkb65mlwklc2cjoqjtqqdah73tkfhz3ouee" }, "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 f5da714f1..046a8cbe0 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:bafybeiddh2iqcn355syeqalmq2hdpczfcx6wijnvtpfie5gi6hasprstii +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaj4us7tbtc2ctpofnrk6fkk7uekcjx65y5wbcwwfbgzeoccyy62e - valory/market_manager_abci:0.1.0:bafybeicbvxvjkoksbknujaid5hx7krjlgm6barcjcwo33tdccanrcp674a -- valory/decision_maker_abci:0.1.0:bafybeibt44wsyruovefpezbuean5rnzccd44zwge2xsddpbp6fevphu2ui -- valory/trader_abci:0.1.0:bafybeig6zcnrmosil45k3crl2le5mxx5gnnsvktjh3oil3a2xigl76gr7m +- valory/decision_maker_abci:0.1.0:bafybeigianh43fjwufi5bv4n4cjsa5nuv5cihuq5db6xyya347d4brxd2m +- valory/trader_abci:0.1.0:bafybeigxsa4uvssmhghokwscwca7flu7eiqr6aq5me4wn2v22od6lxmotm - valory/staking_abci:0.1.0:bafybeidubhfvlf6x627t4wetc6ran5sb4pttjphyhv6vefp2a4kcuca2be - valory/check_stop_trading_abci:0.1.0:bafybeie6vnp4oovs3k6qnqjcjcjiok6u2uu4dkyd5gqibu77zxpcmztbnq - 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 9e0fbfd78..316f72d92 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:bafybeihii7hnxv5pbrb25f5suh5eye62qnjlcy5oq2kpjchxppwwm62mre +agent: valory/trader:0.1.0:bafybeih6wqj5vwkeaq4wbmelcrudbrqcemtqj245usk5nyuvq3z7yxvko4 number_of_agents: 4 deployment: agent: diff --git a/packages/valory/services/trader_omen_gnosis/service.yaml b/packages/valory/services/trader_omen_gnosis/service.yaml index 20ea2c0c3..8fc76ddb5 100644 --- a/packages/valory/services/trader_omen_gnosis/service.yaml +++ b/packages/valory/services/trader_omen_gnosis/service.yaml @@ -8,7 +8,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeihii7hnxv5pbrb25f5suh5eye62qnjlcy5oq2kpjchxppwwm62mre +agent: valory/trader:0.1.0:bafybeih6wqj5vwkeaq4wbmelcrudbrqcemtqj245usk5nyuvq3z7yxvko4 number_of_agents: 1 deployment: agent: diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index e8db58496..5d1b3ad32 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -57,7 +57,7 @@ fingerprint: tests/behaviours/data/.gitkeep: bafybeiekl43sjsyqfgl6y27ve5ydo4svcngrptgtffblokmspfezroxvvi tests/behaviours/dummy_strategy/__init__.py: bafybeiep5w5yckjzy724v63qd5cmzfn3uxytmnizynomxggfobbysfcttq tests/behaviours/dummy_strategy/dummy_strategy.py: bafybeig5e3xfr7gxsakfj4stbxqcwdiljl7klvgahkuwe3obzxgkg3qt2e - tests/behaviours/test_base.py: bafybeifuh6qhdksgishs46bwzyoroe3bzd2umaxgz4hwkxmdiebn4zynme + tests/behaviours/test_base.py: bafybeiagdrveenk62parzchxg2nd2krpzm2pflfv3p4gszjfpnv3r2kpf4 tests/conftest.py: bafybeidy5hw56kw5mxudnfbhvogofn6k4rqb4ux2bd45baedrrhmgyrude utils/__init__.py: bafybeiazrfg3kwfdl5q45azwz6b6mobqxngxpf4hazmrnkhinpk4qhbbf4 utils/nevermined.py: bafybeigallaqxhqopznhjhefr6bukh4ojkz5vdtqyzod5dksshrf24fjgi diff --git a/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py b/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py index 2e7f55060..a1f338aa9 100644 --- a/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py +++ b/packages/valory/skills/decision_maker_abci/tests/behaviours/test_base.py @@ -34,7 +34,9 @@ ) from packages.valory.skills.decision_maker_abci.behaviours.base import ( BET_AMOUNT_FIELD, - remove_fraction_wei, DecisionMakerBaseBehaviour, WXDAI, + DecisionMakerBaseBehaviour, + WXDAI, + remove_fraction_wei, ) from packages.valory.skills.decision_maker_abci.behaviours.blacklisting import ( BlacklistingBehaviour, @@ -189,7 +191,9 @@ def test_wei_to_native(self, wei: int) -> None: assert result == wei / 10**18 @given(st.integers(), st.booleans(), st.booleans()) - def test_collateral_amount_info(self, amount: int, benchmarking_mode_enabled: bool, is_wxdai: bool) -> None: + def test_collateral_amount_info( + self, amount: int, benchmarking_mode_enabled: bool, is_wxdai: bool + ) -> None: """Test the `collateral_amount_info` method.""" # use `BlacklistingBehaviour` because it overrides the `DecisionMakerBaseBehaviour`. self.ffw(BlacklistingBehaviour, {"sampled_bet_index": 0}) @@ -205,10 +209,15 @@ def test_collateral_amount_info(self, amount: int, benchmarking_mode_enabled: bo if benchmarking_mode_enabled or is_wxdai: assert result == f"{behaviour.wei_to_native(amount)} wxDAI" else: - assert result == f"{amount} WEI of the collateral token with address {collateral_token}" + assert ( + result + == f"{amount} WEI of the collateral token with address {collateral_token}" + ) @given(st.integers(), st.integers()) - def test_mock_balance_check(self, collateral_balance: int, native_balance: int) -> None: + def test_mock_balance_check( + self, collateral_balance: int, native_balance: int + ) -> None: """Test the `_mock_balance_check` method.""" # use `BlacklistingBehaviour` because it overrides the `DecisionMakerBaseBehaviour`. self.ffw(BlacklistingBehaviour) diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 4606d52fc..1702b6da9 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -25,8 +25,8 @@ skills: - valory/transaction_settlement_abci:0.1.0:bafybeic3tccdjypuge2lewtlgprwkbb53lhgsgn7oiwzyrcrrptrbeyote - valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq - valory/market_manager_abci:0.1.0:bafybeicbvxvjkoksbknujaid5hx7krjlgm6barcjcwo33tdccanrcp674a -- valory/decision_maker_abci:0.1.0:bafybeibt44wsyruovefpezbuean5rnzccd44zwge2xsddpbp6fevphu2ui -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiddh2iqcn355syeqalmq2hdpczfcx6wijnvtpfie5gi6hasprstii +- valory/decision_maker_abci:0.1.0:bafybeigianh43fjwufi5bv4n4cjsa5nuv5cihuq5db6xyya347d4brxd2m +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaj4us7tbtc2ctpofnrk6fkk7uekcjx65y5wbcwwfbgzeoccyy62e - valory/staking_abci:0.1.0:bafybeidubhfvlf6x627t4wetc6ran5sb4pttjphyhv6vefp2a4kcuca2be - valory/check_stop_trading_abci:0.1.0:bafybeie6vnp4oovs3k6qnqjcjcjiok6u2uu4dkyd5gqibu77zxpcmztbnq - 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 1d1435a6d..1806437b5 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -21,7 +21,7 @@ protocols: - valory/ledger_api:1.0.0:bafybeihdk6psr4guxmbcrc26jr2cbgzpd5aljkqvpwo64bvaz7tdti2oni skills: - valory/abstract_round_abci:0.1.0:bafybeiar2yhzxacfe3qqamqhaihtlcimquwedffctw55sowx6rac3cm3ui -- valory/decision_maker_abci:0.1.0:bafybeibt44wsyruovefpezbuean5rnzccd44zwge2xsddpbp6fevphu2ui +- valory/decision_maker_abci:0.1.0:bafybeigianh43fjwufi5bv4n4cjsa5nuv5cihuq5db6xyya347d4brxd2m - valory/staking_abci:0.1.0:bafybeidubhfvlf6x627t4wetc6ran5sb4pttjphyhv6vefp2a4kcuca2be - valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e behaviours: