33
44import pytest
55
6- import bittensor
7- from bittensor .core .subtensor import Subtensor
86from bittensor .utils import networking
9- from tests .e2e_tests .utils .chain_interactions import register_subnet
107from 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" )
0 commit comments