diff --git a/.github/workflows/e2e-subtensor-tests.yml b/.github/workflows/e2e-subtensor-tests.yml index ab7f71450..1c6251802 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 main + run: git checkout testnet - name: Install Python dependencies run: python3 -m pip install -e . pytest diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index eab80891d..4af28d4ea 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -1426,14 +1426,14 @@ async def sign(wallet: Wallet, message: str, use_hotkey: str): """Sign a message using the provided wallet or hotkey.""" if not use_hotkey: - if not unlock_key(wallet, "coldkey").success: + if not unlock_key(wallet, "cold").success: return False keypair = wallet.coldkey print_verbose( f"Signing using [{COLOR_PALETTE['GENERAL']['COLDKEY']}]coldkey: {wallet.name}" ) else: - if not unlock_key(wallet, "hotkey").success: + if not unlock_key(wallet, "hot").success: return False keypair = wallet.hotkey print_verbose( diff --git a/tests/e2e_tests/test_staking_sudo.py b/tests/e2e_tests/test_staking_sudo.py index abb3fe5d8..6684b1a12 100644 --- a/tests/e2e_tests/test_staking_sudo.py +++ b/tests/e2e_tests/test_staking_sudo.py @@ -47,19 +47,27 @@ def test_staking(local_chain, wallet_setup): extra_args=[ "--wallet-path", wallet_path_alice, - "--wallet-hotkey", - wallet_alice.hotkey_str, "--chain", "ws://127.0.0.1:9945", "--wallet-name", wallet_alice.name, + "--wallet-hotkey", + wallet_alice.hotkey_str, + "--name", + "Test Subnet", + "--repo", + "https://github.com/username/repo", + "--contact", + "alice@opentensor.dev", + "--url", + "https://testsubnet.com", + "--discord", + "alice#1234", + "--description", + "A test subnet for e2e testing", + "--additional-info", + "Created by Alice", "--no-prompt", - "--subnet-name", - "test-subnet", - "--github-repo", - "https://github.com/bittensor/bittensor", - "--subnet-contact", - "test@test.com", ], ) assert f"โœ… Registered subnetwork with netuid: {netuid}" in result.stdout @@ -101,6 +109,9 @@ def test_staking(local_chain, wallet_setup): "ws://127.0.0.1:9945", "--amount", "100", + "--tolerance", + "0.1", + "--partial", "--no-prompt", ], ) @@ -123,7 +134,7 @@ def test_staking(local_chain, wallet_setup): cleaned_stake = [ re.sub(r"\s+", " ", line) for line in show_stake.stdout.splitlines() ] - stake_added = cleaned_stake[9].split()[8] + stake_added = cleaned_stake[8].split("โ”‚")[3].strip().split()[0] assert Balance.from_tao(float(stake_added)) >= Balance.from_tao(100) # Execute remove_stake command and remove all 100 TAO from Alice @@ -143,6 +154,9 @@ def test_staking(local_chain, wallet_setup): "ws://127.0.0.1:9945", "--amount", "100", + "--tolerance", + "0.1", + "--partial", "--no-prompt", ], ) diff --git a/tests/e2e_tests/test_wallet_interactions.py b/tests/e2e_tests/test_wallet_interactions.py index c43efb90b..ad44c5a13 100644 --- a/tests/e2e_tests/test_wallet_interactions.py +++ b/tests/e2e_tests/test_wallet_interactions.py @@ -38,7 +38,7 @@ def test_wallet_overview_inspect(local_chain, wallet_setup): AssertionError: If any of the checks or verifications fail """ print("Testing wallet overview, inspect command ๐Ÿงช") - netuid = 1 + netuid = 2 wallet_path_name = "//Alice" # Create wallet for Alice @@ -55,6 +55,22 @@ def test_wallet_overview_inspect(local_chain, wallet_setup): "ws://127.0.0.1:9945", "--wallet-name", wallet.name, + "--wallet-hotkey", + wallet.hotkey_str, + "--name", + "Test Subnet", + "--repo", + "https://github.com/username/repo", + "--contact", + "test@opentensor.dev", + "--url", + "https://testsubnet.com", + "--discord", + "test#1234", + "--description", + "A test subnet for e2e testing", + "--additional-info", + "Test subnet", "--no-prompt", ], ) @@ -77,26 +93,6 @@ def test_wallet_overview_inspect(local_chain, wallet_setup): # Assert using regex that the subnet is visible in subnets list assert verify_subnet_entry(subnets_list.stdout, netuid, keypair.ss58_address) - # Register Alice in netuid = 1 using her hotkey - register_subnet = exec_command( - command="subnets", - sub_command="register", - extra_args=[ - "--wallet-path", - wallet_path, - "--wallet-name", - wallet.name, - "--hotkey", - wallet.hotkey_str, - "--netuid", - "1", - "--chain", - "ws://127.0.0.1:9945", - "--no-prompt", - ], - ) - assert "โœ… Registered" in register_subnet.stdout - # Check balance of Alice after registering to the subnet wallet_balance = exec_command( command="wallet", @@ -145,31 +141,33 @@ def test_wallet_overview_inspect(local_chain, wallet_setup): axon_active=False, # Axon is not active until we run validator/miner ) - # Execute wallet inspect command - inspect = exec_command( - command="wallet", - sub_command="inspect", - extra_args=[ - "--wallet-path", - wallet_path, - "--wallet-name", - wallet.name, - "--chain", - "ws://127.0.0.1:9945", - ], - ) - - # Assert correct entry is present in wallet inspect - assert validate_wallet_inspect( - inspect.stdout, - coldkey=wallet.name, - balance=Balance.from_tao(balance["free_balance"]), - delegates=None, # We have not delegated anywhere yet - hotkeys_netuid=[ - (1, f"default-{wallet.hotkey.ss58_address}", 0, False) - ], # (netuid, hotkey-display, stake, check_emissions) - ) - print("Passed wallet overview, inspect command โœ…") + # TODO: Re-enable this once inspect is ported over + if False: + # Execute wallet inspect command + inspect = exec_command( + command="wallet", + sub_command="inspect", + extra_args=[ + "--wallet-path", + wallet_path, + "--wallet-name", + wallet.name, + "--chain", + "ws://127.0.0.1:9945", + ], + ) + + # Assert correct entry is present in wallet inspect + assert validate_wallet_inspect( + inspect.stdout, + coldkey=wallet.name, + balance=Balance.from_tao(balance["free_balance"]), + delegates=None, # We have not delegated anywhere yet + hotkeys_netuid=[ + (1, f"default-{wallet.hotkey.ss58_address}", 0, False) + ], # (netuid, hotkey-display, stake, check_emissions) + ) + print("Passed wallet overview command โœ…") def test_wallet_transfer(local_chain, wallet_setup): @@ -353,7 +351,7 @@ def test_wallet_identities(local_chain, wallet_setup): """ print("Testing wallet set-id, get-id, sign command ๐Ÿงช") - netuid = 1 + netuid = 2 wallet_path_alice = "//Alice" # Create wallet for Alice @@ -361,25 +359,6 @@ def test_wallet_identities(local_chain, wallet_setup): wallet_path_alice ) - # Register Alice to the root network (0) - # Either root list neurons + subnet registered can set-id or subnet owners - root_register = exec_command_alice( - command="root", - sub_command="register", - extra_args=[ - "--wallet-path", - wallet_path_alice, - "--network", - "ws://127.0.0.1:9945", - "--wallet-name", - wallet_alice.name, - "--hotkey", - wallet_alice.hotkey_str, - "--no-prompt", - ], - ) - assert "โœ… Registered" in root_register.stdout - # Register a subnet with sudo as Alice result = exec_command_alice( command="subnets", @@ -391,42 +370,36 @@ def test_wallet_identities(local_chain, wallet_setup): "ws://127.0.0.1:9945", "--wallet-name", wallet_alice.name, - "--no-prompt", - ], - ) - assert f"โœ… Registered subnetwork with netuid: {netuid}" in result.stdout - - # Register Alice in netuid = 1 using her hotkey - register_subnet = exec_command_alice( - command="subnets", - sub_command="register", - extra_args=[ - "--wallet-path", - wallet_path_alice, - "--wallet-name", - wallet_alice.name, - "--hotkey", + "--wallet-hotkey", wallet_alice.hotkey_str, - "--netuid", - netuid, - "--chain", - "ws://127.0.0.1:9945", + "--name", + "Test Subnet", + "--repo", + "https://github.com/username/repo", + "--contact", + "alice@opentensor.dev", + "--url", + "https://testsubnet.com", + "--discord", + "alice#1234", + "--description", + "A test subnet for e2e testing", + "--additional-info", + "Created by Alice", "--no-prompt", ], ) - assert "โœ… Registered" in register_subnet.stdout + assert f"โœ… Registered subnetwork with netuid: {netuid}" in result.stdout # Define values for Alice's identity alice_identity = { - "display_name": "Alice", - "legal_name": "Alice OTF", - "web_url": "https://bittensor.com/", - "riot": "MyRiotID", - "email": "alice@opentensor.dev", - "pgp": "D2A1 F4A3 B1D3 5A74 63F0 678E 35E7 041A 22C1 A4FE", - "image_url": "https://bittensor.com/img/dark-Bittensor.svg", - "info": "I am a tester for OTF", - "twitter": "https://x.com/opentensor", + "name": "Alice OTF", + "url": "https://bittensor.com/", + "image": "https://bittensor.com/img/dark-Bittensor.svg", + "discord": "alice#1234", + "description": "I am a tester for OTF", + "additional": "Lead Developer", + "github_repo": "https://github.com/opentensor/bittensor", } # Execute btcli set-identity command @@ -442,25 +415,20 @@ def test_wallet_identities(local_chain, wallet_setup): wallet_alice.name, "--wallet-hotkey", wallet_alice.hotkey_str, - "--display-name", - alice_identity["display_name"], - "--legal-name", - alice_identity["legal_name"], + "--name", + alice_identity["name"], "--web-url", - alice_identity["web_url"], - "--riot", - alice_identity["riot"], - "--email", - alice_identity["email"], - "--pgp", - alice_identity["pgp"], - "--image-url", - alice_identity["image_url"], - "--info", - alice_identity["info"], - "-x", - alice_identity["twitter"], - "--validator", + alice_identity["url"], + "--image-url", + alice_identity["image"], + "--discord", + alice_identity["discord"], + "--description", + alice_identity["description"], + "--additional", + alice_identity["additional"], + "--github", + alice_identity["github_repo"], "--no-prompt", ], ) @@ -469,18 +437,18 @@ def test_wallet_identities(local_chain, wallet_setup): assert "โœ… Success!" in set_id.stdout set_id_output = set_id.stdout.splitlines() - assert alice_identity["display_name"] in set_id_output[7] - assert alice_identity["legal_name"] in set_id_output[8] - assert alice_identity["web_url"] in set_id_output[9] - assert alice_identity["riot"] in set_id_output[10] - assert alice_identity["email"] in set_id_output[11] - assert alice_identity["pgp"] in set_id_output[12] - assert alice_identity["image_url"] in set_id_output[13] - assert alice_identity["twitter"] in set_id_output[14] + assert alice_identity["name"] in set_id_output[6] + assert alice_identity["url"] in set_id_output[7] + assert alice_identity["github_repo"] in set_id_output[8] + assert alice_identity["image"] in set_id_output[9] + assert alice_identity["discord"] in set_id_output[10] + assert alice_identity["description"] in set_id_output[11] + assert alice_identity["additional"] in set_id_output[12] + # TODO: Currently coldkey + hotkey are the same for test wallets. # Maybe we can add a new key to help in distinguishing - assert wallet_alice.hotkey.ss58_address in set_id_output[5] + assert wallet_alice.coldkeypub.ss58_address in set_id_output[5] # Execute btcli get-identity using hotkey get_identity = exec_command_alice( @@ -490,20 +458,20 @@ def test_wallet_identities(local_chain, wallet_setup): "--chain", "ws://127.0.0.1:9945", "--key", - wallet_alice.hotkey.ss58_address, + wallet_alice.coldkeypub.ss58_address, ], ) # Assert all correct values are being fetched for the ID we just set get_identity_output = get_identity.stdout.splitlines() - assert alice_identity["display_name"] in get_identity_output[6] - assert alice_identity["legal_name"] in get_identity_output[7] - assert alice_identity["web_url"] in get_identity_output[8] - assert alice_identity["riot"] in get_identity_output[9] - assert alice_identity["email"] in get_identity_output[10] - assert alice_identity["pgp"] in get_identity_output[11] - assert alice_identity["image_url"] in get_identity_output[12] - assert alice_identity["twitter"] in get_identity_output[13] + assert alice_identity["name"] in get_identity_output[5] + assert alice_identity["url"] in get_identity_output[6] + assert alice_identity["github_repo"] in get_identity_output[7] + assert alice_identity["image"] in get_identity_output[8] + assert alice_identity["discord"] in get_identity_output[9] + assert alice_identity["description"] in get_identity_output[10] + assert alice_identity["additional"] in get_identity_output[11] + # Sign a message using hotkey sign_using_hotkey = exec_command_alice( diff --git a/tests/e2e_tests/utils.py b/tests/e2e_tests/utils.py index ebad8ff46..a568af517 100644 --- a/tests/e2e_tests/utils.py +++ b/tests/e2e_tests/utils.py @@ -74,9 +74,7 @@ def extract_coldkey_balance(text: str, wallet_name: str, coldkey_address: str) - """ pattern = ( rf"{wallet_name}\s+{coldkey_address}\s+" - r"ฯ„([\d,]+\.\d+)\s+" # Free Balance - r"ฯ„([\d,]+\.\d+)\s+" # Staked Balance - r"ฯ„([\d,]+\.\d+)" # Total Balance + r"ฯ„\s*([\d,]+\.\d+)" # Free Balance ) match = re.search(pattern, text) @@ -84,15 +82,11 @@ def extract_coldkey_balance(text: str, wallet_name: str, coldkey_address: str) - if not match: return { "free_balance": 0.0, - "staked_balance": 0.0, - "total_balance": 0.0, } # Return the balances as a dictionary return { "free_balance": float(match.group(1).replace(",", "")), - "staked_balance": float(match.group(2).replace(",", "")), - "total_balance": float(match.group(3).replace(",", "")), } @@ -109,24 +103,11 @@ def verify_subnet_entry(output_text: str, netuid: str, ss58_address: str) -> boo bool: True if the entry is found, False otherwise. """ - pattern = ( - rf"\b{re.escape(str(netuid))}\s*\โ”‚\s*" # NETUID - r"\d+\s*\โ”‚\s*" # N (any number) - r"\d+(?:\.\d+)?\s*[KMB]*\s*\โ”‚\s*" # MAX_N (number with optional decimal and K/M/B suffix) - r"\d+\.\d+%\s*\โ”‚\s*" # EMISSION (percentage) - r"\d+\s*\โ”‚\s*" # TEMPO (any number) - r"ฯ„\d+\.\d+\s*\โ”‚\s*" # RECYCLE (ฯ„ followed by a number) - r"\d+(?:\.\d+)?\s*[KMB]*\s*\โ”‚\s*" # POW (number with optional decimal and K/M/B suffix) - rf"{re.escape(ss58_address)}\b" # SUDO (exact SS58 address) - ) - - # Normalize spaces in the output text - normalized_output = re.sub(r"\s+", " ", output_text) - - # Search for the pattern - match = re.search(pattern, normalized_output) - - return bool(match) + pattern = rf"^\s*{re.escape(str(netuid))}\s*[โ”‚โ”ƒ]" + for line in output_text.splitlines(): + if re.search(pattern, line): + return True + return False def validate_wallet_overview( @@ -148,20 +129,20 @@ def validate_wallet_overview( pattern = rf"{coldkey}\s+" # COLDKEY pattern += rf"{hotkey}\s+" # HOTKEY pattern += rf"{uid}\s+" # UID - pattern += r"True\s+" # ACTIVE - Always True immediately after we register - pattern += r"[\d.]+\s+" # STAKE(ฯ„) + pattern += r"True\s+" # ACTIVE + pattern += r"[\d.]+\s+" # STAKE pattern += r"[\d.]+\s+" # RANK pattern += r"[\d.]+\s+" # TRUST pattern += r"[\d.]+\s+" # CONSENSUS pattern += r"[\d.]+\s+" # INCENTIVE pattern += r"[\d.]+\s+" # DIVIDENDS - pattern += r"\d+\s+" # EMISSION(ฯ) + pattern += r"[\d.]+\s+" # EMISSION pattern += r"[\d.]+\s+" # VTRUST - pattern += r"(?:True|False)?\s*" # VPERMIT (optional) - pattern += r"[\d]+\s+" # UPDATED (any number) + pattern += r"\*?\s*" # VPERMIT (optional *) + pattern += r"[\d]+\s+" # UPDATED pattern += ( r"(?!none)\w+\s+" if axon_active else r"none\s+" - ) # AXON - True if axon is active + ) # AXON pattern += rf"{hotkey_ss58[:10]}\s*" # HOTKEY_SS58 # Search for the pattern in the wallet information