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

Tests: separate templates fixture #2660

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
24 changes: 14 additions & 10 deletions tests/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -87,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)
Expand All @@ -102,14 +95,25 @@ 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)


@pytest.fixture
def subtensor(local_chain):
return Subtensor(network="ws://localhost:9945")
return Subtensor(network="ws://localhost:9944")


@pytest.fixture
Expand Down
10 changes: 3 additions & 7 deletions tests/e2e_tests/test_axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -53,13 +49,13 @@ 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",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"ws://localhost:9944",
"--wallet.path",
alice_wallet.path,
"--wallet.name",
Expand Down
10 changes: 3 additions & 7 deletions tests/e2e_tests/test_dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -112,13 +108,13 @@ 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",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"ws://localhost:9944",
"--wallet.path",
bob_wallet.path,
"--wallet.name",
Expand Down
14 changes: 5 additions & 9 deletions tests/e2e_tests/test_incentive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -75,13 +71,13 @@ 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",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"ws://localhost:9944",
"--wallet.path",
bob_wallet.path,
"--wallet.name",
Expand All @@ -104,13 +100,13 @@ 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",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"ws://localhost:9944",
"--wallet.path",
alice_wallet.path,
"--wallet.name",
Expand Down
16 changes: 9 additions & 7 deletions tests/e2e_tests/test_root_set_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -34,7 +30,13 @@


@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.

Expand Down Expand Up @@ -86,13 +88,13 @@ 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",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"ws://localhost:9944",
"--wallet.path",
alice_wallet.path,
"--wallet.name",
Expand Down
10 changes: 3 additions & 7 deletions tests/e2e_tests/test_subtensor_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
sudo_set_admin_utils,
wait_epoch,
)
from tests.e2e_tests.utils.e2e_test_utils import (
template_path,
templates_repo,
)

"""
Verifies:
Expand All @@ -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

Expand Down Expand Up @@ -163,13 +159,13 @@ 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",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"ws://localhost:9944",
"--wallet.path",
alice_wallet.path,
"--wallet.name",
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e_tests/utils/e2e_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ 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):
subprocess.check_call([sys.executable, "-m", "pip", "install", "."])
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", "."])


def uninstall_templates(install_dir):
Expand Down