1
- import logging
2
1
import time
3
2
4
3
from bittensor_cli .src .bittensor .balances import Balance
5
4
6
- from tests .e2e_tests .utils import setup_wallet
7
-
8
5
"""
9
6
Verify commands:
10
7
18
15
"""
19
16
20
17
21
- def test_root_commands (local_chain ):
18
+ def test_root_commands (local_chain , wallet_setup ):
22
19
"""
23
20
Test the root commands and inspects their output
24
21
@@ -33,16 +30,16 @@ def test_root_commands(local_chain):
33
30
Raises:
34
31
AssertionError: If any of the checks or verifications fail
35
32
"""
36
- logging . info ("Testing Root commands 🧪" )
33
+ print ("Testing Root commands 🧪" )
37
34
38
35
wallet_path_alice = "//Alice"
39
36
wallet_path_bob = "//Bob"
40
37
41
38
# Create wallet for Alice
42
- keypair_alice , wallet_alice , wallet_path_alice , exec_command_alice = setup_wallet (
39
+ keypair_alice , wallet_alice , wallet_path_alice , exec_command_alice = wallet_setup (
43
40
wallet_path_alice
44
41
)
45
- keypair_bob , wallet_bob , wallet_path_bob , exec_command_bob = setup_wallet (
42
+ keypair_bob , wallet_bob , wallet_path_bob , exec_command_bob = wallet_setup (
46
43
wallet_path_bob
47
44
)
48
45
@@ -80,16 +77,16 @@ def test_root_commands(local_chain):
80
77
81
78
# Capture root information and assert correct values
82
79
# First two rows are labels, entries start from the third row
83
- bob_root_info = check_root_list .stdout .splitlines ()[2 ].split ()
80
+ bob_root_info = check_root_list .stdout .splitlines ()[3 ].split ()
84
81
85
82
# UID: First uid is always 0
86
83
assert bob_root_info [0 ] == "0"
87
84
88
85
# ADDRESS: Assert correct hotkey is registered
89
- assert bob_root_info [1 ] == wallet_bob .hotkey .ss58_address
86
+ assert bob_root_info [3 ] == wallet_bob .hotkey .ss58_address
90
87
91
88
# SENATOR: Since there are senator slots empty, Bob is assigned senator status
92
- assert bob_root_info [3 ] == "Yes"
89
+ assert bob_root_info [7 ] == "Yes"
93
90
94
91
# List all root delegates in the network
95
92
check_delegates = exec_command_alice (
@@ -105,7 +102,7 @@ def test_root_commands(local_chain):
105
102
106
103
# Capture delegate information and assert correct values
107
104
# First row are labels, entries start from the second row
108
- bob_delegate_info = check_delegates .stdout .splitlines ()[1 ].split ()
105
+ bob_delegate_info = check_delegates .stdout .splitlines ()[3 ].split ()
109
106
110
107
# INDEX: First uid is always 0
111
108
assert bob_delegate_info [0 ] == "0"
@@ -166,7 +163,7 @@ def test_root_commands(local_chain):
166
163
],
167
164
)
168
165
# Capture delegate information after setting take
169
- bob_delegate_info = check_delegates .stdout .splitlines ()[1 ].split ()
166
+ bob_delegate_info = check_delegates .stdout .splitlines ()[3 ].split ()
170
167
171
168
# Take percentage: This should be 18% by default
172
169
take_percentage = float (bob_delegate_info [7 ].strip ("%" )) / 100
@@ -210,15 +207,13 @@ def test_root_commands(local_chain):
210
207
],
211
208
)
212
209
# First row are headers, records start from second row
213
- alice_delegates_info = alice_delegates .stdout .splitlines ()[1 ].split ()
210
+ alice_delegates_info = alice_delegates .stdout .splitlines ()[4 ].split ()
214
211
215
212
# WALLET: Wallet name of Alice
216
213
assert alice_delegates_info [0 ] == wallet_alice .name
217
214
218
215
# SS58: address of the Bob's hotkey (Alice has staked to Bob)
219
- assert wallet_bob .hotkey .ss58_address .startswith (
220
- alice_delegates_info [1 ].replace ("..." , "" )
221
- )
216
+ assert wallet_bob .hotkey .ss58_address == alice_delegates_info [1 ]
222
217
223
218
# Delegation: This should be 10 as Alice delegated 10 TAO to Bob
224
219
delegate_stake = Balance .from_tao (float (alice_delegates_info [2 ].strip ("τ" )))
@@ -231,7 +226,7 @@ def test_root_commands(local_chain):
231
226
# Total delegated Tao: This is listed at the bottom of the information
232
227
# Since Alice has only delegated to Bob, total should be 10 TAO
233
228
total_delegated_tao = Balance .from_tao (
234
- float (alice_delegates .stdout .splitlines ()[3 ].split ()[3 ].strip ("τ" ))
229
+ float (alice_delegates .stdout .splitlines ()[7 ].split ()[3 ].strip ("τ" ))
235
230
)
236
231
assert total_delegated_tao == Balance .from_tao (10 )
237
232
@@ -261,3 +256,5 @@ def test_root_commands(local_chain):
261
256
],
262
257
)
263
258
assert "✅ Finalized" in undelegate_alice .stdout
259
+
260
+ print ("✅ Passed Root commands" )
0 commit comments