@@ -1981,6 +1981,90 @@ async def test_get_children_substrate_request_exception(subtensor, mocker):
1981
1981
assert result == (False , [], "Formatted error message" )
1982
1982
1983
1983
1984
+ @pytest .mark .asyncio
1985
+ async def test_get_parents_success (subtensor , mocker ):
1986
+ """Tests get_parents when parents are successfully retrieved and formatted."""
1987
+ # Preps
1988
+ fake_hotkey = "valid_hotkey"
1989
+ fake_netuid = 1
1990
+ fake_parents = mocker .Mock (
1991
+ value = [
1992
+ (1000 , ["parent_key_1" ]),
1993
+ (2000 , ["parent_key_2" ]),
1994
+ ]
1995
+ )
1996
+
1997
+ mocked_query = mocker .AsyncMock (return_value = fake_parents )
1998
+ subtensor .substrate .query = mocked_query
1999
+
2000
+ mocked_decode_account_id = mocker .Mock (
2001
+ side_effect = ["decoded_parent_key_1" , "decoded_parent_key_2" ]
2002
+ )
2003
+ mocker .patch .object (async_subtensor , "decode_account_id" , mocked_decode_account_id )
2004
+
2005
+ expected_formatted_parents = [
2006
+ (u64_normalized_float (1000 ), "decoded_parent_key_1" ),
2007
+ (u64_normalized_float (2000 ), "decoded_parent_key_2" ),
2008
+ ]
2009
+
2010
+ # Call
2011
+ result = await subtensor .get_parents (hotkey = fake_hotkey , netuid = fake_netuid )
2012
+
2013
+ # Asserts
2014
+ mocked_query .assert_called_once_with (
2015
+ block_hash = None ,
2016
+ module = "SubtensorModule" ,
2017
+ storage_function = "ParentKeys" ,
2018
+ params = [fake_hotkey , fake_netuid ],
2019
+ reuse_block_hash = False ,
2020
+ )
2021
+ mocked_decode_account_id .assert_has_calls (
2022
+ [mocker .call ("parent_key_1" ), mocker .call ("parent_key_2" )]
2023
+ )
2024
+ assert result == expected_formatted_parents
2025
+
2026
+
2027
+ @pytest .mark .asyncio
2028
+ async def test_get_parents_no_parents (subtensor , mocker ):
2029
+ """Tests get_parents when there are no parents to retrieve."""
2030
+ # Preps
2031
+ fake_hotkey = "valid_hotkey"
2032
+ fake_netuid = 1
2033
+ fake_parents = []
2034
+
2035
+ mocked_query = mocker .AsyncMock (return_value = fake_parents )
2036
+ subtensor .substrate .query = mocked_query
2037
+
2038
+ # Call
2039
+ result = await subtensor .get_parents (hotkey = fake_hotkey , netuid = fake_netuid )
2040
+
2041
+ # Asserts
2042
+ mocked_query .assert_called_once_with (
2043
+ block_hash = None ,
2044
+ module = "SubtensorModule" ,
2045
+ storage_function = "ParentKeys" ,
2046
+ params = [fake_hotkey , fake_netuid ],
2047
+ reuse_block_hash = False ,
2048
+ )
2049
+ assert result == []
2050
+
2051
+
2052
+ @pytest .mark .asyncio
2053
+ async def test_get_parents_substrate_request_exception (subtensor , mocker ):
2054
+ """Tests get_parents when SubstrateRequestException is raised."""
2055
+ # Preps
2056
+ fake_hotkey = "valid_hotkey"
2057
+ fake_netuid = 1
2058
+ fake_exception = async_subtensor .SubstrateRequestException ("Test Exception" )
2059
+
2060
+ mocked_query = mocker .AsyncMock (side_effect = fake_exception )
2061
+ subtensor .substrate .query = mocked_query
2062
+
2063
+ # Call
2064
+ with pytest .raises (async_subtensor .SubstrateRequestException ):
2065
+ await subtensor .get_parents (hotkey = fake_hotkey , netuid = fake_netuid )
2066
+
2067
+
1984
2068
@pytest .mark .asyncio
1985
2069
async def test_get_children_pending (mock_substrate , subtensor ):
1986
2070
mock_substrate .query .return_value .value = [
0 commit comments