diff --git a/tests/e2e_tests/multistep/test_axon.py b/tests/e2e_tests/multistep/test_axon.py index f23fb4da7b..35514a680a 100644 --- a/tests/e2e_tests/multistep/test_axon.py +++ b/tests/e2e_tests/multistep/test_axon.py @@ -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 @@ -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", ], ) @@ -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 diff --git a/tests/e2e_tests/multistep/test_dendrite.py b/tests/e2e_tests/multistep/test_dendrite.py index 6abde7464d..deb37eb133 100644 --- a/tests/e2e_tests/multistep/test_dendrite.py +++ b/tests/e2e_tests/multistep/test_dendrite.py @@ -1,7 +1,6 @@ import asyncio import logging import sys -import time import pytest @@ -17,8 +16,10 @@ setup_wallet, template_path, repo_name, + wait_epoch, ) + logging.basicConfig(level=logging.INFO) """ @@ -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 @@ -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", ], ) @@ -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 @@ -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", ], ) @@ -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") diff --git a/tests/e2e_tests/multistep/test_incentive.py b/tests/e2e_tests/multistep/test_incentive.py index ea5809dd7f..d1b4634653 100644 --- a/tests/e2e_tests/multistep/test_incentive.py +++ b/tests/e2e_tests/multistep/test_incentive.py @@ -1,7 +1,6 @@ import asyncio import logging import sys -import time import pytest @@ -17,6 +16,7 @@ setup_wallet, template_path, repo_name, + wait_epoch, ) logging.basicConfig(level=logging.INFO) @@ -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( @@ -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", ], ) @@ -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", ], ) @@ -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", @@ -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 @@ -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", @@ -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 @@ -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}" - ) diff --git a/tests/e2e_tests/multistep/test_last_tx_block.py b/tests/e2e_tests/multistep/test_last_tx_block.py index b97d54f8fa..5bc4759212 100644 --- a/tests/e2e_tests/multistep/test_last_tx_block.py +++ b/tests/e2e_tests/multistep/test_last_tx_block.py @@ -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 @@ -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] diff --git a/tests/e2e_tests/subcommands/delegation/test_set_delegate_take.py b/tests/e2e_tests/subcommands/delegation/test_set_delegate_take.py index cc7b1b5744..cefb150f70 100644 --- a/tests/e2e_tests/subcommands/delegation/test_set_delegate_take.py +++ b/tests/e2e_tests/subcommands/delegation/test_set_delegate_take.py @@ -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 @@ -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] diff --git a/tests/e2e_tests/subcommands/wallet/test_transfer.py b/tests/e2e_tests/subcommands/wallet/test_transfer.py index 5b491b3f0d..5b22b4e778 100644 --- a/tests/e2e_tests/subcommands/wallet/test_transfer.py +++ b/tests/e2e_tests/subcommands/wallet/test_transfer.py @@ -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( diff --git a/tests/e2e_tests/subcommands/weights/test_commit_weights.py b/tests/e2e_tests/subcommands/weights/test_commit_weights.py index 4c719b0ebd..f04f4f7ab3 100644 --- a/tests/e2e_tests/subcommands/weights/test_commit_weights.py +++ b/tests/e2e_tests/subcommands/weights/test_commit_weights.py @@ -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"]) @@ -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, diff --git a/tests/e2e_tests/utils.py b/tests/e2e_tests/utils.py index 4b485e3bd9..ce7b0bc092 100644 --- a/tests/e2e_tests/utils.py +++ b/tests/e2e_tests/utils.py @@ -1,13 +1,13 @@ +import logging import os import shutil import subprocess import sys - +import time from typing import List -from bittensor import Keypair - import bittensor +from bittensor import Keypair template_path = os.getcwd() + "/neurons/" repo_name = "templates repository" @@ -39,7 +39,7 @@ def exec_command(command, extra_args: List[str]): cli_instance = bittensor.cli(config) command.run(cli_instance) - return keypair, exec_command, wallet_path + return keypair, exec_command, wallet def clone_or_update_templates(): @@ -74,3 +74,18 @@ def uninstall_templates(install_dir): ) # delete everything in directory shutil.rmtree(install_dir) + + +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}" + )