Skip to content

Commit be255c0

Browse files
authored
Merge pull request #186 from opentensor/fix/thewhaleking/edge-case-query-map-keys
edge case query map keys
2 parents 6bb8302 + 0e94d05 commit be255c0

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

async_substrate_interface/utils/decoding.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,14 @@ def concat_hash_len(key_hasher: str) -> int:
135135
if decode_ss58:
136136
if kts[kts.index(", ") + 2 : kts.index(")")] == "scale_info::0":
137137
item_key = ss58_encode(bytes(item_key[0]), runtime.ss58_format)
138-
139138
else:
140-
item_key = tuple(
141-
dk[key + 1] for key in range(len(params), len(param_types) + 1, 2)
142-
)
139+
try:
140+
item_key = tuple(
141+
dk[key + 1]
142+
for key in range(len(params), len(param_types) + 1, 2)
143+
)
144+
except IndexError:
145+
item_key = dk
143146

144147
except Exception as _:
145148
if not ignore_decoding_errors:

tests/integration_tests/test_async_substrate_interface.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,16 @@ async def test_reconnection():
161161
bh = await substrate.get_chain_finalised_head()
162162
assert isinstance(bh, str)
163163
assert isinstance(await substrate.get_block_number(bh), int)
164+
165+
166+
@pytest.mark.asyncio
167+
async def test_query_map_with_odd_number_of_params():
168+
async with AsyncSubstrateInterface(ARCHIVE_ENTRYPOINT, ss58_format=42) as substrate:
169+
qm = await substrate.query_map(
170+
"SubtensorModule",
171+
"Alpha",
172+
["5CoZxgtfhcJKX2HmkwnsN18KbaT9aih9eF3b6qVPTgAUbifj"],
173+
)
174+
first_record = qm.records[0]
175+
assert len(first_record) == 2
176+
assert len(first_record[0]) == 4

tests/integration_tests/test_substrate_interface.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,15 @@ def test_query_multiple():
100100
storage_function="OwnedHotkeys",
101101
block_hash=block_hash,
102102
)
103+
104+
105+
def test_query_map_with_odd_number_of_params():
106+
with SubstrateInterface(LATENT_LITE_ENTRYPOINT, ss58_format=42) as substrate:
107+
qm = substrate.query_map(
108+
"SubtensorModule",
109+
"Alpha",
110+
["5CoZxgtfhcJKX2HmkwnsN18KbaT9aih9eF3b6qVPTgAUbifj"],
111+
)
112+
first_record = qm.records[0]
113+
assert len(first_record) == 2
114+
assert len(first_record[0]) == 4

0 commit comments

Comments
 (0)