1
1
import asyncio
2
2
import logging
3
3
import sys
4
- import time
5
4
6
5
import pytest
7
6
17
16
setup_wallet ,
18
17
template_path ,
19
18
repo_name ,
19
+ wait_epoch ,
20
20
)
21
21
22
22
logging .basicConfig (level = logging .INFO )
44
44
@pytest .mark .asyncio
45
45
async def test_incentive (local_chain ):
46
46
# Register root as Alice - the subnet owner and validator
47
- alice_keypair , alice_exec_command , alice_wallet_path = setup_wallet ("//Alice" )
47
+ alice_keypair , alice_exec_command , alice_wallet = setup_wallet ("//Alice" )
48
48
alice_exec_command (RegisterSubnetworkCommand , ["s" , "create" ])
49
49
# Verify subnet 1 created successfully
50
50
assert local_chain .query ("SubtensorModule" , "NetworksAdded" , [1 ]).serialize ()
51
51
52
52
# Register Bob as miner
53
- bob_keypair , bob_exec_command , bob_wallet_path = setup_wallet ("//Bob" )
53
+ bob_keypair , bob_exec_command , bob_wallet = setup_wallet ("//Bob" )
54
54
55
55
# Register Alice as neuron to the subnet
56
56
alice_exec_command (
@@ -60,17 +60,6 @@ async def test_incentive(local_chain):
60
60
"register" ,
61
61
"--netuid" ,
62
62
"1" ,
63
- "--wallet.name" ,
64
- "default" ,
65
- "--wallet.hotkey" ,
66
- "default" ,
67
- "--wallet.path" ,
68
- alice_wallet_path ,
69
- "--subtensor.network" ,
70
- "local" ,
71
- "--subtensor.chain_endpoint" ,
72
- "ws://localhost:9945" ,
73
- "--no_prompt" ,
74
63
],
75
64
)
76
65
@@ -82,15 +71,6 @@ async def test_incentive(local_chain):
82
71
"register" ,
83
72
"--netuid" ,
84
73
"1" ,
85
- "--wallet.name" ,
86
- "default" ,
87
- "--wallet.hotkey" ,
88
- "default" ,
89
- "--subtensor.network" ,
90
- "local" ,
91
- "--subtensor.chain_endpoint" ,
92
- "ws://localhost:9945" ,
93
- "--no_prompt" ,
94
74
],
95
75
)
96
76
@@ -122,9 +102,9 @@ async def test_incentive(local_chain):
122
102
"--subtensor.chain_endpoint" ,
123
103
"ws://localhost:9945" ,
124
104
"--wallet.path" ,
125
- bob_wallet_path ,
105
+ bob_wallet . path ,
126
106
"--wallet.name" ,
127
- "default" ,
107
+ bob_wallet . name ,
128
108
"--wallet.hotkey" ,
129
109
"default" ,
130
110
"--logging.trace" ,
@@ -137,21 +117,6 @@ async def test_incentive(local_chain):
137
117
stderr = asyncio .subprocess .PIPE ,
138
118
)
139
119
140
- # Function to write output to the log file
141
- async def miner_write_output (stream ):
142
- log_file = "miner.log"
143
- with open (log_file , "a" ) as f :
144
- while True :
145
- line = await stream .readline ()
146
- if not line :
147
- break
148
- f .write (line .decode ())
149
- f .flush ()
150
-
151
- # Create tasks to read stdout and stderr concurrently
152
- asyncio .create_task (miner_write_output (miner_process .stdout ))
153
- asyncio .create_task (miner_write_output (miner_process .stderr ))
154
-
155
120
await asyncio .sleep (
156
121
5
157
122
) # wait for 5 seconds for the metagraph to refresh with latest data
@@ -169,9 +134,9 @@ async def miner_write_output(stream):
169
134
"--subtensor.chain_endpoint" ,
170
135
"ws://localhost:9945" ,
171
136
"--wallet.path" ,
172
- alice_wallet_path ,
137
+ alice_wallet . path ,
173
138
"--wallet.name" ,
174
- "default" ,
139
+ alice_wallet . name ,
175
140
"--wallet.hotkey" ,
176
141
"default" ,
177
142
"--logging.trace" ,
@@ -185,21 +150,6 @@ async def miner_write_output(stream):
185
150
stderr = asyncio .subprocess .PIPE ,
186
151
)
187
152
188
- # Function to write output to the log file
189
- async def validator_write_output (stream ):
190
- log_file = "validator.log"
191
- with open (log_file , "a" ) as f :
192
- while True :
193
- line = await stream .readline ()
194
- if not line :
195
- break
196
- f .write (line .decode ())
197
- f .flush ()
198
-
199
- # Create tasks to read stdout and stderr concurrently
200
- asyncio .create_task (validator_write_output (validator_process .stdout ))
201
- asyncio .create_task (validator_write_output (validator_process .stderr ))
202
-
203
153
await asyncio .sleep (
204
154
5
205
155
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
@@ -289,18 +239,3 @@ async def validator_write_output(stream):
289
239
assert alice_neuron .dividends == 1
290
240
assert alice_neuron .stake .tao == 10_000.0
291
241
assert alice_neuron .validator_trust == 1
292
-
293
-
294
- def wait_epoch (interval , subtensor ):
295
- current_block = subtensor .get_current_block ()
296
- next_tempo_block_start = (current_block - (current_block % interval )) + interval
297
- while current_block < next_tempo_block_start :
298
- time .sleep (1 ) # Wait for 1 second before checking the block number again
299
- current_block = subtensor .get_current_block ()
300
- if current_block % 10 == 0 :
301
- print (
302
- f"Current Block: { current_block } Next tempo at: { next_tempo_block_start } "
303
- )
304
- logging .info (
305
- f"Current Block: { current_block } Next tempo at: { next_tempo_block_start } "
306
- )
0 commit comments