Skip to content

Commit 155ca25

Browse files
authored
Merge pull request #2899 from opentensor/fix/roman/get_next_epoch_start_block
e2e tests are working with subtensor patch
2 parents c8d3d59 + 9b30583 commit 155ca25

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

bittensor/core/async_subtensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ async def get_next_epoch_start_block(
17961796
netuid=netuid, block=block, block_hash=block_hash, reuse_block=reuse_block
17971797
)
17981798

1799-
if block and blocks_since_last_step and tempo:
1799+
if block and blocks_since_last_step is not None and tempo:
18001800
return block - blocks_since_last_step + tempo + 1
18011801
return None
18021802

bittensor/core/subtensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ def get_next_epoch_start_block(
13851385
blocks_since_last_step = self.blocks_since_last_step(netuid=netuid, block=block)
13861386
tempo = self.tempo(netuid=netuid, block=block)
13871387

1388-
if block and blocks_since_last_step and tempo:
1388+
if block and blocks_since_last_step is not None and tempo:
13891389
return block - blocks_since_last_step + tempo + 1
13901390
return None
13911391

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)