Skip to content

Commit

Permalink
Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
thewhaleking committed Sep 30, 2024
1 parent 0e93148 commit ae9ba26
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
6 changes: 4 additions & 2 deletions bittensor_cli/src/bittensor/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
console,
err_console,
decode_hex_identity_dict,
validate_chain_endpoint
validate_chain_endpoint,
)


Expand Down Expand Up @@ -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"
Expand Down
25 changes: 16 additions & 9 deletions bittensor_cli/src/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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])),
Expand Down
28 changes: 22 additions & 6 deletions tests/e2e_tests/test_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -224,7 +228,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
Expand Down Expand Up @@ -261,7 +269,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
Expand Down Expand Up @@ -293,7 +305,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")
Expand Down Expand Up @@ -344,7 +360,7 @@ def check_balance(exec_command, wallet, expected_balance):
"--network",
"ws://127.0.0.1:9945",
"--wallet-name",
wallet.name
wallet.name,
],
)

Expand Down

0 comments on commit ae9ba26

Please sign in to comment.