Skip to content

Commit c7b89a2

Browse files
committed
Tests added
1 parent bd1319c commit c7b89a2

File tree

2 files changed

+101
-2
lines changed

2 files changed

+101
-2
lines changed

bittensor_cli/src/commands/subnets/subnets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ async def burn_cost(
14391439
if current_burn_cost:
14401440
if json_output:
14411441
json_console.print(
1442-
json.dumps({"burn_cost": current_burn_cost, "error": ""})
1442+
json.dumps({"burn_cost": current_burn_cost.to_dict(), "error": ""})
14431443
)
14441444
else:
14451445
console.print(

tests/e2e_tests/test_staking_sudo.py

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"""
77
Verify commands:
88
9+
* btcli s burn-cost
910
* btcli subnets create
11+
* btcli subnets set-identity
12+
* btcli subnets get-identity
1013
* btcli subnets register
1114
* btcli stake add
1215
* btcli stake remove
@@ -40,6 +43,21 @@ def test_staking(local_chain, wallet_setup):
4043
wallet_path_alice
4144
)
4245

46+
burn_cost = exec_command_alice(
47+
"subnets",
48+
"burn-cost",
49+
extra_args=[
50+
"--network",
51+
"ws://127.0.0.1:9945",
52+
"--json-output",
53+
],
54+
)
55+
burn_cost_output = json.loads(burn_cost.stdout)
56+
expected_burn_cost = Balance.from_tao(1000.0)
57+
assert burn_cost_output["error"] == ""
58+
assert burn_cost_output["burn_cost"]["rao"] == expected_burn_cost.rao
59+
assert burn_cost_output["burn_cost"]["tao"] == expected_burn_cost.tao
60+
4361
# Register a subnet with sudo as Alice
4462
result = exec_command_alice(
4563
command="subnets",
@@ -68,9 +86,12 @@ def test_staking(local_chain, wallet_setup):
6886
"--additional-info",
6987
"Created by Alice",
7088
"--no-prompt",
89+
"--json-output",
7190
],
7291
)
73-
assert f"✅ Registered subnetwork with netuid: {netuid}" in result.stdout
92+
result_output = json.loads(result.stdout)
93+
assert result_output["success"] is True
94+
assert result_output["netuid"] == 2
7495

7596
# Register Alice in netuid = 1 using her hotkey
7697
register_subnet = exec_command_alice(
@@ -92,6 +113,84 @@ def test_staking(local_chain, wallet_setup):
92113
)
93114
assert "✅ Already Registered" in register_subnet.stdout
94115

116+
register_subnet_json = exec_command_alice(
117+
command="subnets",
118+
sub_command="register",
119+
extra_args=[
120+
"--wallet-path",
121+
wallet_path_alice,
122+
"--wallet-name",
123+
wallet_alice.name,
124+
"--hotkey",
125+
wallet_alice.hotkey_str,
126+
"--netuid",
127+
netuid,
128+
"--chain",
129+
"ws://127.0.0.1:9945",
130+
"--no-prompt",
131+
"--json-output",
132+
],
133+
)
134+
register_subnet_json_output = json.loads(register_subnet_json.stdout)
135+
assert register_subnet_json_output["success"] is True
136+
assert register_subnet_json_output["msg"] == "Already registered"
137+
138+
# set identity
139+
set_identity = exec_command_alice(
140+
"subnets",
141+
"set-identity",
142+
extra_args=[
143+
"--wallet-path",
144+
wallet_path_alice,
145+
"--wallet-name",
146+
wallet_alice.name,
147+
"--hotkey",
148+
wallet_alice.hotkey_str,
149+
"--chain",
150+
"ws://127.0.0.1:9945",
151+
"--netuid",
152+
netuid,
153+
"--subnet-name",
154+
sn_name := "Test Subnet",
155+
"--github-repo",
156+
sn_github := "https://github.com/username/repo",
157+
"--subnet-contact",
158+
sn_contact := "[email protected]",
159+
"--subnet-url",
160+
sn_url := "https://testsubnet.com",
161+
"--discord",
162+
sn_discord := "alice#1234",
163+
"--description",
164+
sn_description := "A test subnet for e2e testing",
165+
"--additional-info",
166+
sn_add_info := "Created by Alice",
167+
"--json-output",
168+
"--no-prompt",
169+
],
170+
)
171+
set_identity_output = json.loads(set_identity.stdout)
172+
assert set_identity_output["success"] is True
173+
174+
get_identity = exec_command_alice(
175+
"subnets",
176+
"get-identity",
177+
extra_args=[
178+
"--chain",
179+
"ws://127.0.0.1:9945",
180+
"--netuid",
181+
netuid,
182+
"--json-output",
183+
],
184+
)
185+
get_identity_output = json.loads(get_identity.stdout)
186+
assert get_identity_output["subnet_name"] == sn_name
187+
assert get_identity_output["github_repo"] == sn_github
188+
assert get_identity_output["subnet_contact"] == sn_contact
189+
assert get_identity_output["subnet_url"] == sn_url
190+
assert get_identity_output["discord"] == sn_discord
191+
assert get_identity_output["description"] == sn_description
192+
assert get_identity_output["additional"] == sn_add_info
193+
95194
# Add stake to Alice's hotkey
96195
add_stake = exec_command_alice(
97196
command="stake",

0 commit comments

Comments
 (0)