Skip to content

Commit

Permalink
test_root_register_add_member_senate.py: drop dependence on exact lin…
Browse files Browse the repository at this point in the history
…e numbers, change magic constant 1 to netuid
  • Loading branch information
µ authored and Reinier Heeres committed Aug 7, 2024
1 parent 0c4032e commit 4c16695
Showing 1 changed file with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,22 @@
from ...utils import setup_wallet


def assert_sequence(lines,sequence):
sequence_ptr = 0
for line in lines:
lineset = set(line.split())
seqset = sequence[sequence_ptr]
if lineset.intersection(seqset) == seqset:
sequence_ptr += 1
if sequence_ptr >= len(sequence):
# all items seen
break
assert sequence_ptr == len(sequence), f"Did not find sequence[{sequence_ptr}] = '{sequence[sequence_ptr]}' in output"


def test_root_register_add_member_senate(local_chain, capsys):
netuid = 1

# Register root as Alice - the subnet owner
alice_keypair, exec_command, wallet = setup_wallet("//Alice")
exec_command(RegisterSubnetworkCommand, ["s", "create"])
Expand All @@ -23,7 +38,7 @@ def test_root_register_add_member_senate(local_chain, capsys):
"s",
"register",
"--netuid",
"1",
str(netuid),
],
)

Expand All @@ -42,8 +57,8 @@ def test_root_register_add_member_senate(local_chain, capsys):

exec_command(SetTakeCommand, ["r", "set_take", "--take", "0.8"])

# Verify subnet 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
# Verify subnet <netuid> created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [netuid]).serialize()
# Query local chain for senate members
members = local_chain.query("SenateMembers", "Members").serialize()
assert len(members) == 3
Expand All @@ -65,18 +80,13 @@ def test_root_register_add_member_senate(local_chain, capsys):
lines = captured.out.splitlines()

# assert output is graph Titling "Senate" with names and addresses
assert "Senate" in lines[17].strip().split()
assert "NAME" in lines[18].strip().split()
assert "ADDRESS" in lines[18].strip().split()
assert (
"5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" in lines[19].strip().split()
)
assert (
"5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy" in lines[20].strip().split()
)
assert (
"5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" in lines[21].strip().split()
)
assert_sequence(lines,(
{"Senate"},
{"NAME","ADDRESS"},
{"5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL"},
{"5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy"},
{"5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"},
))

exec_command(
RootRegisterCommand,
Expand Down Expand Up @@ -114,18 +124,11 @@ def test_root_register_add_member_senate(local_chain, capsys):
lines = captured.out.splitlines()

# assert output is graph Titling "Senate" with names and addresses
assert "Senate" in lines[2].strip().split()
assert "NAME" in lines[3].strip().split()
assert "ADDRESS" in lines[3].strip().split()
assert (
"5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" in lines[4].strip().split()
)
assert (
"5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy" in lines[5].strip().split()
)
assert (
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" in lines[6].strip().split()
)
assert (
"5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" in lines[7].strip().split()
)
assert_sequence(lines,(
{"Senate"},
{"NAME","ADDRESS"},
{"5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL"},
{"5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy"},
{"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"},
{"5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"},
))

0 comments on commit 4c16695

Please sign in to comment.