Skip to content

Commit 3adfc84

Browse files
committed
update unit tests
1 parent cbd5d68 commit 3adfc84

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

tests/unit_tests/test_async_subtensor.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,31 +3780,40 @@ async def test_get_subnet_price(subtensor, mocker):
37803780
@pytest.mark.asyncio
37813781
async def test_get_subnet_prices(subtensor, mocker):
37823782
"""Test get_subnet_prices returns the correct value."""
3783-
# preps
3784-
mocked_determine_block_hash = mocker.patch.object(subtensor, "determine_block_hash")
3783+
# Preps
3784+
fake_netuids = [1, 2]
3785+
fake_price_1 = Balance.from_tao(0.5)
3786+
fake_price_2 = Balance.from_tao(1.5)
3787+
fake_block_hash = "fake_block_hash"
37853788

3786-
async def fake_current_sqrt_prices():
3787-
yield [0, {"bits": 0}]
3788-
yield [1, {"bits": 3155343338053956962}]
3789+
mocked_determine_block_hash = mocker.patch.object(
3790+
subtensor, "determine_block_hash", return_value=fake_block_hash
3791+
)
3792+
mocked_get_all_subnets_netuid = mocker.patch.object(
3793+
subtensor, "get_all_subnets_netuid", return_value=fake_netuids
3794+
)
37893795

3790-
expected_prices = {0: Balance.from_tao(1), 1: Balance.from_tao(0.029258617)}
3791-
mocked_query_map = mocker.patch.object(
3792-
subtensor.substrate, "query_map", return_value=fake_current_sqrt_prices()
3796+
async def fake_get_subnet_price(netuid, **kwargs):
3797+
if netuid == 1:
3798+
return fake_price_1
3799+
elif netuid == 2:
3800+
return fake_price_2
3801+
3802+
mocked_get_subnet_price = mocker.patch.object(
3803+
subtensor, "get_subnet_price", side_effect=fake_get_subnet_price
37933804
)
37943805

3806+
expected_prices = {0: Balance.from_tao(1), 1: fake_price_1, 2: fake_price_2}
3807+
37953808
# Call
37963809
result = await subtensor.get_subnet_prices()
37973810

37983811
# Asserts
3799-
mocked_determine_block_hash.assert_awaited_once_with(
3800-
block=None, block_hash=None, reuse_block=False
3801-
)
3802-
mocked_query_map.assert_awaited_once_with(
3803-
module="Swap",
3804-
storage_function="AlphaSqrtPrice",
3805-
block_hash=mocked_determine_block_hash.return_value,
3806-
page_size=129, # total number of subnets
3812+
mocked_determine_block_hash.assert_awaited_once_with(None, None)
3813+
mocked_get_all_subnets_netuid.assert_awaited_once_with(
3814+
block=None, block_hash=fake_block_hash, reuse_block=False
38073815
)
3816+
assert mocked_get_subnet_price.call_count == 2
38083817
assert result == expected_prices
38093818

38103819

tests/unit_tests/test_subtensor.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,28 +4056,28 @@ def test_get_subnet_price(subtensor, mocker):
40564056

40574057
def test_get_subnet_prices(subtensor, mocker):
40584058
"""Test get_subnet_prices returns the correct value."""
4059-
# preps
4060-
mocked_determine_block_hash = mocker.patch.object(subtensor, "determine_block_hash")
4061-
fake_prices = [
4062-
[0, {"bits": 0}],
4063-
[1, {"bits": 3155343338053956962}],
4064-
]
4065-
expected_prices = {0: Balance.from_tao(1), 1: Balance.from_tao(0.029258617)}
4066-
mocked_query_map = mocker.patch.object(
4067-
subtensor.substrate, "query_map", return_value=fake_prices
4059+
# Preps
4060+
fake_netuids = [1, 2]
4061+
fake_price_1 = Balance.from_tao(0.5)
4062+
fake_price_2 = Balance.from_tao(1.5)
4063+
4064+
mocked_get_all_subnets_netuid = mocker.patch.object(
4065+
subtensor, "get_all_subnets_netuid", return_value=fake_netuids
4066+
)
4067+
mocked_get_subnet_price = mocker.patch.object(
4068+
subtensor, "get_subnet_price", side_effect=[fake_price_1, fake_price_2]
40684069
)
40694070

4071+
expected_prices = {0: Balance.from_tao(1), 1: fake_price_1, 2: fake_price_2}
4072+
40704073
# Call
40714074
result = subtensor.get_subnet_prices()
40724075

40734076
# Asserts
4074-
mocked_determine_block_hash.assert_called_once_with(block=None)
4075-
mocked_query_map.assert_called_once_with(
4076-
module="Swap",
4077-
storage_function="AlphaSqrtPrice",
4078-
block_hash=mocked_determine_block_hash.return_value,
4079-
page_size=129, # total number of subnets
4080-
)
4077+
mocked_get_all_subnets_netuid.assert_called_once_with(block=None)
4078+
assert mocked_get_subnet_price.call_count == 2
4079+
mocked_get_subnet_price.assert_any_call(1, block=None)
4080+
mocked_get_subnet_price.assert_any_call(2, block=None)
40814081
assert result == expected_prices
40824082

40834083

0 commit comments

Comments
 (0)