Skip to content

Commit 4278a3d

Browse files
authored
Merge pull request #3059 from opentensor/fix/roman/add-wait-for-amount-of-You-need-to-wait-for-the-amount-of-tempo-in-the-chain-equal-to-OwnerHyperparamRateLimit-tempo
add getting OwnerHyperparamRateLimit in e2e test
2 parents 53036c7 + f4b80e6 commit 4278a3d

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

tests/e2e_tests/test_liquid_alpha.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
sudo_set_hyperparameter_values,
66
sudo_set_admin_utils,
77
)
8+
from tests.e2e_tests.utils.e2e_test_utils import wait_to_start_call
89

910

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

4748
# Register root as Alice
48-
assert subtensor.register_subnet(alice_wallet), "Unable to register the subnet"
49+
assert subtensor.register_subnet(alice_wallet), "Unable to register the subnet."
4950

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

54+
assert wait_to_start_call(subtensor, alice_wallet, netuid), (
55+
"Subnet failed to start."
56+
)
57+
5358
# Register a neuron (Alice) to the subnet
5459
assert subtensor.burned_register(alice_wallet, netuid), (
5560
"Unable to register Alice as a neuron"
5661
)
5762

5863
# Stake to become to top neuron after the first epoch
59-
subtensor.add_stake(
60-
alice_wallet,
64+
assert subtensor.add_stake(
65+
wallet=alice_wallet,
6166
netuid=netuid,
6267
amount=Balance.from_tao(10_000),
63-
)
68+
), "Failed to stake"
6469

6570
# Assert liquid alpha is disabled
6671
assert (
6772
subtensor.get_subnet_hyperparameters(netuid=netuid).liquid_alpha_enabled
6873
is False
69-
), "Liquid alpha is enabled by default"
74+
), "Liquid alpha is enabled by default."
7075

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

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

8994
assert subtensor.get_subnet_hyperparameters(
9095
netuid,
91-
).liquid_alpha_enabled, "Failed to enable liquid alpha"
96+
).liquid_alpha_enabled, "Failed to enable liquid alpha."
9297

9398
# Attempt to set alpha high & low after enabling the hyperparameter
9499
alpha_values = "26001, 54099"
@@ -98,19 +103,30 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
98103
alice_wallet,
99104
call_function="sudo_set_alpha_values",
100105
call_params=call_params,
101-
), "Unable to set alpha_values"
106+
), "Unable to set alpha_values."
102107
assert subtensor.get_subnet_hyperparameters(netuid).alpha_high == 54099, (
103-
"Failed to set alpha high"
108+
"Failed to set alpha high."
104109
)
105110
assert subtensor.get_subnet_hyperparameters(netuid).alpha_low == 26001, (
106-
"Failed to set alpha low"
111+
"Failed to set alpha low."
107112
)
108113

109114
# Testing alpha high upper and lower bounds
110115

111116
# 1. Test setting Alpha_high too low
112117
alpha_high_too_low = 87
113118

119+
# Test needs to wait for the amount of tempo in the chain equal to OwnerHyperparamRateLimit
120+
owner_hyperparam_ratelimit = subtensor.substrate.query(
121+
module="SubtensorModule", storage_function="OwnerHyperparamRateLimit"
122+
)
123+
logging.console.info(
124+
f"OwnerHyperparamRateLimit is {owner_hyperparam_ratelimit} tempo(s)."
125+
)
126+
subtensor.wait_for_block(
127+
subtensor.block + subtensor.tempo(netuid) * owner_hyperparam_ratelimit
128+
)
129+
114130
call_params = liquid_alpha_call_params(netuid, f"6553, {alpha_high_too_low}")
115131
result, error_message = sudo_set_hyperparameter_values(
116132
local_chain,
@@ -120,7 +136,7 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
120136
return_error_message=True,
121137
)
122138

123-
assert result is False, "Able to set incorrect alpha_high value"
139+
assert result is False, "Able to set incorrect alpha_high value."
124140
assert error_message["name"] == "AlphaHighTooLow"
125141

126142
# 2. Test setting Alpha_high too high
@@ -149,7 +165,7 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
149165
call_params=call_params,
150166
return_error_message=True,
151167
)
152-
assert result is False, "Able to set incorrect alpha_low value"
168+
assert result is False, "Able to set incorrect alpha_low value."
153169
assert error_message["name"] == "AlphaLowOutOfRange"
154170

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

168184
# Setting normal alpha values
@@ -173,21 +189,21 @@ def test_liquid_alpha(local_chain, subtensor, alice_wallet):
173189
alice_wallet,
174190
call_function="sudo_set_alpha_values",
175191
call_params=call_params,
176-
), "Unable to set liquid alpha values"
192+
), "Unable to set liquid alpha values."
177193

178194
assert subtensor.get_subnet_hyperparameters(netuid).alpha_high == 53083, (
179-
"Failed to set alpha high"
195+
"Failed to set alpha high."
180196
)
181197
assert subtensor.get_subnet_hyperparameters(netuid).alpha_low == 6553, (
182-
"Failed to set alpha low"
198+
"Failed to set alpha low."
183199
)
184200

185201
# Disable Liquid Alpha
186202
assert sudo_set_hyperparameter_bool(
187203
local_chain, alice_wallet, "sudo_set_liquid_alpha_enabled", False, netuid
188-
), "Unable to disable liquid alpha"
204+
), "Unable to disable liquid alpha."
189205

190206
assert subtensor.get_subnet_hyperparameters(netuid).liquid_alpha_enabled is False, (
191-
"Failed to disable liquid alpha"
207+
"Failed to disable liquid alpha."
192208
)
193209
logging.console.info("✅ Passed test_liquid_alpha")

0 commit comments

Comments
 (0)