Skip to content

Commit 50fc0aa

Browse files
author
Roman
committed
add unit tests for get_subnet_info to subtensors
1 parent 4b8fef8 commit 50fc0aa

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

tests/unit_tests/test_async_subtensor.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,3 +3314,60 @@ async def test_get_subnet_validator_permits_is_none(subtensor, mocker):
33143314
)
33153315

33163316
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+

tests/unit_tests/test_subtensor.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,3 +3668,55 @@ def test_is_subnet_active(subtensor, mocker, query_return, expected):
36683668
)
36693669

36703670
assert result == expected
3671+
3672+
3673+
# `geg_l_subnet_info` tests
3674+
def test_get_subnet_info_success(mocker, subtensor):
3675+
"""Test get_subnet_info returns correct data when subnet information is found."""
3676+
# Prep
3677+
netuid = mocker.Mock()
3678+
block = mocker.Mock()
3679+
3680+
mocker.patch.object(subtensor, "query_runtime_api")
3681+
mocker.patch.object(
3682+
subtensor_module.SubnetInfo,
3683+
"from_dict",
3684+
)
3685+
3686+
# Call
3687+
result = subtensor.get_subnet_info(netuid=netuid, block=block)
3688+
3689+
# Asserts
3690+
subtensor.query_runtime_api.assert_called_once_with(
3691+
runtime_api="SubnetInfoRuntimeApi",
3692+
method="get_subnet_info_v2",
3693+
params=[netuid],
3694+
block=block,
3695+
)
3696+
subtensor_module.SubnetInfo.from_dict.assert_called_once_with(
3697+
subtensor.query_runtime_api.return_value,
3698+
)
3699+
assert result == subtensor_module.SubnetInfo.from_dict.return_value
3700+
3701+
3702+
def test_get_subnet_info_no_data(mocker, subtensor):
3703+
"""Test get_subnet_info returns None."""
3704+
# Prep
3705+
netuid = mocker.Mock()
3706+
block = mocker.Mock()
3707+
mocker.patch.object(subtensor_module.SubnetInfo, "from_dict")
3708+
mocker.patch.object(subtensor, "query_runtime_api", return_value=None)
3709+
3710+
# Call
3711+
result = subtensor.get_subnet_info(netuid=netuid, block=block)
3712+
3713+
# Asserts
3714+
subtensor.query_runtime_api.assert_called_once_with(
3715+
runtime_api="SubnetInfoRuntimeApi",
3716+
method="get_subnet_info_v2",
3717+
params=[netuid],
3718+
block=block,
3719+
)
3720+
subtensor_module.SubnetInfo.from_dict.assert_not_called()
3721+
assert result is None
3722+

0 commit comments

Comments
 (0)