Skip to content

Commit cb9d160

Browse files
committed
Test Staking
1 parent 512a295 commit cb9d160

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

bittensor_cli/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4501,7 +4501,7 @@ def sudo_get(
45014501
45024502
[green]$[/green] btcli sudo get --netuid 1
45034503
"""
4504-
self.verbosity_handler(quiet, verbose)
4504+
self.verbosity_handler(quiet, verbose, json_output)
45054505
return self._run_command(
45064506
sudo.get_hyperparameters(
45074507
self.initialize_chain(network), netuid, json_output

bittensor_cli/src/commands/stake/list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ def create_table(hotkey_: str, substakes: list[StakeInfo]):
229229
{
230230
"netuid": netuid,
231231
"subnet_name": subnet_name,
232-
"value": tao_value.tao,
233-
"stake_value": stake_value,
232+
"value": tao_value_.tao,
233+
"stake_value": substake_.stake.tao,
234234
"rate": pool.price.tao,
235235
"swap_value": swap_value,
236236
"registered": True if substake_.is_registered else False,

bittensor_cli/src/commands/sudo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ async def get_hyperparameters(
657657
)
658658
if json_output:
659659
json_console.print(json.dumps(dict_out))
660-
console.print(table)
660+
else:
661+
console.print(table)
661662
return True
662663

663664

tests/e2e_tests/test_staking_sudo.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import re
23

34
from bittensor_cli.src.bittensor.balances import Balance
@@ -129,8 +130,10 @@ def test_staking(local_chain, wallet_setup):
129130
wallet_alice.name,
130131
"--chain",
131132
"ws://127.0.0.1:9945",
133+
"--verbose",
132134
],
133135
)
136+
134137
# Assert correct stake is added
135138
cleaned_stake = [
136139
re.sub(r"\s+", " ", line) for line in show_stake.stdout.splitlines()
@@ -151,6 +154,9 @@ def test_staking(local_chain, wallet_setup):
151154
"--json-output",
152155
],
153156
)
157+
show_stake_json_output = json.loads(show_stake_json.stdout)
158+
alice_stake = show_stake_json_output["stake_info"][keypair_alice.ss58_address][0]
159+
assert Balance.from_tao(alice_stake["stake_value"]) > Balance.from_tao(90.0)
154160

155161
# Execute remove_stake command and remove all alpha stakes from Alice
156162
remove_stake = exec_command_alice(
@@ -196,7 +202,24 @@ def test_staking(local_chain, wallet_setup):
196202
max_burn_tao = all_hyperparams[22].split()[3]
197203

198204
# Assert max_burn is 100 TAO from default
199-
assert Balance.from_tao(float(max_burn_tao)) == Balance.from_tao(100)
205+
assert Balance.from_tao(float(max_burn_tao)) == Balance.from_tao(100.0)
206+
207+
hyperparams_json = exec_command_alice(
208+
command="sudo",
209+
sub_command="get",
210+
extra_args=[
211+
"--chain",
212+
"ws://127.0.0.1:9945",
213+
"--netuid",
214+
netuid,
215+
"--json-output",
216+
],
217+
)
218+
hyperparams_json_output = json.loads(hyperparams_json.stdout)
219+
max_burn_tao_from_json = next(
220+
filter(lambda x: x["hyperparameter"] == "max_burn", hyperparams_json_output)
221+
)["value"]
222+
assert Balance.from_rao(max_burn_tao_from_json) == Balance.from_tao(100.0)
200223

201224
# Change max_burn hyperparameter to 10 TAO
202225
change_hyperparams = exec_command_alice(
@@ -241,4 +264,24 @@ def test_staking(local_chain, wallet_setup):
241264

242265
# Assert max_burn is now 10 TAO
243266
assert Balance.from_tao(float(updated_max_burn_tao)) == Balance.from_tao(10)
267+
268+
updated_hyperparams_json = exec_command_alice(
269+
command="sudo",
270+
sub_command="get",
271+
extra_args=[
272+
"--chain",
273+
"ws://127.0.0.1:9945",
274+
"--netuid",
275+
netuid,
276+
"--json-output",
277+
],
278+
)
279+
updated_hyperparams_json_output = json.loads(updated_hyperparams_json.stdout)
280+
max_burn_tao_from_json = next(
281+
filter(
282+
lambda x: x["hyperparameter"] == "max_burn", updated_hyperparams_json_output
283+
)
284+
)["value"]
285+
assert Balance.from_rao(max_burn_tao_from_json) == Balance.from_tao(10.0)
286+
244287
print("✅ Passed staking and sudo commands")

0 commit comments

Comments
 (0)