Skip to content

Commit 2698f8a

Browse files
author
Roman
committed
check weird behavior and add logging.console
1 parent 91a5a51 commit 2698f8a

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

tests/e2e_tests/test_metagraph.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,35 @@ def test_metagraph(subtensor, alice_wallet, bob_wallet, dave_wallet):
4848
logging.console.info("Testing test_metagraph_command")
4949
alice_subnet_netuid = 2
5050

51-
# Register the subnet through Alice
51+
logging.console.info("Register the subnet through Alice")
5252
assert subtensor.register_subnet(alice_wallet, True, True), (
5353
"Unable to register the subnet"
5454
)
5555

56-
# Verify subnet was created successfully
56+
logging.console.info("Verify subnet was created successfully")
5757
assert subtensor.subnet_exists(alice_subnet_netuid), (
5858
"Subnet wasn't created successfully"
5959
)
6060

61-
# make sure we passed start_call limit (10 blocks)
61+
logging.console.info("Make sure we passed start_call limit (10 blocks)")
6262
subtensor.wait_for_block(subtensor.block + 10)
6363
assert subtensor.start_call(alice_wallet, alice_subnet_netuid, True, True)[0]
6464

65-
# Initialize metagraph
65+
logging.console.info("Initialize metagraph")
6666
metagraph = subtensor.metagraph(netuid=alice_subnet_netuid)
6767

68-
# Assert metagraph has only Alice (owner)
68+
logging.console.info("Assert metagraph has only Alice (owner)")
6969
assert len(metagraph.uids) == 1, "Metagraph doesn't have exactly 1 neuron"
7070

71-
# Register Bob to the subnet
71+
logging.console.info("Register Bob to the subnet")
7272
assert subtensor.burned_register(bob_wallet, alice_subnet_netuid), (
7373
"Unable to register Bob as a neuron"
7474
)
7575

76-
# Refresh the metagraph
76+
logging.console.info("Refresh the metagraph")
7777
metagraph.sync(subtensor=subtensor)
7878

79-
# Assert metagraph has Alice and Bob neurons
79+
logging.console.info("Assert metagraph has Alice and Bob neurons")
8080
assert len(metagraph.uids) == 2, "Metagraph doesn't have exactly 2 neurons"
8181
assert metagraph.hotkeys[0] == alice_wallet.hotkey.ss58_address, (
8282
"Alice's hotkey doesn't match in metagraph"
@@ -89,36 +89,33 @@ def test_metagraph(subtensor, alice_wallet, bob_wallet, dave_wallet):
8989
assert metagraph.n.min() == 2, "Metagraph's min n is not 2"
9090
assert len(metagraph.addresses) == 2, "Metagraph doesn't have exactly 2 address"
9191

92-
# Fetch UID of Bob
92+
logging.console.info("Fetch UID of Bob")
9393
uid = subtensor.get_uid_for_hotkey_on_subnet(
9494
bob_wallet.hotkey.ss58_address, netuid=alice_subnet_netuid
9595
)
9696

97-
# Fetch neuron info of Bob through subtensor and metagraph
97+
logging.console.info("Fetch neuron info of Bob through subtensor and metagraph")
9898
neuron_info_bob = subtensor.neuron_for_uid(uid, netuid=alice_subnet_netuid)
99-
print(">>> neuron_info_bob", neuron_info_bob)
99+
100100
metagraph_dict = neuron_to_dict(metagraph.neurons[uid])
101101
subtensor_dict = neuron_to_dict(neuron_info_bob)
102102

103-
print(">>> metagraph_dict", metagraph_dict)
104-
print(">>> subtensor_dict", subtensor_dict)
105-
106-
# Verify neuron info is the same in both objects
103+
logging.console.info("Verify neuron info is the same in both objects")
107104
assert metagraph_dict == subtensor_dict, (
108105
"Neuron info of Bob doesn't match b/w metagraph & subtensor"
109106
)
110107

111-
# Create pre_dave metagraph for future verifications
108+
logging.console.info("Create pre_dave metagraph for future verifications")
112109
metagraph_pre_dave = subtensor.metagraph(netuid=alice_subnet_netuid)
113110

114-
# Register Dave as a neuron
111+
logging.console.info("Register Dave as a neuron")
115112
assert subtensor.burned_register(dave_wallet, alice_subnet_netuid), (
116113
"Unable to register Dave as a neuron"
117114
)
118115

119116
metagraph.sync(subtensor=subtensor)
120117

121-
# Assert metagraph now includes Dave's neuron
118+
logging.console.info("Assert metagraph now includes Dave's neuron")
122119
assert len(metagraph.uids) == 3, (
123120
"Metagraph doesn't have exactly 3 neurons post Dave"
124121
)
@@ -132,7 +129,7 @@ def test_metagraph(subtensor, alice_wallet, bob_wallet, dave_wallet):
132129
assert metagraph.n.min() == 3, "Metagraph's min n is not 3 post Dave"
133130
assert len(metagraph.addresses) == 3, "Metagraph doesn't have 3 addresses post Dave"
134131

135-
# Add stake by Bob
132+
logging.console.info("Add stake by Bob")
136133
tao = Balance.from_tao(10_000)
137134
alpha, _ = subtensor.subnet(alice_subnet_netuid).tao_to_alpha_with_slippage(tao)
138135
assert subtensor.add_stake(
@@ -143,13 +140,13 @@ def test_metagraph(subtensor, alice_wallet, bob_wallet, dave_wallet):
143140
wait_for_finalization=True,
144141
), "Failed to add stake for Bob"
145142

146-
# Assert stake is added after updating metagraph
143+
logging.console.info("Assert stake is added after updating metagraph")
147144
metagraph.sync(subtensor=subtensor)
148145
assert 0.95 < metagraph.neurons[1].stake.rao / alpha.rao < 1.05, (
149146
"Bob's stake not updated in metagraph"
150147
)
151148

152-
# Test the save() and load() mechanism
149+
logging.console.info("Test the save() and load() mechanism")
153150
# We save the metagraph and pre_dave loads it
154151
# We do this in the /tmp dir to avoid interfering or interacting with user data
155152
metagraph_save_root_dir = ["/", "tmp", "bittensor-e2e", "metagraphs"]
@@ -161,7 +158,7 @@ def test_metagraph(subtensor, alice_wallet, bob_wallet, dave_wallet):
161158
finally:
162159
shutil.rmtree(os.path.join(*metagraph_save_root_dir))
163160

164-
# Ensure data is synced between two metagraphs
161+
logging.console.info("Ensure data is synced between two metagraphs")
165162
assert len(metagraph.uids) == len(metagraph_pre_dave.uids), (
166163
"UID count mismatch after save and load"
167164
)

0 commit comments

Comments
 (0)