Skip to content

Commit

Permalink
Merge pull request #283 from valory-xyz/test/base
Browse files Browse the repository at this point in the history
Implement tests for the base
  • Loading branch information
Divya-Solulab authored Jun 21, 2024
2 parents e896147 + 23e4fcc commit 64fa99d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 15 deletions.
12 changes: 6 additions & 6 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader_omen_gnosis/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +34,8 @@
)
from packages.valory.skills.decision_maker_abci.behaviours.base import (
BET_AMOUNT_FIELD,
DecisionMakerBaseBehaviour,
WXDAI,
remove_fraction_wei,
)
from packages.valory.skills.decision_maker_abci.behaviours.blacklisting import (
Expand Down Expand Up @@ -180,6 +183,55 @@ 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

@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}"
)

@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",
(
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 64fa99d

Please sign in to comment.