@@ -3780,31 +3780,40 @@ async def test_get_subnet_price(subtensor, mocker):
37803780@pytest .mark .asyncio
37813781async 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
0 commit comments