From 6f69f4a878f9f0e6657273f21c8a998cae12171e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBy=C5=BAniewski?= Date: Tue, 11 Feb 2025 18:57:32 +0100 Subject: [PATCH 1/4] tests: separate templates fixture --- tests/e2e_tests/conftest.py | 20 ++++++++++++-------- tests/e2e_tests/test_axon.py | 8 ++------ tests/e2e_tests/test_dendrite.py | 8 ++------ tests/e2e_tests/test_incentive.py | 10 +++------- tests/e2e_tests/test_root_set_weights.py | 8 ++------ tests/e2e_tests/test_subtensor_functions.py | 8 ++------ tests/e2e_tests/utils/e2e_test_utils.py | 2 +- 7 files changed, 24 insertions(+), 40 deletions(-) diff --git a/tests/e2e_tests/conftest.py b/tests/e2e_tests/conftest.py index 1590e5d6e5..40bbfd8ba2 100644 --- a/tests/e2e_tests/conftest.py +++ b/tests/e2e_tests/conftest.py @@ -49,13 +49,6 @@ def local_chain(request): # Pattern match indicates node is compiled and ready pattern = re.compile(r"Imported #1") - - # install neuron templates - logging.info("downloading and installing neuron templates from github") - # commit with subnet-template-repo changes for rust wallet - templates_dir = clone_or_update_templates() - install_templates(templates_dir) - timestamp = int(time.time()) def wait_for_node_start(process, pattern): @@ -102,8 +95,19 @@ def read_output(): # Ensure the process has terminated process.wait() - # uninstall templates + +@pytest.fixture +def templates(): + logging.info("downloading and installing neuron templates from github") + + templates_dir = clone_or_update_templates() + + install_templates(templates_dir) + + yield templates_dir + logging.info("uninstalling neuron templates") + uninstall_templates(template_path) diff --git a/tests/e2e_tests/test_axon.py b/tests/e2e_tests/test_axon.py index f89d29ff0d..f2a9e2e74d 100644 --- a/tests/e2e_tests/test_axon.py +++ b/tests/e2e_tests/test_axon.py @@ -4,14 +4,10 @@ import pytest from bittensor.utils import networking -from tests.e2e_tests.utils.e2e_test_utils import ( - template_path, - templates_repo, -) @pytest.mark.asyncio -async def test_axon(subtensor, alice_wallet): +async def test_axon(subtensor, templates, alice_wallet): """ Test the Axon mechanism and successful registration on the network. @@ -53,7 +49,7 @@ async def test_axon(subtensor, alice_wallet): cmd = " ".join( [ f"{sys.executable}", - f'"{template_path}{templates_repo}/miner.py"', + f'"{templates}/miner.py"', "--netuid", str(netuid), "--subtensor.network", diff --git a/tests/e2e_tests/test_dendrite.py b/tests/e2e_tests/test_dendrite.py index 070ffdf3ee..b887c3999e 100644 --- a/tests/e2e_tests/test_dendrite.py +++ b/tests/e2e_tests/test_dendrite.py @@ -10,14 +10,10 @@ sudo_set_hyperparameter_values, wait_epoch, ) -from tests.e2e_tests.utils.e2e_test_utils import ( - template_path, - templates_repo, -) @pytest.mark.asyncio -async def test_dendrite(local_chain, subtensor, alice_wallet, bob_wallet): +async def test_dendrite(local_chain, subtensor, templates, alice_wallet, bob_wallet): """ Test the Dendrite mechanism @@ -112,7 +108,7 @@ async def test_dendrite(local_chain, subtensor, alice_wallet, bob_wallet): cmd = " ".join( [ f"{sys.executable}", - f'"{template_path}{templates_repo}/validator.py"', + f'"{templates}/validator.py"', "--netuid", str(netuid), "--subtensor.network", diff --git a/tests/e2e_tests/test_incentive.py b/tests/e2e_tests/test_incentive.py index 6f73799c31..d326f431d7 100644 --- a/tests/e2e_tests/test_incentive.py +++ b/tests/e2e_tests/test_incentive.py @@ -7,14 +7,10 @@ sudo_set_hyperparameter_values, wait_epoch, ) -from tests.e2e_tests.utils.e2e_test_utils import ( - template_path, - templates_repo, -) @pytest.mark.asyncio -async def test_incentive(local_chain, subtensor, alice_wallet, bob_wallet): +async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wallet): """ Test the incentive mechanism and interaction of miners/validators @@ -75,7 +71,7 @@ async def test_incentive(local_chain, subtensor, alice_wallet, bob_wallet): cmd = " ".join( [ f"{sys.executable}", - f'"{template_path}{templates_repo}/miner.py"', + f'"{templates}/miner.py"', "--netuid", str(netuid), "--subtensor.network", @@ -104,7 +100,7 @@ async def test_incentive(local_chain, subtensor, alice_wallet, bob_wallet): cmd = " ".join( [ f"{sys.executable}", - f'"{template_path}{templates_repo}/validator.py"', + f'"{templates}/validator.py"', "--netuid", str(netuid), "--subtensor.network", diff --git a/tests/e2e_tests/test_root_set_weights.py b/tests/e2e_tests/test_root_set_weights.py index a6fd9a160b..1c57e1c2fe 100644 --- a/tests/e2e_tests/test_root_set_weights.py +++ b/tests/e2e_tests/test_root_set_weights.py @@ -6,10 +6,6 @@ wait_epoch, sudo_set_hyperparameter_values, ) -from tests.e2e_tests.utils.e2e_test_utils import ( - template_path, - templates_repo, -) FAST_BLOCKS_SPEEDUP_FACTOR = 5 @@ -34,7 +30,7 @@ @pytest.mark.asyncio -async def test_root_reg_hyperparams(local_chain, subtensor, alice_wallet, bob_wallet): +async def test_root_reg_hyperparams(local_chain, subtensor, templates, alice_wallet, bob_wallet): """ Test root weights and hyperparameters in the Subtensor network. @@ -86,7 +82,7 @@ async def test_root_reg_hyperparams(local_chain, subtensor, alice_wallet, bob_wa cmd = " ".join( [ f"{sys.executable}", - f'"{template_path}{templates_repo}/validator.py"', + f'"{templates}/validator.py"', "--netuid", str(netuid), "--subtensor.network", diff --git a/tests/e2e_tests/test_subtensor_functions.py b/tests/e2e_tests/test_subtensor_functions.py index 831df35dcc..e2d46c58b3 100644 --- a/tests/e2e_tests/test_subtensor_functions.py +++ b/tests/e2e_tests/test_subtensor_functions.py @@ -8,10 +8,6 @@ sudo_set_admin_utils, wait_epoch, ) -from tests.e2e_tests.utils.e2e_test_utils import ( - template_path, - templates_repo, -) """ Verifies: @@ -35,7 +31,7 @@ @pytest.mark.asyncio -async def test_subtensor_extrinsics(subtensor, alice_wallet, bob_wallet): +async def test_subtensor_extrinsics(subtensor, templates, alice_wallet, bob_wallet): """ Tests subtensor extrinsics @@ -163,7 +159,7 @@ async def test_subtensor_extrinsics(subtensor, alice_wallet, bob_wallet): cmd = " ".join( [ f"{sys.executable}", - f'"{template_path}{templates_repo}/validator.py"', + f'"{templates}/validator.py"', "--netuid", str(netuid), "--subtensor.network", diff --git a/tests/e2e_tests/utils/e2e_test_utils.py b/tests/e2e_tests/utils/e2e_test_utils.py index ebf6a6a1e2..513f6fee74 100644 --- a/tests/e2e_tests/utils/e2e_test_utils.py +++ b/tests/e2e_tests/utils/e2e_test_utils.py @@ -73,7 +73,7 @@ def clone_or_update_templates(specific_commit=None): os.chdir(cwd) - return install_dir + templates_repo + "/" + return install_dir + templates_repo def install_templates(install_dir): From bd0f540bc7ff417733460b74fc5caca0a87c9a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBy=C5=BAniewski?= Date: Tue, 11 Feb 2025 19:03:58 +0100 Subject: [PATCH 2/4] style: ruff formating --- tests/e2e_tests/test_root_set_weights.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/e2e_tests/test_root_set_weights.py b/tests/e2e_tests/test_root_set_weights.py index 1c57e1c2fe..fe87520493 100644 --- a/tests/e2e_tests/test_root_set_weights.py +++ b/tests/e2e_tests/test_root_set_weights.py @@ -30,7 +30,13 @@ @pytest.mark.asyncio -async def test_root_reg_hyperparams(local_chain, subtensor, templates, alice_wallet, bob_wallet): +async def test_root_reg_hyperparams( + local_chain, + subtensor, + templates, + alice_wallet, + bob_wallet, +): """ Test root weights and hyperparameters in the Subtensor network. From 90433a0ea69364e8f60ea940ead55b555237d65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBy=C5=BAniewski?= Date: Tue, 11 Feb 2025 20:06:18 +0100 Subject: [PATCH 3/4] tests: use 9944 as a default port --- tests/e2e_tests/conftest.py | 4 ++-- tests/e2e_tests/test_axon.py | 2 +- tests/e2e_tests/test_dendrite.py | 2 +- tests/e2e_tests/test_incentive.py | 4 ++-- tests/e2e_tests/test_root_set_weights.py | 2 +- tests/e2e_tests/test_subtensor_functions.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/e2e_tests/conftest.py b/tests/e2e_tests/conftest.py index 40bbfd8ba2..7d72315b90 100644 --- a/tests/e2e_tests/conftest.py +++ b/tests/e2e_tests/conftest.py @@ -80,7 +80,7 @@ def read_output(): wait_for_node_start(process, pattern) # Run the test, passing in substrate interface - yield SubstrateInterface(url="ws://127.0.0.1:9945") + yield SubstrateInterface(url="ws://127.0.0.1:9944") # Terminate the process group (includes all child processes) os.killpg(os.getpgid(process.pid), signal.SIGTERM) @@ -113,7 +113,7 @@ def templates(): @pytest.fixture def subtensor(local_chain): - return Subtensor(network="ws://localhost:9945") + return Subtensor(network="ws://localhost:9944") @pytest.fixture diff --git a/tests/e2e_tests/test_axon.py b/tests/e2e_tests/test_axon.py index f2a9e2e74d..0d3825b465 100644 --- a/tests/e2e_tests/test_axon.py +++ b/tests/e2e_tests/test_axon.py @@ -55,7 +55,7 @@ async def test_axon(subtensor, templates, alice_wallet): "--subtensor.network", "local", "--subtensor.chain_endpoint", - "ws://localhost:9945", + "ws://localhost:9944", "--wallet.path", alice_wallet.path, "--wallet.name", diff --git a/tests/e2e_tests/test_dendrite.py b/tests/e2e_tests/test_dendrite.py index b887c3999e..c4ebcef35b 100644 --- a/tests/e2e_tests/test_dendrite.py +++ b/tests/e2e_tests/test_dendrite.py @@ -114,7 +114,7 @@ async def test_dendrite(local_chain, subtensor, templates, alice_wallet, bob_wal "--subtensor.network", "local", "--subtensor.chain_endpoint", - "ws://localhost:9945", + "ws://localhost:9944", "--wallet.path", bob_wallet.path, "--wallet.name", diff --git a/tests/e2e_tests/test_incentive.py b/tests/e2e_tests/test_incentive.py index d326f431d7..ae445914d7 100644 --- a/tests/e2e_tests/test_incentive.py +++ b/tests/e2e_tests/test_incentive.py @@ -77,7 +77,7 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa "--subtensor.network", "local", "--subtensor.chain_endpoint", - "ws://localhost:9945", + "ws://localhost:9944", "--wallet.path", bob_wallet.path, "--wallet.name", @@ -106,7 +106,7 @@ async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wa "--subtensor.network", "local", "--subtensor.chain_endpoint", - "ws://localhost:9945", + "ws://localhost:9944", "--wallet.path", alice_wallet.path, "--wallet.name", diff --git a/tests/e2e_tests/test_root_set_weights.py b/tests/e2e_tests/test_root_set_weights.py index fe87520493..83b3284e37 100644 --- a/tests/e2e_tests/test_root_set_weights.py +++ b/tests/e2e_tests/test_root_set_weights.py @@ -94,7 +94,7 @@ async def test_root_reg_hyperparams( "--subtensor.network", "local", "--subtensor.chain_endpoint", - "ws://localhost:9945", + "ws://localhost:9944", "--wallet.path", alice_wallet.path, "--wallet.name", diff --git a/tests/e2e_tests/test_subtensor_functions.py b/tests/e2e_tests/test_subtensor_functions.py index e2d46c58b3..590842c900 100644 --- a/tests/e2e_tests/test_subtensor_functions.py +++ b/tests/e2e_tests/test_subtensor_functions.py @@ -165,7 +165,7 @@ async def test_subtensor_extrinsics(subtensor, templates, alice_wallet, bob_wall "--subtensor.network", "local", "--subtensor.chain_endpoint", - "ws://localhost:9945", + "ws://localhost:9944", "--wallet.path", alice_wallet.path, "--wallet.name", From 3d632d1d6e9f90d571585275bdb3fc6a7eb4b46a Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 11 Feb 2025 12:50:38 -0800 Subject: [PATCH 4/4] improve `install_templates` logic --- tests/e2e_tests/utils/e2e_test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e_tests/utils/e2e_test_utils.py b/tests/e2e_tests/utils/e2e_test_utils.py index 513f6fee74..8d187d967f 100644 --- a/tests/e2e_tests/utils/e2e_test_utils.py +++ b/tests/e2e_tests/utils/e2e_test_utils.py @@ -77,7 +77,7 @@ def clone_or_update_templates(specific_commit=None): def install_templates(install_dir): - subprocess.check_call([sys.executable, "-m", "pip", "install", "."]) + subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", "."]) def uninstall_templates(install_dir):