Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def u64_normalized_float(x: int) -> float:
return float(x) / float(U64_MAX)


def string_to_u64(value: str) -> int:
"""Converts a string to u64"""
return float_to_u64(float(value))


def float_to_u64(value: float) -> int:
"""Converts a float to a u64 int"""
# Ensure the input is within the expected range
Expand All @@ -142,6 +147,11 @@ def u64_to_float(value: int) -> float:
return min(value / u64_max, 1.0) # Ensure the result is never greater than 1.0


def string_to_u16(value: str) -> int:
"""Converts a string to a u16 int"""
return float_to_u16(float(value))


def float_to_u16(value: float) -> int:
# Ensure the input is within the expected range
if not (0 <= value <= 1):
Expand Down
6 changes: 3 additions & 3 deletions bittensor_cli/src/commands/sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
normalize_hyperparameters,
unlock_key,
blocks_to_duration,
float_to_u64,
float_to_u16,
json_console,
string_to_u16,
string_to_u64,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -108,7 +108,7 @@ def type_converter_with_retry(type_, val, arg_name):
except ValueError:
return type_converter_with_retry(type_, None, arg_name)

arg_types = {"bool": string_to_bool, "u16": float_to_u16, "u64": float_to_u64}
arg_types = {"bool": string_to_bool, "u16": string_to_u16, "u64": string_to_u64}
arg_type_output = {"bool": "bool", "u16": "float", "u64": "float"}

call_crafter = {"netuid": netuid}
Expand Down
28 changes: 28 additions & 0 deletions tests/e2e_tests/test_staking_sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,31 @@ def test_staking(local_chain, wallet_setup):
assert yuma3_val["value"] is True
assert yuma3_val["normalized_value"] is True
print("✅ Passed staking and sudo commands")

change_arbitrary_hyperparam = exec_command_alice(
command="sudo",
sub_command="set",
extra_args=[
"--wallet-path",
wallet_path_alice,
"--wallet-name",
wallet_alice.name,
"--hotkey",
wallet_alice.hotkey_str,
"--chain",
"ws://127.0.0.1:9945",
"--netuid",
netuid,
"--param",
"sudo_set_bonds_penalty", # arbitrary hyperparam
"--value",
"0", # int/float value
"--no-prompt",
"--json-output",
],
)
change_arbitrary_hyperparam_json = json.loads(change_arbitrary_hyperparam.stdout)
assert change_arbitrary_hyperparam_json["success"] is True, (
change_arbitrary_hyperparam.stdout,
change_arbitrary_hyperparam.stderr,
)
Loading