Skip to content
Merged
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
52 changes: 34 additions & 18 deletions tests/e2e_tests/test_liquid_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
sudo_set_hyperparameter_values,
sudo_set_admin_utils,
)
from tests.e2e_tests.utils.e2e_test_utils import wait_to_start_call


def liquid_alpha_call_params(netuid: int, alpha_values: str):
Expand Down Expand Up @@ -45,28 +46,32 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
logging.console.info("Testing test_liquid_alpha_enabled")

# Register root as Alice
assert subtensor.register_subnet(alice_wallet), "Unable to register the subnet"
assert subtensor.register_subnet(alice_wallet), "Unable to register the subnet."

# Verify subnet created successfully
assert subtensor.subnet_exists(netuid)

assert wait_to_start_call(subtensor, alice_wallet, netuid), (
"Subnet failed to start."
)

# Register a neuron (Alice) to the subnet
assert subtensor.burned_register(alice_wallet, netuid), (
"Unable to register Alice as a neuron"
)

# Stake to become to top neuron after the first epoch
subtensor.add_stake(
alice_wallet,
assert subtensor.add_stake(
wallet=alice_wallet,
netuid=netuid,
amount=Balance.from_tao(10_000),
)
), "Failed to stake"

# Assert liquid alpha is disabled
assert (
subtensor.get_subnet_hyperparameters(netuid=netuid).liquid_alpha_enabled
is False
), "Liquid alpha is enabled by default"
), "Liquid alpha is enabled by default."

# Attempt to set alpha high/low while disabled (should fail)
alpha_values = "6553, 53083"
Expand All @@ -78,7 +83,7 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
call_params=call_params,
return_error_message=True,
)
assert result is False, "Alpha values set while being disabled"
assert result is False, "Alpha values set while being disabled."
assert error_message["name"] == "LiquidAlphaDisabled"

# Enabled liquid alpha on the subnet
Expand All @@ -88,7 +93,7 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):

assert subtensor.get_subnet_hyperparameters(
netuid,
).liquid_alpha_enabled, "Failed to enable liquid alpha"
).liquid_alpha_enabled, "Failed to enable liquid alpha."

# Attempt to set alpha high & low after enabling the hyperparameter
alpha_values = "26001, 54099"
Expand All @@ -98,19 +103,30 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
alice_wallet,
call_function="sudo_set_alpha_values",
call_params=call_params,
), "Unable to set alpha_values"
), "Unable to set alpha_values."
assert subtensor.get_subnet_hyperparameters(netuid).alpha_high == 54099, (
"Failed to set alpha high"
"Failed to set alpha high."
)
assert subtensor.get_subnet_hyperparameters(netuid).alpha_low == 26001, (
"Failed to set alpha low"
"Failed to set alpha low."
)

# Testing alpha high upper and lower bounds

# 1. Test setting Alpha_high too low
alpha_high_too_low = 87

# Test needs to wait for the amount of tempo in the chain equal to OwnerHyperparamRateLimit
owner_hyperparam_ratelimit = subtensor.substrate.query(
module="SubtensorModule", storage_function="OwnerHyperparamRateLimit"
)
logging.console.info(
f"OwnerHyperparamRateLimit is {owner_hyperparam_ratelimit} tempo(s)."
)
subtensor.wait_for_block(
subtensor.block + subtensor.tempo(netuid) * owner_hyperparam_ratelimit
)

call_params = liquid_alpha_call_params(netuid, f"6553, {alpha_high_too_low}")
result, error_message = sudo_set_hyperparameter_values(
local_chain,
Expand All @@ -120,7 +136,7 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
return_error_message=True,
)

assert result is False, "Able to set incorrect alpha_high value"
assert result is False, "Able to set incorrect alpha_high value."
assert error_message["name"] == "AlphaHighTooLow"

# 2. Test setting Alpha_high too high
Expand Down Expand Up @@ -149,7 +165,7 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
call_params=call_params,
return_error_message=True,
)
assert result is False, "Able to set incorrect alpha_low value"
assert result is False, "Able to set incorrect alpha_low value."
assert error_message["name"] == "AlphaLowOutOfRange"

# 2. Test setting Alpha_low too high
Expand All @@ -162,7 +178,7 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
call_params=call_params,
return_error_message=True,
)
assert result is False, "Able to set incorrect alpha_low value"
assert result is False, "Able to set incorrect alpha_low value."
assert error_message["name"] == "AlphaLowOutOfRange"

# Setting normal alpha values
Expand All @@ -173,21 +189,21 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
alice_wallet,
call_function="sudo_set_alpha_values",
call_params=call_params,
), "Unable to set liquid alpha values"
), "Unable to set liquid alpha values."

assert subtensor.get_subnet_hyperparameters(netuid).alpha_high == 53083, (
"Failed to set alpha high"
"Failed to set alpha high."
)
assert subtensor.get_subnet_hyperparameters(netuid).alpha_low == 6553, (
"Failed to set alpha low"
"Failed to set alpha low."
)

# Disable Liquid Alpha
assert sudo_set_hyperparameter_bool(
local_chain, alice_wallet, "sudo_set_liquid_alpha_enabled", False, netuid
), "Unable to disable liquid alpha"
), "Unable to disable liquid alpha."

assert subtensor.get_subnet_hyperparameters(netuid).liquid_alpha_enabled is False, (
"Failed to disable liquid alpha"
"Failed to disable liquid alpha."
)
logging.console.info("✅ Passed test_liquid_alpha")
Loading