@@ -5645,3 +5645,125 @@ async def test_blocks_until_next_epoch_uses_default_tempo(subtensor, mocker):
56455645 spy_tempo .assert_not_awaited ()
56465646 assert result is not None
56475647 assert isinstance (result , int )
5648+
5649+
5650+ @pytest .mark .asyncio
5651+ async def test_get_stake_info_for_coldkeys_none (subtensor , mocker ):
5652+ """Tests get_stake_info_for_coldkeys method when query_runtime_api returns None."""
5653+ # Preps
5654+ fake_coldkey_ss58s = ["coldkey1" , "coldkey2" ]
5655+ fake_block = 123
5656+ fake_block_hash = None
5657+ fake_reuse_block = False
5658+
5659+ mocked_query_runtime_api = mocker .AsyncMock (
5660+ autospec = subtensor .query_runtime_api , return_value = None
5661+ )
5662+ subtensor .query_runtime_api = mocked_query_runtime_api
5663+
5664+ # Call
5665+ result = await subtensor .get_stake_info_for_coldkeys (
5666+ coldkey_ss58s = fake_coldkey_ss58s ,
5667+ block = fake_block ,
5668+ block_hash = fake_block_hash ,
5669+ reuse_block = fake_reuse_block ,
5670+ )
5671+
5672+ # Asserts
5673+ assert result == {}
5674+ mocked_query_runtime_api .assert_called_once_with (
5675+ runtime_api = "StakeInfoRuntimeApi" ,
5676+ method = "get_stake_info_for_coldkeys" ,
5677+ params = [fake_coldkey_ss58s ],
5678+ block = fake_block ,
5679+ block_hash = fake_block_hash ,
5680+ reuse_block = fake_reuse_block ,
5681+ )
5682+
5683+
5684+ @pytest .mark .asyncio
5685+ async def test_get_stake_info_for_coldkeys_success (subtensor , mocker ):
5686+ """Tests get_stake_info_for_coldkeys method when query_runtime_api returns data."""
5687+ # Preps
5688+ fake_coldkey_ss58s = ["coldkey1" , "coldkey2" ]
5689+ fake_block = 123
5690+ fake_block_hash = None
5691+ fake_reuse_block = False
5692+
5693+ fake_ck1 = b"\x16 :\xec h\r \xde ,g\x03 R1\xb9 \x88 q\xe7 9\xb8 \x88 \x93 \xae \xd2 )?*\r p\xb2 \xe6 2\xad s\x1c "
5694+ fake_ck2 = b"\x17 :\xec h\r \xde ,g\x03 R1\xb9 \x88 q\xe7 9\xb8 \x88 \x93 \xae \xd2 )?*\r p\xb2 \xe6 2\xad s\x1d "
5695+ fake_decoded_ck1 = "decoded_coldkey1"
5696+ fake_decoded_ck2 = "decoded_coldkey2"
5697+
5698+ stake_info_dict_1 = {
5699+ "netuid" : 1 ,
5700+ "hotkey" : b"\x16 :\xec h\r \xde ,g\x03 R1\xb9 \x88 q\xe7 9\xb8 \x88 \x93 \xae \xd2 )?*\r p\xb2 \xe6 2\xad s\x1c " ,
5701+ "coldkey" : fake_ck1 ,
5702+ "stake" : 1000 ,
5703+ "locked" : 0 ,
5704+ "emission" : 100 ,
5705+ "drain" : 0 ,
5706+ "is_registered" : True ,
5707+ }
5708+ stake_info_dict_2 = {
5709+ "netuid" : 2 ,
5710+ "hotkey" : b"\x17 :\xec h\r \xde ,g\x03 R1\xb9 \x88 q\xe7 9\xb8 \x88 \x93 \xae \xd2 )?*\r p\xb2 \xe6 2\xad s\x1d " ,
5711+ "coldkey" : fake_ck2 ,
5712+ "stake" : 2000 ,
5713+ "locked" : 0 ,
5714+ "emission" : 200 ,
5715+ "drain" : 0 ,
5716+ "is_registered" : False ,
5717+ }
5718+
5719+ fake_query_result = [
5720+ (fake_ck1 , [stake_info_dict_1 ]),
5721+ (fake_ck2 , [stake_info_dict_2 ]),
5722+ ]
5723+
5724+ mocked_query_runtime_api = mocker .AsyncMock (
5725+ autospec = subtensor .query_runtime_api , return_value = fake_query_result
5726+ )
5727+ subtensor .query_runtime_api = mocked_query_runtime_api
5728+
5729+ mocked_decode_account_id = mocker .patch .object (
5730+ async_subtensor ,
5731+ "decode_account_id" ,
5732+ side_effect = [fake_decoded_ck1 , fake_decoded_ck2 ],
5733+ )
5734+
5735+ mock_stake_info_1 = mocker .Mock (spec = StakeInfo )
5736+ mock_stake_info_2 = mocker .Mock (spec = StakeInfo )
5737+ mocked_stake_info_list_from_dicts = mocker .patch .object (
5738+ async_subtensor .StakeInfo ,
5739+ "list_from_dicts" ,
5740+ side_effect = [[mock_stake_info_1 ], [mock_stake_info_2 ]],
5741+ )
5742+
5743+ # Call
5744+ result = await subtensor .get_stake_info_for_coldkeys (
5745+ coldkey_ss58s = fake_coldkey_ss58s ,
5746+ block = fake_block ,
5747+ block_hash = fake_block_hash ,
5748+ reuse_block = fake_reuse_block ,
5749+ )
5750+
5751+ # Asserts
5752+ assert result == {
5753+ fake_decoded_ck1 : [mock_stake_info_1 ],
5754+ fake_decoded_ck2 : [mock_stake_info_2 ],
5755+ }
5756+ mocked_query_runtime_api .assert_called_once_with (
5757+ runtime_api = "StakeInfoRuntimeApi" ,
5758+ method = "get_stake_info_for_coldkeys" ,
5759+ params = [fake_coldkey_ss58s ],
5760+ block = fake_block ,
5761+ block_hash = fake_block_hash ,
5762+ reuse_block = fake_reuse_block ,
5763+ )
5764+ mocked_decode_account_id .assert_has_calls (
5765+ [mocker .call (fake_ck1 ), mocker .call (fake_ck2 )]
5766+ )
5767+ mocked_stake_info_list_from_dicts .assert_has_calls (
5768+ [mocker .call ([stake_info_dict_1 ]), mocker .call ([stake_info_dict_2 ])]
5769+ )
0 commit comments