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

Test Emissions E2E #2036

Merged
merged 31 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3fdc2ed
Test emissions
Jun 17, 2024
61c6074
Test emissions e2e
Jun 18, 2024
b255de7
Merge branch 'staging' into feature/opendansor/test_emissions
Jun 18, 2024
00b2365
Update e2e-subtensor-tests.yaml
Jun 18, 2024
9a26626
Update e2e-subtensor-tests.yaml
Jun 18, 2024
2926a6b
Test emissions
Jun 17, 2024
a8087b2
Test emissions e2e
Jun 18, 2024
b865b1b
Update e2e-subtensor-tests.yaml
Jun 18, 2024
be457bb
Update e2e-subtensor-tests.yaml
Jun 18, 2024
56c0241
Merge remote-tracking branch 'origin/feature/opendansor/test_emission…
Jun 18, 2024
8b3b65e
Add delay to setting weights .
Jun 18, 2024
6d2cf6d
Merge branch 'staging' into feature/opendansor/test_emissions
Jun 20, 2024
2e70603
Allow test to pass
Jun 21, 2024
5c38137
Merge branch 'staging' into feature/opendansor/test_emissions
Jun 21, 2024
6d93fe7
Allow test to pass
Jun 21, 2024
22f968f
Merge branch 'staging' into feature/opendansor/test_emissions
Jun 21, 2024
4808274
Rename wait_epoch to wait_interval,
Jun 24, 2024
bdc968b
test passing locally
Jun 24, 2024
9b92c29
Merge branch 'staging' into feature/opendansor/test_emissions
Jun 24, 2024
1b483cb
Testing: Tempirarily increased time
ibraheem-opentensor Jun 25, 2024
1eb7d5e
add wait for inclusion and finalization flags
Jun 25, 2024
fac4a4d
Merge branch 'staging' into feature/opendansor/test_emissions
Jun 25, 2024
bcd1380
Attempt to parallelize the e2e jobs.
Jun 25, 2024
b0a33eb
Update to use github env files.
Jun 25, 2024
b0212e0
Update github workflow.
Jun 25, 2024
938f8bc
Update faucet.
Jun 25, 2024
4e4e388
Update to have 10 tests run in parallel.
Jun 25, 2024
69d9196
Update to have 5 tests run in parallel with retry
Jun 25, 2024
eca3e8e
Update to have 8 tests run in parallel with retry
Jun 25, 2024
371dde4
Unite swap hotkey tests into one.
Jun 26, 2024
7e7b7ed
Merge branch 'staging' into feature/opendansor/test_emissions
Jun 26, 2024
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
4 changes: 2 additions & 2 deletions tests/e2e_tests/multistep/test_axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tests.e2e_tests.utils import (
setup_wallet,
template_path,
repo_name,
templates_repo,
write_output_log_to_file,
)

Expand Down Expand Up @@ -67,7 +67,7 @@ async def test_axon(local_chain):
cmd = " ".join(
[
f"{sys.executable}",
f'"{template_path}{repo_name}/neurons/miner.py"',
f'"{template_path}{templates_repo}/neurons/miner.py"',
"--no_prompt",
"--netuid",
"1",
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e_tests/multistep/test_dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from tests.e2e_tests.utils import (
setup_wallet,
template_path,
repo_name,
templates_repo,
wait_epoch,
write_output_log_to_file,
)
Expand Down Expand Up @@ -95,7 +95,7 @@ async def test_dendrite(local_chain):
cmd = " ".join(
[
f"{sys.executable}",
f'"{template_path}{repo_name}/neurons/validator.py"',
f'"{template_path}{templates_repo}/neurons/validator.py"',
"--no_prompt",
"--netuid",
"1",
Expand Down
257 changes: 257 additions & 0 deletions tests/e2e_tests/multistep/test_emissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
import asyncio
import logging
import sys

import pytest

import bittensor
from bittensor.commands import (
RegisterCommand,
RegisterSubnetworkCommand,
StakeCommand,
RootRegisterCommand,
RootSetBoostCommand,
SubnetSudoCommand,
RootSetWeightsCommand,
SetTakeCommand,
)
from tests.e2e_tests.utils import (
setup_wallet,
template_path,
templates_repo,
wait_epoch,
)

logging.basicConfig(level=logging.INFO)

"""
Test the emissions mechanism.

Verify that for the miner:
* trust
* rank
* consensus
* incentive
* emission
are updated with proper values after an epoch has passed.

For the validator verify that:
* validator_permit
* validator_trust
* dividends
* stake
are updated with proper values after an epoch has passed.

"""


@pytest.mark.asyncio
async def test_emissions(local_chain):
# 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 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()

# Register Bob as miner
bob_keypair, bob_exec_command, bob_wallet = setup_wallet("//Bob")

# Register Alice as neuron to the subnet
alice_exec_command(
RegisterCommand,
[
"s",
"register",
"--netuid",
"1",
],
)

# Register Bob as neuron to the subnet
bob_exec_command(
RegisterCommand,
[
"s",
"register",
"--netuid",
"1",
],
)

subtensor = bittensor.subtensor(network="ws://localhost:9945")
# assert two neurons are in network
assert len(subtensor.neurons(netuid=1)) == 2

# Alice to stake to become to top neuron after the first epoch
alice_exec_command(
StakeCommand,
[
"stake",
"add",
"--amount",
"10000",
],
)

# register Alice as validator
cmd = " ".join(
[
f"{sys.executable}",
f'"{template_path}{templates_repo}/neurons/validator.py"',
"--no_prompt",
"--netuid",
"1",
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--wallet.path",
alice_wallet.path,
"--wallet.name",
alice_wallet.name,
"--wallet.hotkey",
"default",
"--logging.trace",
]
)
# run validator in the background

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

# register validator with root network
alice_exec_command(
RootRegisterCommand,
[
"root",
"register",
"--netuid",
"1",
],
)

alice_exec_command(
RootSetBoostCommand,
[
"root",
"boost",
"--netuid",
"1",
"--increase",
"1000",
],
)

# wait until 360 blocks pass (subnet tempo)
wait_epoch(360, subtensor)

alice_exec_command(
RootSetWeightsCommand,
[
"root",
"weights",
"--netuid",
"1",
"--weights",
"0.3",
"--wallet.name",
"default",
"--wallet.hotkey",
"default",
],
)

# Set delegate take for Alice
alice_exec_command(SetTakeCommand, ["r", "set_take", "--take", "0.15"])

# Lower the rate limit
alice_exec_command(
SubnetSudoCommand,
[
"sudo",
"set",
"hyperparameters",
"--netuid",
"1",
"--wallet.name",
alice_wallet.name,
"--param",
"weights_rate_limit",
"--value",
"1",
"--wait_for_inclusion",
"True",
"--wait_for_finalization",
"True",
],
)

# register Bob as miner
cmd = " ".join(
[
f"{sys.executable}",
f'"{template_path}{templates_repo}/neurons/miner.py"',
"--no_prompt",
"--netuid",
"1",
"--subtensor.network",
"local",
"--subtensor.chain_endpoint",
"ws://localhost:9945",
"--wallet.path",
bob_wallet.path,
"--wallet.name",
bob_wallet.name,
"--wallet.hotkey",
"default",
"--logging.trace",
]
)

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

# wait epoch until for emissions to get distributed
wait_epoch(360, subtensor)

# refresh metagraph
subtensor = bittensor.subtensor(network="ws://localhost:9945")

# get current emissions and validate that Alice has gotten tao
weights = [(0, [(0, 65535), (1, 65535)])]
assert subtensor.weights(netuid=1) == weights

neurons = subtensor.neurons(netuid=1)
bob = neurons[1]
alice = neurons[0]

assert bob.emission > 0
assert bob.consensus == 1
assert bob.incentive == 1
assert bob.rank == 1
assert bob.trust == 1

assert alice.emission > 0
assert alice.bonds == [(1, 65535)]
assert alice.dividends == 1
assert alice.stake.tao > 10000 # assert an increase in stake
assert alice.validator_permit is True
assert alice.validator_trust == 1
assert alice.weights == [(0, 65535), (1, 65535)]

assert (
subtensor.get_emission_value_by_subnet(netuid=1) > 0
) # emission on this subnet is strictly greater than 0
6 changes: 3 additions & 3 deletions tests/e2e_tests/multistep/test_incentive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from tests.e2e_tests.utils import (
setup_wallet,
template_path,
repo_name,
templates_repo,
wait_epoch,
write_output_log_to_file,
)
Expand Down Expand Up @@ -94,7 +94,7 @@ async def test_incentive(local_chain):
cmd = " ".join(
[
f"{sys.executable}",
f'"{template_path}{repo_name}/neurons/miner.py"',
f'"{template_path}{templates_repo}/neurons/miner.py"',
"--no_prompt",
"--netuid",
"1",
Expand Down Expand Up @@ -132,7 +132,7 @@ async def test_incentive(local_chain):
cmd = " ".join(
[
f"{sys.executable}",
f'"{template_path}{repo_name}/neurons/validator.py"',
f'"{template_path}{templates_repo}/neurons/validator.py"',
"--no_prompt",
"--netuid",
"1",
Expand Down
11 changes: 2 additions & 9 deletions tests/e2e_tests/subcommands/weights/test_commit_weights.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import time

import numpy as np

Expand All @@ -13,7 +12,7 @@
RevealWeightCommand,
SubnetSudoCommand,
)
from tests.e2e_tests.utils import setup_wallet
from tests.e2e_tests.utils import setup_wallet, wait_epoch

"""
Test the Commit/Reveal weights mechanism.
Expand Down Expand Up @@ -188,13 +187,7 @@ def test_commit_and_reveal_weights(local_chain):
assert interval > 0, "Invalid WeightCommitRevealInterval"

# Wait until the reveal block range
current_block = subtensor.get_current_block()
reveal_block_start = (commit_block - (commit_block % interval)) + interval
while current_block < reveal_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} Revealing at: {reveal_block_start}")
wait_epoch(interval, subtensor)

# Configure the CLI arguments for the RevealWeightCommand
exec_command(
Expand Down
Loading
Loading