Skip to content

Commit 1b37093

Browse files
authored
Merge branch 'staging' into feat/roman/add-get-owned-hotkeys
2 parents 59e88f1 + fc47114 commit 1b37093

File tree

7 files changed

+85
-53
lines changed

7 files changed

+85
-53
lines changed

.github/workflows/e2e-subtensor-tests.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ jobs:
8080
- name: Check-out repository
8181
uses: actions/checkout@v4
8282

83+
- name: Set up Python ${{ matrix.python-version }}
84+
uses: actions/setup-python@v5
85+
with:
86+
python-version: ${{ matrix.python-version }}
87+
8388
- name: Install uv
8489
uses: astral-sh/setup-uv@v4
8590

tests/e2e_tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def try_start_docker():
164164
print("Docker wasn't run. Manual start may be required.")
165165
return False
166166

167-
container_name = f"test_local_chain_{str(time.time()).replace(".", "_")}"
167+
container_name = f"test_local_chain_{str(time.time()).replace('.', '_')}"
168168

169169
# Command to start container
170170
cmds = [

tests/e2e_tests/test_commit_weights.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from tests.e2e_tests.utils.chain_interactions import (
88
sudo_set_admin_utils,
99
sudo_set_hyperparameter_bool,
10+
use_and_wait_for_next_nonce,
1011
wait_epoch,
1112
)
1213

@@ -227,42 +228,44 @@ async def test_commit_weights_uses_next_nonce(local_chain, subtensor, alice_wall
227228
salt3[0] += 2 # Increment the first byte to produce a different commit hash
228229

229230
# Commit all three salts
230-
success, message = subtensor.commit_weights(
231-
alice_wallet,
232-
netuid,
233-
salt=salt,
234-
uids=weight_uids,
235-
weights=weight_vals,
236-
wait_for_inclusion=False, # Don't wait for inclusion, we are testing the nonce when there is a tx in the pool
237-
wait_for_finalization=False,
238-
)
239-
240-
assert success is True
241-
242-
success, message = subtensor.commit_weights(
243-
alice_wallet,
244-
netuid,
245-
salt=salt2,
246-
uids=weight_uids,
247-
weights=weight_vals,
248-
wait_for_inclusion=False,
249-
wait_for_finalization=False,
250-
)
251-
252-
assert success is True
253-
254-
# Commit the third salt
255-
success, message = subtensor.commit_weights(
256-
alice_wallet,
257-
netuid,
258-
salt=salt3,
259-
uids=weight_uids,
260-
weights=weight_vals,
261-
wait_for_inclusion=False,
262-
wait_for_finalization=False,
263-
)
264-
265-
assert success is True
231+
async with use_and_wait_for_next_nonce(subtensor, alice_wallet):
232+
success, message = subtensor.commit_weights(
233+
alice_wallet,
234+
netuid,
235+
salt=salt,
236+
uids=weight_uids,
237+
weights=weight_vals,
238+
wait_for_inclusion=False, # Don't wait for inclusion, we are testing the nonce when there is a tx in the pool
239+
wait_for_finalization=False,
240+
)
241+
242+
assert success is True
243+
244+
async with use_and_wait_for_next_nonce(subtensor, alice_wallet):
245+
success, message = subtensor.commit_weights(
246+
alice_wallet,
247+
netuid,
248+
salt=salt2,
249+
uids=weight_uids,
250+
weights=weight_vals,
251+
wait_for_inclusion=False,
252+
wait_for_finalization=False,
253+
)
254+
255+
assert success is True
256+
257+
async with use_and_wait_for_next_nonce(subtensor, alice_wallet):
258+
success, message = subtensor.commit_weights(
259+
alice_wallet,
260+
netuid,
261+
salt=salt3,
262+
uids=weight_uids,
263+
weights=weight_vals,
264+
wait_for_inclusion=False,
265+
wait_for_finalization=False,
266+
)
267+
268+
assert success is True
266269

267270
# Wait a few blocks
268271
await asyncio.sleep(10) # Wait for the txs to be included in the chain

tests/e2e_tests/test_incentive.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa
8484
async with templates.miner(bob_wallet, netuid):
8585
async with templates.validator(alice_wallet, netuid) as validator:
8686
# wait for the Validator to process and set_weights
87-
async with asyncio.timeout(60):
88-
await validator.set_weights.wait()
87+
await asyncio.wait_for(validator.set_weights.wait(), 60)
8988

9089
# Wait till new epoch
9190
await wait_interval(tempo, subtensor, netuid)

tests/e2e_tests/test_set_weights.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from tests.e2e_tests.utils.chain_interactions import (
77
sudo_set_hyperparameter_bool,
88
sudo_set_admin_utils,
9+
use_and_wait_for_next_nonce,
910
wait_epoch,
1011
)
1112

@@ -108,16 +109,17 @@ async def test_set_weights_uses_next_nonce(local_chain, subtensor, alice_wallet)
108109

109110
# Set weights for each subnet
110111
for netuid in netuids:
111-
success, message = subtensor.set_weights(
112-
alice_wallet,
113-
netuid,
114-
uids=weight_uids,
115-
weights=weight_vals,
116-
wait_for_inclusion=False, # Don't wait for inclusion, we are testing the nonce when there is a tx in the pool
117-
wait_for_finalization=False,
118-
)
119-
120-
assert success is True, f"Failed to set weights for subnet {netuid}"
112+
async with use_and_wait_for_next_nonce(subtensor, alice_wallet):
113+
success, message = subtensor.set_weights(
114+
alice_wallet,
115+
netuid,
116+
uids=weight_uids,
117+
weights=weight_vals,
118+
wait_for_inclusion=False, # Don't wait for inclusion, we are testing the nonce when there is a tx in the pool
119+
wait_for_finalization=False,
120+
)
121+
122+
assert success is True, message
121123

122124
# Wait for the txs to be included in the chain
123125
await wait_epoch(subtensor, netuid=netuids[-1], times=4)

tests/e2e_tests/utils/chain_interactions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import asyncio
7+
import contextlib
78
import unittest.mock
89
from typing import Union, Optional, TYPE_CHECKING
910

@@ -150,6 +151,30 @@ async def wait_interval(
150151
)
151152

152153

154+
@contextlib.asynccontextmanager
155+
async def use_and_wait_for_next_nonce(
156+
subtensor: "Subtensor",
157+
wallet: "Wallet",
158+
sleep: float = 0.25,
159+
timeout: float = 15.0,
160+
):
161+
"""
162+
ContextManager that makes sure the Nonce has been consumed after sending Extrinsic.
163+
"""
164+
165+
nonce = subtensor.substrate.get_account_next_index(wallet.hotkey.ss58_address)
166+
167+
yield
168+
169+
async def wait_for_new_nonce():
170+
while nonce == subtensor.substrate.get_account_next_index(
171+
wallet.hotkey.ss58_address
172+
):
173+
await asyncio.sleep(sleep)
174+
175+
await asyncio.wait_for(wait_for_new_nonce(), timeout)
176+
177+
153178
# Helper to execute sudo wrapped calls on the chain
154179
def sudo_set_admin_utils(
155180
substrate: "SubstrateInterface",

tests/e2e_tests/utils/e2e_test_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ async def __aenter__(self):
116116

117117
self.__reader_task = asyncio.create_task(self._reader())
118118

119-
async with asyncio.timeout(30):
120-
await self.started.wait()
119+
await asyncio.wait_for(self.started.wait(), 30)
121120

122121
return self
123122

@@ -166,8 +165,7 @@ async def __aenter__(self):
166165

167166
self.__reader_task = asyncio.create_task(self._reader())
168167

169-
async with asyncio.timeout(30):
170-
await self.started.wait()
168+
await asyncio.wait_for(self.started.wait(), 30)
171169

172170
return self
173171

0 commit comments

Comments
 (0)