Skip to content

Commit b369eb2

Browse files
Merge pull request #2130 from opentensor/fix/wallet-for-release-7.3.0
Fix wallet for tests
2 parents 1828433 + 23397db commit b369eb2

File tree

8 files changed

+45
-142
lines changed

8 files changed

+45
-142
lines changed

tests/e2e_tests/multistep/test_axon.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@pytest.mark.asyncio
3333
async def test_axon(local_chain):
3434
# Register root as Alice
35-
alice_keypair, exec_command, wallet_path = setup_wallet("//Alice")
35+
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
3636
exec_command(RegisterSubnetworkCommand, ["s", "create"])
3737

3838
# Verify subnet 1 created successfully
@@ -46,17 +46,6 @@ async def test_axon(local_chain):
4646
"register",
4747
"--netuid",
4848
"1",
49-
"--wallet.name",
50-
"default",
51-
"--wallet.hotkey",
52-
"default",
53-
"--wallet.path",
54-
wallet_path,
55-
"--subtensor.network",
56-
"local",
57-
"--subtensor.chain_endpoint",
58-
"ws://localhost:9945",
59-
"--no_prompt",
6049
],
6150
)
6251

@@ -86,19 +75,20 @@ async def test_axon(local_chain):
8675
"--subtensor.chain_endpoint",
8776
"ws://localhost:9945",
8877
"--wallet.path",
89-
wallet_path,
78+
wallet.path,
9079
"--wallet.name",
91-
"default",
80+
wallet.name,
9281
"--wallet.hotkey",
9382
"default",
9483
]
9584
)
9685

97-
await asyncio.create_subprocess_shell(
86+
axon_process = await asyncio.create_subprocess_shell(
9887
cmd,
9988
stdout=asyncio.subprocess.PIPE,
10089
stderr=asyncio.subprocess.PIPE,
10190
)
91+
10292
await asyncio.sleep(
10393
5
10494
) # wait for 5 seconds for the metagraph to refresh with latest data

tests/e2e_tests/multistep/test_dendrite.py

+8-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import logging
33
import sys
4-
import time
54

65
import pytest
76

@@ -17,8 +16,10 @@
1716
setup_wallet,
1817
template_path,
1918
repo_name,
19+
wait_epoch,
2020
)
2121

22+
2223
logging.basicConfig(level=logging.INFO)
2324

2425
"""
@@ -35,7 +36,7 @@
3536
@pytest.mark.asyncio
3637
async def test_dendrite(local_chain):
3738
# Register root as Alice - the subnet owner
38-
alice_keypair, exec_command, wallet_path = setup_wallet("//Alice")
39+
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
3940
exec_command(RegisterSubnetworkCommand, ["s", "create"])
4041

4142
# Verify subnet 1 created successfully
@@ -51,15 +52,6 @@ async def test_dendrite(local_chain):
5152
"register",
5253
"--netuid",
5354
"1",
54-
"--wallet.name",
55-
"default",
56-
"--wallet.hotkey",
57-
"default",
58-
"--subtensor.network",
59-
"local",
60-
"--subtensor.chain_endpoint",
61-
"ws://localhost:9945",
62-
"--no_prompt",
6355
],
6456
)
6557

@@ -111,20 +103,21 @@ async def test_dendrite(local_chain):
111103
"--subtensor.chain_endpoint",
112104
"ws://localhost:9945",
113105
"--wallet.path",
114-
wallet_path,
106+
wallet.path,
115107
"--wallet.name",
116-
"default",
108+
wallet.name,
117109
"--wallet.hotkey",
118110
"default",
119111
]
120112
)
121113

122114
# run validator in the background
123-
await asyncio.create_subprocess_shell(
115+
dendrite_process = await asyncio.create_subprocess_shell(
124116
cmd,
125117
stdout=asyncio.subprocess.PIPE,
126118
stderr=asyncio.subprocess.PIPE,
127119
)
120+
128121
await asyncio.sleep(
129122
5
130123
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
@@ -137,12 +130,6 @@ async def test_dendrite(local_chain):
137130
"register",
138131
"--netuid",
139132
"1",
140-
"--wallet.name",
141-
"default",
142-
"--wallet.hotkey",
143-
"default",
144-
"--subtensor.chain_endpoint",
145-
"ws://localhost:9945",
146133
],
147134
)
148135

@@ -155,28 +142,10 @@ async def test_dendrite(local_chain):
155142
"1",
156143
"--increase",
157144
"1",
158-
"--wallet.name",
159-
"default",
160-
"--wallet.hotkey",
161-
"default",
162-
"--subtensor.chain_endpoint",
163-
"ws://localhost:9945",
164145
],
165146
)
166147
# get current block, wait until 360 blocks pass (subnet tempo)
167-
interval = 360
168-
current_block = subtensor.get_current_block()
169-
next_tempo_block_start = (current_block - (current_block % interval)) + interval
170-
while current_block < next_tempo_block_start:
171-
time.sleep(1) # Wait for 1 second before checking the block number again
172-
current_block = subtensor.get_current_block()
173-
if current_block % 10 == 0:
174-
print(
175-
f"Current Block: {current_block} Next tempo at: {next_tempo_block_start}"
176-
)
177-
logging.info(
178-
f"Current Block: {current_block} Next tempo at: {next_tempo_block_start}"
179-
)
148+
wait_epoch(360, subtensor)
180149

181150
# refresh metagraph
182151
metagraph = bittensor.metagraph(netuid=1, network="ws://localhost:9945")

tests/e2e_tests/multistep/test_incentive.py

+7-72
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import logging
33
import sys
4-
import time
54

65
import pytest
76

@@ -17,6 +16,7 @@
1716
setup_wallet,
1817
template_path,
1918
repo_name,
19+
wait_epoch,
2020
)
2121

2222
logging.basicConfig(level=logging.INFO)
@@ -44,13 +44,13 @@
4444
@pytest.mark.asyncio
4545
async def test_incentive(local_chain):
4646
# 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")
4848
alice_exec_command(RegisterSubnetworkCommand, ["s", "create"])
4949
# Verify subnet 1 created successfully
5050
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
5151

5252
# 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")
5454

5555
# Register Alice as neuron to the subnet
5656
alice_exec_command(
@@ -60,17 +60,6 @@ async def test_incentive(local_chain):
6060
"register",
6161
"--netuid",
6262
"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",
7463
],
7564
)
7665

@@ -82,15 +71,6 @@ async def test_incentive(local_chain):
8271
"register",
8372
"--netuid",
8473
"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",
9474
],
9575
)
9676

@@ -122,9 +102,9 @@ async def test_incentive(local_chain):
122102
"--subtensor.chain_endpoint",
123103
"ws://localhost:9945",
124104
"--wallet.path",
125-
bob_wallet_path,
105+
bob_wallet.path,
126106
"--wallet.name",
127-
"default",
107+
bob_wallet.name,
128108
"--wallet.hotkey",
129109
"default",
130110
"--logging.trace",
@@ -137,21 +117,6 @@ async def test_incentive(local_chain):
137117
stderr=asyncio.subprocess.PIPE,
138118
)
139119

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-
155120
await asyncio.sleep(
156121
5
157122
) # wait for 5 seconds for the metagraph to refresh with latest data
@@ -169,9 +134,9 @@ async def miner_write_output(stream):
169134
"--subtensor.chain_endpoint",
170135
"ws://localhost:9945",
171136
"--wallet.path",
172-
alice_wallet_path,
137+
alice_wallet.path,
173138
"--wallet.name",
174-
"default",
139+
alice_wallet.name,
175140
"--wallet.hotkey",
176141
"default",
177142
"--logging.trace",
@@ -185,21 +150,6 @@ async def miner_write_output(stream):
185150
stderr=asyncio.subprocess.PIPE,
186151
)
187152

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-
203153
await asyncio.sleep(
204154
5
205155
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
@@ -289,18 +239,3 @@ async def validator_write_output(stream):
289239
assert alice_neuron.dividends == 1
290240
assert alice_neuron.stake.tao == 10_000.0
291241
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-
)

tests/e2e_tests/multistep/test_last_tx_block.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# https://discord.com/channels/799672011265015819/1176889736636407808/1236057424134144152
1010
def test_takes(local_chain):
1111
# Register root as Alice
12-
keypair, exec_command, wallet_path = setup_wallet("//Alice")
12+
keypair, exec_command, wallet = setup_wallet("//Alice")
1313
exec_command(RootRegisterCommand, ["root", "register"])
1414

1515
# Create subnet 1 and verify created successfully
@@ -21,7 +21,7 @@ def test_takes(local_chain):
2121
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
2222

2323
# Register and nominate Bob
24-
keypair, exec_command, wallet_path = setup_wallet("//Bob")
24+
keypair, exec_command, wallet = setup_wallet("//Bob")
2525
assert (
2626
local_chain.query(
2727
"SubtensorModule", "LastTxBlock", [keypair.ss58_address]

tests/e2e_tests/subcommands/delegation/test_set_delegate_take.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def test_set_delegate_increase_take(local_chain):
1010
# Register root as Alice
11-
keypair, exec_command, wallet_path = setup_wallet("//Alice")
11+
keypair, exec_command, wallet = setup_wallet("//Alice")
1212
exec_command(RootRegisterCommand, ["root", "register"])
1313

1414
# Create subnet 1 and verify created successfully
@@ -20,7 +20,7 @@ def test_set_delegate_increase_take(local_chain):
2020
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
2121

2222
# Register and nominate Bob
23-
keypair, exec_command, wallet_path = setup_wallet("//Bob")
23+
keypair, exec_command, wallet = setup_wallet("//Bob")
2424
assert (
2525
local_chain.query(
2626
"SubtensorModule", "LastTxBlock", [keypair.ss58_address]

tests/e2e_tests/subcommands/wallet/test_transfer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Example test using the local_chain fixture
77
def test_transfer(local_chain):
8-
keypair, exec_command, wallet_path = setup_wallet("//Alice")
8+
keypair, exec_command, wallet = setup_wallet("//Alice")
99

1010
acc_before = local_chain.query("System", "Account", [keypair.ss58_address])
1111
exec_command(

tests/e2e_tests/subcommands/weights/test_commit_weights.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
def test_commit_and_reveal_weights(local_chain):
3232
# Register root as Alice
33-
keypair, exec_command, wallet_path = setup_wallet("//Alice")
33+
keypair, exec_command, wallet = setup_wallet("//Alice")
3434

3535
exec_command(RegisterSubnetworkCommand, ["s", "create"])
3636

@@ -48,12 +48,6 @@ def test_commit_and_reveal_weights(local_chain):
4848
["s", "register", "--netuid", "1", "--wallet.path", "/tmp/btcli-wallet"],
4949
)
5050

51-
# Create a test wallet and set the coldkey, coldkeypub, and hotkey
52-
wallet = bittensor.wallet(path="/tmp/btcli-wallet")
53-
wallet.set_coldkey(keypair=keypair, encrypt=False, overwrite=True)
54-
wallet.set_coldkeypub(keypair=keypair, encrypt=False, overwrite=True)
55-
wallet.set_hotkey(keypair=keypair, encrypt=False, overwrite=True)
56-
5751
# Stake to become to top neuron after the first epoch
5852
exec_command(
5953
StakeCommand,

0 commit comments

Comments
 (0)