Skip to content

Commit 6e8048b

Browse files
authored
Merge pull request #275 from opentensor/tests/update-tests-for-btwallet3
Adds overwrite flag and updates tests for btwallet3
2 parents c7b0224 + 3d4cf23 commit 6e8048b

5 files changed

Lines changed: 40 additions & 25 deletions

File tree

.github/workflows/e2e-subtensor-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161

6262
- name: Setup subtensor repo
6363
working-directory: ${{ github.workspace }}/subtensor
64-
run: git checkout testnet
64+
run: git checkout main
6565

6666
- name: Install Python dependencies
6767
run: python3 -m pip install -e . pytest

bittensor_cli/cli.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,10 @@ class Options:
132132
ss58_address = typer.Option(
133133
None, "--ss58", "--ss58-address", help="The SS58 address of the coldkey."
134134
)
135-
overwrite_coldkey = typer.Option(
135+
overwrite = typer.Option(
136136
False,
137-
help="Overwrite the old coldkey with the newly generated coldkey.",
138-
prompt=True,
139-
)
140-
overwrite_hotkey = typer.Option(
141-
False,
142-
help="Overwrite the old hotkey with the newly generated hotkey.",
143-
prompt=True,
137+
"--overwrite/--no-overwrite",
138+
help="Overwrite the existing wallet file with the new one.",
144139
)
145140
network = typer.Option(
146141
None,
@@ -1725,6 +1720,7 @@ def wallet_regen_coldkey(
17251720
json: Optional[str] = Options.json,
17261721
json_password: Optional[str] = Options.json_password,
17271722
use_password: Optional[bool] = Options.use_password,
1723+
overwrite: bool = Options.overwrite,
17281724
quiet: bool = Options.quiet,
17291725
verbose: bool = Options.verbose,
17301726
):
@@ -1770,6 +1766,7 @@ def wallet_regen_coldkey(
17701766
json,
17711767
json_password,
17721768
use_password,
1769+
overwrite,
17731770
)
17741771
)
17751772

@@ -1780,6 +1777,7 @@ def wallet_regen_coldkey_pub(
17801777
wallet_hotkey: Optional[str] = Options.wallet_hotkey,
17811778
public_key_hex: Optional[str] = Options.public_hex_key,
17821779
ss58_address: Optional[str] = Options.ss58_address,
1780+
overwrite: bool = Options.overwrite,
17831781
quiet: bool = Options.quiet,
17841782
verbose: bool = Options.verbose,
17851783
):
@@ -1826,7 +1824,7 @@ def wallet_regen_coldkey_pub(
18261824
rich.print("[red]Error: Invalid SS58 address or public key![/red]")
18271825
raise typer.Exit()
18281826
return self._run_command(
1829-
wallets.regen_coldkey_pub(wallet, ss58_address, public_key_hex)
1827+
wallets.regen_coldkey_pub(wallet, ss58_address, public_key_hex, overwrite)
18301828
)
18311829

18321830
def wallet_regen_hotkey(
@@ -1842,6 +1840,7 @@ def wallet_regen_hotkey(
18421840
False, # Overriden to False
18431841
help="Set to 'True' to protect the generated Bittensor key with a password.",
18441842
),
1843+
overwrite: bool = Options.overwrite,
18451844
quiet: bool = Options.quiet,
18461845
verbose: bool = Options.verbose,
18471846
):
@@ -1880,6 +1879,7 @@ def wallet_regen_hotkey(
18801879
json,
18811880
json_password,
18821881
use_password,
1882+
overwrite,
18831883
)
18841884
)
18851885

@@ -1898,6 +1898,7 @@ def wallet_new_hotkey(
18981898
False, # Overriden to False
18991899
help="Set to 'True' to protect the generated Bittensor key with a password.",
19001900
),
1901+
overwrite: bool = Options.overwrite,
19011902
quiet: bool = Options.quiet,
19021903
verbose: bool = Options.verbose,
19031904
):
@@ -1935,7 +1936,9 @@ def wallet_new_hotkey(
19351936
validate=WV.WALLET,
19361937
)
19371938
n_words = get_n_words(n_words)
1938-
return self._run_command(wallets.new_hotkey(wallet, n_words, use_password))
1939+
return self._run_command(
1940+
wallets.new_hotkey(wallet, n_words, use_password, overwrite)
1941+
)
19391942

19401943
def wallet_new_coldkey(
19411944
self,
@@ -1949,6 +1952,7 @@ def wallet_new_coldkey(
19491952
help="The number of words used in the mnemonic. Options: [12, 15, 18, 21, 24]",
19501953
),
19511954
use_password: Optional[bool] = Options.use_password,
1955+
overwrite: bool = Options.overwrite,
19521956
quiet: bool = Options.quiet,
19531957
verbose: bool = Options.verbose,
19541958
):
@@ -1985,7 +1989,9 @@ def wallet_new_coldkey(
19851989
validate=WV.NONE,
19861990
)
19871991
n_words = get_n_words(n_words)
1988-
return self._run_command(wallets.new_coldkey(wallet, n_words, use_password))
1992+
return self._run_command(
1993+
wallets.new_coldkey(wallet, n_words, use_password, overwrite)
1994+
)
19891995

19901996
def wallet_check_ck_swap(
19911997
self,
@@ -2019,6 +2025,7 @@ def wallet_create_wallet(
20192025
wallet_hotkey: Optional[str] = Options.wallet_hotkey,
20202026
n_words: Optional[int] = None,
20212027
use_password: bool = Options.use_password,
2028+
overwrite: bool = Options.overwrite,
20222029
quiet: bool = Options.quiet,
20232030
verbose: bool = Options.verbose,
20242031
):
@@ -2064,6 +2071,7 @@ def wallet_create_wallet(
20642071
wallet,
20652072
n_words,
20662073
use_password,
2074+
overwrite,
20672075
)
20682076
)
20692077

bittensor_cli/src/commands/wallets.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ async def regen_coldkey(
6969
json_path: Optional[str] = None,
7070
json_password: Optional[str] = "",
7171
use_password: Optional[bool] = True,
72+
overwrite: Optional[bool] = False,
7273
):
7374
"""Creates a new coldkey under this wallet"""
7475
json_str: Optional[str] = None
@@ -83,7 +84,7 @@ async def regen_coldkey(
8384
seed=seed,
8485
json=(json_str, json_password) if all([json_str, json_password]) else None,
8586
use_password=use_password,
86-
overwrite=False,
87+
overwrite=overwrite,
8788
)
8889

8990
if isinstance(new_wallet, Wallet):
@@ -101,13 +102,14 @@ async def regen_coldkey_pub(
101102
wallet: Wallet,
102103
ss58_address: str,
103104
public_key_hex: str,
105+
overwrite: Optional[bool] = False,
104106
):
105107
"""Creates a new coldkeypub under this wallet."""
106108
try:
107109
new_coldkeypub = wallet.regenerate_coldkeypub(
108110
ss58_address=ss58_address,
109111
public_key=public_key_hex,
110-
overwrite=False,
112+
overwrite=overwrite,
111113
)
112114
if isinstance(new_coldkeypub, Wallet):
113115
console.print(
@@ -125,6 +127,7 @@ async def regen_hotkey(
125127
json_path: Optional[str],
126128
json_password: Optional[str] = "",
127129
use_password: Optional[bool] = False,
130+
overwrite: Optional[bool] = False,
128131
):
129132
"""Creates a new hotkey under this wallet."""
130133
json_str: Optional[str] = None
@@ -141,7 +144,7 @@ async def regen_hotkey(
141144
seed=seed,
142145
json=(json_str, json_password) if all([json_str, json_password]) else None,
143146
use_password=use_password,
144-
overwrite=False,
147+
overwrite=overwrite,
145148
)
146149
if isinstance(new_hotkey, Wallet):
147150
console.print(
@@ -158,13 +161,14 @@ async def new_hotkey(
158161
wallet: Wallet,
159162
n_words: int,
160163
use_password: bool,
164+
overwrite: Optional[bool] = False,
161165
):
162166
"""Creates a new hotkey under this wallet."""
163167
try:
164168
wallet.create_new_hotkey(
165169
n_words=n_words,
166170
use_password=use_password,
167-
overwrite=False,
171+
overwrite=overwrite,
168172
)
169173
except KeyFileError:
170174
print_error("KeyFileError: File is not writable")
@@ -174,13 +178,14 @@ async def new_coldkey(
174178
wallet: Wallet,
175179
n_words: int,
176180
use_password: bool,
181+
overwrite: Optional[bool] = False,
177182
):
178183
"""Creates a new coldkey under this wallet."""
179184
try:
180185
wallet.create_new_coldkey(
181186
n_words=n_words,
182187
use_password=use_password,
183-
overwrite=False,
188+
overwrite=overwrite,
184189
)
185190
except KeyFileError:
186191
print_error("KeyFileError: File is not writable")
@@ -190,13 +195,14 @@ async def wallet_create(
190195
wallet: Wallet,
191196
n_words: int = 12,
192197
use_password: bool = True,
198+
overwrite: Optional[bool] = False,
193199
):
194200
"""Creates a new wallet."""
195201
try:
196202
wallet.create_new_coldkey(
197203
n_words=n_words,
198204
use_password=use_password,
199-
overwrite=False,
205+
overwrite=overwrite,
200206
)
201207
except KeyFileError:
202208
print_error("KeyFileError: File is not writable")
@@ -205,7 +211,7 @@ async def wallet_create(
205211
wallet.create_new_hotkey(
206212
n_words=n_words,
207213
use_password=False,
208-
overwrite=False,
214+
overwrite=overwrite,
209215
)
210216
except KeyFileError:
211217
print_error("KeyFileError: File is not writable")

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ scalecodec==1.2.11
1616
substrate-interface~=1.7.9
1717
typer~=0.12
1818
websockets>=14.1
19-
bittensor-wallet>=2.1.3
19+
bittensor-wallet>=3.0.0
2020
bt-decode==0.4.0

tests/e2e_tests/test_wallet_creations.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_wallet_creations(wallet_setup):
304304
assert wallet_status, message
305305

306306

307-
def test_wallet_regen(wallet_setup):
307+
def test_wallet_regen(wallet_setup, capfd):
308308
"""
309309
Test the regeneration of coldkeys, hotkeys, and coldkeypub files using mnemonics or ss58 address.
310310
@@ -342,7 +342,8 @@ def test_wallet_regen(wallet_setup):
342342
# Verify the command has output, as expected
343343
assert result.stdout is not None
344344

345-
mnemonics = extract_mnemonics_from_commands(result.stdout)
345+
captured = capfd.readouterr()
346+
mnemonics = extract_mnemonics_from_commands(captured.out)
346347

347348
wallet_status, message = verify_wallet_dir(
348349
wallet_path,
@@ -372,8 +373,8 @@ def test_wallet_regen(wallet_setup):
372373
"--mnemonic",
373374
mnemonics["coldkey"],
374375
"--no-use-password",
376+
"--overwrite"
375377
],
376-
inputs=["y", "y"],
377378
)
378379

379380
# Wait a bit to ensure file system updates modification time
@@ -412,8 +413,8 @@ def test_wallet_regen(wallet_setup):
412413
wallet_path,
413414
"--ss58-address",
414415
ss58_address,
416+
"--overwrite"
415417
],
416-
inputs=["y"],
417418
)
418419

419420
# Wait a bit to ensure file system updates modification time
@@ -447,8 +448,8 @@ def test_wallet_regen(wallet_setup):
447448
"--mnemonic",
448449
mnemonics["hotkey"],
449450
"--no-use-password",
451+
"--overwrite",
450452
],
451-
inputs=["y"],
452453
)
453454

454455
# Wait a bit to ensure file system updates modification time

0 commit comments

Comments
 (0)