Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug in the get_subnets function #2240

Open
wants to merge 21 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8022866
Applies fix and assertions
ibraheem-opentensor Aug 14, 2024
96badeb
Debug commit
ibraheem-opentensor Aug 15, 2024
af76ca3
Fixed a bug in the get_subnets function
niljub Aug 15, 2024
40512c8
Dummy commit
ibraheem-opentensor Aug 15, 2024
bf00b93
Merge branch 'staging' into hotfix/7.3.0/get-subnets-fix/niljub
niljub Aug 16, 2024
89d0bd3
Merge branch 'staging' into hotfix/7.3.0/get-subnets-fix/niljub
niljub Aug 17, 2024
1934ad3
Changed the test to test 500 subnets
niljub Aug 19, 2024
65aa008
Merge branch 'hotfix/7.3.0/get-subnets-fix/niljub' of https://github.…
niljub Aug 19, 2024
ad1c35a
Fixed a bug in the get_subnets function (again)
niljub Aug 19, 2024
0d236db
Child Hotkeys netuid Refactor
Aug 29, 2024
4379c59
CHK Test
Aug 29, 2024
4b046c3
u16 float limit
Aug 29, 2024
dfe3cfd
Merge branch 'staging' into feat/opendansor/chk
Aug 29, 2024
f0e09f2
Merge pull request #2276 from opentensor/feat/opendansor/chk
Aug 29, 2024
0d7361b
Merge branch 'staging' into hotfix/7.3.0/get-subnets-fix/niljub
distributedstatemachine Sep 3, 2024
f7345a6
Merge branch 'staging' into fix/metagraph-load-and-assertions
ibraheem-opentensor Sep 3, 2024
d438b0f
Merge pull request #2235 from opentensor/fix/metagraph-load-and-asser…
ibraheem-opentensor Sep 3, 2024
6a7b2ca
Add reconnection logic + tests
roman-opentensor Sep 3, 2024
5fcdcfd
Merge pull request #2280 from opentensor/feat/roman/add-subtensor-rec…
roman-opentensor Sep 3, 2024
c7b4739
removed exit sys call for ConnectionRefusedError in _get_substrate (#…
garrett-opentensor Sep 6, 2024
8cdf462
Merge branch 'staging' into hotfix/7.3.0/get-subnets-fix/niljub
niljub Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bittensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4253,11 +4253,11 @@ def get_subnets(self, block: Optional[int] = None) -> List[int]:
available for neuron participation and collaboration.
"""
result = self.query_map_subtensor("NetworksAdded", block)
return (
[network[0].value for network in result.records]
if result and hasattr(result, "records")
else []
)
subnets = []
if result and hasattr(result, "records"):
for record in result.records:
subnets.append(record[0].value)
return subnets

def get_all_subnets_info(self, block: Optional[int] = None) -> List[SubnetInfo]:
"""
Expand Down
18 changes: 18 additions & 0 deletions tests/unit_tests/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,24 @@ def test_get_subnets_no_block_specified(mocker, subtensor):
subtensor.query_map_subtensor.assert_called_once_with("NetworksAdded", None)


def test_get_subnets_correct_length(mocker, subtensor):
"""Test get_subnets returns a list of the correct length."""
# Prep
block = 123
num_records = 50
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this test for length > 100?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right—I missed a zero. I've added it and pushed a changed version along with the updated test, but the test still doesn't catch the issue. I also updated get_subnets again and verified it by running your snippet.

import bittensor

sub = bittensor.subtensor("wss://test.chain.opentensor.ai:443")
subnets = sub.get_subnets()
n_subnets = sub.get_total_subnets()

len(subnets) == n_subnets
# True; Expected: True

mock_records = [(mocker.MagicMock(value=i), True) for i in range(num_records)]
mock_result = mocker.MagicMock()
mock_result.records = mock_records
mocker.patch.object(subtensor, "query_map_subtensor", return_value=mock_result)

# Call
result = subtensor.get_subnets(block)

# Asserts
assert len(result) == num_records
subtensor.query_map_subtensor.assert_called_once_with("NetworksAdded", block)


# `get_all_subnets_info` tests
def test_get_all_subnets_info_success(mocker, subtensor):
"""Test get_all_subnets_info returns correct data when subnet information is found."""
Expand Down