diff --git a/bittensor_cli/src/bittensor/chain_data.py b/bittensor_cli/src/bittensor/chain_data.py index 61eb20e3..b6bb985c 100644 --- a/bittensor_cli/src/bittensor/chain_data.py +++ b/bittensor_cli/src/bittensor/chain_data.py @@ -660,12 +660,8 @@ def fix_decoded_values(cls, decoded: dict) -> "DynamicInfo": alpha_out = Balance.from_rao(decoded["alpha_out"]).set_unit(netuid) alpha_in = Balance.from_rao(decoded["alpha_in"]).set_unit(netuid) tao_in = Balance.from_rao(decoded["tao_in"]).set_unit(0) - total_locked = Balance.from_rao(decoded["total_locked"]).set_unit( - netuid - ) - owner_locked = Balance.from_rao(decoded["owner_locked"]).set_unit( - netuid - ) + total_locked = Balance.from_rao(decoded["total_locked"]).set_unit(netuid) + owner_locked = Balance.from_rao(decoded["owner_locked"]).set_unit(netuid) price = ( Balance.from_tao(tao_in.tao / alpha_in.tao) if alpha_in.tao > 0 @@ -766,6 +762,7 @@ def alpha_to_tao_with_slippage(self, alpha: Balance) -> tuple[Balance, Balance]: @dataclass class DynamicPoolInfoV2: """Dataclass for dynamic pool info.""" + netuid: int alpha_issuance: int alpha_outstanding: int @@ -836,10 +833,12 @@ def __init__( self.price = Balance.from_tao(1.0) def __str__(self) -> str: - return (f"DynamicPool( alpha_issuance={self.alpha_issuance}, " - f"alpha_outstanding={self.alpha_outstanding}, " - f"alpha_reserve={self.alpha_reserve}, " - f"tao_reserve={self.tao_reserve}, k={self.k}, price={self.price} )") + return ( + f"DynamicPool( alpha_issuance={self.alpha_issuance}, " + f"alpha_outstanding={self.alpha_outstanding}, " + f"alpha_reserve={self.alpha_reserve}, " + f"tao_reserve={self.tao_reserve}, k={self.k}, price={self.price} )" + ) def __repr__(self) -> str: return self.__str__() @@ -922,6 +921,7 @@ def alpha_to_tao_with_slippage(self, alpha: Balance) -> Tuple[Balance, Balance]: @dataclass class ScheduledColdkeySwapInfo: """Dataclass for scheduled coldkey swap information.""" + old_coldkey: str new_coldkey: str arbitration_block: int @@ -966,9 +966,7 @@ def decode_account_id_list(cls, vec_u8: list[int]) -> Optional[list[str]]: ) if decoded is None: return None - return [ - ss58_encode(account_id, SS58_FORMAT) for account_id in decoded - ] + return [ss58_encode(account_id, SS58_FORMAT) for account_id in decoded] @dataclass @@ -994,15 +992,20 @@ class SubnetState: @classmethod def from_vec_u8(cls, vec_u8: list[int]) -> Optional["SubnetState"]: - if len(vec_u8) == 0: return None + if len(vec_u8) == 0: + return None decoded = from_scale_encoding(vec_u8, ChainDataType.SubnetState, is_option=True) - if decoded is None: return None + if decoded is None: + return None return SubnetState.fix_decoded_values(decoded) @classmethod def list_from_vec_u8(cls, vec_u8: list[int]) -> list["SubnetState"]: - decoded = from_scale_encoding( vec_u8, ChainDataType.SubnetState, is_vec=True, is_option=True ) - if decoded is None:return [] + decoded = from_scale_encoding( + vec_u8, ChainDataType.SubnetState, is_vec=True, is_option=True + ) + if decoded is None: + return [] decoded = [SubnetState.fix_decoded_values(d) for d in decoded] return decoded @@ -1010,26 +1013,35 @@ def list_from_vec_u8(cls, vec_u8: list[int]) -> list["SubnetState"]: def fix_decoded_values(cls, decoded: dict) -> "SubnetState": netuid = decoded["netuid"] return SubnetState( - netuid = netuid, - hotkeys = [ss58_encode(val, SS58_FORMAT) for val in decoded["hotkeys"]], - coldkeys = [ss58_encode(val, SS58_FORMAT) for val in decoded["coldkeys"]], - active = decoded["active"], - validator_permit = decoded["validator_permit"], - pruning_score = [u16_normalized_float(val) for val in decoded["pruning_score"]], - last_update = decoded["last_update"], - emission = [Balance.from_rao( val ).set_unit(netuid) for val in decoded["emission"]], - dividends = [u16_normalized_float(val) for val in decoded["dividends"]], - incentives = [u16_normalized_float(val) for val in decoded["incentives"]], - consensus = [u16_normalized_float(val) for val in decoded["consensus"]], - trust = [u16_normalized_float(val) for val in decoded["trust"]], - rank = [u16_normalized_float(val) for val in decoded["rank"]], - block_at_registration = decoded["block_at_registration"], - local_stake = [Balance.from_rao( val ).set_unit(netuid) for val in decoded["local_stake"]], - global_stake = [Balance.from_rao( val ).set_unit(0) for val in decoded["global_stake"]], - stake_weight = [u16_normalized_float(val) for val in decoded["stake_weight"]], - emission_history = decoded["emission_history"] + netuid=netuid, + hotkeys=[ss58_encode(val, SS58_FORMAT) for val in decoded["hotkeys"]], + coldkeys=[ss58_encode(val, SS58_FORMAT) for val in decoded["coldkeys"]], + active=decoded["active"], + validator_permit=decoded["validator_permit"], + pruning_score=[ + u16_normalized_float(val) for val in decoded["pruning_score"] + ], + last_update=decoded["last_update"], + emission=[ + Balance.from_rao(val).set_unit(netuid) for val in decoded["emission"] + ], + dividends=[u16_normalized_float(val) for val in decoded["dividends"]], + incentives=[u16_normalized_float(val) for val in decoded["incentives"]], + consensus=[u16_normalized_float(val) for val in decoded["consensus"]], + trust=[u16_normalized_float(val) for val in decoded["trust"]], + rank=[u16_normalized_float(val) for val in decoded["rank"]], + block_at_registration=decoded["block_at_registration"], + local_stake=[ + Balance.from_rao(val).set_unit(netuid) for val in decoded["local_stake"] + ], + global_stake=[ + Balance.from_rao(val).set_unit(0) for val in decoded["global_stake"] + ], + stake_weight=[u16_normalized_float(val) for val in decoded["stake_weight"]], + emission_history=decoded["emission_history"], ) + class SubstakeElements: @staticmethod def decode(result: list[int]) -> list[dict]: @@ -1049,7 +1061,6 @@ def decode(result: list[int]) -> list[dict]: return result - custom_rpc_type_registry = { "types": { "SubnetInfo": { diff --git a/setup.py b/setup.py index f5f23114..f9c92cda 100644 --- a/setup.py +++ b/setup.py @@ -64,7 +64,8 @@ def read_requirements(path): long_description_content_type="text/markdown", url="https://github.com/opentensor/btcli", author="bittensor.com", - packages=find_packages(exclude=["tests", "tests.*", "*/tests/*", "*/tests"]) + ['bittensor_cli.src.bittensor.templates'], + packages=find_packages(exclude=["tests", "tests.*", "*/tests/*", "*/tests"]) + + ["bittensor_cli.src.bittensor.templates"], include_package_data=True, package_data={ "": ["templates/*"], diff --git a/tests/e2e_tests/test_senate.py b/tests/e2e_tests/test_senate.py index f3b3ac7f..83ad9082 100644 --- a/tests/e2e_tests/test_senate.py +++ b/tests/e2e_tests/test_senate.py @@ -88,7 +88,7 @@ def test_senate(local_chain, wallet_setup): # Assert Bob is now part of the senate assert wallet_bob.hotkey.ss58_address in root_senate_after_reg.stdout - + # Manually add a proposal on the chain & assert success = asyncio.run(call_add_proposal(local_chain, wallet_bob)) assert success is True @@ -154,10 +154,10 @@ def test_senate(local_chain, wallet_setup): assert proposals_after_aye_output[5] == "Aye" # Aye votes increased to 1 - assert proposals_after_aye_output[2] == '1' + assert proposals_after_aye_output[2] == "1" # Nay votes remain 0 - assert proposals_after_aye_output[3] == '0' + assert proposals_after_aye_output[3] == "0" # Register Alice to the root network (0) # Registering to root automatically makes you a senator if eligible diff --git a/tests/e2e_tests/utils.py b/tests/e2e_tests/utils.py index 53761e90..f5a70e70 100644 --- a/tests/e2e_tests/utils.py +++ b/tests/e2e_tests/utils.py @@ -11,7 +11,9 @@ from bittensor_wallet import Wallet if TYPE_CHECKING: - from bittensor_cli.src.bittensor.async_substrate_interface import AsyncSubstrateInterface + from bittensor_cli.src.bittensor.async_substrate_interface import ( + AsyncSubstrateInterface, + ) template_path = os.getcwd() + "/neurons/" templates_repo = "templates repository" @@ -287,7 +289,9 @@ def uninstall_templates(install_dir): shutil.rmtree(install_dir) -async def call_add_proposal(substrate: "AsyncSubstrateInterface", wallet: Wallet) -> bool: +async def call_add_proposal( + substrate: "AsyncSubstrateInterface", wallet: Wallet +) -> bool: async with substrate: proposal_call = await substrate.compose_call( call_module="System", @@ -304,7 +308,9 @@ async def call_add_proposal(substrate: "AsyncSubstrateInterface", wallet: Wallet }, ) - extrinsic = await substrate.create_signed_extrinsic(call=call, keypair=wallet.coldkey) + extrinsic = await substrate.create_signed_extrinsic( + call=call, keypair=wallet.coldkey + ) response = await substrate.submit_extrinsic( extrinsic, wait_for_inclusion=True,