Skip to content

Commit 9b30583

Browse files
author
Roman
committed
add unit test for 3 scenarios
1 parent d6393f9 commit 9b30583

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/unit_tests/test_async_subtensor.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,3 +3370,38 @@ async def test_get_subnet_info_no_data(mocker, subtensor):
33703370
)
33713371
async_subtensor.SubnetInfo.from_dict.assert_not_called()
33723372
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

tests/unit_tests/test_subtensor.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3719,3 +3719,30 @@ def test_get_subnet_info_no_data(mocker, subtensor):
37193719
)
37203720
subtensor_module.SubnetInfo.from_dict.assert_not_called()
37213721
assert result is None
3722+
3723+
3724+
@pytest.mark.parametrize(
3725+
"call_return, expected",
3726+
[[10, 111], [None, None], [0, 121]],
3727+
)
3728+
def test_get_next_epoch_start_block(mocker, subtensor, call_return, expected):
3729+
"""Check that get_next_epoch_start_block returns the correct value."""
3730+
# Prep
3731+
netuid = mocker.Mock()
3732+
block = 20
3733+
3734+
mocked_blocks_since_last_step = mocker.Mock(return_value=call_return)
3735+
subtensor.blocks_since_last_step = mocked_blocks_since_last_step
3736+
3737+
mocker.patch.object(subtensor, "tempo", return_value=100)
3738+
3739+
# Call
3740+
result = subtensor.get_next_epoch_start_block(netuid=netuid, block=block)
3741+
3742+
# Asserts
3743+
mocked_blocks_since_last_step.assert_called_once_with(
3744+
netuid=netuid,
3745+
block=block,
3746+
)
3747+
subtensor.tempo.assert_called_once_with(netuid=netuid, block=block)
3748+
assert result == expected

0 commit comments

Comments
 (0)