Skip to content

Commit

Permalink
Merge branch 'staging' into fix/security-vulnerability-ansible-certifi
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheem-opentensor authored Aug 7, 2024
2 parents b2a91d8 + 26d20cf commit 203a654
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 168 deletions.
13 changes: 9 additions & 4 deletions tests/e2e_tests/multistep/test_axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import pytest

import bittensor
from bittensor.utils import networking
from bittensor import logging
from bittensor.commands import (
RegisterCommand,
RegisterSubnetworkCommand,
)
from bittensor.utils import networking
from tests.e2e_tests.utils import (
setup_wallet,
template_path,
Expand All @@ -31,13 +32,16 @@

@pytest.mark.asyncio
async def test_axon(local_chain):
logging.info("Testing test_axon")
netuid = 1
# Register root as Alice
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
exec_command(RegisterSubnetworkCommand, ["s", "create"])

# Verify subnet <netuid> created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()
assert local_chain.query(
"SubtensorModule", "NetworksAdded", [netuid]
).serialize(), "Subnet wasn't created successfully"

# Register a neuron to the subnet
exec_command(
Expand All @@ -55,7 +59,7 @@ async def test_axon(local_chain):
# validate one miner with ip of none
old_axon = metagraph.axons[0]

assert len(metagraph.axons) == 1
assert len(metagraph.axons) == 1, "Expected 1 axon, but got len(metagraph.axons)"
assert old_axon.hotkey == alice_keypair.ss58_address
assert old_axon.coldkey == alice_keypair.ss58_address
assert old_axon.ip == "0.0.0.0"
Expand Down Expand Up @@ -89,7 +93,7 @@ async def test_axon(local_chain):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)

logging.info("Neuron Alice is now mining")
await asyncio.sleep(
5
) # wait for 5 seconds for the metagraph to refresh with latest data
Expand All @@ -105,3 +109,4 @@ async def test_axon(local_chain):
assert updated_axon.port == 8091
assert updated_axon.hotkey == alice_keypair.ss58_address
assert updated_axon.coldkey == alice_keypair.ss58_address
logging.info("Passed test_axon")
19 changes: 11 additions & 8 deletions tests/e2e_tests/multistep/test_dendrite.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import asyncio
import logging
import sys

import pytest

import bittensor
from bittensor import logging
from bittensor.commands import (
RegisterCommand,
RegisterSubnetworkCommand,
StakeCommand,
RootRegisterCommand,
RootSetBoostCommand,
StakeCommand,
)
from tests.e2e_tests.utils import (
setup_wallet,
Expand All @@ -19,9 +19,6 @@
wait_epoch,
)


logging.basicConfig(level=logging.INFO)

"""
Test the dendrites mechanism.
Expand All @@ -35,13 +32,16 @@

@pytest.mark.asyncio
async def test_dendrite(local_chain):
logging.info("Testing test_dendrite")
netuid = 1
# Register root as Alice - the subnet owner
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
exec_command(RegisterSubnetworkCommand, ["s", "create"])

# Verify subnet <netuid> created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()
assert local_chain.query(
"SubtensorModule", "NetworksAdded", [netuid]
).serialize(), "Subnet wasn't created successfully"

bob_keypair, exec_command, wallet_path = setup_wallet("//Bob")

Expand Down Expand Up @@ -83,7 +83,9 @@ async def test_dendrite(local_chain):
metagraph = bittensor.metagraph(netuid=netuid, network="ws://localhost:9945")
neuron = metagraph.neurons[0]
# assert stake is 10000
assert neuron.stake.tao == 10_000.0
assert (
neuron.stake.tao == 10_000.0
), f"Expected 10_000.0 staked TAO, but got {neuron.stake.tao}"

# assert neuron is not validator
assert neuron.active is True
Expand Down Expand Up @@ -118,7 +120,7 @@ async def test_dendrite(local_chain):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)

logging.info("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 @@ -159,3 +161,4 @@ async def test_dendrite(local_chain):
assert neuron.validator_permit is True
assert neuron.hotkey == bob_keypair.ss58_address
assert neuron.coldkey == bob_keypair.ss58_address
logging.info("Passed test_dendrite")
25 changes: 16 additions & 9 deletions tests/e2e_tests/multistep/test_emissions.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import asyncio
import logging
import sys

import pytest

import bittensor
from bittensor import logging
from bittensor.commands import (
RegisterCommand,
RegisterSubnetworkCommand,
StakeCommand,
RootRegisterCommand,
RootSetBoostCommand,
SubnetSudoCommand,
RootSetWeightsCommand,
SetTakeCommand,
StakeCommand,
SubnetSudoCommand,
)
from tests.e2e_tests.utils import (
setup_wallet,
Expand All @@ -22,8 +22,6 @@
wait_epoch,
)

logging.basicConfig(level=logging.INFO)

"""
Test the emissions mechanism.
Expand All @@ -46,13 +44,17 @@


@pytest.mark.asyncio
@pytest.mark.skip
async def test_emissions(local_chain):
logging.info("Testing test_emissions")
netuid = 1
# Register root as Alice - the subnet owner and validator
alice_keypair, alice_exec_command, alice_wallet = setup_wallet("//Alice")
alice_exec_command(RegisterSubnetworkCommand, ["s", "create"])
# Verify subnet <netuid> created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()
assert local_chain.query(
"SubtensorModule", "NetworksAdded", [netuid]
).serialize(), "Subnet wasn't created successfully"

# Register Bob as miner
bob_keypair, bob_exec_command, bob_wallet = setup_wallet("//Bob")
Expand Down Expand Up @@ -126,7 +128,7 @@ async def test_emissions(local_chain):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)

logging.info("Neuron Alice is now validating")
await asyncio.sleep(5)

# register validator with root network
Expand Down Expand Up @@ -189,7 +191,7 @@ async def test_emissions(local_chain):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)

logging.info("Neuron Bob is now mining")
await wait_epoch(subtensor)

logging.warning("Setting root set weights")
Expand Down Expand Up @@ -250,7 +252,9 @@ async def test_emissions(local_chain):

# get current emissions and validate that Alice has gotten tao
weights = [(0, [(0, 65535), (1, 65535)])]
assert subtensor.weights(netuid=netuid) == weights
assert (
subtensor.weights(netuid=netuid) == weights
), "Weights set vs weights in subtensor don't match"

neurons = subtensor.neurons(netuid=netuid)
bob = neurons[1]
Expand All @@ -273,4 +277,7 @@ async def test_emissions(local_chain):

assert (
subtensor.get_emission_value_by_subnet(netuid=netuid) > 0
), (
"Emissions are not greated than 0"
) # emission on this subnet is strictly greater than 0
logging.info("Passed test_emissions")
21 changes: 13 additions & 8 deletions tests/e2e_tests/multistep/test_incentive.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import asyncio
import logging
import sys

import pytest

import bittensor
from bittensor import logging
from bittensor.commands import (
RegisterCommand,
RegisterSubnetworkCommand,
StakeCommand,
RootRegisterCommand,
RootSetBoostCommand,
StakeCommand,
)
from tests.e2e_tests.utils import (
setup_wallet,
Expand All @@ -19,8 +19,6 @@
wait_epoch,
)

logging.basicConfig(level=logging.INFO)

"""
Test the incentive mechanism.
Expand All @@ -43,12 +41,15 @@

@pytest.mark.asyncio
async def test_incentive(local_chain):
logging.info("Testing test_incentive")
netuid = 1
# Register root as Alice - the subnet owner and validator
alice_keypair, alice_exec_command, alice_wallet = setup_wallet("//Alice")
alice_exec_command(RegisterSubnetworkCommand, ["s", "create"])
# Verify subnet <netuid> created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()
assert local_chain.query(
"SubtensorModule", "NetworksAdded", [netuid]
).serialize(), "Subnet wasn't created successfully"

# Register Bob as miner
bob_keypair, bob_exec_command, bob_wallet = setup_wallet("//Bob")
Expand Down Expand Up @@ -77,7 +78,9 @@ async def test_incentive(local_chain):

subtensor = bittensor.subtensor(network="ws://localhost:9945")
# assert two neurons are in network
assert len(subtensor.neurons(netuid=netuid)) == 2
assert (
len(subtensor.neurons(netuid=netuid)) == 2
), "Alice & Bob not registered in the subnet"

# Alice to stake to become to top neuron after the first epoch
alice_exec_command(
Expand Down Expand Up @@ -117,7 +120,7 @@ async def test_incentive(local_chain):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)

logging.info("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 @@ -150,7 +153,7 @@ async def test_incentive(local_chain):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)

logging.info("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 @@ -221,6 +224,7 @@ async def test_incentive(local_chain):
wait_for_inclusion=True,
wait_for_finalization=True,
)
logging.info("Alice neuron set weights successfully")

# wait epoch until weight go into effect
await wait_epoch(subtensor)
Expand All @@ -240,3 +244,4 @@ async def test_incentive(local_chain):
assert alice_neuron.dividends == 1
assert alice_neuron.stake.tao == 10_000.0
assert alice_neuron.validator_trust == 1
logging.info("Passed test_incentive")
51 changes: 0 additions & 51 deletions tests/e2e_tests/multistep/test_last_tx_block.py

This file was deleted.

17 changes: 11 additions & 6 deletions tests/e2e_tests/subcommands/delegation/test_set_delegate_take.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
from bittensor.commands.delegates import SetTakeCommand, NominateCommand
from bittensor import logging
from bittensor.commands.delegates import NominateCommand, SetTakeCommand
from bittensor.commands.network import RegisterSubnetworkCommand
from bittensor.commands.register import RegisterCommand
from bittensor.commands.root import RootRegisterCommand

from tests.e2e_tests.utils import setup_wallet


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

# Create subnet 1 and verify created successfully
assert not (local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize())
assert not (
local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
), "Subnet is already registered"

exec_command(RegisterSubnetworkCommand, ["s", "create"])
assert local_chain.query("SubtensorModule", "NetworksAdded", [1])

assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
assert local_chain.query(
"SubtensorModule", "NetworksAdded", [1]
).serialize(), "Subnet wasn't registered"

# Register and nominate Bob
keypair, exec_command, wallet = setup_wallet("//Bob")
Expand Down Expand Up @@ -53,4 +57,5 @@ def test_set_delegate_increase_take(local_chain):
exec_command(SetTakeCommand, ["r", "set_take", "--take", "0.15"])
assert local_chain.query(
"SubtensorModule", "Delegates", [keypair.ss58_address]
).value == int(0.15 * 65535)
).value == int(0.15 * 65535), "Take value set incorrectly"
logging.info("Passed test_set_delegate_increase_take")
Loading

0 comments on commit 203a654

Please sign in to comment.