Skip to content

Commit 29d433a

Browse files
tests: AsyncSubtensor E2E
1 parent da63e51 commit 29d433a

23 files changed

+650
-517
lines changed

tests/e2e_tests/conftest.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
import time
1010

1111
import pytest
12+
import pytest_asyncio
1213
from async_substrate_interface import SubstrateInterface
1314

1415
from bittensor.core.async_subtensor import AsyncSubtensor
15-
from bittensor.core.subtensor import Subtensor
1616
from bittensor.utils.btlogging import logging
1717
from tests.e2e_tests.utils.e2e_test_utils import (
18+
SyncSubtensor,
1819
Templates,
1920
setup_wallet,
2021
)
@@ -221,14 +222,17 @@ def templates():
221222
yield templates
222223

223224

224-
@pytest.fixture
225-
def subtensor(local_chain):
226-
return Subtensor(network="ws://localhost:9944")
227-
228-
229-
@pytest.fixture
230-
def async_subtensor(local_chain):
231-
return AsyncSubtensor(network="ws://localhost:9944")
225+
@pytest_asyncio.fixture(
226+
params=[
227+
SyncSubtensor,
228+
AsyncSubtensor,
229+
],
230+
)
231+
async def subtensor(local_chain, request):
232+
async with request.param(
233+
network=local_chain.url,
234+
) as subtensor:
235+
yield subtensor
232236

233237

234238
@pytest.fixture

tests/e2e_tests/test_axon.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ async def test_axon(subtensor, templates, alice_wallet):
2424
netuid = 2
2525

2626
# Register a subnet, netuid 2
27-
assert subtensor.register_subnet(alice_wallet), "Subnet wasn't created"
27+
assert await subtensor.register_subnet(alice_wallet), "Subnet wasn't created"
2828

2929
# Verify subnet <netuid> created successfully
30-
assert subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
30+
assert await subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
3131

32-
metagraph = subtensor.metagraph(netuid)
32+
metagraph = await subtensor.metagraph(netuid)
3333

3434
# Validate current metagraph stats
3535
old_axon = metagraph.axons[0]
@@ -49,7 +49,7 @@ async def test_axon(subtensor, templates, alice_wallet):
4949
await asyncio.sleep(5)
5050

5151
# Refresh the metagraph
52-
metagraph = subtensor.metagraph(netuid)
52+
metagraph = await subtensor.metagraph(netuid)
5353
updated_axon = metagraph.axons[0]
5454
external_ip = networking.get_external_ip()
5555

tests/e2e_tests/test_commit_reveal_v3.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
3333
logging.console.info("Testing test_commit_and_reveal_weights")
3434

3535
# Register root as Alice
36-
assert subtensor.register_subnet(alice_wallet), "Unable to register the subnet"
36+
assert await subtensor.register_subnet(
37+
alice_wallet,
38+
), "Unable to register the subnet"
3739

3840
# Verify subnet 2 created successfully
39-
assert subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
41+
assert await subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
4042

4143
logging.console.info("Subnet 2 is registered")
4244

@@ -50,7 +52,9 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
5052
), "Unable to enable commit reveal on the subnet"
5153

5254
# Verify commit_reveal was enabled
53-
assert subtensor.commit_reveal_enabled(netuid), "Failed to enable commit/reveal"
55+
assert await subtensor.commit_reveal_enabled(
56+
netuid,
57+
), "Failed to enable commit/reveal"
5458
logging.console.info("Commit reveal enabled")
5559

5660
# Change the weights rate limit on the subnet
@@ -66,9 +70,9 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
6670

6771
# Verify weights rate limit was changed
6872
assert (
69-
subtensor.get_subnet_hyperparameters(netuid=netuid).weights_rate_limit == 0
70-
), "Failed to set weights_rate_limit"
71-
assert subtensor.weights_rate_limit(netuid=netuid) == 0
73+
await subtensor.get_subnet_hyperparameters(netuid=netuid)
74+
).weights_rate_limit == 0, "Failed to set weights_rate_limit"
75+
assert await subtensor.weights_rate_limit(netuid=netuid) == 0
7276
logging.console.info("sudo_set_weights_set_rate_limit executed: set to 0")
7377

7478
# Change the tempo of the subnet from default 360
@@ -83,7 +87,7 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
8387
)[0]
8488
is True
8589
)
86-
tempo = subtensor.get_subnet_hyperparameters(netuid=netuid).tempo
90+
tempo = await subtensor.tempo(netuid)
8791
assert tempo_set == tempo
8892
logging.console.info(f"sudo_set_tempo executed: set to {tempo_set}")
8993

@@ -95,14 +99,14 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
9599
)
96100

97101
# Fetch current block and calculate next tempo for the subnet
98-
current_block = subtensor.get_current_block()
102+
current_block = await subtensor.get_current_block()
99103
upcoming_tempo = next_tempo(current_block, tempo, netuid)
100104
logging.console.info(
101105
f"Checking if window is too low with Current block: {current_block}, next tempo: {upcoming_tempo}"
102106
)
103107

104108
# Wait for 2 tempos to pass as CR3 only reveals weights after 2 tempos
105-
subtensor.wait_for_block(20)
109+
await subtensor.wait_for_block(20)
106110

107111
# Lower than this might mean weights will get revealed before we can check them
108112
if upcoming_tempo - current_block < 3:
@@ -112,15 +116,15 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
112116
netuid=netuid,
113117
reporting_interval=1,
114118
)
115-
current_block = subtensor.get_current_block()
116-
latest_drand_round = subtensor.last_drand_round()
119+
current_block = await subtensor.get_current_block()
120+
latest_drand_round = await subtensor.last_drand_round()
117121
upcoming_tempo = next_tempo(current_block, tempo, netuid)
118122
logging.console.info(
119123
f"Post first wait_interval (to ensure window isnt too low): {current_block}, next tempo: {upcoming_tempo}, drand: {latest_drand_round}"
120124
)
121125

122126
# Commit weights
123-
success, message = subtensor.set_weights(
127+
success, message = await subtensor.set_weights(
124128
alice_wallet,
125129
netuid,
126130
uids=weight_uids,
@@ -139,8 +143,8 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
139143
f"Successfully set weights: uids {weight_uids}, weights {weight_vals}, reveal_round: {expected_reveal_round}"
140144
)
141145

142-
current_block = subtensor.get_current_block()
143-
latest_drand_round = subtensor.last_drand_round()
146+
current_block = await subtensor.get_current_block()
147+
latest_drand_round = await subtensor.last_drand_round()
144148
upcoming_tempo = next_tempo(current_block, tempo, netuid)
145149
logging.console.info(
146150
f"After setting weights: Current block: {current_block}, next tempo: {upcoming_tempo}, drand: {latest_drand_round}"
@@ -152,32 +156,32 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
152156
), "Revealed drand pulse is older than the drand pulse right after setting weights"
153157

154158
# Fetch current commits pending on the chain
155-
commits_on_chain = subtensor.get_current_weight_commit_info(netuid=netuid)
159+
commits_on_chain = await subtensor.get_current_weight_commit_info(netuid=netuid)
156160
address, commit, reveal_round = commits_on_chain[0]
157161

158162
# Assert correct values are committed on the chain
159163
assert expected_reveal_round == reveal_round
160164
assert address == alice_wallet.hotkey.ss58_address
161165

162166
# Ensure no weights are available as of now
163-
assert subtensor.weights(netuid=netuid) == []
167+
assert await subtensor.weights(netuid=netuid) == []
164168

165169
# Wait for the next tempo so weights can be revealed
166170
await wait_interval(
167-
subtensor.get_subnet_hyperparameters(netuid=netuid).tempo,
171+
tempo,
168172
subtensor,
169173
netuid=netuid,
170174
reporting_interval=1,
171175
)
172176

173177
# Fetch the latest drand pulse
174-
latest_drand_round = subtensor.last_drand_round()
178+
latest_drand_round = await subtensor.last_drand_round()
175179
logging.console.info(
176180
f"Latest drand round after waiting for tempo: {latest_drand_round}"
177181
)
178182

179183
# Fetch weights on the chain as they should be revealed now
180-
revealed_weights_ = subtensor.weights(netuid=netuid)
184+
revealed_weights_ = await subtensor.weights(netuid=netuid)
181185

182186
print("revealed weights", revealed_weights_)
183187
revealed_weights = revealed_weights_[0][1]
@@ -186,7 +190,7 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
186190
assert weight_vals[0] == revealed_weights[0][1]
187191

188192
# Now that the commit has been revealed, there shouldn't be any pending commits
189-
assert subtensor.get_current_weight_commit_info(netuid=netuid) == []
193+
assert await subtensor.get_current_weight_commit_info(netuid=netuid) == []
190194

191195
# Ensure the drand_round is always in the positive w.r.t expected when revealed
192196
assert (

0 commit comments

Comments
 (0)