Skip to content

Commit b5cf8ae

Browse files
committed
Test Wallet Creations
1 parent bd81cba commit b5cf8ae

File tree

2 files changed

+83
-7
lines changed

2 files changed

+83
-7
lines changed

bittensor_cli/src/commands/wallets.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ async def regen_coldkey(
144144
use_password=use_password,
145145
overwrite=overwrite,
146146
)
147-
148147
if isinstance(new_wallet, Wallet):
149148
console.print(
150149
"\n✅ [dark_sea_green]Regenerated coldkey successfully!\n",
151-
f"[dark_sea_green]Wallet name: ({new_wallet.name}), path: ({new_wallet.path}), coldkey ss58: ({new_wallet.coldkeypub.ss58_address})",
150+
f"[dark_sea_green]Wallet name: ({new_wallet.name}), "
151+
f"path: ({new_wallet.path}), "
152+
f"coldkey ss58: ({new_wallet.coldkeypub.ss58_address})",
152153
)
153154
if json_output:
154155
json_console.print(
@@ -373,19 +374,23 @@ async def new_coldkey(
373374
"data": {
374375
"name": wallet.name,
375376
"path": wallet.path,
376-
"hotkey": wallet.hotkey_str,
377-
"hotkey_ss58": wallet.hotkey.ss58_address,
378377
"coldkey_ss58": wallet.coldkeypub.ss58_address,
379378
},
380379
"error": "",
381380
}
382381
)
383382
)
384-
except KeyFileError:
383+
except KeyFileError as e:
385384
print_error("KeyFileError: File is not writable")
386385
if json_output:
387386
json_console.print(
388-
'{"success": false, "error": "Keyfile is not writable", "data": null}'
387+
json.dumps(
388+
{
389+
"success": False,
390+
"error": f"Keyfile is not writable: {e}",
391+
"data": None,
392+
}
393+
)
389394
)
390395

391396

tests/e2e_tests/test_wallet_creations.py

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23
import re
34
import time
@@ -195,6 +196,15 @@ def test_wallet_creations(wallet_setup):
195196
)
196197
assert wallet_status, message
197198

199+
json_result = exec_command(
200+
command="wallet",
201+
sub_command="list",
202+
extra_args=["--wallet-path", wallet_path, "--json-output"],
203+
)
204+
json_wallet = json.loads(json_result.stdout)["wallets"][0]
205+
assert json_wallet["ss58_address"] == wallet.coldkey.ss58_address
206+
assert json_wallet["hotkeys"][0]["ss58_address"] == wallet.hotkey.ss58_address
207+
198208
# -----------------------------
199209
# Command 1: <btcli w create>
200210
# -----------------------------
@@ -267,6 +277,27 @@ def test_wallet_creations(wallet_setup):
267277
wallet_status, message = verify_wallet_dir(wallet_path, "new_coldkey")
268278
assert wallet_status, message
269279

280+
json_creation = exec_command(
281+
"wallet",
282+
"new-coldkey",
283+
extra_args=[
284+
"--wallet-name",
285+
"new_json_coldkey",
286+
"--wallet-path",
287+
wallet_path,
288+
"--n-words",
289+
"12",
290+
"--no-use-password",
291+
"--json-output",
292+
],
293+
)
294+
json_creation_output = json.loads(json_creation.stdout)
295+
assert json_creation_output["success"] is True
296+
assert json_creation_output["data"]["name"] == "new_json_coldkey"
297+
assert "coldkey_ss58" in json_creation_output["data"]
298+
assert json_creation_output["error"] == ""
299+
new_json_coldkey_ss58 = json_creation_output["data"]["coldkey_ss58"]
300+
270301
# -----------------------------
271302
# Command 3: <btcli w new_hotkey>
272303
# -----------------------------
@@ -303,6 +334,29 @@ def test_wallet_creations(wallet_setup):
303334
)
304335
assert wallet_status, message
305336

337+
new_hotkey_json = exec_command(
338+
"wallet",
339+
sub_command="new-hotkey",
340+
extra_args=[
341+
"--wallet-name",
342+
"new_json_coldkey",
343+
"--hotkey",
344+
"new_json_hotkey",
345+
"--wallet-path",
346+
wallet_path,
347+
"--n-words",
348+
"12",
349+
"--no-use-password",
350+
"--json-output",
351+
],
352+
)
353+
new_hotkey_json_output = json.loads(new_hotkey_json.stdout)
354+
assert new_hotkey_json_output["success"] is True
355+
assert new_hotkey_json_output["data"]["name"] == "new_json_coldkey"
356+
assert new_hotkey_json_output["data"]["hotkey"] == "new_json_hotkey"
357+
assert new_hotkey_json_output["data"]["coldkey_ss58"] == new_json_coldkey_ss58
358+
assert new_hotkey_json_output["error"] == ""
359+
306360

307361
def test_wallet_regen(wallet_setup, capfd):
308362
"""
@@ -385,7 +439,24 @@ def test_wallet_regen(wallet_setup, capfd):
385439
assert (
386440
initial_coldkey_mod_time != new_coldkey_mod_time
387441
), "Coldkey file was not regenerated as expected"
388-
print("Passed wallet regen_coldkey command ✅")
442+
# Underlying Rust is broken. Will add this in when that is fixed: https://github.com/opentensor/btwallet/issues/118
443+
# json_result = exec_command(
444+
# command="wallet",
445+
# sub_command="regen-coldkey",
446+
# extra_args=[
447+
# "--wallet-name",
448+
# "new_wallet",
449+
# "--hotkey",
450+
# "new_hotkey",
451+
# "--wallet-path",
452+
# wallet_path,
453+
# "--mnemonic",
454+
# mnemonics["coldkey"],
455+
# "--no-use-password",
456+
# "--overwrite",
457+
# "--json-output"
458+
# ],
459+
# )
389460

390461
# -----------------------------
391462
# Command 2: <btcli w regen_coldkeypub>

0 commit comments

Comments
 (0)