From a1effa6b1e50dd82e5fcf83ecb3dcddb7bfee477 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Mon, 21 Aug 2023 14:27:22 -0400 Subject: [PATCH 01/11] add state calls api --- bittensor/subtensor.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/bittensor/subtensor.py b/bittensor/subtensor.py index 642d62dfbb..4c57e1302f 100644 --- a/bittensor/subtensor.py +++ b/bittensor/subtensor.py @@ -1189,6 +1189,47 @@ def make_substrate_call_with_retry(): ) return make_substrate_call_with_retry() + + def state_call( + self, + method: str, + data: str, + block: Optional[int] = None, + ) -> Optional[object]: + @retry(delay=2, tries=3, backoff=2, max_delay=4) + def make_substrate_call_with_retry(): + with self.substrate as substrate: + block_hash = None if block == None else substrate.get_block_hash(block) + params = [method, data] + if block_hash: + params = params + [block_hash] + return substrate.rpc_request( + method="state_call", + params=params + ) + + return make_substrate_call_with_retry() + + def query_runtime_api( + self, + runtime_api: str, + method: str, + params: Optional[Union[bytearray, str]] = '0x', + block: Optional[int] = None, + ) -> Optional[bytes]: + """ + Returns a Scale Bytes type that should be decoded. + """ + json_result = self.state_call( + method=f"{runtime_api}_{method}", + data='0x' if params is None else params.hex() if isinstance(params, bytearray) else params, + block=block + ) + + if json_result is None: + return None + + return json_result["result"] ##################################### #### Hyper parameter calls. #### From 2496852a550a2b1dc7241ce023a374ef12bcfa68 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Mon, 21 Aug 2023 14:27:48 -0400 Subject: [PATCH 02/11] add overload for decoding from multiple types --- bittensor/chain_data.py | 45 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/bittensor/chain_data.py b/bittensor/chain_data.py index 380fda16b9..a6651fa95c 100644 --- a/bittensor/chain_data.py +++ b/bittensor/chain_data.py @@ -21,7 +21,7 @@ from enum import Enum from dataclasses import dataclass from scalecodec.types import GenericCall -from typing import List, Tuple, Dict, Optional, Any, TypedDict +from typing import List, Tuple, Dict, Optional, Any, TypedDict, overload, Union from scalecodec.base import RuntimeConfiguration, ScaleBytes from scalecodec.type_registry import load_type_registry_preset from scalecodec.utils.ss58 import ss58_encode @@ -225,15 +225,52 @@ class ChainDataType(Enum): U16_MAX = 65535 U64_MAX = 18446744073709551615 +@overload +def from_scale_encoding( + input: List[int], + type_name: ChainDataType, + is_vec: bool = False, + is_option: bool = False, +) -> Optional[Dict]: + ... +@overload def from_scale_encoding( - vec_u8: List[int], + input: bytes, type_name: ChainDataType, is_vec: bool = False, is_option: bool = False, ) -> Optional[Dict]: - as_bytes = bytes(vec_u8) - as_scale_bytes = ScaleBytes(as_bytes) + ... + +@overload +def from_scale_encoding( + input: ScaleBytes, + type_name: ChainDataType, + is_vec: bool = False, + is_option: bool = False, +) -> Optional[Dict]: + ... + +def from_scale_encoding( + input: Union[List[int], bytes, ScaleBytes], + type_name: ChainDataType, + is_vec: bool = False, + is_option: bool = False, +) -> Optional[Dict]: + if isinstance(input, ScaleBytes): + as_scale_bytes = input + else: + if isinstance(input, list) and all([isinstance(i, int) for i in input]): + vec_u8 = input + as_bytes = bytes(vec_u8) + elif isinstance(input, bytes): + as_bytes = input + else: + raise TypeError("input must be a List[int], bytes, or ScaleBytes") + + as_scale_bytes = ScaleBytes(as_bytes) + rpc_runtime_config = RuntimeConfiguration() rpc_runtime_config.update_type_registry(load_type_registry_preset("legacy")) rpc_runtime_config.update_type_registry(custom_rpc_type_registry) From 65c8c5ca947e8ae921d76fdd188259566cfbc35b Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Mon, 21 Aug 2023 14:43:35 -0400 Subject: [PATCH 03/11] use state call for neurons lite --- bittensor/subtensor.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/bittensor/subtensor.py b/bittensor/subtensor.py index 4c57e1302f..9d4b28d840 100644 --- a/bittensor/subtensor.py +++ b/bittensor/subtensor.py @@ -1933,26 +1933,24 @@ def neurons_lite( neuron (List[NeuronInfoLite]): List of neuron lite metadata objects. """ + hex_scale_bytes_result = self.query_runtime_api( + runtime_api="NeuronInfoRuntimeApi", + method="get_neurons_lite", + params=self.substrate.encode_scale( + 'u16', value=netuid, block_hash=self.substrate.get_block_hash(block) if block is not None else None + ).data, + block=block, + ) - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_substrate_call_with_retry(): - with self.substrate as substrate: - block_hash = None if block == None else substrate.get_block_hash(block) - params = [netuid] - if block_hash: - params = params + [block_hash] - return substrate.rpc_request( - method="neuronInfo_getNeuronsLite", # custom rpc method - params=params, - ) - - json_body = make_substrate_call_with_retry() - result = json_body["result"] - - if result in (None, []): - return [] + if hex_scale_bytes_result == None: + return None + + hex_bytes_result = self.substrate.decode_scale( + 'Bytes>', hex_scale_bytes_result + ) + bytes_result = bytes.fromhex(hex_bytes_result[2:]) - return NeuronInfoLite.list_from_vec_u8(result) + return NeuronInfoLite.list_from_vec_u8(bytes_result) def metagraph( self, netuid: int, lite: bool = True, block: Optional[int] = None From 8e3e7fc8cee2b8302ff63c7b1114c826aa16b73f Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 23 Aug 2023 13:57:21 -0400 Subject: [PATCH 04/11] custom registry for runtime apis / encoding params --- bittensor/__init__.py | 35 ++++++++++++++++++++++++++-- bittensor/subtensor.py | 52 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/bittensor/__init__.py b/bittensor/__init__.py index 128fc4817f..6592827291 100644 --- a/bittensor/__init__.py +++ b/bittensor/__init__.py @@ -111,8 +111,39 @@ def debug(on: bool = True): } # --- Type Registry --- -__type_registry__ = {"types": {"Balance": "u64"}} # Need to override default u128 - +__type_registry__ = { + "types": { + "Balance": "u64", # Need to override default u128 + }, + "runtime_api": { + "NeuronInfoRuntimeApi": { + "methods": { + "get_neuron_lite": { + 'params': [ + { + "name": "netuid", + "type": "u16", + }, + { + "name": "uid", + "type": "u16", + }, + ], + "type": "Vec", + }, + "get_neurons_lite": { + 'params': [ + { + "name": "netuid", + "type": "u16", + }, + ], + "type": "Vec", + }, + } + }, + } +} from .errors import * diff --git a/bittensor/subtensor.py b/bittensor/subtensor.py index 9d4b28d840..f9eeb27d5e 100644 --- a/bittensor/subtensor.py +++ b/bittensor/subtensor.py @@ -25,8 +25,10 @@ from retry import retry from loguru import logger -from typing import List, Dict, Union, Optional, Tuple +from typing import List, Dict, Union, Optional, Tuple, TypedDict, Any from substrateinterface.base import QueryMapResult, SubstrateInterface +from scalecodec.base import RuntimeConfiguration +from scalecodec.type_registry import load_type_registry_preset # Local imports. from .chain_data import ( @@ -38,6 +40,7 @@ AxonInfo, ProposalVoteData, ProposalCallData, + custom_rpc_type_registry, ) from .errors import * from .extrinsics.network import register_subnetwork_extrinsic @@ -69,6 +72,10 @@ logger = logger.opt(colors=True) +class ParamWithTypes(TypedDict): + name: str # Name of the parameter. + type: str # ScaleType string of the parameter. + class subtensor: """Factory Class for bittensor.subtensor @@ -1214,22 +1221,59 @@ def query_runtime_api( self, runtime_api: str, method: str, - params: Optional[Union[bytearray, str]] = '0x', + params: Optional[List[ParamWithTypes]], block: Optional[int] = None, ) -> Optional[bytes]: """ Returns a Scale Bytes type that should be decoded. """ + call_definition = bittensor.__type_registry__['runtime_api'][runtime_api]['methods'][method] json_result = self.state_call( method=f"{runtime_api}_{method}", - data='0x' if params is None else params.hex() if isinstance(params, bytearray) else params, + data='0x' if params is None else self._encode_params( + call_definition=call_definition, + params=params + ), block=block ) if json_result is None: return None - return json_result["result"] + return_type = call_definition['type'] + + as_scale_bytes = scalecodec.ScaleBytes( json_result['result'] ) + + rpc_runtime_config = RuntimeConfiguration() + rpc_runtime_config.update_type_registry(load_type_registry_preset('legacy')) + rpc_runtime_config.update_type_registry(custom_rpc_type_registry) + + obj = rpc_runtime_config.create_scale_object(return_type) + + return obj.decode(as_scale_bytes) + + + def _encode_params( + self, + call_definition: List[ParamWithTypes], + params: Union[List[Any], Dict[str, str]], + ) -> str: + """ + Returns a hex encoded string of the params using their types. + """ + param_data = scalecodec.ScaleBytes(b'') + + for i, param in enumerate(call_definition['params']): + scale_obj = self.substrate.create_scale_object(param['type']) + if type(params) is list: + param_data += scale_obj.encode(params[i]) + else: + if param['name'] not in params: + raise ValueError(f"Missing param {param['name']} in params dict.") + + param_data += scale_obj.encode(params[param['name']]) + + return param_data.to_hex() ##################################### #### Hyper parameter calls. #### From 942e3effa5cadf1ba04de3053558e7b77fc2d67d Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 23 Aug 2023 13:57:30 -0400 Subject: [PATCH 05/11] fix usage for neurons pull --- bittensor/subtensor.py | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/bittensor/subtensor.py b/bittensor/subtensor.py index f9eeb27d5e..0fda5b1873 100644 --- a/bittensor/subtensor.py +++ b/bittensor/subtensor.py @@ -1943,26 +1943,23 @@ def neuron_for_uid_lite( """ if uid == None: return NeuronInfoLite._null_neuron() + + hex_bytes_result = self.query_runtime_api( + runtime_api="NeuronInfoRuntimeApi", + method="get_neuron_lite", + params={ + "netuid": netuid, + "uid": uid, + }, + block=block, + ) - @retry(delay=2, tries=3, backoff=2, max_delay=4) - def make_substrate_call_with_retry(): - with self.substrate as substrate: - block_hash = None if block == None else substrate.get_block_hash(block) - params = [netuid, uid] - if block_hash: - params = params + [block_hash] - return substrate.rpc_request( - method="neuronInfo_getNeuronLite", # custom rpc method - params=params, - ) - - json_body = make_substrate_call_with_retry() - result = json_body["result"] - - if result in (None, []): + if hex_bytes_result == None: return NeuronInfoLite._null_neuron() + + bytes_result = bytes.fromhex(hex_bytes_result[2:]) - return NeuronInfoLite.from_vec_u8(result) + return NeuronInfoLite.from_vec_u8(bytes_result) def neurons_lite( self, netuid: int, block: Optional[int] = None @@ -1977,21 +1974,16 @@ def neurons_lite( neuron (List[NeuronInfoLite]): List of neuron lite metadata objects. """ - hex_scale_bytes_result = self.query_runtime_api( + hex_bytes_result = self.query_runtime_api( runtime_api="NeuronInfoRuntimeApi", method="get_neurons_lite", - params=self.substrate.encode_scale( - 'u16', value=netuid, block_hash=self.substrate.get_block_hash(block) if block is not None else None - ).data, + params=[netuid], block=block, ) - if hex_scale_bytes_result == None: + if hex_bytes_result == None: return None - hex_bytes_result = self.substrate.decode_scale( - 'Bytes>', hex_scale_bytes_result - ) bytes_result = bytes.fromhex(hex_bytes_result[2:]) return NeuronInfoLite.list_from_vec_u8(bytes_result) From 276809f783ecfceeb726f29880ee38451f433f66 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 23 Aug 2023 16:08:52 -0400 Subject: [PATCH 06/11] add check for 0x --- bittensor/subtensor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bittensor/subtensor.py b/bittensor/subtensor.py index 0fda5b1873..7f47431780 100644 --- a/bittensor/subtensor.py +++ b/bittensor/subtensor.py @@ -1957,7 +1957,10 @@ def neuron_for_uid_lite( if hex_bytes_result == None: return NeuronInfoLite._null_neuron() - bytes_result = bytes.fromhex(hex_bytes_result[2:]) + if hex_bytes_result.startswith("0x"): + bytes_result = bytes.fromhex(hex_bytes_result[2:]) + else: + bytes_result = bytes.fromhex(hex_bytes_result) return NeuronInfoLite.from_vec_u8(bytes_result) @@ -1984,7 +1987,10 @@ def neurons_lite( if hex_bytes_result == None: return None - bytes_result = bytes.fromhex(hex_bytes_result[2:]) + if hex_bytes_result.startswith("0x"): + bytes_result = bytes.fromhex(hex_bytes_result[2:]) + else: + bytes_result = bytes.fromhex(hex_bytes_result) return NeuronInfoLite.list_from_vec_u8(bytes_result) From 991a18308f76a728dfd3fb103f102c1abf328792 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 23 Aug 2023 16:10:06 -0400 Subject: [PATCH 07/11] remove overload --- bittensor/chain_data.py | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/bittensor/chain_data.py b/bittensor/chain_data.py index a6651fa95c..c127bdc944 100644 --- a/bittensor/chain_data.py +++ b/bittensor/chain_data.py @@ -21,7 +21,7 @@ from enum import Enum from dataclasses import dataclass from scalecodec.types import GenericCall -from typing import List, Tuple, Dict, Optional, Any, TypedDict, overload, Union +from typing import List, Tuple, Dict, Optional, Any, TypedDict, Union from scalecodec.base import RuntimeConfiguration, ScaleBytes from scalecodec.type_registry import load_type_registry_preset from scalecodec.utils.ss58 import ss58_encode @@ -225,33 +225,6 @@ class ChainDataType(Enum): U16_MAX = 65535 U64_MAX = 18446744073709551615 -@overload -def from_scale_encoding( - input: List[int], - type_name: ChainDataType, - is_vec: bool = False, - is_option: bool = False, -) -> Optional[Dict]: - ... - -@overload -def from_scale_encoding( - input: bytes, - type_name: ChainDataType, - is_vec: bool = False, - is_option: bool = False, -) -> Optional[Dict]: - ... - -@overload -def from_scale_encoding( - input: ScaleBytes, - type_name: ChainDataType, - is_vec: bool = False, - is_option: bool = False, -) -> Optional[Dict]: - ... - def from_scale_encoding( input: Union[List[int], bytes, ScaleBytes], type_name: ChainDataType, From 2bfdd8502b3143c52bcafa87fb0c7cc76f90b4b7 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 23 Aug 2023 16:11:11 -0400 Subject: [PATCH 08/11] run black --- bittensor/__init__.py | 8 +++--- bittensor/chain_data.py | 3 ++- bittensor/subtensor.py | 58 ++++++++++++++++++++--------------------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/bittensor/__init__.py b/bittensor/__init__.py index 6592827291..472718f6ee 100644 --- a/bittensor/__init__.py +++ b/bittensor/__init__.py @@ -119,11 +119,11 @@ def debug(on: bool = True): "NeuronInfoRuntimeApi": { "methods": { "get_neuron_lite": { - 'params': [ + "params": [ { "name": "netuid", "type": "u16", - }, + }, { "name": "uid", "type": "u16", @@ -132,7 +132,7 @@ def debug(on: bool = True): "type": "Vec", }, "get_neurons_lite": { - 'params': [ + "params": [ { "name": "netuid", "type": "u16", @@ -142,7 +142,7 @@ def debug(on: bool = True): }, } }, - } + }, } from .errors import * diff --git a/bittensor/chain_data.py b/bittensor/chain_data.py index c127bdc944..10a8ec275f 100644 --- a/bittensor/chain_data.py +++ b/bittensor/chain_data.py @@ -225,6 +225,7 @@ class ChainDataType(Enum): U16_MAX = 65535 U64_MAX = 18446744073709551615 + def from_scale_encoding( input: Union[List[int], bytes, ScaleBytes], type_name: ChainDataType, @@ -241,7 +242,7 @@ def from_scale_encoding( as_bytes = input else: raise TypeError("input must be a List[int], bytes, or ScaleBytes") - + as_scale_bytes = ScaleBytes(as_bytes) rpc_runtime_config = RuntimeConfiguration() diff --git a/bittensor/subtensor.py b/bittensor/subtensor.py index 7f47431780..1e8a91b25a 100644 --- a/bittensor/subtensor.py +++ b/bittensor/subtensor.py @@ -72,9 +72,10 @@ logger = logger.opt(colors=True) + class ParamWithTypes(TypedDict): - name: str # Name of the parameter. - type: str # ScaleType string of the parameter. + name: str # Name of the parameter. + type: str # ScaleType string of the parameter. class subtensor: @@ -1196,7 +1197,7 @@ def make_substrate_call_with_retry(): ) return make_substrate_call_with_retry() - + def state_call( self, method: str, @@ -1210,13 +1211,10 @@ def make_substrate_call_with_retry(): params = [method, data] if block_hash: params = params + [block_hash] - return substrate.rpc_request( - method="state_call", - params=params - ) + return substrate.rpc_request(method="state_call", params=params) return make_substrate_call_with_retry() - + def query_runtime_api( self, runtime_api: str, @@ -1225,34 +1223,34 @@ def query_runtime_api( block: Optional[int] = None, ) -> Optional[bytes]: """ - Returns a Scale Bytes type that should be decoded. + Returns a Scale Bytes type that should be decoded. """ - call_definition = bittensor.__type_registry__['runtime_api'][runtime_api]['methods'][method] + call_definition = bittensor.__type_registry__["runtime_api"][runtime_api][ + "methods" + ][method] json_result = self.state_call( method=f"{runtime_api}_{method}", - data='0x' if params is None else self._encode_params( - call_definition=call_definition, - params=params - ), - block=block + data="0x" + if params is None + else self._encode_params(call_definition=call_definition, params=params), + block=block, ) if json_result is None: return None - - return_type = call_definition['type'] - as_scale_bytes = scalecodec.ScaleBytes( json_result['result'] ) + return_type = call_definition["type"] + + as_scale_bytes = scalecodec.ScaleBytes(json_result["result"]) rpc_runtime_config = RuntimeConfiguration() - rpc_runtime_config.update_type_registry(load_type_registry_preset('legacy')) + rpc_runtime_config.update_type_registry(load_type_registry_preset("legacy")) rpc_runtime_config.update_type_registry(custom_rpc_type_registry) obj = rpc_runtime_config.create_scale_object(return_type) return obj.decode(as_scale_bytes) - - + def _encode_params( self, call_definition: List[ParamWithTypes], @@ -1261,17 +1259,17 @@ def _encode_params( """ Returns a hex encoded string of the params using their types. """ - param_data = scalecodec.ScaleBytes(b'') + param_data = scalecodec.ScaleBytes(b"") - for i, param in enumerate(call_definition['params']): - scale_obj = self.substrate.create_scale_object(param['type']) + for i, param in enumerate(call_definition["params"]): + scale_obj = self.substrate.create_scale_object(param["type"]) if type(params) is list: param_data += scale_obj.encode(params[i]) else: - if param['name'] not in params: + if param["name"] not in params: raise ValueError(f"Missing param {param['name']} in params dict.") - param_data += scale_obj.encode(params[param['name']]) + param_data += scale_obj.encode(params[param["name"]]) return param_data.to_hex() @@ -1943,11 +1941,11 @@ def neuron_for_uid_lite( """ if uid == None: return NeuronInfoLite._null_neuron() - + hex_bytes_result = self.query_runtime_api( runtime_api="NeuronInfoRuntimeApi", method="get_neuron_lite", - params={ + params={ "netuid": netuid, "uid": uid, }, @@ -1956,7 +1954,7 @@ def neuron_for_uid_lite( if hex_bytes_result == None: return NeuronInfoLite._null_neuron() - + if hex_bytes_result.startswith("0x"): bytes_result = bytes.fromhex(hex_bytes_result[2:]) else: @@ -1986,7 +1984,7 @@ def neurons_lite( if hex_bytes_result == None: return None - + if hex_bytes_result.startswith("0x"): bytes_result = bytes.fromhex(hex_bytes_result[2:]) else: From 11f5a8cb814f21a88930170eb13e6407ff21e47f Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 23 Aug 2023 16:33:27 -0400 Subject: [PATCH 09/11] remove unused utils and fix tests --- tests/unit_tests/utils/test_utils.py | 75 ++-------------------------- 1 file changed, 4 insertions(+), 71 deletions(-) diff --git a/tests/unit_tests/utils/test_utils.py b/tests/unit_tests/utils/test_utils.py index 3845596b2a..7db0a7b45c 100644 --- a/tests/unit_tests/utils/test_utils.py +++ b/tests/unit_tests/utils/test_utils.py @@ -45,73 +45,6 @@ from tests.helpers import _get_mock_wallet as _generate_wallet, _get_mock_keypair - -@fixture(scope="function") -def setup_chain(): - operating_system = "OSX" if platform == "darwin" else "Linux" - path = "./bin/chain/{}/node-subtensor".format(operating_system) - logger.info(path) - if not path: - logger.error( - "make sure the NODE_SUBTENSOR_BIN env var is set and points to the node-subtensor binary" - ) - sys.exit() - - # Select a port - port = select_port() - - # Delete existing wallets - # subprocess.Popen(["rm", '-r', '~/.bittensor/wallets/*testwallet'], close_fds=True, shell=False) - - # Purge chain first - subprocess.Popen([path, "purge-chain", "--dev", "-y"], close_fds=True, shell=False) - proc = subprocess.Popen( - [ - path, - "--dev", - "--port", - str(port + 1), - "--ws-port", - str(port), - "--rpc-port", - str(port + 2), - "--tmp", - ], - close_fds=True, - shell=False, - ) - - # Wait 4 seconds for the node to come up - time.sleep(4) - - yield port - - # Wait 4 seconds for the node to come up - time.sleep(4) - - # Kill process - os.system("kill %i" % proc.pid) - - -@pytest.fixture(scope="session", autouse=True) -def initialize_tests(): - # Kill any running process before running tests - os.system("pkill node-subtensor") - - -def select_port(): - port = random.randrange(1000, 65536, 5) - return port - - -def setup_subtensor(port: int): - chain_endpoint = "localhost:{}".format(port) - subtensor = bittensor.subtensor( - chain_endpoint=chain_endpoint, - ) - return subtensor, port - - def construct_config(): parser = bittensor.cli.__create_parser__() defaults = bittensor.config(parser=parser, args=[]) @@ -191,7 +124,7 @@ def test_solve_for_difficulty_fast(self): subtensor.difficulty = MagicMock(return_value=10) solution = bittensor.utils.registration._solve_for_difficulty_fast( - subtensor, wallet, netuid=-1, num_processes=num_proc + subtensor, wallet, netuid=-2, num_processes=num_proc ) seal = solution.seal assert bittensor.utils.registration._seal_meets_difficulty(seal, 10, limit) @@ -213,7 +146,7 @@ def test_solve_for_difficulty_fast_registered_already(self): subtensor = MagicMock() subtensor.get_current_block = MagicMock(return_value=1) subtensor.difficulty = MagicMock( - return_value=int(1e10) + return_value=int(1e20) ) # set high to make solving take a long time subtensor.substrate = MagicMock() subtensor.get_block_hash = MagicMock(return_value=block_hash) @@ -226,7 +159,7 @@ def test_solve_for_difficulty_fast_registered_already(self): # all arugments should return None to indicate an early return solution = bittensor.utils.registration._solve_for_difficulty_fast( - subtensor, wallet, netuid=-1, num_processes=1, update_interval=1000 + subtensor, wallet, netuid=-2, num_processes=1, update_interval=1000 ) assert solution is None @@ -261,7 +194,7 @@ def test_solve_for_difficulty_fast_missing_hash(self): assert bittensor.utils.registration._seal_meets_difficulty(seal, 1, limit) subtensor.difficulty = MagicMock(return_value=10) solution = bittensor.utils.registration._solve_for_difficulty_fast( - subtensor, wallet, netuid=-1, num_processes=num_proc + subtensor, wallet, netuid=-2, num_processes=num_proc ) seal = solution.seal assert bittensor.utils.registration._seal_meets_difficulty(seal, 10, limit) From d8b31e40cc008b7f666b04c7149d428ccc4540b1 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 23 Aug 2023 16:33:32 -0400 Subject: [PATCH 10/11] run black --- tests/unit_tests/utils/test_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_tests/utils/test_utils.py b/tests/unit_tests/utils/test_utils.py index 7db0a7b45c..07d7f87f98 100644 --- a/tests/unit_tests/utils/test_utils.py +++ b/tests/unit_tests/utils/test_utils.py @@ -45,6 +45,7 @@ from tests.helpers import _get_mock_wallet as _generate_wallet, _get_mock_keypair + def construct_config(): parser = bittensor.cli.__create_parser__() defaults = bittensor.config(parser=parser, args=[]) From 3b522b29d6133d9d77e7988c537598f4847f3774 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 23 Aug 2023 16:39:25 -0400 Subject: [PATCH 11/11] Fix test --- tests/unit_tests/utils/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/utils/test_utils.py b/tests/unit_tests/utils/test_utils.py index 07d7f87f98..307891a13c 100644 --- a/tests/unit_tests/utils/test_utils.py +++ b/tests/unit_tests/utils/test_utils.py @@ -428,7 +428,7 @@ def test_check_for_newest_block_and_update_new_block(self): self.assertEqual( bittensor.utils.registration._check_for_newest_block_and_update( subtensor, - -1, # netuid + -2, # netuid MagicMock(), mock_hotkey_bytes, MagicMock(),