3
3
4
4
import pytest
5
5
6
- import bittensor
7
- from bittensor .core .subtensor import Subtensor
8
6
from bittensor .utils import networking
9
- from tests .e2e_tests .utils .chain_interactions import register_subnet
10
7
from tests .e2e_tests .utils .e2e_test_utils import (
11
- setup_wallet ,
12
8
template_path ,
13
9
templates_repo ,
14
10
)
15
11
16
12
17
13
@pytest .mark .asyncio
18
- async def test_axon (local_chain ):
14
+ async def test_axon (subtensor , alice_wallet ):
19
15
"""
20
16
Test the Axon mechanism and successful registration on the network.
21
17
@@ -30,33 +26,24 @@ async def test_axon(local_chain):
30
26
31
27
print ("Testing test_axon" )
32
28
33
- netuid = 1
34
- # Register root as Alice - the subnet owner
35
- alice_keypair , wallet = setup_wallet ("//Alice" )
29
+ netuid = 2
36
30
37
- subtensor = Subtensor (network = "ws://localhost:9945" )
31
+ # Register a subnet, netuid 2
32
+ assert subtensor .register_subnet (alice_wallet ), "Subnet wasn't created"
38
33
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 "
41
36
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 )
53
38
54
39
# Validate current metagraph stats
55
40
old_axon = metagraph .axons [0 ]
56
41
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"
58
42
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
60
47
), "Coldkey mismatch for the axon"
61
48
assert old_axon .ip == "0.0.0.0" , f"Expected IP 0.0.0.0, but got { old_axon .ip } "
62
49
assert old_axon .port == 0 , f"Expected port 0, but got { old_axon .port } "
@@ -66,17 +53,17 @@ async def test_axon(local_chain):
66
53
cmd = " " .join (
67
54
[
68
55
f"{ sys .executable } " ,
69
- f'"{ template_path } { templates_repo } /neurons/ miner.py"' ,
56
+ f'"{ template_path } { templates_repo } /miner.py"' ,
70
57
"--netuid" ,
71
58
str (netuid ),
72
59
"--subtensor.network" ,
73
60
"local" ,
74
61
"--subtensor.chain_endpoint" ,
75
62
"ws://localhost:9945" ,
76
63
"--wallet.path" ,
77
- wallet .path ,
64
+ alice_wallet .path ,
78
65
"--wallet.name" ,
79
- wallet .name ,
66
+ alice_wallet .name ,
80
67
"--wallet.hotkey" ,
81
68
"default" ,
82
69
]
@@ -95,7 +82,7 @@ async def test_axon(local_chain):
95
82
await asyncio .sleep (5 )
96
83
97
84
# Refresh the metagraph
98
- metagraph = bittensor . Metagraph (netuid = netuid , network = "ws://localhost:9945" )
85
+ metagraph = subtensor . metagraph (netuid )
99
86
updated_axon = metagraph .axons [0 ]
100
87
external_ip = networking .get_external_ip ()
101
88
@@ -119,11 +106,11 @@ async def test_axon(local_chain):
119
106
assert updated_axon .port == 8091 , f"Expected port 8091, but got { updated_axon .port } "
120
107
121
108
assert (
122
- updated_axon .hotkey == alice_keypair .ss58_address
109
+ updated_axon .hotkey == alice_wallet . hotkey .ss58_address
123
110
), "Hotkey mismatch after mining"
124
111
125
112
assert (
126
- updated_axon .coldkey == alice_keypair .ss58_address
113
+ updated_axon .coldkey == alice_wallet . coldkey .ss58_address
127
114
), "Coldkey mismatch after mining"
128
115
129
116
print ("✅ Passed test_axon" )
0 commit comments