Skip to content

Commit 0a46cbd

Browse files
authored
Merge pull request #2639 from opentensor/tests/zyzniewski/fix_e2e
Fix e2e tests
2 parents 9661a37 + 83d483d commit 0a46cbd

16 files changed

+416
-548
lines changed

tests/e2e_tests/conftest.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
import pytest
1010
from async_substrate_interface import SubstrateInterface
11+
from bittensor.core.subtensor import Subtensor
1112

1213
from bittensor.utils.btlogging import logging
1314
from tests.e2e_tests.utils.e2e_test_utils import (
1415
clone_or_update_templates,
1516
install_templates,
17+
setup_wallet,
1618
template_path,
1719
uninstall_templates,
1820
)
@@ -103,3 +105,26 @@ def read_output():
103105
# uninstall templates
104106
logging.info("uninstalling neuron templates")
105107
uninstall_templates(template_path)
108+
109+
110+
@pytest.fixture
111+
def subtensor(local_chain):
112+
return Subtensor(network="ws://localhost:9945")
113+
114+
115+
@pytest.fixture
116+
def alice_wallet():
117+
keypair, wallet = setup_wallet("//Alice")
118+
return wallet
119+
120+
121+
@pytest.fixture
122+
def bob_wallet():
123+
keypair, wallet = setup_wallet("//Bob")
124+
return wallet
125+
126+
127+
@pytest.fixture
128+
def dave_wallet():
129+
keypair, wallet = setup_wallet("//Dave")
130+
return wallet

tests/e2e_tests/test_axon.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33

44
import pytest
55

6-
import bittensor
7-
from bittensor.core.subtensor import Subtensor
86
from bittensor.utils import networking
9-
from tests.e2e_tests.utils.chain_interactions import register_subnet
107
from tests.e2e_tests.utils.e2e_test_utils import (
11-
setup_wallet,
128
template_path,
139
templates_repo,
1410
)
1511

1612

1713
@pytest.mark.asyncio
18-
async def test_axon(local_chain):
14+
async def test_axon(subtensor, alice_wallet):
1915
"""
2016
Test the Axon mechanism and successful registration on the network.
2117
@@ -30,33 +26,24 @@ async def test_axon(local_chain):
3026

3127
print("Testing test_axon")
3228

33-
netuid = 1
34-
# Register root as Alice - the subnet owner
35-
alice_keypair, wallet = setup_wallet("//Alice")
29+
netuid = 2
3630

37-
subtensor = Subtensor(network="ws://localhost:9945")
31+
# Register a subnet, netuid 2
32+
assert subtensor.register_subnet(alice_wallet), "Subnet wasn't created"
3833

39-
# Register a subnet, netuid 1
40-
assert register_subnet(local_chain, wallet), "Subnet wasn't created"
34+
# Verify subnet <netuid> created successfully
35+
assert subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
4136

42-
# Verify subnet <netuid 1> created successfully
43-
assert local_chain.query(
44-
"SubtensorModule", "NetworksAdded", [netuid]
45-
).serialize(), "Subnet wasn't created successfully"
46-
47-
# Register Alice to the network
48-
assert subtensor.burned_register(
49-
wallet, netuid
50-
), f"Neuron wasn't registered to subnet {netuid}"
51-
52-
metagraph = bittensor.Metagraph(netuid=netuid, network="ws://localhost:9945")
37+
metagraph = subtensor.metagraph(netuid)
5338

5439
# Validate current metagraph stats
5540
old_axon = metagraph.axons[0]
5641
assert len(metagraph.axons) == 1, f"Expected 1 axon, but got {len(metagraph.axons)}"
57-
assert old_axon.hotkey == alice_keypair.ss58_address, "Hotkey mismatch for the axon"
5842
assert (
59-
old_axon.coldkey == alice_keypair.ss58_address
43+
old_axon.hotkey == alice_wallet.hotkey.ss58_address
44+
), "Hotkey mismatch for the axon"
45+
assert (
46+
old_axon.coldkey == alice_wallet.coldkey.ss58_address
6047
), "Coldkey mismatch for the axon"
6148
assert old_axon.ip == "0.0.0.0", f"Expected IP 0.0.0.0, but got {old_axon.ip}"
6249
assert old_axon.port == 0, f"Expected port 0, but got {old_axon.port}"
@@ -66,17 +53,17 @@ async def test_axon(local_chain):
6653
cmd = " ".join(
6754
[
6855
f"{sys.executable}",
69-
f'"{template_path}{templates_repo}/neurons/miner.py"',
56+
f'"{template_path}{templates_repo}/miner.py"',
7057
"--netuid",
7158
str(netuid),
7259
"--subtensor.network",
7360
"local",
7461
"--subtensor.chain_endpoint",
7562
"ws://localhost:9945",
7663
"--wallet.path",
77-
wallet.path,
64+
alice_wallet.path,
7865
"--wallet.name",
79-
wallet.name,
66+
alice_wallet.name,
8067
"--wallet.hotkey",
8168
"default",
8269
]
@@ -95,7 +82,7 @@ async def test_axon(local_chain):
9582
await asyncio.sleep(5)
9683

9784
# Refresh the metagraph
98-
metagraph = bittensor.Metagraph(netuid=netuid, network="ws://localhost:9945")
85+
metagraph = subtensor.metagraph(netuid)
9986
updated_axon = metagraph.axons[0]
10087
external_ip = networking.get_external_ip()
10188

@@ -119,11 +106,11 @@ async def test_axon(local_chain):
119106
assert updated_axon.port == 8091, f"Expected port 8091, but got {updated_axon.port}"
120107

121108
assert (
122-
updated_axon.hotkey == alice_keypair.ss58_address
109+
updated_axon.hotkey == alice_wallet.hotkey.ss58_address
123110
), "Hotkey mismatch after mining"
124111

125112
assert (
126-
updated_axon.coldkey == alice_keypair.ss58_address
113+
updated_axon.coldkey == alice_wallet.coldkey.ss58_address
127114
), "Coldkey mismatch after mining"
128115

129116
print("✅ Passed test_axon")

tests/e2e_tests/test_commit_reveal_v3.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@
44
import numpy as np
55
import pytest
66
from bittensor.utils.btlogging import logging
7-
from bittensor.core.subtensor import Subtensor
87
from bittensor.utils.balance import Balance
98
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
109
from tests.e2e_tests.utils.chain_interactions import (
11-
add_stake,
12-
register_subnet,
10+
sudo_set_admin_utils,
1311
sudo_set_hyperparameter_bool,
1412
sudo_set_hyperparameter_values,
1513
wait_interval,
16-
sudo_set_admin_utils,
1714
next_tempo,
1815
)
19-
from tests.e2e_tests.utils.e2e_test_utils import setup_wallet
2016

2117

2218
@pytest.mark.parametrize("local_chain", [False], indirect=True)
2319
@pytest.mark.asyncio
24-
async def test_commit_and_reveal_weights_cr3(local_chain):
20+
async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_wallet):
2521
"""
2622
Tests the commit/reveal weights mechanism (CR3)
2723
@@ -36,31 +32,16 @@ async def test_commit_and_reveal_weights_cr3(local_chain):
3632
Raises:
3733
AssertionError: If any of the checks or verifications fail
3834
"""
39-
netuid = 1
35+
netuid = 2
4036
logging.console.info("Testing test_commit_and_reveal_weights")
4137

4238
# Register root as Alice
43-
keypair, alice_wallet = setup_wallet("//Alice")
44-
assert register_subnet(local_chain, alice_wallet), "Unable to register the subnet"
45-
46-
# Verify subnet 1 created successfully
47-
assert local_chain.query(
48-
"SubtensorModule", "NetworksAdded", [1]
49-
).serialize(), "Subnet wasn't created successfully"
50-
51-
logging.console.info("Subnet 1 is registered")
39+
assert subtensor.register_subnet(alice_wallet), "Unable to register the subnet"
5240

53-
subtensor = Subtensor(network="ws://localhost:9945")
41+
# Verify subnet 2 created successfully
42+
assert subtensor.subnet_exists(netuid), "Subnet wasn't created successfully"
5443

55-
# Register Alice to the subnet
56-
assert subtensor.burned_register(
57-
alice_wallet, netuid
58-
), "Unable to register Alice as a neuron"
59-
logging.console.info("Registered Alice to subnet 1")
60-
61-
# Stake to become to top neuron after the first epoch
62-
add_stake(local_chain, alice_wallet, Balance.from_tao(100_000))
63-
logging.console.info("Stake added by Alice")
44+
logging.console.info("Subnet 2 is registered")
6445

6546
# Enable commit_reveal on the subnet
6647
assert sudo_set_hyperparameter_bool(
@@ -123,6 +104,10 @@ async def test_commit_and_reveal_weights_cr3(local_chain):
123104
logging.console.info(
124105
f"Checking if window is too low with Current block: {current_block}, next tempo: {upcoming_tempo}"
125106
)
107+
108+
# Wait for 2 tempos to pass as CR3 only reveals weights after 2 tempos
109+
subtensor.wait_for_block(20)
110+
126111
# Lower than this might mean weights will get revealed before we can check them
127112
if upcoming_tempo - current_block < 3:
128113
await wait_interval(
@@ -198,7 +183,6 @@ async def test_commit_and_reveal_weights_cr3(local_chain):
198183
# Fetch weights on the chain as they should be revealed now
199184
revealed_weights_ = subtensor.weights(netuid=netuid)
200185

201-
time.sleep(10)
202186
print("revealed weights", revealed_weights_)
203187
revealed_weights = revealed_weights_[0][1]
204188
# Assert correct weights were revealed

0 commit comments

Comments
 (0)