Skip to content

Commit 512a295

Browse files
committed
Test senate
1 parent 337c04e commit 512a295

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

bittensor_cli/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ def verbosity_handler(
11161116
if quiet and verbose:
11171117
err_console.print("Cannot specify both `--quiet` and `--verbose`")
11181118
raise typer.Exit()
1119-
if json_console and verbose:
1119+
if json_output and verbose:
11201120
verbosity_console_handler(3)
11211121
elif json_output or quiet:
11221122
verbosity_console_handler(0)

bittensor_cli/src/commands/sudo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ def display_votes(
355355
def serialize_vote_data(
356356
vote_data: "ProposalVoteData", delegate_info: dict[str, DelegatesDetails]
357357
) -> list[dict[str, bool]]:
358-
vote_list = []
358+
vote_list = {}
359359
for address in vote_data.ayes:
360360
f_add = delegate_info[address].display if address in delegate_info else address
361-
vote_list.append({f_add: True})
361+
vote_list[f_add] = True
362362
for address in vote_data.nays:
363363
f_add = delegate_info[address].display if address in delegate_info else address
364-
vote_list.append({f_add: False})
364+
vote_list[f_add] = False
365365
return vote_list
366366

367367

tests/e2e_tests/test_senate.py

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import asyncio
1111
import json
12+
1213
from .utils import call_add_proposal
1314

1415

@@ -104,7 +105,6 @@ def test_senate(local_chain, wallet_setup):
104105
"--verbose",
105106
],
106107
)
107-
print(">>>", proposals.stdout, proposals.stderr)
108108
proposals_output = proposals.stdout.splitlines()[9].split()
109109

110110
# Assert the hash is of correct format
@@ -114,7 +114,7 @@ def test_senate(local_chain, wallet_setup):
114114
# 0 Ayes for the proposal
115115
assert proposals_output[2] == "0"
116116

117-
# 0 Nayes for the proposal
117+
# 0 Nays for the proposal
118118
assert proposals_output[4] == "0"
119119

120120
# Assert initial threshold is 3
@@ -123,15 +123,16 @@ def test_senate(local_chain, wallet_setup):
123123
json_proposals = exec_command_bob(
124124
command="sudo",
125125
sub_command="proposals",
126-
extra_args=[
127-
"--chain",
128-
"ws://127.0.0.1:9945",
129-
"--json-output"
130-
]
126+
extra_args=["--chain", "ws://127.0.0.1:9945", "--json-output"],
131127
)
132-
json_proposals_outout = json.loads(json_proposals.stdout)
128+
json_proposals_output = json.loads(json_proposals.stdout)
133129

134-
assert False, json_proposals_outout
130+
assert len(json_proposals_output) == 1
131+
assert json_proposals_output[0]["threshold"] == 3
132+
assert json_proposals_output[0]["ayes"] == 0
133+
assert json_proposals_output[0]["nays"] == 0
134+
assert json_proposals_output[0]["votes"] == {}
135+
assert json_proposals_output[0]["call_data"] == "System.remark(remark: (0,))"
135136

136137
# Vote on the proposal by Bob (vote aye)
137138
vote_aye = exec_command_bob(
@@ -176,6 +177,26 @@ def test_senate(local_chain, wallet_setup):
176177
# Nay votes remain 0
177178
assert proposals_after_aye_output[4] == "0"
178179

180+
proposals_after_aye_json = exec_command_bob(
181+
command="sudo",
182+
sub_command="proposals",
183+
extra_args=[
184+
"--chain",
185+
"ws://127.0.0.1:9945",
186+
"--json-output",
187+
],
188+
)
189+
proposals_after_aye_json_output = json.loads(proposals_after_aye_json.stdout)
190+
assert len(proposals_after_aye_json_output) == 1
191+
assert proposals_after_aye_json_output[0]["threshold"] == 3
192+
assert proposals_after_aye_json_output[0]["ayes"] == 1
193+
assert proposals_after_aye_json_output[0]["nays"] == 0
194+
assert len(proposals_after_aye_json_output[0]["votes"]) == 1
195+
assert proposals_after_aye_json_output[0]["votes"][keypair_bob.ss58_address] is True
196+
assert (
197+
proposals_after_aye_json_output[0]["call_data"] == "System.remark(remark: (0,))"
198+
)
199+
179200
# Register Alice to the root network (0)
180201
# Registering to root automatically makes you a senator if eligible
181202
root_register = exec_command_alice(
@@ -245,4 +266,20 @@ def test_senate(local_chain, wallet_setup):
245266
# Assert vote casted as Nay
246267
assert proposals_after_nay_output[10].split()[1] == "Nay"
247268

269+
proposals_after_nay_json = exec_command_bob(
270+
command="sudo",
271+
sub_command="proposals",
272+
extra_args=[
273+
"--chain",
274+
"ws://127.0.0.1:9945",
275+
"--json-output",
276+
],
277+
)
278+
proposals_after_nay_json_output = json.loads(proposals_after_nay_json.stdout)
279+
assert len(proposals_after_nay_json_output) == 1
280+
assert proposals_after_nay_json_output[0]["nays"] == 1
281+
assert (
282+
proposals_after_nay_json_output[0]["votes"][keypair_alice.ss58_address] is False
283+
)
284+
248285
print("✅ Passed senate commands")

tests/e2e_tests/test_staking_sudo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def test_staking(local_chain, wallet_setup):
148148
wallet_alice.name,
149149
"--chain",
150150
"ws://127.0.0.1:9945",
151-
"--json-output"
151+
"--json-output",
152152
],
153153
)
154154

0 commit comments

Comments
 (0)