diff --git a/tests/e2e_tests/subcommands/root/test_root_register_add_member_senate.py b/tests/e2e_tests/subcommands/root/test_root_register_add_member_senate.py index 26e227c4e0..2e863e1ca5 100644 --- a/tests/e2e_tests/subcommands/root/test_root_register_add_member_senate.py +++ b/tests/e2e_tests/subcommands/root/test_root_register_add_member_senate.py @@ -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"]) @@ -23,7 +38,7 @@ def test_root_register_add_member_senate(local_chain, capsys): "s", "register", "--netuid", - "1", + str(netuid), ], ) @@ -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 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 @@ -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, @@ -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"}, + ))