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
41 changes: 34 additions & 7 deletions tests/e2e_tests/test_commitment.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pytest
from async_substrate_interface.errors import SubstrateRequestException

from bittensor import logging
from async_substrate_interface.errors import SubstrateRequestException
from tests.e2e_tests.utils.chain_interactions import sudo_set_admin_utils

logging.set_trace()


def test_commitment(subtensor, alice_wallet):
def test_commitment(local_chain, subtensor, alice_wallet):
with pytest.raises(SubstrateRequestException, match="AccountNotAllowedCommit"):
subtensor.set_commitment(
alice_wallet,
Expand Down Expand Up @@ -37,14 +38,27 @@ def test_commitment(subtensor, alice_wallet):
data="Hello World!",
)

status, error = sudo_set_admin_utils(
local_chain,
alice_wallet,
call_module="Commitments",
call_function="set_max_space",
call_params={
"netuid": 1,
"new_limit": len("Hello World!"),
},
)

assert status is True, error

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

assert "Hello World!" == subtensor.get_commitment(
Expand All @@ -59,7 +73,7 @@ def test_commitment(subtensor, alice_wallet):


@pytest.mark.asyncio
async def test_commitment_async(async_subtensor, alice_wallet):
async def test_commitment_async(local_chain, async_subtensor, alice_wallet):
async with async_subtensor as sub:
with pytest.raises(SubstrateRequestException, match="AccountNotAllowedCommit"):
await sub.set_commitment(
Expand Down Expand Up @@ -91,14 +105,27 @@ async def test_commitment_async(async_subtensor, alice_wallet):
data="Hello World!",
)

status, error = sudo_set_admin_utils(
local_chain,
alice_wallet,
call_module="Commitments",
call_function="set_max_space",
call_params={
"netuid": 1,
"new_limit": len("Hello World!"),
},
)

assert status is True, error

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

assert "Hello World!" == await sub.get_commitment(
Expand Down
19 changes: 18 additions & 1 deletion tests/e2e_tests/test_incentive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import pytest

from tests.e2e_tests.utils.chain_interactions import (
root_set_subtensor_hyperparameter_values,
sudo_set_admin_utils,
wait_epoch,
wait_interval,
)

DURATION_OF_START_CALL = 10


@pytest.mark.asyncio
async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wallet):
Expand Down Expand Up @@ -53,7 +56,7 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa

assert alice_neuron.validator_permit is True
assert alice_neuron.dividends == 0
assert alice_neuron.stake.tao > 0
assert alice_neuron.stake.tao == 0
assert alice_neuron.validator_trust == 0
assert alice_neuron.incentive == 0
assert alice_neuron.consensus == 0
Expand All @@ -66,6 +69,20 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
assert bob_neuron.rank == 0
assert bob_neuron.trust == 0

subtensor.wait_for_block(DURATION_OF_START_CALL)

# Subnet "Start Call" https://github.com/opentensor/bits/pull/13
status, error = await root_set_subtensor_hyperparameter_values(
local_chain,
alice_wallet,
call_function="start_call",
call_params={
"netuid": netuid,
},
)

assert status is True, error

# update weights_set_rate_limit for fast-blocks
tempo = subtensor.tempo(netuid)
status, error = sudo_set_admin_utils(
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e_tests/test_metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ def test_metagraph_info(subtensor, alice_wallet):
blocks_since_last_step=1,
subnet_emission=Balance(0),
alpha_in=Balance.from_tao(10),
alpha_out=Balance.from_tao(2),
alpha_out=Balance.from_tao(1),
tao_in=Balance.from_tao(10),
alpha_out_emission=Balance.from_tao(1),
alpha_out_emission=Balance(0),
alpha_in_emission=Balance(0),
tao_in_emission=Balance(0),
pending_alpha_emission=Balance.from_tao(0.820004577),
pending_alpha_emission=Balance(0),
pending_root_emission=Balance(0),
subnet_volume=Balance(0),
moving_price=Balance(0),
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_tests/test_staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_single_operation(subtensor, alice_wallet, bob_wallet):
alice_wallet,
bob_wallet.hotkey.ss58_address,
netuid=1,
amount=Balance.from_tao(10_000),
amount=Balance.from_tao(1),
wait_for_inclusion=True,
wait_for_finalization=True,
)
Expand Down
9 changes: 3 additions & 6 deletions tests/e2e_tests/utils/chain_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def sudo_set_admin_utils(
wallet: "Wallet",
call_function: str,
call_params: dict,
call_module: str = "AdminUtils",
) -> tuple[bool, Optional[dict]]:
"""
Wraps the call in sudo to set hyperparameter values using AdminUtils.
Expand All @@ -195,7 +196,7 @@ def sudo_set_admin_utils(
tuple[bool, Optional[dict]]: (success status, error details).
"""
inner_call = substrate.compose_call(
call_module="AdminUtils",
call_module=call_module,
call_function=call_function,
call_params=call_params,
)
Expand All @@ -222,7 +223,6 @@ async def root_set_subtensor_hyperparameter_values(
wallet: "Wallet",
call_function: str,
call_params: dict,
return_error_message: bool = False,
) -> tuple[bool, str]:
"""
Sets liquid alpha values using AdminUtils. Mimics setting hyperparams
Expand All @@ -240,10 +240,7 @@ async def root_set_subtensor_hyperparameter_values(
wait_for_finalization=True,
)

if return_error_message:
return response.is_success, response.error_message

return response.is_success, ""
return response.is_success, response.error_message


def set_identity(
Expand Down
Loading