diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index ea272b22e..5ceeb0b44 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -712,11 +712,11 @@ def initialize_chain( network: Optional[str] = None, ) -> SubtensorInterface: """ - Intelligently initializes a connection to the chain, depending on the supplied (or in config) values. Set's the + Intelligently initializes a connection to the chain, depending on the supplied (or in config) values. Sets the `self.not_subtensor` object to this created connection. - :param network: Network name (e.g. finney, test, etc.) - :param chain: the chain endpoint (e.g. ws://127.0.0.1:9945, wss://entrypoint-finney.opentensor.ai:443, etc.) + :param network: Network name (e.g. finney, test, etc.) or + chain endpoint (e.g. ws://127.0.0.1:9945, wss://entrypoint-finney.opentensor.ai:443) """ if not self.not_subtensor: if network: @@ -897,7 +897,9 @@ def set_config( if valid_endpoint: if valid_endpoint in Constants.network_map.values(): known_network = next( - key for key, value in Constants.network_map.items() if value == network + key + for key, value in Constants.network_map.items() + if value == network ) args["network"] = known_network if not Confirm.ask( @@ -2802,7 +2804,7 @@ def root_my_delegates( wallet_path, wallet_hotkey, ask_for=([WO.NAME] if not all_wallets else [WO.PATH]), - validate=WV.WALLET if not all_wallets else WV.NONE + validate=WV.WALLET if not all_wallets else WV.NONE, ) self._run_command( root.my_delegates(wallet, self.initialize_chain(network), all_wallets) @@ -2860,7 +2862,7 @@ def root_list_delegates( [green]$[/green] btcli root list_delegates --subtensor.network finney # can also be `test` or `local` - [blue bold]NOTE[/blue bold]: This commmand is intended for use within a + [blue bold]NOTE[/blue bold]: This command is intended for use within a console application. It prints directly to the console and does not return any value. """ self.verbosity_handler(quiet, verbose) @@ -2868,9 +2870,12 @@ def root_list_delegates( if network: if network == "finney": network = "wss://archive.chain.opentensor.ai:443" - elif self.config.get("network"): - if self.config.get("network") == "finney": - network = "wss://archive.chain.opentensor.ai:443" + elif (conf_net := self.config.get("network")) == "finney": + network = "wss://archive.chain.opentensor.ai:443" + elif conf_net: + network = conf_net + else: + network = "wss://archive.chain.opentensor.ai:443" sub = self.initialize_chain(network) return self._run_command(root.list_delegates(sub)) diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 46a3a2c9c..246c01a67 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -34,7 +34,7 @@ console, err_console, decode_hex_identity_dict, - validate_chain_endpoint + validate_chain_endpoint, ) @@ -84,7 +84,9 @@ def __init__(self, network): self.chain_endpoint = network if network in Constants.network_map.values(): self.network = next( - key for key, value in Constants.network_map.items() if value == network + key + for key, value in Constants.network_map.items() + if value == network ) else: self.network = "custom" diff --git a/bittensor_cli/src/commands/root.py b/bittensor_cli/src/commands/root.py index 716602af6..c9d8f9241 100644 --- a/bittensor_cli/src/commands/root.py +++ b/bittensor_cli/src/commands/root.py @@ -490,13 +490,19 @@ async def _do_delegation(staking_balance_: Balance) -> tuple[bool, str]: call = await subtensor.substrate.compose_call( call_module="SubtensorModule", call_function="add_stake", - call_params={"hotkey": delegate_ss58, "amount_staked": staking_balance_.rao}, + call_params={ + "hotkey": delegate_ss58, + "amount_staked": staking_balance_.rao, + }, ) else: call = await subtensor.substrate.compose_call( call_module="SubtensorModule", call_function="remove_stake", - call_params={"hotkey": delegate_ss58, "amount_unstaked": staking_balance_.rao}, + call_params={ + "hotkey": delegate_ss58, + "amount_unstaked": staking_balance_.rao, + }, ) return await subtensor.sign_and_send_extrinsic( call, wallet, wait_for_inclusion, wait_for_finalization @@ -576,7 +582,7 @@ async def get_stake_for_coldkey_and_hotkey( staking_balance = Balance.from_tao(amount) # Check enough balance to stake. - if delegate_string == "delegate" and staking_balance > my_prev_coldkey_balance: + if delegate_string == "delegate" and staking_balance > my_prev_coldkey_balance: err_console.print( ":cross_mark: [red]Not enough balance to stake[/red]:\n" f" [bold blue]current balance[/bold blue]:{my_prev_coldkey_balance}\n" @@ -726,21 +732,22 @@ async def _get_list() -> tuple: ) return sm, rn, di, ts - with console.status( f":satellite: Syncing with chain: [white]{subtensor}[/white] ...", spinner="aesthetic", ): - senate_members, root_neurons, delegate_info, total_stakes = await _get_list() - total_tao = sum(float(Balance.from_rao(total_stakes[neuron.hotkey])) for neuron in root_neurons) + total_tao = sum( + float(Balance.from_rao(total_stakes[neuron.hotkey])) + for neuron in root_neurons + ) table = Table( Column( "[bold white]UID", style="dark_orange", no_wrap=True, - footer=f"[bold]{len(root_neurons)}[/bold]" + footer=f"[bold]{len(root_neurons)}[/bold]", ), Column( "[bold white]NAME", @@ -757,7 +764,7 @@ async def _get_list() -> tuple: justify="right", style="light_goldenrod2", no_wrap=True, - footer=f"{total_tao:.2f} (\u03c4) " + footer=f"{total_tao:.2f} (\u03c4) ", ), Column( "[bold white]SENATOR", @@ -777,7 +784,7 @@ async def _get_list() -> tuple: f"[red]Error: No neurons detected on the network:[/red] [white]{subtensor}" ) raise typer.Exit() - + sorted_root_neurons = sorted( root_neurons, key=lambda neuron: float(Balance.from_rao(total_stakes[neuron.hotkey])), diff --git a/tests/e2e_tests/test_root.py b/tests/e2e_tests/test_root.py index 7fe4432a9..26485c259 100644 --- a/tests/e2e_tests/test_root.py +++ b/tests/e2e_tests/test_root.py @@ -70,7 +70,7 @@ def test_root_commands(local_chain, wallet_setup): command="root", sub_command="list", extra_args=[ - "--chain", + "--network", "ws://127.0.0.1:9945", ], ) @@ -93,7 +93,7 @@ def test_root_commands(local_chain, wallet_setup): command="root", sub_command="list-delegates", extra_args=[ - "--chain", + "--network", "ws://127.0.0.1:9945", ], ) @@ -131,7 +131,7 @@ def test_root_commands(local_chain, wallet_setup): extra_args=[ "--wallet-path", wallet_path_bob, - "--chain", + "--network", "ws://127.0.0.1:9945", "--wallet-name", wallet_bob.name, @@ -150,7 +150,7 @@ def test_root_commands(local_chain, wallet_setup): command="root", sub_command="list-delegates", extra_args=[ - "--chain", + "--network", "ws://127.0.0.1:9945", ], ) @@ -168,14 +168,14 @@ def test_root_commands(local_chain, wallet_setup): extra_args=[ "--wallet-path", wallet_path_alice, - "--chain", + "--network", "ws://127.0.0.1:9945", "--wallet-name", wallet_alice.name, "--delegate-ss58key", wallet_bob.hotkey.ss58_address, "--amount", - f"10", + "10", "--no-prompt", ], ) @@ -185,13 +185,17 @@ def test_root_commands(local_chain, wallet_setup): exec_command=exec_command_alice, wallet=wallet_alice, delegate_ss58key=wallet_bob.hotkey.ss58_address, - delegate_amount=10 + delegate_amount=10, ) check_balance( exec_command=exec_command_alice, wallet=wallet_alice, - expected_balance={'free_balance': 999990.0, 'staked_balance': 10.0, 'total_balance': 1000000.0}, + expected_balance={ + "free_balance": 999990.0, + "staked_balance": 10.0, + "total_balance": 1000000.0, + }, ) # TODO: Ask nucleus the rate limit and wait epoch @@ -206,14 +210,12 @@ def test_root_commands(local_chain, wallet_setup): extra_args=[ "--wallet-path", wallet_path_alice, - "--chain", + "--network", "ws://127.0.0.1:9945", "--wallet-name", wallet_alice.name, "--delegate-ss58key", wallet_bob.hotkey.ss58_address, - "--network", - "local", "--amount", f"10", "--no-prompt", @@ -224,7 +226,11 @@ def test_root_commands(local_chain, wallet_setup): check_balance( exec_command=exec_command_alice, wallet=wallet_alice, - expected_balance={'free_balance': 1000000.0, 'staked_balance': 0.0, 'total_balance': 1000000.0}, + expected_balance={ + "free_balance": 1000000.0, + "staked_balance": 0.0, + "total_balance": 1000000.0, + }, ) # TODO: Ask nucleus the rate limit and wait epoch @@ -239,14 +245,12 @@ def test_root_commands(local_chain, wallet_setup): extra_args=[ "--wallet-path", wallet_path_alice, - "--chain", + "--network", "ws://127.0.0.1:9945", "--wallet-name", wallet_alice.name, "--delegate-ss58key", wallet_bob.hotkey.ss58_address, - "--network", - "local", "--all", "--no-prompt", ], @@ -263,7 +267,11 @@ def test_root_commands(local_chain, wallet_setup): check_balance( exec_command=exec_command_alice, wallet=wallet_alice, - expected_balance={'free_balance': 0.0000005, 'staked_balance': 999999.9999995, 'total_balance': 1000000.0}, + expected_balance={ + "free_balance": 0.0000005, + "staked_balance": 999999.9999995, + "total_balance": 1000000.0, + }, ) # TODO: Ask nucleus the rate limit and wait epoch @@ -278,14 +286,12 @@ def test_root_commands(local_chain, wallet_setup): extra_args=[ "--wallet-path", wallet_path_alice, - "--chain", + "--network", "ws://127.0.0.1:9945", "--wallet-name", wallet_alice.name, "--delegate-ss58key", wallet_bob.hotkey.ss58_address, - "--network", - "local", "--all", "--no-prompt", ], @@ -295,7 +301,11 @@ def test_root_commands(local_chain, wallet_setup): check_balance( exec_command=exec_command_alice, wallet=wallet_alice, - expected_balance={'free_balance': 1000000.0, 'staked_balance': 0.0, 'total_balance': 1000000.0}, + expected_balance={ + "free_balance": 1000000.0, + "staked_balance": 0.0, + "total_balance": 1000000.0, + }, ) print("✅ Passed Root commands") @@ -309,12 +319,10 @@ def check_my_delegates(exec_command, wallet, delegate_ss58key, delegate_amount): extra_args=[ "--wallet-path", wallet.path, - "--chain", + "--network", "ws://127.0.0.1:9945", "--wallet-name", wallet.name, - "--network", - "local", ], ) # First row are headers, records start from second row @@ -345,12 +353,10 @@ def check_balance(exec_command, wallet, expected_balance): extra_args=[ "--wallet-path", wallet.path, - "--chain", + "--network", "ws://127.0.0.1:9945", "--wallet-name", wallet.name, - "--network", - "local", ], )