Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wallet for tests #2130

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions tests/e2e_tests/multistep/test_axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@pytest.mark.asyncio
async def test_axon(local_chain):
# Register root as Alice
alice_keypair, exec_command, wallet_path = setup_wallet("//Alice")
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
exec_command(RegisterSubnetworkCommand, ["s", "create"])

# Verify subnet 1 created successfully
Expand All @@ -46,17 +46,6 @@ async def test_axon(local_chain):
"register",
"--netuid",
"1",
"--wallet.name",
"default",
"--wallet.hotkey",
"default",
"--wallet.path",
wallet_path,
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--no_prompt",
],
)

Expand Down Expand Up @@ -86,19 +75,20 @@ async def test_axon(local_chain):
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--wallet.path",
wallet_path,
wallet.path,
"--wallet.name",
"default",
wallet.name,
"--wallet.hotkey",
"default",
]
)

await asyncio.create_subprocess_shell(
axon_process = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)

await asyncio.sleep(
5
) # wait for 5 seconds for the metagraph to refresh with latest data
Expand Down
47 changes: 8 additions & 39 deletions tests/e2e_tests/multistep/test_dendrite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import logging
import sys
import time

import pytest

Expand All @@ -17,8 +16,10 @@
setup_wallet,
template_path,
repo_name,
wait_epoch,
)


logging.basicConfig(level=logging.INFO)

"""
Expand All @@ -35,7 +36,7 @@
@pytest.mark.asyncio
async def test_dendrite(local_chain):
# Register root as Alice - the subnet owner
alice_keypair, exec_command, wallet_path = setup_wallet("//Alice")
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
exec_command(RegisterSubnetworkCommand, ["s", "create"])

# Verify subnet 1 created successfully
Expand All @@ -51,15 +52,6 @@ async def test_dendrite(local_chain):
"register",
"--netuid",
"1",
"--wallet.name",
"default",
"--wallet.hotkey",
"default",
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--no_prompt",
],
)

Expand Down Expand Up @@ -111,20 +103,21 @@ async def test_dendrite(local_chain):
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--wallet.path",
wallet_path,
wallet.path,
"--wallet.name",
"default",
wallet.name,
"--wallet.hotkey",
"default",
]
)

# run validator in the background
await asyncio.create_subprocess_shell(
dendrite_process = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)

await asyncio.sleep(
5
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
Expand All @@ -137,12 +130,6 @@ async def test_dendrite(local_chain):
"register",
"--netuid",
"1",
"--wallet.name",
"default",
"--wallet.hotkey",
"default",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
],
)

Expand All @@ -155,28 +142,10 @@ async def test_dendrite(local_chain):
"1",
"--increase",
"1",
"--wallet.name",
"default",
"--wallet.hotkey",
"default",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
],
)
# get current block, wait until 360 blocks pass (subnet tempo)
interval = 360
current_block = subtensor.get_current_block()
next_tempo_block_start = (current_block - (current_block % interval)) + interval
while current_block < next_tempo_block_start:
time.sleep(1) # Wait for 1 second before checking the block number again
current_block = subtensor.get_current_block()
if current_block % 10 == 0:
print(
f"Current Block: {current_block} Next tempo at: {next_tempo_block_start}"
)
logging.info(
f"Current Block: {current_block} Next tempo at: {next_tempo_block_start}"
)
wait_epoch(360, subtensor)

# refresh metagraph
metagraph = bittensor.metagraph(netuid=1, network="ws://localhost:9945")
Expand Down
79 changes: 7 additions & 72 deletions tests/e2e_tests/multistep/test_incentive.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import logging
import sys
import time

import pytest

Expand All @@ -17,6 +16,7 @@
setup_wallet,
template_path,
repo_name,
wait_epoch,
)

logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -44,13 +44,13 @@
@pytest.mark.asyncio
async def test_incentive(local_chain):
# Register root as Alice - the subnet owner and validator
alice_keypair, alice_exec_command, alice_wallet_path = setup_wallet("//Alice")
alice_keypair, alice_exec_command, alice_wallet = setup_wallet("//Alice")
alice_exec_command(RegisterSubnetworkCommand, ["s", "create"])
# Verify subnet 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()

# Register Bob as miner
bob_keypair, bob_exec_command, bob_wallet_path = setup_wallet("//Bob")
bob_keypair, bob_exec_command, bob_wallet = setup_wallet("//Bob")

# Register Alice as neuron to the subnet
alice_exec_command(
Expand All @@ -60,17 +60,6 @@ async def test_incentive(local_chain):
"register",
"--netuid",
"1",
"--wallet.name",
"default",
"--wallet.hotkey",
"default",
"--wallet.path",
alice_wallet_path,
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--no_prompt",
],
)

Expand All @@ -82,15 +71,6 @@ async def test_incentive(local_chain):
"register",
"--netuid",
"1",
"--wallet.name",
"default",
"--wallet.hotkey",
"default",
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--no_prompt",
],
)

Expand Down Expand Up @@ -122,9 +102,9 @@ async def test_incentive(local_chain):
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--wallet.path",
bob_wallet_path,
bob_wallet.path,
"--wallet.name",
"default",
bob_wallet.name,
"--wallet.hotkey",
"default",
"--logging.trace",
Expand All @@ -137,21 +117,6 @@ async def test_incentive(local_chain):
stderr=asyncio.subprocess.PIPE,
)

# Function to write output to the log file
async def miner_write_output(stream):
log_file = "miner.log"
with open(log_file, "a") as f:
while True:
line = await stream.readline()
if not line:
break
f.write(line.decode())
f.flush()

# Create tasks to read stdout and stderr concurrently
asyncio.create_task(miner_write_output(miner_process.stdout))
asyncio.create_task(miner_write_output(miner_process.stderr))

await asyncio.sleep(
5
) # wait for 5 seconds for the metagraph to refresh with latest data
Expand All @@ -169,9 +134,9 @@ async def miner_write_output(stream):
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--wallet.path",
alice_wallet_path,
alice_wallet.path,
"--wallet.name",
"default",
alice_wallet.name,
"--wallet.hotkey",
"default",
"--logging.trace",
Expand All @@ -185,21 +150,6 @@ async def miner_write_output(stream):
stderr=asyncio.subprocess.PIPE,
)

# Function to write output to the log file
async def validator_write_output(stream):
log_file = "validator.log"
with open(log_file, "a") as f:
while True:
line = await stream.readline()
if not line:
break
f.write(line.decode())
f.flush()

# Create tasks to read stdout and stderr concurrently
asyncio.create_task(validator_write_output(validator_process.stdout))
asyncio.create_task(validator_write_output(validator_process.stderr))

await asyncio.sleep(
5
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
Expand Down Expand Up @@ -289,18 +239,3 @@ async def validator_write_output(stream):
assert alice_neuron.dividends == 1
assert alice_neuron.stake.tao == 10_000.0
assert alice_neuron.validator_trust == 1


def wait_epoch(interval, subtensor):
current_block = subtensor.get_current_block()
next_tempo_block_start = (current_block - (current_block % interval)) + interval
while current_block < next_tempo_block_start:
time.sleep(1) # Wait for 1 second before checking the block number again
current_block = subtensor.get_current_block()
if current_block % 10 == 0:
print(
f"Current Block: {current_block} Next tempo at: {next_tempo_block_start}"
)
logging.info(
f"Current Block: {current_block} Next tempo at: {next_tempo_block_start}"
)
4 changes: 2 additions & 2 deletions tests/e2e_tests/multistep/test_last_tx_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# https://discord.com/channels/799672011265015819/1176889736636407808/1236057424134144152
def test_takes(local_chain):
# Register root as Alice
keypair, exec_command, wallet_path = setup_wallet("//Alice")
keypair, exec_command, wallet = setup_wallet("//Alice")
exec_command(RootRegisterCommand, ["root", "register"])

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

# Register and nominate Bob
keypair, exec_command, wallet_path = setup_wallet("//Bob")
keypair, exec_command, wallet = setup_wallet("//Bob")
assert (
local_chain.query(
"SubtensorModule", "LastTxBlock", [keypair.ss58_address]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def test_set_delegate_increase_take(local_chain):
# Register root as Alice
keypair, exec_command, wallet_path = setup_wallet("//Alice")
keypair, exec_command, wallet = setup_wallet("//Alice")
exec_command(RootRegisterCommand, ["root", "register"])

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

# Register and nominate Bob
keypair, exec_command, wallet_path = setup_wallet("//Bob")
keypair, exec_command, wallet = setup_wallet("//Bob")
assert (
local_chain.query(
"SubtensorModule", "LastTxBlock", [keypair.ss58_address]
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_tests/subcommands/wallet/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Example test using the local_chain fixture
def test_transfer(local_chain):
keypair, exec_command, wallet_path = setup_wallet("//Alice")
keypair, exec_command, wallet = setup_wallet("//Alice")

acc_before = local_chain.query("System", "Account", [keypair.ss58_address])
exec_command(
Expand Down
8 changes: 1 addition & 7 deletions tests/e2e_tests/subcommands/weights/test_commit_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

def test_commit_and_reveal_weights(local_chain):
# Register root as Alice
keypair, exec_command, wallet_path = setup_wallet("//Alice")
keypair, exec_command, wallet = setup_wallet("//Alice")

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

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

# Create a test wallet and set the coldkey, coldkeypub, and hotkey
wallet = bittensor.wallet(path="/tmp/btcli-wallet")
wallet.set_coldkey(keypair=keypair, encrypt=False, overwrite=True)
wallet.set_coldkeypub(keypair=keypair, encrypt=False, overwrite=True)
wallet.set_hotkey(keypair=keypair, encrypt=False, overwrite=True)

# Stake to become to top neuron after the first epoch
exec_command(
StakeCommand,
Expand Down
Loading