From e88e54ea2eb53d951e3bcfdbb8287d560bb4c269 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 13 Dec 2024 16:46:04 -0800 Subject: [PATCH 1/6] Adds overwrite and updates tests for btwallet3 --- bittensor_cli/cli.py | 30 +++++++++++++++--------- bittensor_cli/src/commands/wallets.py | 20 ++++++++++------ requirements.txt | 2 +- tests/e2e_tests/test_wallet_creations.py | 11 +++++---- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 892d56fa..71d86f97 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -132,15 +132,10 @@ class Options: ss58_address = typer.Option( None, "--ss58", "--ss58-address", help="The SS58 address of the coldkey." ) - overwrite_coldkey = typer.Option( + overwrite = typer.Option( False, - help="Overwrite the old coldkey with the newly generated coldkey.", - prompt=True, - ) - overwrite_hotkey = typer.Option( - False, - help="Overwrite the old hotkey with the newly generated hotkey.", - prompt=True, + "--overwrite/--no-overwrite", + help="Overwrite the existing wallet file with the new one.", ) network = typer.Option( None, @@ -1725,6 +1720,7 @@ def wallet_regen_coldkey( json: Optional[str] = Options.json, json_password: Optional[str] = Options.json_password, use_password: Optional[bool] = Options.use_password, + overwrite: bool = Options.overwrite, quiet: bool = Options.quiet, verbose: bool = Options.verbose, ): @@ -1770,6 +1766,7 @@ def wallet_regen_coldkey( json, json_password, use_password, + overwrite, ) ) @@ -1780,6 +1777,7 @@ def wallet_regen_coldkey_pub( wallet_hotkey: Optional[str] = Options.wallet_hotkey, public_key_hex: Optional[str] = Options.public_hex_key, ss58_address: Optional[str] = Options.ss58_address, + overwrite: bool = Options.overwrite, quiet: bool = Options.quiet, verbose: bool = Options.verbose, ): @@ -1826,7 +1824,7 @@ def wallet_regen_coldkey_pub( rich.print("[red]Error: Invalid SS58 address or public key![/red]") raise typer.Exit() return self._run_command( - wallets.regen_coldkey_pub(wallet, ss58_address, public_key_hex) + wallets.regen_coldkey_pub(wallet, ss58_address, public_key_hex, overwrite) ) def wallet_regen_hotkey( @@ -1842,6 +1840,7 @@ def wallet_regen_hotkey( False, # Overriden to False help="Set to 'True' to protect the generated Bittensor key with a password.", ), + overwrite: bool = Options.overwrite, quiet: bool = Options.quiet, verbose: bool = Options.verbose, ): @@ -1880,6 +1879,7 @@ def wallet_regen_hotkey( json, json_password, use_password, + overwrite, ) ) @@ -1898,6 +1898,7 @@ def wallet_new_hotkey( False, # Overriden to False help="Set to 'True' to protect the generated Bittensor key with a password.", ), + overwrite: bool = Options.overwrite, quiet: bool = Options.quiet, verbose: bool = Options.verbose, ): @@ -1935,7 +1936,9 @@ def wallet_new_hotkey( validate=WV.WALLET, ) n_words = get_n_words(n_words) - return self._run_command(wallets.new_hotkey(wallet, n_words, use_password)) + return self._run_command( + wallets.new_hotkey(wallet, n_words, use_password, overwrite) + ) def wallet_new_coldkey( self, @@ -1949,6 +1952,7 @@ def wallet_new_coldkey( help="The number of words used in the mnemonic. Options: [12, 15, 18, 21, 24]", ), use_password: Optional[bool] = Options.use_password, + overwrite: bool = Options.overwrite, quiet: bool = Options.quiet, verbose: bool = Options.verbose, ): @@ -1985,7 +1989,9 @@ def wallet_new_coldkey( validate=WV.NONE, ) n_words = get_n_words(n_words) - return self._run_command(wallets.new_coldkey(wallet, n_words, use_password)) + return self._run_command( + wallets.new_coldkey(wallet, n_words, use_password, overwrite) + ) def wallet_check_ck_swap( self, @@ -2019,6 +2025,7 @@ def wallet_create_wallet( wallet_hotkey: Optional[str] = Options.wallet_hotkey, n_words: Optional[int] = None, use_password: bool = Options.use_password, + overwrite: bool = Options.overwrite, quiet: bool = Options.quiet, verbose: bool = Options.verbose, ): @@ -2064,6 +2071,7 @@ def wallet_create_wallet( wallet, n_words, use_password, + overwrite, ) ) diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index 9a8b0bfa..d49c03e2 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -69,6 +69,7 @@ async def regen_coldkey( json_path: Optional[str] = None, json_password: Optional[str] = "", use_password: Optional[bool] = True, + overwrite: Optional[bool] = False, ): """Creates a new coldkey under this wallet""" json_str: Optional[str] = None @@ -83,7 +84,7 @@ async def regen_coldkey( seed=seed, json=(json_str, json_password) if all([json_str, json_password]) else None, use_password=use_password, - overwrite=False, + overwrite=overwrite, ) if isinstance(new_wallet, Wallet): @@ -101,13 +102,14 @@ async def regen_coldkey_pub( wallet: Wallet, ss58_address: str, public_key_hex: str, + overwrite: Optional[bool] = False, ): """Creates a new coldkeypub under this wallet.""" try: new_coldkeypub = wallet.regenerate_coldkeypub( ss58_address=ss58_address, public_key=public_key_hex, - overwrite=False, + overwrite=overwrite, ) if isinstance(new_coldkeypub, Wallet): console.print( @@ -125,6 +127,7 @@ async def regen_hotkey( json_path: Optional[str], json_password: Optional[str] = "", use_password: Optional[bool] = False, + overwrite: Optional[bool] = False, ): """Creates a new hotkey under this wallet.""" json_str: Optional[str] = None @@ -141,7 +144,7 @@ async def regen_hotkey( seed=seed, json=(json_str, json_password) if all([json_str, json_password]) else None, use_password=use_password, - overwrite=False, + overwrite=overwrite, ) if isinstance(new_hotkey, Wallet): console.print( @@ -158,13 +161,14 @@ async def new_hotkey( wallet: Wallet, n_words: int, use_password: bool, + overwrite: Optional[bool] = False, ): """Creates a new hotkey under this wallet.""" try: wallet.create_new_hotkey( n_words=n_words, use_password=use_password, - overwrite=False, + overwrite=overwrite, ) except KeyFileError: print_error("KeyFileError: File is not writable") @@ -174,13 +178,14 @@ async def new_coldkey( wallet: Wallet, n_words: int, use_password: bool, + overwrite: Optional[bool] = False, ): """Creates a new coldkey under this wallet.""" try: wallet.create_new_coldkey( n_words=n_words, use_password=use_password, - overwrite=False, + overwrite=overwrite, ) except KeyFileError: print_error("KeyFileError: File is not writable") @@ -190,13 +195,14 @@ async def wallet_create( wallet: Wallet, n_words: int = 12, use_password: bool = True, + overwrite: Optional[bool] = False, ): """Creates a new wallet.""" try: wallet.create_new_coldkey( n_words=n_words, use_password=use_password, - overwrite=False, + overwrite=overwrite, ) except KeyFileError: print_error("KeyFileError: File is not writable") @@ -205,7 +211,7 @@ async def wallet_create( wallet.create_new_hotkey( n_words=n_words, use_password=False, - overwrite=False, + overwrite=overwrite, ) except KeyFileError: print_error("KeyFileError: File is not writable") diff --git a/requirements.txt b/requirements.txt index 4aa89c36..0a6f921c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,5 +16,5 @@ scalecodec==1.2.11 substrate-interface~=1.7.9 typer~=0.12 websockets>=14.1 -bittensor-wallet>=2.1.3 +bittensor-wallet>=3.0.0 bt-decode==0.4.0 \ No newline at end of file diff --git a/tests/e2e_tests/test_wallet_creations.py b/tests/e2e_tests/test_wallet_creations.py index 23b1e18f..7490a480 100644 --- a/tests/e2e_tests/test_wallet_creations.py +++ b/tests/e2e_tests/test_wallet_creations.py @@ -304,7 +304,7 @@ def test_wallet_creations(wallet_setup): assert wallet_status, message -def test_wallet_regen(wallet_setup): +def test_wallet_regen(wallet_setup, capfd): """ Test the regeneration of coldkeys, hotkeys, and coldkeypub files using mnemonics or ss58 address. @@ -342,7 +342,8 @@ def test_wallet_regen(wallet_setup): # Verify the command has output, as expected assert result.stdout is not None - mnemonics = extract_mnemonics_from_commands(result.stdout) + captured = capfd.readouterr() + mnemonics = extract_mnemonics_from_commands(captured.out) wallet_status, message = verify_wallet_dir( wallet_path, @@ -372,8 +373,8 @@ def test_wallet_regen(wallet_setup): "--mnemonic", mnemonics["coldkey"], "--no-use-password", + "--overwrite" ], - inputs=["y", "y"], ) # Wait a bit to ensure file system updates modification time @@ -412,8 +413,8 @@ def test_wallet_regen(wallet_setup): wallet_path, "--ss58-address", ss58_address, + "--overwrite" ], - inputs=["y"], ) # Wait a bit to ensure file system updates modification time @@ -447,8 +448,8 @@ def test_wallet_regen(wallet_setup): "--mnemonic", mnemonics["hotkey"], "--no-use-password", + "--overwrite", ], - inputs=["y"], ) # Wait a bit to ensure file system updates modification time From 12aab4aede7c93d9f9ca5cc75d750a98c53272cc Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 21 Jan 2025 17:15:16 +0200 Subject: [PATCH 2/6] Fix arg order --- bittensor_cli/cli.py | 2 +- bittensor_cli/src/commands/stake/children_hotkeys.py | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 892d56fa..c27f3366 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -2345,8 +2345,8 @@ def pgp_check(s: str): twitter_url, info_, validator_id, - prompt, subnet_netuid, + prompt, ) ) diff --git a/bittensor_cli/src/commands/stake/children_hotkeys.py b/bittensor_cli/src/commands/stake/children_hotkeys.py index fc913faa..66f25d3e 100644 --- a/bittensor_cli/src/commands/stake/children_hotkeys.py +++ b/bittensor_cli/src/commands/stake/children_hotkeys.py @@ -299,11 +299,7 @@ async def get_total_stake_for_hk(hotkey: str, parent: bool = False): params=[hotkey], reuse_block_hash=True, ) - stake = ( - Balance.from_rao(_result) - if _result is not None - else Balance(0) - ) + stake = Balance.from_rao(_result) if _result is not None else Balance(0) if parent: console.print( f"\nYour Hotkey: [bright_magenta]{hotkey}[/bright_magenta] | Total Stake: [dark_orange]{stake}t[/dark_orange]\n", From fdfabcdea16c2311d964b902af9cf744db4e4341 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 23 Jan 2025 10:42:03 -0800 Subject: [PATCH 3/6] Bumps version + changelog. Updates e2e test branch --- .github/workflows/e2e-subtensor-tests.yml | 2 +- CHANGELOG.md | 9 +++++++++ bittensor_cli/__init__.py | 2 +- bittensor_cli/cli.py | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-subtensor-tests.yml b/.github/workflows/e2e-subtensor-tests.yml index 1c625180..ab7f7145 100644 --- a/.github/workflows/e2e-subtensor-tests.yml +++ b/.github/workflows/e2e-subtensor-tests.yml @@ -61,7 +61,7 @@ jobs: - name: Setup subtensor repo working-directory: ${{ github.workspace }}/subtensor - run: git checkout testnet + run: git checkout main - name: Install Python dependencies run: python3 -m pip install -e . pytest diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b1c06a5..50cef614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 8.4.3 /2025-01-23 + +## What's Changed +* Removes the `.value` checks as we no longer use SCALE objects. by @thewhaleking in https://github.com/opentensor/btcli/pull/270 +* Backmerge main to staging 842 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/273 +* Fix arg order for set-identity by @thewhaleking in https://github.com/opentensor/btcli/pull/282 + +**Full Changelog**: https://github.com/opentensor/btcli/compare/v8.4.2...v8.4.3 + ## 8.4.2 /2024-12-12 ## What's Changed diff --git a/bittensor_cli/__init__.py b/bittensor_cli/__init__.py index a61da5cd..3c2718ba 100644 --- a/bittensor_cli/__init__.py +++ b/bittensor_cli/__init__.py @@ -18,6 +18,6 @@ from .cli import CLIManager -__version__ = "8.4.2" +__version__ = "8.4.3" __all__ = ["CLIManager", "__version__"] diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index eeb5e7cf..49d6383b 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -58,7 +58,7 @@ class GitError(Exception): pass -__version__ = "8.4.2" +__version__ = "8.4.3" _core_version = re.match(r"^\d+\.\d+\.\d+", __version__).group(0) From b984011857baa9d3bb0fd77850a149fa785721ee Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 23 Jan 2025 10:44:46 -0800 Subject: [PATCH 4/6] Updates changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50cef614..e21eb135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,6 @@ ## 8.4.3 /2025-01-23 ## What's Changed -* Removes the `.value` checks as we no longer use SCALE objects. by @thewhaleking in https://github.com/opentensor/btcli/pull/270 * Backmerge main to staging 842 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/273 * Fix arg order for set-identity by @thewhaleking in https://github.com/opentensor/btcli/pull/282 From 3d4cf23851ec53cb0d25ad9d88ba7ee1daf8f1a4 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 23 Jan 2025 13:21:45 -0800 Subject: [PATCH 5/6] Updates e2e test branch for subtensor --- .github/workflows/e2e-subtensor-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-subtensor-tests.yml b/.github/workflows/e2e-subtensor-tests.yml index 1c625180..ab7f7145 100644 --- a/.github/workflows/e2e-subtensor-tests.yml +++ b/.github/workflows/e2e-subtensor-tests.yml @@ -61,7 +61,7 @@ jobs: - name: Setup subtensor repo working-directory: ${{ github.workspace }}/subtensor - run: git checkout testnet + run: git checkout main - name: Install Python dependencies run: python3 -m pip install -e . pytest From 9a18258f62f8418ce63b2c6aa7d6eae91eded30e Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 23 Jan 2025 14:16:28 -0800 Subject: [PATCH 6/6] Updates changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e21eb135..7fc63805 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## What's Changed * Backmerge main to staging 842 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/273 * Fix arg order for set-identity by @thewhaleking in https://github.com/opentensor/btcli/pull/282 +* Adds updates to btwallet3, adds overwrite flag and updates tests by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/275 **Full Changelog**: https://github.com/opentensor/btcli/compare/v8.4.2...v8.4.3