Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes get_all_commitments, adds tests. #2699

Merged
merged 4 commits into from
Feb 25, 2025
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
2 changes: 1 addition & 1 deletion bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ async def get_all_commitments(
)
result = {}
async for id_, value in query:
result[decode_account_id(id_[0])] = decode_account_id(value)
result[decode_account_id(id_[0])] = decode_metadata(value)
return result

async def get_current_weight_commit_info(
Expand Down
2 changes: 1 addition & 1 deletion bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def get_all_commitments(
)
result = {}
for id_, value in query:
result[decode_account_id(id_[0])] = decode_account_id(value)
result[decode_account_id(id_[0])] = decode_metadata(value)
return result

def get_current_weight_commit_info(
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import pytest
from async_substrate_interface import SubstrateInterface
from bittensor.core.subtensor import Subtensor

from bittensor.core.async_subtensor import AsyncSubtensor
from bittensor.core.subtensor import Subtensor
from bittensor.utils.btlogging import logging
from tests.e2e_tests.utils.e2e_test_utils import (
Templates,
Expand Down Expand Up @@ -101,6 +102,11 @@ def subtensor(local_chain):
return Subtensor(network="ws://localhost:9944")


@pytest.fixture
def async_subtensor(local_chain):
return AsyncSubtensor(network="ws://localhost:9944")


@pytest.fixture
def alice_wallet():
keypair, wallet = setup_wallet("//Alice")
Expand Down
58 changes: 58 additions & 0 deletions tests/e2e_tests/test_commitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,61 @@ def test_commitment(subtensor, alice_wallet):
netuid=1,
uid=uid,
)

assert (
subtensor.get_all_commitments(netuid=1)[alice_wallet.hotkey.ss58_address]
== "Hello World!"
)


@pytest.mark.asyncio
async def test_commitment_async(async_subtensor, alice_wallet):
async with async_subtensor as sub:
with pytest.raises(SubstrateRequestException, match="AccountNotAllowedCommit"):
await sub.set_commitment(
alice_wallet,
netuid=1,
data="Hello World!",
)

assert await sub.burned_register(
alice_wallet,
netuid=1,
)

uid = await sub.get_uid_for_hotkey_on_subnet(
alice_wallet.hotkey.ss58_address,
netuid=1,
)

assert uid is not None

assert "" == await sub.get_commitment(
netuid=1,
uid=uid,
)

assert await sub.set_commitment(
alice_wallet,
netuid=1,
data="Hello World!",
)

with pytest.raises(
SubstrateRequestException,
match="CommitmentSetRateLimitExceeded",
):
await sub.set_commitment(
alice_wallet,
netuid=1,
data="Hello World!",
)

assert "Hello World!" == await sub.get_commitment(
netuid=1,
uid=uid,
)

assert (await sub.get_all_commitments(netuid=1))[
alice_wallet.hotkey.ss58_address
] == "Hello World!"
Loading