Skip to content

Commit

Permalink
Merge pull request #2211 from opentensor/tests/fixes-e2e-after-new-bi…
Browse files Browse the repository at this point in the history
…ttensor

Fixes tests depending on explicit line numbers
  • Loading branch information
ibraheem-opentensor authored Aug 7, 2024
2 parents 5b20f93 + ad9ce91 commit f9677da
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_root_register_add_member_senate(local_chain, capsys):

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

captured = capsys.readouterr()
# Verify subnet 1 created successfully
assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize()
# Query local chain for senate members
Expand All @@ -62,21 +63,14 @@ def test_root_register_add_member_senate(local_chain, capsys):
)

captured = capsys.readouterr()
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 "Senate" in captured.out
assert "NAME" in captured.out
assert "ADDRESS" in captured.out
assert "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" in captured.out
assert "5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy" in captured.out
assert "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" in captured.out

exec_command(
RootRegisterCommand,
Expand Down Expand Up @@ -111,21 +105,12 @@ def test_root_register_add_member_senate(local_chain, capsys):
)

captured = capsys.readouterr()
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 "Senate" in captured.out
assert "NAME" in captured.out
assert "ADDRESS" in captured.out
assert "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" in captured.out
assert "5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy" in captured.out
assert "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" in captured.out
assert "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" in captured.out
32 changes: 5 additions & 27 deletions tests/e2e_tests/subcommands/root/test_root_view_proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
setup_wallet,
call_add_proposal,
)
import bittensor


def test_root_view_proposal(local_chain, capsys):
Expand Down Expand Up @@ -35,30 +34,9 @@ def test_root_view_proposal(local_chain, capsys):
]

captured = capsys.readouterr()
lines = captured.out.splitlines()
for line in lines:
bittensor.logging.info(line)
output = captured.out

# Assert that the length of the lines is as expected
assert len(lines) == 6

# Check each line for expected content
assert (
lines[0] == "📡 Syncing with chain: local ..."
), f"Expected '📡 Syncing with chain: local ...', got {lines[0]}"
assert (
lines[1].strip()
== "Proposals Active Proposals: 1 Senate Size: 3"
), f"Expected 'Proposals Active Proposals: 1 Senate Size: 3', got {lines[1].strip()}"
assert (
lines[2].strip().startswith("HASH")
), f"Expected line starting with 'HASH', got {lines[2].strip()}"
assert (
lines[3]
.strip()
.startswith(
"0x78b8a348690f565efe3730cd8189f7388c0a896b6fd090276639c9130c0eba47"
)
), f"Expected line starting with '0x78b8a348690f565efe3730cd8189f7388c0a896b6fd090276639c9130c0eba47', got {lines[3].strip()}"
assert lines[4].strip() == "\x00)", f"Expected '\x00)', got {lines[4].strip()}"
assert lines[5].strip() == "", f"Expected empty line, got {lines[5].strip()}"
for expected_line in simulated_output:
assert (
expected_line in output
), f"Expected '{expected_line}' to be in the output"
46 changes: 15 additions & 31 deletions tests/e2e_tests/subcommands/stake/test_stake_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,26 @@ def test_stake_show(local_chain, capsys):
# Execute the command
exec_command(StakeShow, ["stake", "show"])
captured = capsys.readouterr()
lines = captured.out.split("\n")

# Ensure there are enough lines
assert len(lines) >= 5, "Output has fewer than 5 lines."
output = captured.out

# Check the header line
header = lines[0]
assert "Coldkey" in header, "Header missing 'Coldkey'."
assert "Balance" in header, "Header missing 'Balance'."
assert "Account" in header, "Header missing 'Account'."
assert "Stake" in header, "Header missing 'Stake'."
assert "Rate" in header, "Header missing 'Rate'."
assert "Coldkey" in output, "Output missing 'Coldkey'."
assert "Balance" in output, "Output missing 'Balance'."
assert "Account" in output, "Output missing 'Account'."
assert "Stake" in output, "Output missing 'Stake'."
assert "Rate" in output, "Output missing 'Rate'."

# Check the first line of data
values1 = lines[1].strip().split()
assert values1[0] == "default", f"Expected 'default', got {values1[0]}."
assert (
values1[1].replace("τ", "") == "1000000.000000"
), f"Expected '1000000.000000', got {values1[1]}."
assert "default" in output, "Output missing 'default'."
assert "1000000.000000" in output.replace(
"τ", ""
), "Output missing '1000000.000000'."

# Check the second line of data
values2 = lines[2].strip().split()
assert values2[0] == "default", f"Expected 'default', got {values2[0]}."
assert (
values2[1].replace("τ", "") == "0.000000"
), f"Expected '0.000000', got {values2[1]}."
assert values2[2] == "0/d", f"Expected '0/d', got {values2[2]}."
assert "0.000000" in output.replace("τ", ""), "Output missing '0.000000'."
assert "0/d" in output, "Output missing '0/d'."

# Check the third line of data
values3 = lines[3].strip().split()
assert (
values3[0].replace("τ", "") == "1000000.00000"
), f"Expected '1000000.00000', got {values3[0]}."
assert (
values3[1].replace("τ", "") == "0.00000"
), f"Expected '0.00000', got {values3[1]}."
assert (
values3[2].replace("τ", "") == "0.00000/d"
), f"Expected '0.00000/d', got {values3[2]}."
assert "1000000.00000" in output.replace("τ", ""), "Output missing '1000000.00000'."
assert "0.00000" in output.replace("τ", ""), "Output missing '0.00000'."
assert "0.00000/d" in output.replace("τ", ""), "Output missing '0.00000/d'."
9 changes: 3 additions & 6 deletions tests/e2e_tests/subcommands/subnet/test_metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ def test_metagraph_command(local_chain, capsys):
exec_command(MetagraphCommand, ["subnet", "metagraph", "--netuid", "1"])

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

# Assert metagraph is printed for netuid 1
assert "Metagraph: net: local:1" in lines[2]
assert "Metagraph: net: local:1" in captured.out

# Register Bob as neuron to the subnet
bob_keypair, bob_exec_command, bob_wallet = setup_wallet("//Bob")
Expand All @@ -55,10 +54,9 @@ def test_metagraph_command(local_chain, capsys):
)

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

# Assert neuron was registered
assert "✅ Registered" in lines[3]
assert "✅ Registered" in captured.out

# Refresh the metagraph
metagraph = subtensor.metagraph(netuid=1)
Expand Down Expand Up @@ -87,10 +85,9 @@ def test_metagraph_command(local_chain, capsys):
)

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

# Assert neuron was registered
assert "✅ Registered" in lines[3]
assert "✅ Registered" in captured.out

# Refresh the metagraph
metagraph = subtensor.metagraph(netuid=1)
Expand Down

0 comments on commit f9677da

Please sign in to comment.