Skip to content

Commit 17d061d

Browse files
author
Roman
committed
test_commit_weights.py to non-fast block
1 parent 18271af commit 17d061d

File tree

1 file changed

+26
-52
lines changed

1 file changed

+26
-52
lines changed

tests/e2e_tests/test_commit_weights.py

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import asyncio
2-
import time
32

43
import numpy as np
54
import pytest
65

7-
from bittensor.utils.btlogging import logging
86
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
97
from tests.e2e_tests.utils.chain_interactions import (
108
sudo_set_admin_utils,
@@ -152,6 +150,7 @@ async def test_commit_and_reveal_weights_legacy(local_chain, subtensor, alice_wa
152150
print("✅ Passed test_commit_and_reveal_weights")
153151

154152

153+
@pytest.mark.parametrize("local_chain", [False], indirect=True)
155154
@pytest.mark.asyncio
156155
async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wallet):
157156
"""
@@ -167,17 +166,30 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
167166
Raises:
168167
AssertionError: If any of the checks or verifications fail
169168
"""
169+
subnet_tempo = 10
170+
netuid = 2
171+
170172
# Wait for 2 tempos to pass as CR3 only reveals weights after 2 tempos
171-
subtensor.wait_for_block(21)
173+
subtensor.wait_for_block(subnet_tempo * 2 + 1)
172174

173-
netuid = 2
174175
print("Testing test_commit_and_reveal_weights")
175176
# Register root as Alice
176177
assert subtensor.register_subnet(alice_wallet), "Unable to register the subnet"
177178

178179
# Verify subnet 1 created successfully
179180
assert subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
180181

182+
# weights sensitive to epoch changes
183+
assert sudo_set_admin_utils(
184+
local_chain,
185+
alice_wallet,
186+
call_function="sudo_set_tempo",
187+
call_params={
188+
"netuid": netuid,
189+
"tempo": subnet_tempo,
190+
},
191+
)
192+
181193
# Enable commit_reveal on the subnet
182194
assert sudo_set_hyperparameter_bool(
183195
local_chain,
@@ -205,19 +217,7 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
205217
call_params={"netuid": netuid, "weights_set_rate_limit": "0"},
206218
)
207219

208-
assert error is None
209-
assert status is True
210-
211-
# weights sensitive to epoch changes
212-
assert sudo_set_admin_utils(
213-
local_chain,
214-
alice_wallet,
215-
call_function="sudo_set_tempo",
216-
call_params={
217-
"netuid": netuid,
218-
"tempo": 100,
219-
},
220-
)
220+
assert error is None and status is True, f"Failed to set rate limit: {error}"
221221

222222
assert (
223223
subtensor.get_subnet_hyperparameters(netuid=netuid).weights_rate_limit == 0
@@ -248,14 +248,13 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
248248
salt=salt,
249249
uids=weight_uids,
250250
weights=weight_vals,
251-
wait_for_inclusion=False,
252-
# Don't wait for inclusion, we are testing the nonce when there is a tx in the pool
251+
wait_for_inclusion=False, # Don't wait for inclusion, we are testing the nonce when there is a tx in the pool
253252
wait_for_finalization=False,
254253
)
255254

256255
assert success is True
257256

258-
await asyncio.sleep(1)
257+
subtensor.wait_for_block(subtensor.block + 1)
259258

260259
async with use_and_wait_for_next_nonce(subtensor, alice_wallet):
261260
success, message = subtensor.commit_weights(
@@ -270,7 +269,7 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
270269

271270
assert success is True
272271

273-
await asyncio.sleep(1)
272+
subtensor.wait_for_block(subtensor.block + 1)
274273

275274
async with use_and_wait_for_next_nonce(subtensor, alice_wallet):
276275
success, message = subtensor.commit_weights(
@@ -285,44 +284,19 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
285284

286285
assert success is True
287286

288-
await asyncio.sleep(1)
289-
290-
# Sometimes the network does not have time to release data, and it requires several additional blocks (subtensor issue)
291-
# Call get_metagraph_info since if faster and chipper
292-
extra_time = time.time()
293-
while (
294-
len(
295-
subtensor.query_module(
296-
module="SubtensorModule",
297-
name="WeightCommits",
298-
params=[netuid, alice_wallet.hotkey.ss58_address],
299-
).value
300-
)
301-
< 3
302-
):
303-
if time.time() - extra_time > 120:
304-
pytest.skip(
305-
"Skipping due to FLAKY TEST. Check the same tests with another Python version or run again."
306-
)
307-
308-
logging.console.info(
309-
f"Additional fast block to wait chain data updated: {subtensor.block}"
310-
)
311-
await asyncio.sleep(0.25)
287+
# Wait a few blocks
288+
await wait_epoch(subtensor, netuid) # Wait for the txs to be included in the chain
312289

313290
# Query the WeightCommits storage map for all three salts
314-
query = subtensor.query_module(
291+
weight_commits = subtensor.query_module(
315292
module="SubtensorModule",
316293
name="WeightCommits",
317294
params=[netuid, alice_wallet.hotkey.ss58_address],
318295
)
319-
320-
weight_commits = query.value
321-
322296
# Assert that the committed weights are set correctly
323-
assert weight_commits is not None, "Weight commit not found in storage"
324-
commit_hash, commit_block, reveal_block, expire_block = weight_commits[0]
297+
assert weight_commits.value is not None, "Weight commit not found in storage"
298+
commit_hash, commit_block, reveal_block, expire_block = weight_commits.value[0]
325299
assert commit_block > 0, f"Invalid block number: {commit_block}"
326300

327301
# Check for three commits in the WeightCommits storage map
328-
assert len(weight_commits) == 3, "Expected 3 weight commits"
302+
assert len(weight_commits.value) == 3, "Expected 3 weight commits"

0 commit comments

Comments
 (0)