Skip to content

Commit

Permalink
Merge pull request #2443 from opentensor/feat/abe/e2e-tests-1
Browse files Browse the repository at this point in the history
E2E tests - Increasing Subtensor coverage (Pt 1)
  • Loading branch information
ibraheem-opentensor authored Nov 20, 2024
2 parents bcc7dc2 + ef47604 commit 666e741
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 95 deletions.
16 changes: 9 additions & 7 deletions tests/e2e_tests/test_axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import pytest

import bittensor
from bittensor.core.subtensor import Subtensor
from bittensor.utils import networking
from bittensor.utils.btlogging import logging
from tests.e2e_tests.utils.chain_interactions import register_neuron, register_subnet
from tests.e2e_tests.utils.chain_interactions import register_subnet
from tests.e2e_tests.utils.e2e_test_utils import (
setup_wallet,
template_path,
Expand All @@ -28,12 +28,14 @@ async def test_axon(local_chain):
AssertionError: If any of the checks or verifications fail
"""

logging.info("Testing test_axon")
print("Testing test_axon")

netuid = 1
# Register root as Alice - the subnet owner
alice_keypair, wallet = setup_wallet("//Alice")

subtensor = Subtensor(network="ws://localhost:9945")

# Register a subnet, netuid 1
assert register_subnet(local_chain, wallet), "Subnet wasn't created"

Expand All @@ -43,8 +45,8 @@ async def test_axon(local_chain):
).serialize(), "Subnet wasn't created successfully"

# Register Alice to the network
assert register_neuron(
local_chain, wallet, netuid
assert subtensor.burned_register(
wallet, netuid
), f"Neuron wasn't registered to subnet {netuid}"

metagraph = bittensor.Metagraph(netuid=netuid, network="ws://localhost:9945")
Expand Down Expand Up @@ -87,7 +89,7 @@ async def test_axon(local_chain):
stderr=asyncio.subprocess.PIPE,
)

logging.info("Neuron Alice is now mining")
print("Neuron Alice is now mining")

# Waiting for 5 seconds for metagraph to be updated
await asyncio.sleep(5)
Expand Down Expand Up @@ -124,4 +126,4 @@ async def test_axon(local_chain):
updated_axon.coldkey == alice_keypair.ss58_address
), "Coldkey mismatch after mining"

logging.info("✅ Passed test_axon")
print("✅ Passed test_axon")
14 changes: 7 additions & 7 deletions tests/e2e_tests/test_commit_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

from bittensor.core.subtensor import Subtensor
from bittensor.utils.balance import Balance
from bittensor.utils.btlogging import logging
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
from tests.e2e_tests.utils.chain_interactions import (
add_stake,
register_neuron,
register_subnet,
sudo_set_hyperparameter_bool,
sudo_set_hyperparameter_values,
Expand All @@ -34,7 +32,7 @@ async def test_commit_and_reveal_weights(local_chain):
AssertionError: If any of the checks or verifications fail
"""
netuid = 1
logging.info("Testing test_commit_and_reveal_weights")
print("Testing test_commit_and_reveal_weights")
# Register root as Alice
keypair, alice_wallet = setup_wallet("//Alice")
assert register_subnet(local_chain, alice_wallet), "Unable to register the subnet"
Expand All @@ -44,8 +42,11 @@ async def test_commit_and_reveal_weights(local_chain):
"SubtensorModule", "NetworksAdded", [1]
).serialize(), "Subnet wasn't created successfully"

assert register_neuron(
local_chain, alice_wallet, netuid
subtensor = Subtensor(network="ws://localhost:9945")

# Register Alice to the subnet
assert subtensor.burned_register(
alice_wallet, netuid
), "Unable to register Alice as a neuron"

# Stake to become to top neuron after the first epoch
Expand All @@ -60,7 +61,6 @@ async def test_commit_and_reveal_weights(local_chain):
netuid,
), "Unable to enable commit reveal on the subnet"

subtensor = Subtensor(network="ws://localhost:9945")
assert subtensor.get_subnet_hyperparameters(
netuid=netuid,
).commit_reveal_weights_enabled, "Failed to enable commit/reveal"
Expand Down Expand Up @@ -169,4 +169,4 @@ async def test_commit_and_reveal_weights(local_chain):
assert (
weight_vals[0] == revealed_weights.value[0][1]
), f"Incorrect revealed weights. Expected: {weights[0]}, Actual: {revealed_weights.value[0][1]}"
logging.info("✅ Passed test_commit_and_reveal_weights")
print("✅ Passed test_commit_and_reveal_weights")
10 changes: 5 additions & 5 deletions tests/e2e_tests/test_dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from bittensor.utils.balance import Balance
from bittensor.utils.btlogging import logging
from tests.e2e_tests.utils.chain_interactions import (
register_neuron,
register_subnet,
add_stake,
wait_epoch,
Expand Down Expand Up @@ -52,13 +51,14 @@ async def test_dendrite(local_chain):
# Register Bob
bob_keypair, bob_wallet = setup_wallet("//Bob")

subtensor = Subtensor(network="ws://localhost:9945")

# Register Bob to the network
assert register_neuron(
local_chain, bob_wallet, netuid
), f"Neuron wasn't registered to subnet {netuid}"
assert subtensor.burned_register(
bob_wallet, netuid
), "Unable to register Bob as a neuron"

metagraph = Metagraph(netuid=netuid, network="ws://localhost:9945")
subtensor = Subtensor(network="ws://localhost:9945")

# Assert one neuron is Bob
assert len(subtensor.neurons(netuid=netuid)) == 1
Expand Down
24 changes: 14 additions & 10 deletions tests/e2e_tests/test_incentive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

import pytest

from bittensor import Subtensor, logging
from bittensor.core.subtensor import Subtensor
from tests.e2e_tests.utils.chain_interactions import (
add_stake,
register_neuron,
register_subnet,
wait_epoch,
)
Expand Down Expand Up @@ -38,7 +37,7 @@ async def test_incentive(local_chain):
AssertionError: If any of the checks or verifications fail
"""

logging.info("Testing test_incentive")
print("Testing test_incentive")
netuid = 1

# Register root as Alice - the subnet owner and validator
Expand All @@ -53,13 +52,18 @@ async def test_incentive(local_chain):
# Register Bob as miner
bob_keypair, bob_wallet = setup_wallet("//Bob")

subtensor = Subtensor(network="ws://localhost:9945")

# Register Alice as a neuron on the subnet
register_neuron(local_chain, alice_wallet, netuid)
assert subtensor.burned_register(
alice_wallet, netuid
), "Unable to register Alice as a neuron"

# Register Bob as a neuron on the subnet
register_neuron(local_chain, bob_wallet, netuid)
assert subtensor.burned_register(
bob_wallet, netuid
), "Unable to register Bob as a neuron"

subtensor = Subtensor(network="ws://localhost:9945")
# Assert two neurons are in network
assert (
len(subtensor.neurons(netuid=netuid)) == 2
Expand Down Expand Up @@ -95,7 +99,7 @@ async def test_incentive(local_chain):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
logging.info("Neuron Bob is now mining")
print("Neuron Bob is now mining")
await asyncio.sleep(
5
) # wait for 5 seconds for the metagraph to refresh with latest data
Expand Down Expand Up @@ -127,7 +131,7 @@ async def test_incentive(local_chain):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
logging.info("Neuron Alice is now validating")
print("Neuron Alice is now validating")
await asyncio.sleep(
5
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
Expand Down Expand Up @@ -163,7 +167,7 @@ async def test_incentive(local_chain):
wait_for_finalization=True,
period=5 * FAST_BLOCKS_SPEEDUP_FACTOR,
)
logging.info("Alice neuron set weights successfully")
print("Alice neuron set weights successfully")

await wait_epoch(subtensor)

Expand All @@ -183,4 +187,4 @@ async def test_incentive(local_chain):
assert alice_neuron.stake.tao == 10_000.0
assert alice_neuron.validator_trust == 1

logging.info("✅ Passed test_incentive")
print("✅ Passed test_incentive")
9 changes: 4 additions & 5 deletions tests/e2e_tests/test_liquid_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from bittensor.utils.btlogging import logging
from tests.e2e_tests.utils.chain_interactions import (
add_stake,
register_neuron,
register_subnet,
sudo_set_hyperparameter_bool,
sudo_set_hyperparameter_values,
Expand Down Expand Up @@ -44,16 +43,16 @@ def test_liquid_alpha(local_chain):
# Verify subnet 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()

# Register a neuron to the subnet
assert register_neuron(
local_chain, alice_wallet, netuid
# Register a neuron (Alice) to the subnet
subtensor = Subtensor(network="ws://localhost:9945")
assert subtensor.burned_register(
alice_wallet, netuid
), "Unable to register Alice as a neuron"

# Stake to become to top neuron after the first epoch
add_stake(local_chain, alice_wallet, Balance.from_tao(100_000))

# Assert liquid alpha is disabled
subtensor = Subtensor(network="ws://localhost:9945")
assert (
subtensor.get_subnet_hyperparameters(netuid=netuid).liquid_alpha_enabled
is False
Expand Down
9 changes: 4 additions & 5 deletions tests/e2e_tests/test_metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from bittensor.utils.btlogging import logging
from tests.e2e_tests.utils.chain_interactions import (
add_stake,
register_neuron,
register_subnet,
)
from tests.e2e_tests.utils.e2e_test_utils import (
Expand Down Expand Up @@ -72,8 +71,8 @@ def test_metagraph(local_chain):
assert len(metagraph.uids) == 0, "Metagraph is not empty"

# Register Bob to the subnet
assert register_neuron(
local_chain, bob_wallet, netuid
assert subtensor.burned_register(
bob_wallet, netuid
), "Unable to register Bob as a neuron"

# Refresh the metagraph
Expand Down Expand Up @@ -108,8 +107,8 @@ def test_metagraph(local_chain):
metagraph_pre_dave = subtensor.metagraph(netuid=1)

# Register Dave as a neuron
assert register_neuron(
local_chain, dave_wallet, netuid
assert subtensor.burned_register(
dave_wallet, netuid
), "Unable to register Dave as a neuron"

metagraph.sync(subtensor=subtensor)
Expand Down
Loading

0 comments on commit 666e741

Please sign in to comment.