Skip to content

Commit 80634e0

Browse files
authored
Merge pull request #2699 from opentensor/fix/thewhaleking/get-all-commitments-fix
Fixes get_all_commitments, adds tests.
2 parents 4ec4618 + 6eac932 commit 80634e0

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

bittensor/core/async_subtensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ async def get_all_commitments(
999999
)
10001000
result = {}
10011001
async for id_, value in query:
1002-
result[decode_account_id(id_[0])] = decode_account_id(value)
1002+
result[decode_account_id(id_[0])] = decode_metadata(value)
10031003
return result
10041004

10051005
async def get_current_weight_commit_info(

bittensor/core/subtensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ def get_all_commitments(
754754
)
755755
result = {}
756756
for id_, value in query:
757-
result[decode_account_id(id_[0])] = decode_account_id(value)
757+
result[decode_account_id(id_[0])] = decode_metadata(value)
758758
return result
759759

760760
def get_current_weight_commit_info(

tests/e2e_tests/conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
import pytest
1010
from async_substrate_interface import SubstrateInterface
11-
from bittensor.core.subtensor import Subtensor
1211

12+
from bittensor.core.async_subtensor import AsyncSubtensor
13+
from bittensor.core.subtensor import Subtensor
1314
from bittensor.utils.btlogging import logging
1415
from tests.e2e_tests.utils.e2e_test_utils import (
1516
Templates,
@@ -101,6 +102,11 @@ def subtensor(local_chain):
101102
return Subtensor(network="ws://localhost:9944")
102103

103104

105+
@pytest.fixture
106+
def async_subtensor(local_chain):
107+
return AsyncSubtensor(network="ws://localhost:9944")
108+
109+
104110
@pytest.fixture
105111
def alice_wallet():
106112
keypair, wallet = setup_wallet("//Alice")

tests/e2e_tests/test_commitment.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,61 @@ def test_commitment(subtensor, alice_wallet):
5151
netuid=1,
5252
uid=uid,
5353
)
54+
55+
assert (
56+
subtensor.get_all_commitments(netuid=1)[alice_wallet.hotkey.ss58_address]
57+
== "Hello World!"
58+
)
59+
60+
61+
@pytest.mark.asyncio
62+
async def test_commitment_async(async_subtensor, alice_wallet):
63+
async with async_subtensor as sub:
64+
with pytest.raises(SubstrateRequestException, match="AccountNotAllowedCommit"):
65+
await sub.set_commitment(
66+
alice_wallet,
67+
netuid=1,
68+
data="Hello World!",
69+
)
70+
71+
assert await sub.burned_register(
72+
alice_wallet,
73+
netuid=1,
74+
)
75+
76+
uid = await sub.get_uid_for_hotkey_on_subnet(
77+
alice_wallet.hotkey.ss58_address,
78+
netuid=1,
79+
)
80+
81+
assert uid is not None
82+
83+
assert "" == await sub.get_commitment(
84+
netuid=1,
85+
uid=uid,
86+
)
87+
88+
assert await sub.set_commitment(
89+
alice_wallet,
90+
netuid=1,
91+
data="Hello World!",
92+
)
93+
94+
with pytest.raises(
95+
SubstrateRequestException,
96+
match="CommitmentSetRateLimitExceeded",
97+
):
98+
await sub.set_commitment(
99+
alice_wallet,
100+
netuid=1,
101+
data="Hello World!",
102+
)
103+
104+
assert "Hello World!" == await sub.get_commitment(
105+
netuid=1,
106+
uid=uid,
107+
)
108+
109+
assert (await sub.get_all_commitments(netuid=1))[
110+
alice_wallet.hotkey.ss58_address
111+
] == "Hello World!"

0 commit comments

Comments
 (0)