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/e2e tests staging #1943

Merged
merged 53 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2e7dc06
Add an example of test that verifies console output
gztensor May 23, 2024
1229ebb
refactor the transfer case
open-junius May 27, 2024
0eb3ea9
add stake case
open-junius May 27, 2024
3d5010b
add set tx limit extrinsic
open-junius May 27, 2024
0115dfe
revert transfer
open-junius May 27, 2024
81973e6
format code
open-junius May 27, 2024
6fc3c61
revert code change
open-junius May 27, 2024
0030051
revert bittensor part
open-junius May 27, 2024
2cc072f
Merge branch 'staging' into tests/e2e-tests-staging
open-junius May 27, 2024
62b5bb9
first stake case
open-junius May 27, 2024
6e42709
add stake show case
open-junius May 27, 2024
4e30ef9
revert change
open-junius May 28, 2024
273cedc
revert change
open-junius May 28, 2024
168cb5f
add stake add case
open-junius May 28, 2024
b030a64
try add remove stake case
open-junius May 28, 2024
49e8ea0
stake test passed
open-junius May 29, 2024
1c1bef0
start root test cases
open-junius May 29, 2024
0fab75a
more root test
open-junius May 29, 2024
6db7eed
Merge branch 'staging' into tests/e2e-tests-staging
open-junius May 29, 2024
5ce8fc1
Merge branch 'staging' into tests/e2e-tests-staging
open-junius May 29, 2024
e98d832
revert change
open-junius May 29, 2024
2070fe5
check in test
open-junius May 29, 2024
ef6562e
add senate view case
open-junius May 30, 2024
3a7bb39
add senate view case
open-junius May 30, 2024
ca63c9d
two more commands
open-junius May 30, 2024
0a167c8
more test case
open-junius Jun 3, 2024
6bb5a9b
fix lint
open-junius Jun 3, 2024
499214d
nominate case done
open-junius Jun 4, 2024
f3c9548
clean up code
Jun 7, 2024
1e0b1b2
add comments
open-junius Jun 7, 2024
28abbf3
merge with target branch
open-junius Jun 7, 2024
c0296f0
fix format issue
open-junius Jun 7, 2024
5c1b2fb
fix format
open-junius Jun 7, 2024
fba8795
revert is_hotkey_delegate
open-junius Jun 7, 2024
a6a05b7
Merge branch 'staging' into tests/e2e-tests-staging
open-junius Jun 10, 2024
e8ad9c9
senate vote ok
open-junius Jun 10, 2024
17896c3
update comment
open-junius Jun 10, 2024
347288f
update multistep cases
open-junius Jun 10, 2024
afddb48
refactor
open-junius Jun 10, 2024
029c4b6
fix bug
open-junius Jun 10, 2024
70169f5
update test case
open-junius Jun 10, 2024
0be6e7d
update test case
open-junius Jun 10, 2024
0d11bfe
update case
open-junius Jun 10, 2024
4fc7ddc
fix test error
open-junius Jun 10, 2024
95f5948
Merge branch 'staging' into tests/e2e-tests-staging
distributedstatemachine Jun 11, 2024
cc6a13c
delete not runable case
open-junius Jun 12, 2024
98e43ff
merge with target branch
open-junius Jun 12, 2024
c56bf7e
remove unranable case
open-junius Jun 12, 2024
9d638a3
fix test
open-junius Jun 12, 2024
b00067b
fix test case
open-junius Jun 12, 2024
3f76665
fix wallet setup
open-junius Jun 12, 2024
f9555d2
fix case
open-junius Jun 12, 2024
01ade63
Merge branch 'staging' into tests/e2e-tests-staging
open-junius Jun 13, 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
12 changes: 6 additions & 6 deletions bittensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4270,9 +4270,9 @@ def make_substrate_call_with_retry(encoded_hotkey_: List[int]):

return self.substrate.rpc_request(
method="delegateInfo_getDelegate", # custom rpc method
params=[encoded_hotkey_, block_hash]
if block_hash
else [encoded_hotkey_],
params=(
[encoded_hotkey_, block_hash] if block_hash else [encoded_hotkey_]
),
)

encoded_hotkey = ss58_to_vec_u8(hotkey_ss58)
Expand Down Expand Up @@ -4376,9 +4376,9 @@ def make_substrate_call_with_retry(encoded_coldkey_: List[int]):

return self.substrate.rpc_request(
method="delegateInfo_getDelegated",
params=[block_hash, encoded_coldkey_]
if block_hash
else [encoded_coldkey_],
params=(
[block_hash, encoded_coldkey_] if block_hash else [encoded_coldkey_]
),
)

encoded_coldkey = ss58_to_vec_u8(coldkey_ss58)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_tests/multistep/test_axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@pytest.mark.asyncio
async def test_axon(local_chain):
# Register root as Alice
alice_keypair, exec_command, wallet_path = setup_wallet("//Alice")
alice_keypair, exec_command, wallet_path = setup_wallet("//Alice", True)
exec_command(RegisterSubnetworkCommand, ["s", "create"])

# Verify subnet 1 created successfully
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 @@ -25,13 +25,13 @@
@pytest.mark.asyncio
async def test_dendrite(local_chain):
# Register root as Alice - the subnet owner
alice_keypair, exec_command, wallet_path = setup_wallet("//Alice")
alice_keypair, exec_command, wallet_path = setup_wallet("//Alice", True)
exec_command(RegisterSubnetworkCommand, ["s", "create"])

# Verify subnet 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()

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

# Register a neuron to the subnet
exec_command(
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e_tests/multistep/test_last_tx_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# https://discord.com/channels/799672011265015819/1176889736636407808/1236057424134144152
def test_takes(local_chain):
# Register root as Alice
keypair, exec_command, wallet_path = setup_wallet("//Alice")
keypair, exec_command, wallet_path = setup_wallet("//Alice", True)
exec_command(RootRegisterCommand, ["root", "register"])

# Create subnet 1 and verify created successfully
Expand All @@ -21,7 +21,7 @@ def test_takes(local_chain):
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()

# Register and nominate Bob
keypair, exec_command, wallet_path = setup_wallet("//Bob")
keypair, exec_command, wallet_path = setup_wallet("//Bob", True)
assert (
local_chain.query(
"SubtensorModule", "LastTxBlock", [keypair.ss58_address]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def test_set_delegate_increase_take(local_chain):
# Register root as Alice
keypair, exec_command, wallet_path = setup_wallet("//Alice")
keypair, exec_command, wallet_path = setup_wallet("//Alice", True)
exec_command(RootRegisterCommand, ["root", "register"])

# Create subnet 1 and verify created successfully
Expand All @@ -20,7 +20,7 @@ def test_set_delegate_increase_take(local_chain):
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()

# Register and nominate Bob
keypair, exec_command, wallet_path = setup_wallet("//Bob")
keypair, exec_command, wallet_path = setup_wallet("//Bob", True)
assert (
local_chain.query(
"SubtensorModule", "LastTxBlock", [keypair.ss58_address]
Expand Down
Empty file.
59 changes: 59 additions & 0 deletions tests/e2e_tests/subcommands/root/test_root_boost_weights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from bittensor.commands.root import RootSetBoostCommand, RootSetWeightsCommand
from bittensor.commands.stake import StakeCommand
from bittensor.commands.unstake import UnStakeCommand
from bittensor.commands.network import RegisterSubnetworkCommand
from bittensor.commands.register import RegisterCommand
from ...utils import new_wallet, sudo_call_set_network_limit
import bittensor


# we can't test it now since the root network weights can't be set
Copy link

@opendansor opendansor Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we cant test this right now, should we remove it until we can properly test it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls keep it in the repo. I need some time to try, then know what's the correct parameter and how to check.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep this in a separate branch? There is no need to push this in while its still under development and not ready to go out to the public. Every test we run on the Bittensor side actually tests what it is supposed to test. This will add tests that don't actually test what they claim to test, and we will be required to "remember" that X or Y test is incomplete, giving us holes in what bugs and issues can go unnoticed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will remove it.

# Test case to set weights for root network
def test_root_get_set_weights(local_chain, capsys):
(wallet, exec_command) = new_wallet("//Alice", "//Bob")
assert sudo_call_set_network_limit(local_chain, wallet)

assert not local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()

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

# assert (
# local_chain.query("SubtensorModule", "Uids", [1, wallet.hotkey.ss58_address])
# == None
# )

# exec_command(RegisterCommand, ["subnets", "register", "--netuid", "0"])

# can not set weights for root network. update needed from python implementation
# netuids = "1,2,4"
# weights = "0.1,0.3,0.6"
# exec_command(
# RootSetWeightsCommand,
# ["root", "weights", "--netuids", netuids, "--weights", weights],
# )

# weights = local_chain.query_map(
# "SubtensorModule", "Weights", [wallet.hotkey.ss58_address]
# )

# netuid = "1"
# increase = "0.01"

# exec_command(
# RootSetBoostCommand,
# ["root", "boost", "--netuid", netuid, "--increase", increase],
# )

# weights = local_chain.query("SubtensorModule", "Weights", [1])
# assert weights == 1

# captured = capsys.readouterr()
# lines = captured.out.splitlines()

# for line in lines:
# bittensor.logging.info(line)

# assert len(lines) == 4
21 changes: 21 additions & 0 deletions tests/e2e_tests/subcommands/root/test_root_delegate_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from bittensor.commands.delegates import ListDelegatesCommand
from bittensor.commands.root import RootRegisterCommand
from bittensor.commands.delegates import SetTakeCommand
from ...utils import new_wallet


# delegate seems hard code the network config
def test_root_delegate_list(local_chain, capsys):
(wallet, exec_command) = new_wallet("//Alice", "//Bob")

# 1200 hardcoded block gap
exec_command(
ListDelegatesCommand,
["root", "list_delegates"],
)

captured = capsys.readouterr()
lines = captured.out.splitlines()

# the command print too many lines
assert len(lines) > 200
101 changes: 101 additions & 0 deletions tests/e2e_tests/subcommands/root/test_root_delegate_stake_unstake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from bittensor.commands.delegates import DelegateStakeCommand, DelegateUnstakeCommand
from bittensor.commands.stake import StakeCommand
from bittensor.commands.delegates import SetTakeCommand
from bittensor.commands.network import RegisterSubnetworkCommand
from bittensor.commands.register import RegisterCommand

from ...utils import (
new_wallet,
call_add_proposal,
sudo_call_set_network_limit,
sudo_call_set_target_stakes_per_interval,
)


# delegate seems hard code the network config
def test_root_delegate_stake(local_chain, capsys):
(wallet, exec_command) = new_wallet("//Alice", "//Bob")

stakes = local_chain.query(
"SubtensorModule",
"Stake",
[wallet.hotkey.ss58_address, wallet.coldkey.ss58_address],
)
assert stakes == 0

assert sudo_call_set_network_limit(local_chain, wallet)
assert sudo_call_set_target_stakes_per_interval(local_chain, wallet)

exec_command(RegisterSubnetworkCommand, ["s", "create"])
exec_command(RegisterCommand, ["s", "register", "--neduid", "1"])

stake_amount = 2
exec_command(StakeCommand, ["stake", "add", "--amount", str(stake_amount)])

stakes = local_chain.query(
"SubtensorModule",
"Stake",
[wallet.hotkey.ss58_address, wallet.coldkey.ss58_address],
)

assert stakes > 1_000_000_000

delegates = local_chain.query(
"SubtensorModule",
"Delegates",
[wallet.hotkey.ss58_address],
)

assert delegates == 11796

# stake 1 TAO
# exec_command(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of these commented out blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to add and reduce stake

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but the code is commented out... Meaning the test doesn't actually add or reduce stake, and test that stake is added or reduced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will just keep it in my local branch

# DelegateStakeCommand,
# [
# "root",
# "delegate",
# "--delegate_ss58key",
# wallet.hotkey.ss58_address,
# "--amount",
# "1",
# ],
# )

# new_stakes = local_chain.query(
# "SubtensorModule",
# "Stake",
# [wallet.hotkey.ss58_address, wallet.coldkey.ss58_address],
# )

# tolerance = 10000

# assert (
# stakes.serialize() + 1_000_000_000 - tolerance
# < new_stakes.serialize()
# < stakes.serialize() + 1_000_000_000 + tolerance
# )

# unstake 1 TAO
# exec_command(
# DelegateUnstakeCommand,
# [
# "root",
# "delegate",
# "--delegate_ss58key",
# wallet.hotkey.ss58_address,
# "--amount",
# "1",
# ],
# )

# stakes = local_chain.query(
# "SubtensorModule",
# "Stake",
# [wallet.hotkey.ss58_address, wallet.coldkey.ss58_address],
# )

# assert (
# stakes.serialize() + 1_000_000_000 - tolerance
# < new_stakes.serialize()
# < stakes.serialize() + 1_000_000_000 + tolerance
# )
38 changes: 38 additions & 0 deletions tests/e2e_tests/subcommands/root/test_root_get_set_weights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from bittensor.commands.root import RootSetWeightsCommand, RootGetWeightsCommand
from bittensor.commands.network import RegisterSubnetworkCommand
from ...utils import new_wallet, sudo_call_set_network_limit


# we can't test it now since the root network weights can't be set

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test run correctly? Maybe we write this test when the command is updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extrinsic in subtensor side is updated. From @distributedstatemachine , I know cortex team will change accordingly.

# Test case to set weights for root network and get the weights
def test_root_get_set_weights(local_chain, capsys):
(wallet, exec_command) = new_wallet("//Alice", "//Bob")
assert sudo_call_set_network_limit(local_chain, wallet)
assert not local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()

exec_command(RegisterSubnetworkCommand, ["s", "create"])
exec_command(RegisterSubnetworkCommand, ["s", "create"])
exec_command(RegisterSubnetworkCommand, ["s", "create"])

assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
assert local_chain.query("SubtensorModule", "NetworksAdded", [2]).serialize()
assert local_chain.query("SubtensorModule", "NetworksAdded", [4]).serialize()

netuids = "1,2,4"
weights = "0.1,0.3,0.6"

# this command need update, should set the netuid. subtensor not accept the weight set for root network
exec_command(
RootSetWeightsCommand,
["root", "weights", "--netuids", netuids, "--weights", weights],
)

weights = local_chain.query("SubtensorModule", "Weights", [1, 0])

exec_command(
RootGetWeightsCommand,
["root", "get_weights"],
)

captured = capsys.readouterr()
lines = captured.out.splitlines()
30 changes: 30 additions & 0 deletions tests/e2e_tests/subcommands/root/test_root_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from bittensor.commands.root import RootList
from ...utils import new_wallet
from bittensor.commands.network import RegisterSubnetworkCommand
import bittensor


# test case to list the root network
def test_root_list(local_chain, capsys):
(wallet, exec_command) = new_wallet("//Alice", "//Bob")

exec_command(RootList, ["root", "list"])
captured = capsys.readouterr()
lines = captured.out.split("\n")

assert len(lines) >= 4
bittensor.logging.info(lines)

# assert "Root Network" in lines[0]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these lines commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the description, we always get the extra output about bittensor version. so just commented out, can add them back after version is aligned.

# assert "UID NAME ADDRESS STAKE" in lines[1]

exec_command(RegisterSubnetworkCommand, ["s", "create"])

exec_command(RootList, ["root", "list"])
captured = capsys.readouterr()
lines = captured.out.splitlines()

assert len(lines) >= 4
# assert "Root Network" in lines[0]
# assert "UID NAME ADDRESS STAKE" in lines[1]
# assert "1" in lines[2]
47 changes: 47 additions & 0 deletions tests/e2e_tests/subcommands/root/test_root_nominate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from bittensor.commands.delegates import NominateCommand
from bittensor.commands.stake import StakeCommand
from bittensor.commands.delegates import SetTakeCommand
from bittensor.commands.network import RegisterSubnetworkCommand
from bittensor.commands.register import RegisterCommand

from ...utils import (
new_wallet,
call_add_proposal,
sudo_call_set_network_limit,
sudo_call_set_target_stakes_per_interval,
)


# delegate seems hard code the network config
def test_root_nominate(local_chain, capsys):
(wallet, exec_command) = new_wallet("//Alice", "//Bob")

delegates = local_chain.query(
"SubtensorModule",
"Delegates",
[wallet.hotkey.ss58_address],
)

assert delegates == 11796

assert sudo_call_set_network_limit(local_chain, wallet)
assert sudo_call_set_target_stakes_per_interval(local_chain, wallet)

exec_command(RegisterSubnetworkCommand, ["s", "create"])
exec_command(RegisterCommand, ["s", "register", "--neduid", "1"])

exec_command(
NominateCommand,
[
"root",
"nominate",
],
)

delegates = local_chain.query(
"SubtensorModule",
"Delegates",
[wallet.hotkey.ss58_address],
)

assert delegates == 11796
Loading
Loading