Skip to content

Commit 4845a7e

Browse files
committed
Changed return types and fixed tests to reflect this
1 parent d6e9e24 commit 4845a7e

File tree

5 files changed

+17
-51
lines changed

5 files changed

+17
-51
lines changed

bittensor/core/async_subtensor.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ async def get_parents(
980980
block: Optional[int] = None,
981981
block_hash: Optional[str] = None,
982982
reuse_block: bool = False,
983-
) -> tuple[bool, list[tuple[float, str]], str]:
983+
) -> list[tuple[float, str]]:
984984
"""
985985
This method retrieves the parent of a given hotkey and netuid. It queries the SubtensorModule's ParentKeys
986986
storage function to get the children and formats them before returning as a tuple.
@@ -993,8 +993,7 @@ async def get_parents(
993993
reuse_block (bool): Whether to reuse the last-used block hash.
994994
995995
Returns:
996-
A tuple containing a boolean indicating success or failure, a list of formatted
997-
parents [(proportion, parent)], and an error message (if applicable)
996+
A list of formatted parents [(proportion, parent)]
998997
"""
999998
block_hash = await self.determine_block_hash(block, block_hash, reuse_block)
1000999
parents = await self.substrate.query(
@@ -1011,9 +1010,9 @@ async def get_parents(
10111010
formatted_child = decode_account_id(parent[0])
10121011
normalized_proportion = u64_normalized_float(proportion)
10131012
formatted_parents.append((normalized_proportion, formatted_child))
1014-
return True, formatted_parents, ""
1013+
return formatted_parents
10151014
else:
1016-
return True, [], ""
1015+
return []
10171016

10181017
async def get_children(
10191018
self,

bittensor/core/subtensor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ def get_hyperparameter(
753753

754754
def get_parents(
755755
self, hotkey: str, netuid: int, block: Optional[int] = None
756-
) -> tuple[bool, list[tuple[float, str]], str]:
756+
) -> list[tuple[float, str]]:
757757
"""
758758
This method retrieves the parent of a given hotkey and netuid. It queries the SubtensorModule's ParentKeys
759759
storage function to get the children and formats them before returning as a tuple.
@@ -764,8 +764,7 @@ def get_parents(
764764
block (Optional[int]): The block number for which the children are to be retrieved.
765765
766766
Returns:
767-
A tuple containing a boolean indicating success or failure, a list of formatted
768-
parents [(proportion, parent)], and an error message (if applicable)
767+
A list of formatted parents [(proportion, parent)]
769768
"""
770769
parents = self.substrate.query(
771770
module="SubtensorModule",

tests/e2e_tests/test_hotkeys.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,8 @@ async def test_children(local_chain, subtensor, alice_wallet, bob_wallet, dave_w
276276
assert success is True
277277
assert children == [(1.0, bob_wallet.hotkey.ss58_address)]
278278

279-
success_, parent_, error_ = subtensor.get_parents(
280-
bob_wallet.hotkey.ss58_address, dave_subnet_netuid
281-
)
279+
parent_ = subtensor.get_parents(bob_wallet.hotkey.ss58_address, dave_subnet_netuid)
282280

283-
assert error_ == ""
284-
assert success_ is True
285281
assert parent_ == [(1.0, alice_wallet.hotkey.ss58_address)]
286282

287283
# pending queue is empty

tests/unit_tests/test_async_subtensor.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ async def test_get_parents_success(subtensor, mocker):
20212021
mocked_decode_account_id.assert_has_calls(
20222022
[mocker.call("parent_key_1"), mocker.call("parent_key_2")]
20232023
)
2024-
assert result == (True, expected_formatted_parents, "")
2024+
assert result == expected_formatted_parents
20252025

20262026

20272027
@pytest.mark.asyncio
@@ -2046,7 +2046,7 @@ async def test_get_parents_no_parents(subtensor, mocker):
20462046
params=[fake_hotkey, fake_netuid],
20472047
reuse_block_hash=False,
20482048
)
2049-
assert result == (True, [], "")
2049+
assert result == []
20502050

20512051

20522052
@pytest.mark.asyncio
@@ -2060,24 +2060,9 @@ async def test_get_parents_substrate_request_exception(subtensor, mocker):
20602060
mocked_query = mocker.AsyncMock(side_effect=fake_exception)
20612061
subtensor.substrate.query = mocked_query
20622062

2063-
mocked_format_error_message = mocker.Mock(return_value="Formatted error message")
2064-
mocker.patch.object(
2065-
async_subtensor, "format_error_message", mocked_format_error_message
2066-
)
2067-
20682063
# Call
2069-
result = await subtensor.get_parents(hotkey=fake_hotkey, netuid=fake_netuid)
2070-
2071-
# Asserts
2072-
mocked_query.assert_called_once_with(
2073-
block_hash=None,
2074-
module="SubtensorModule",
2075-
storage_function="ParentKeys",
2076-
params=[fake_hotkey, fake_netuid],
2077-
reuse_block_hash=False,
2078-
)
2079-
mocked_format_error_message.assert_called_once_with(fake_exception)
2080-
assert result == (False, [], "Formatted error message")
2064+
with pytest.raises(async_subtensor.SubstrateRequestException):
2065+
await subtensor.get_parents(hotkey=fake_hotkey, netuid=fake_netuid)
20812066

20822067

20832068
@pytest.mark.asyncio

tests/unit_tests/test_subtensor.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from async_substrate_interface import sync_substrate
99
from async_substrate_interface.types import ScaleObj
1010
import websockets
11+
from substrateinterface.exceptions import SubstrateRequestException
1112

1213
from bittensor import StakeInfo
1314
from bittensor.core import settings
@@ -3786,7 +3787,7 @@ def test_get_parents_success(subtensor, mocker):
37863787
mocked_decode_account_id.assert_has_calls(
37873788
[mocker.call("parent_key_1"), mocker.call("parent_key_2")]
37883789
)
3789-
assert result == (True, expected_formatted_parents, "")
3790+
assert result == expected_formatted_parents
37903791

37913792

37923793
def test_get_parents_no_parents(subtensor, mocker):
@@ -3809,33 +3810,19 @@ def test_get_parents_no_parents(subtensor, mocker):
38093810
storage_function="ParentKeys",
38103811
params=[fake_hotkey, fake_netuid],
38113812
)
3812-
assert result == (True, [], "")
3813+
assert result == []
38133814

38143815

38153816
def test_get_parents_substrate_request_exception(subtensor, mocker):
38163817
"""Tests get_parents when SubstrateRequestException is raised."""
38173818
# Preps
38183819
fake_hotkey = "valid_hotkey"
38193820
fake_netuid = 1
3820-
fake_exception = subtensor_module.SubstrateRequestException("Test Exception")
3821+
fake_exception = SubstrateRequestException("Test Exception")
38213822

38223823
mocked_query = mocker.MagicMock(side_effect=fake_exception)
38233824
subtensor.substrate.query = mocked_query
38243825

3825-
mocked_format_error_message = mocker.Mock(return_value="Formatted error message")
3826-
mocker.patch.object(
3827-
subtensor_module, "format_error_message", mocked_format_error_message
3828-
)
3829-
38303826
# Call
3831-
result = subtensor.get_parents(hotkey=fake_hotkey, netuid=fake_netuid)
3832-
3833-
# Asserts
3834-
mocked_query.assert_called_once_with(
3835-
block_hash=None,
3836-
module="SubtensorModule",
3837-
storage_function="ParentKeys",
3838-
params=[fake_hotkey, fake_netuid],
3839-
)
3840-
mocked_format_error_message.assert_called_once_with(fake_exception)
3841-
assert result == (False, [], "Formatted error message")
3827+
with pytest.raises(SubstrateRequestException):
3828+
subtensor.get_parents(hotkey=fake_hotkey, netuid=fake_netuid)

0 commit comments

Comments
 (0)