From 795ad76a3de2bc4b39014e0a6ccd806ad533e159 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 23 Jul 2025 13:36:47 +0200 Subject: [PATCH 1/2] Fix for handling tuples for `additional` --- bittensor_cli/src/bittensor/utils.py | 33 ++++++++++++++++------------ tests/unit_tests/test_utils.py | 29 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 tests/unit_tests/test_utils.py diff --git a/bittensor_cli/src/bittensor/utils.py b/bittensor_cli/src/bittensor/utils.py index 0b2493db0..ef5f2e4b1 100644 --- a/bittensor_cli/src/bittensor/utils.py +++ b/bittensor_cli/src/bittensor/utils.py @@ -622,20 +622,23 @@ def decode_hex_identity_dict(info_dictionary) -> dict[str, Any]: Examples: input_dict = { - ... "name": {"value": "0x6a6f686e"}, - ... "additional": [ - ... [{"data": "0x64617461"}] - ... ] - ... } + "name": {"value": "0x6a6f686e"}, + "additional": [ + {"data1": "0x64617461"}, + ("data2", "0x64617461") + ] + } decode_hex_identity_dict(input_dict) - {'name': 'john', 'additional': [('data', 'data')]} + {'name': 'john', 'additional': [('data1', 'data'), ('data2', 'data')]} """ - def get_decoded(data: str) -> str: + def get_decoded(data: Optional[str]) -> str: """Decodes a hex-encoded string.""" + if data is None: + return "" try: return hex_to_bytes(data).decode() - except UnicodeDecodeError: + except (UnicodeDecodeError, ValueError): print(f"Could not decode: {key}: {item}") for key, value in info_dictionary.items(): @@ -651,12 +654,14 @@ def get_decoded(data: str) -> str: if key == "additional": additional = [] for item in value: - additional.append( - tuple( - get_decoded(data=next(iter(sub_item.values()))) - for sub_item in item - ) - ) + if isinstance(item, dict): + for k, v in item.items(): + additional.append((k, get_decoded(v))) + else: + if isinstance(item, (tuple, list)) and len(item) == 2: + k_, v = item + k = k_ if k_ is not None else "" + additional.append((k, get_decoded(v))) info_dictionary[key] = additional return info_dictionary diff --git a/tests/unit_tests/test_utils.py b/tests/unit_tests/test_utils.py new file mode 100644 index 000000000..9aa737032 --- /dev/null +++ b/tests/unit_tests/test_utils.py @@ -0,0 +1,29 @@ +from bittensor_cli.src.bittensor import utils +import pytest + + +@pytest.mark.parametrize( + "input_dict,expected_result", + [ + ( + { + "name": {"value": "0x6a6f686e"}, + "additional": [{"data1": "0x64617461"}, ("data2", "0x64617461")], + }, + {"name": "john", "additional": [("data1", "data"), ("data2", "data")]}, + ), + ( + {"name": {"value": "0x6a6f686e"}, "additional": [("data2", "0x64617461")]}, + {"name": "john", "additional": [("data2", "data")]}, + ), + ( + { + "name": {"value": "0x6a6f686e"}, + "additional": [(None, None)], + }, + {"name": "john", "additional": [("", "")]}, + ), + ], +) +def test_decode_hex_identity_dict(input_dict, expected_result): + assert utils.decode_hex_identity_dict(input_dict) == expected_result From e2e9bf3f08576b8030e77fa4ca7d02d4bc78daca Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 23 Jul 2025 14:13:54 +0200 Subject: [PATCH 2/2] ## What's Changed * Fix for handling tuples for `additional` by @thewhaleking in https://github.com/opentensor/btcli/pull/557 **Full Changelog**: https://github.com/opentensor/btcli/compare/v9.8.6...v9.8.7 --- CHANGELOG.md | 5 +++++ pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7de27c26b..1d444460b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 9.8.7 /2025-07-23 +* Fix for handling tuples for `additional` by @thewhaleking in https://github.com/opentensor/btcli/pull/557 + +**Full Changelog**: https://github.com/opentensor/btcli/compare/v9.8.6...v9.8.7 + ## 9.8.6 /2025-07-22 * Hyperparam discrepancy between set/get by @thewhaleking in https://github.com/opentensor/btcli/pull/552 * Hyperparameters in alphabetical order for `btcli sudo get/set` by @basfroman in https://github.com/opentensor/btcli/pull/553 diff --git a/pyproject.toml b/pyproject.toml index e310a0f35..c4b709ffc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "bittensor-cli" -version = "9.8.6" +version = "9.8.7" description = "Bittensor CLI" readme = "README.md" authors = [