Skip to content

Commit

Permalink
Feat/rao changes (#10)
Browse files Browse the repository at this point in the history
* update lib and pyi for NeuronInfo fields

* bump ver

* change ver to pre-release

* chore: ruff

* chore: ruff

* use tuple instead

* use older version of bittensor for testing

* add more logging to test and attr fix

* use new neuron info for tests

* copy over test utils; stop using bittensor for comp

* use test utils for all tests
  • Loading branch information
camfairchild authored Jan 21, 2025
1 parent 65e9d2d commit f20d7d6
Show file tree
Hide file tree
Showing 8 changed files with 1,264 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tests/neurons.hex

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/neurons_lite.hex

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions tests/test_decode_delegate_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
fix_field as fix_field_fixes,
py_getattr as py_getattr_fixes,
)
from .utils import chain_data

TEST_DELEGATE_INFO_HEX = {
"delegated normal": lambda: get_file_bytes("tests/delegated_info.hex"),
Expand Down Expand Up @@ -54,7 +55,7 @@ def test_decode_delegated_matches_python_impl(self):
)
)

delegate_info_py_list = bittensor.DelegateInfo.delegated_list_from_vec_u8(
delegate_info_py_list = chain_data.DelegateInfo.delegated_list_from_vec_u8(
list(TEST_DELEGATE_INFO_HEX["delegated normal"]())
)

Expand Down Expand Up @@ -102,8 +103,8 @@ def test_decode_vec_matches_python_impl(self):
bt_decode.DelegateInfo.decode_vec(TEST_DELEGATE_INFO_HEX["vec normal"]())
)

delegates_info_py: List[bittensor.DelegateInfo] = (
bittensor.DelegateInfo.list_from_vec_u8(
delegates_info_py: List[chain_data.DelegateInfo] = (
chain_data.DelegateInfo.list_from_vec_u8(
list(TEST_DELEGATE_INFO_HEX["vec normal"]())
)
)
Expand Down
20 changes: 11 additions & 9 deletions tests/test_decode_neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
import netaddr
import unittest

import bt_decode
import bittensor
import bt_decode

from . import (
get_file_bytes,
fix_field as fix_field_fixes,
py_getattr as py_getattr_fixes,
)

from .utils import chain_data

TEST_NEURON_INFO_LITE_HEX = {
"normal": "c40352ca71e26e83b6c86058fd4d3c9643ea5dc11f120a7c80f47ec5770b457d8853018ca894cb3d02aaf9b96741c831a3970cf250a58ec46e6a66f269be0b4b040400ba94330000000000c7020000e0aaf22c000000000000000000000000ad240404000000000000000000000000000000000000000000000000000000000000000000048853018ca894cb3d02aaf9b96741c831a3970cf250a58ec46e6a66f269be0b4b1ee07d572901f6fc6f002901210166e7030000006e1e9b00007d05",
"normal": "fe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c0008010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c0bbb22f41921010bbb22f41921010bbb22f4192101000007989cc65f0100000000009801feff0300",
"vec normal": lambda: get_file_bytes("tests/neurons_lite.hex"),
}

TEST_NEURON_INFO_HEX = {
"normal": "c40352ca71e26e83b6c86058fd4d3c9643ea5dc11f120a7c80f47ec5770b457d8853018ca894cb3d02aaf9b96741c831a3970cf250a58ec46e6a66f269be0b4b040400ba94330000000000c7020000e0aaf22c000000000000000000000000ad240404000000000000000000000000000000000000000000000000000000000000000000048853018ca894cb3d02aaf9b96741c831a3970cf250a58ec46e6a66f269be0b4b6220f458c056ce4900c0bc4276030000006e1e9b00000404feff0300009d03",
"normal": "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c0408010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c00000000000000000000002d0101000000",
"vec normal": lambda: get_file_bytes("tests/neurons.hex"),
}

Expand Down Expand Up @@ -69,7 +71,7 @@ def test_decode_matches_python_impl(self):
bytes.fromhex(TEST_NEURON_INFO_LITE_HEX["normal"])
)

neuron_info_py = bittensor.NeuronInfoLite.from_vec_u8(
neuron_info_py = chain_data.NeuronInfoLite.from_vec_u8(
list(bytes.fromhex(TEST_NEURON_INFO_LITE_HEX["normal"]))
)

Expand Down Expand Up @@ -112,8 +114,8 @@ def test_decode_vec_matches_python_impl(self):
)
)

neurons_info_py: List[bittensor.NeuronInfoLite] = (
bittensor.NeuronInfoLite.list_from_vec_u8(
neurons_info_py: List[chain_data.NeuronInfoLite] = (
chain_data.NeuronInfoLite.list_from_vec_u8(
list(TEST_NEURON_INFO_LITE_HEX["vec normal"]())
)
)
Expand Down Expand Up @@ -159,7 +161,7 @@ def test_decode_matches_python_impl(self):
bytes.fromhex(TEST_NEURON_INFO_HEX["normal"])
)

neuron_info_py = bittensor.NeuronInfo.from_vec_u8(
neuron_info_py = chain_data.NeuronInfo.from_vec_u8(
list(bytes.fromhex(TEST_NEURON_INFO_HEX["normal"]))
)

Expand Down Expand Up @@ -198,8 +200,8 @@ def test_decode_vec_matches_python_impl(self):
TEST_NEURON_INFO_HEX["vec normal"]()
)

neurons_info_py: List[bittensor.NeuronInfo] = (
bittensor.NeuronInfo.list_from_vec_u8(
neurons_info_py: List[chain_data.NeuronInfo] = (
chain_data.NeuronInfo.list_from_vec_u8(
list(TEST_NEURON_INFO_HEX["vec normal"]())
)
)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_decode_stake_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
fix_field as fix_field_fixes,
py_getattr as py_getattr_fixes,
)
from .utils import chain_data

TEST_STAKE_INFO_HEX = {
"vec normal": "08e4df2c7397e1443378b4cec0f2fca9dac1d0923d020e7aab11dd41428014ab595c40bc195cb2fd36b8b0e2397087c73b555b81e0bfe2975a40b9f78e039d44420759e02b6017ae4f8eac06ab73ff50aa97c0aafd27cd5c311e2fbbe5628f24901f4e3e1b06695c40bc195cb2fd36b8b0e2397087c73b555b81e0bfe2975a40b9f78e039d4442e25c4a0c",
Expand Down Expand Up @@ -49,8 +50,8 @@ def test_decode_vec_matches_python_impl(self):
bytes.fromhex(TEST_STAKE_INFO_HEX["vec normal"])
)

stake_info_py_list: List[bittensor.StakeInfo] = (
bittensor.StakeInfo.list_from_vec_u8(
stake_info_py_list: List[chain_data.StakeInfo] = (
chain_data.StakeInfo.list_from_vec_u8(
list(bytes.fromhex(TEST_STAKE_INFO_HEX["vec normal"]))
)
)
Expand Down Expand Up @@ -95,8 +96,8 @@ def test_decode_vec_vec_matches_python_impl(self):
)

# Poor method name, should be dict_of_list_from_vec_u8
stake_info_py_dict: Dict[str, List[bittensor.StakeInfo]] = (
bittensor.StakeInfo.list_of_tuple_from_vec_u8(
stake_info_py_dict: Dict[str, List[chain_data.StakeInfo]] = (
chain_data.StakeInfo.list_of_tuple_from_vec_u8(
list(bytes.fromhex(TEST_STAKE_INFO_HEX["vec vec normal"]))
)
)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_decode_subnet_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
fix_field as fix_field_fixes,
py_getattr as py_getattr_fixes,
)
from .utils import chain_data

TEST_SUBNET_INFO_HEX = {
"normal": "0828feff010013ffffffffffffffff214e010104feff0300c8010401040d03a1050000c28ff4070398b6d54370c07a546ab0bab5ca9847eb5890ada1bda127633e607097ad4517dd2ca0f010",
Expand Down Expand Up @@ -56,7 +57,7 @@ def test_decode_matches_python_impl(self):
bytes.fromhex(TEST_SUBNET_INFO_HEX["normal"])
)

subnet_info_py = bittensor.SubnetInfo.from_vec_u8(
subnet_info_py = chain_data.SubnetInfo.from_vec_u8(
list(bytes.fromhex(TEST_SUBNET_INFO_HEX["normal"]))
)

Expand Down Expand Up @@ -120,7 +121,7 @@ def test_decode_vec_option_matches_python_impl(self):
)

subnet_info_list_py = (
bittensor.SubnetInfo.list_from_vec_u8( # Option specified internally
chain_data.SubnetInfo.list_from_vec_u8( # Option specified internally
TEST_SUBNET_INFO_HEX["vec option normal"]()
)
)
Expand Down
Empty file added tests/utils/__init__.py
Empty file.
Loading

0 comments on commit f20d7d6

Please sign in to comment.