@@ -3314,3 +3314,94 @@ async def test_get_subnet_validator_permits_is_none(subtensor, mocker):
3314
3314
)
3315
3315
3316
3316
assert result is None
3317
+
3318
+
3319
+ @pytest .mark .asyncio
3320
+ async def test_get_subnet_info_success (mocker , subtensor ):
3321
+ """Test get_subnet_info returns correct data when subnet information is found."""
3322
+ # Prep
3323
+ netuid = mocker .Mock ()
3324
+ block = mocker .Mock ()
3325
+
3326
+ mocker .patch .object (subtensor , "query_runtime_api" )
3327
+ mocker .patch .object (
3328
+ async_subtensor .SubnetInfo ,
3329
+ "from_dict" ,
3330
+ )
3331
+
3332
+ # Call
3333
+ result = await subtensor .get_subnet_info (netuid = netuid , block = block )
3334
+
3335
+ # Asserts
3336
+ subtensor .query_runtime_api .assert_awaited_once_with (
3337
+ runtime_api = "SubnetInfoRuntimeApi" ,
3338
+ method = "get_subnet_info_v2" ,
3339
+ params = [netuid ],
3340
+ block = block ,
3341
+ block_hash = None ,
3342
+ reuse_block = False ,
3343
+ )
3344
+ async_subtensor .SubnetInfo .from_dict .assert_called_once_with (
3345
+ subtensor .query_runtime_api .return_value ,
3346
+ )
3347
+ assert result == async_subtensor .SubnetInfo .from_dict .return_value
3348
+
3349
+
3350
+ @pytest .mark .asyncio
3351
+ async def test_get_subnet_info_no_data (mocker , subtensor ):
3352
+ """Test get_subnet_info returns None."""
3353
+ # Prep
3354
+ netuid = mocker .Mock ()
3355
+ block = mocker .Mock ()
3356
+ mocker .patch .object (async_subtensor .SubnetInfo , "from_dict" )
3357
+ mocker .patch .object (subtensor , "query_runtime_api" , return_value = None )
3358
+
3359
+ # Call
3360
+ result = await subtensor .get_subnet_info (netuid = netuid , block = block )
3361
+
3362
+ # Asserts
3363
+ subtensor .query_runtime_api .assert_awaited_once_with (
3364
+ runtime_api = "SubnetInfoRuntimeApi" ,
3365
+ method = "get_subnet_info_v2" ,
3366
+ params = [netuid ],
3367
+ block = block ,
3368
+ block_hash = None ,
3369
+ reuse_block = False ,
3370
+ )
3371
+ async_subtensor .SubnetInfo .from_dict .assert_not_called ()
3372
+ assert result is None
3373
+
3374
+
3375
+ @pytest .mark .parametrize (
3376
+ "call_return, expected" ,
3377
+ [[10 , 111 ], [None , None ], [0 , 121 ]],
3378
+ )
3379
+ @pytest .mark .asyncio
3380
+ async def test_get_next_epoch_start_block (mocker , subtensor , call_return , expected ):
3381
+ """Check that get_next_epoch_start_block returns the correct value."""
3382
+ # Prep
3383
+ netuid = mocker .Mock ()
3384
+ block = 20
3385
+
3386
+ fake_block_hash = mocker .Mock ()
3387
+ mocker .patch .object (subtensor , "get_block_hash" , return_value = fake_block_hash )
3388
+
3389
+ mocked_blocks_since_last_step = mocker .AsyncMock (return_value = call_return )
3390
+ subtensor .blocks_since_last_step = mocked_blocks_since_last_step
3391
+
3392
+ mocker .patch .object (subtensor , "tempo" , return_value = 100 )
3393
+
3394
+ # Call
3395
+ result = await subtensor .get_next_epoch_start_block (netuid = netuid , block = block )
3396
+
3397
+ # Asserts
3398
+ mocked_blocks_since_last_step .assert_called_once_with (
3399
+ netuid = netuid ,
3400
+ block = block ,
3401
+ block_hash = fake_block_hash ,
3402
+ reuse_block = False ,
3403
+ )
3404
+ subtensor .tempo .assert_awaited_once_with (
3405
+ netuid = netuid , block = block , block_hash = fake_block_hash , reuse_block = False
3406
+ )
3407
+ assert result == expected
0 commit comments