#!/usr/bin/env python3 """ CLI Structure Test Script This script tests that the multi-chain CLI commands are properly structured and available, even if the daemon doesn't have multi-chain support yet. """ import subprocess import json import sys from pathlib import Path def run_cli_command(command, check=True, timeout=30): """Run a CLI command and return the result""" try: # Use the aitbc command from the installed package full_command = f"aitbc {command}" result = subprocess.run( full_command, shell=True, capture_output=True, text=True, timeout=timeout, check=check ) return result.stdout, result.stderr, result.returncode except subprocess.TimeoutExpired: return "", "Command timed out", 1 except subprocess.CalledProcessError as e: return e.stdout, e.stderr, e.returncode def test_cli_help(): """Test that CLI help works""" print("šŸ” Testing CLI help...") stdout, stderr, code = run_cli_command("--help") if code == 0 and "AITBC" in stdout: print("āœ… CLI help works") return True else: print("āŒ CLI help failed") return False def test_wallet_help(): """Test that wallet help works""" print("\nšŸ” Testing wallet help...") stdout, stderr, code = run_cli_command("wallet --help") if code == 0 and "chain" in stdout and "create-in-chain" in stdout: print("āœ… Wallet help shows multi-chain commands") return True else: print("āŒ Wallet help missing multi-chain commands") return False def test_chain_help(): """Test that chain help works""" print("\nšŸ” Testing chain help...") stdout, stderr, code = run_cli_command("wallet chain --help") expected_commands = ["list", "create", "status", "wallets", "info", "balance", "migrate"] found_commands = [] if code == 0: for cmd in expected_commands: if cmd in stdout: found_commands.append(cmd) if len(found_commands) >= len(expected_commands) - 1: # Allow for minor differences print(f"āœ… Chain help shows {len(found_commands)}/{len(expected_commands)} expected commands") print(f" Found: {', '.join(found_commands)}") return True else: print(f"āŒ Chain help missing commands. Found: {found_commands}") return False def test_chain_commands_exist(): """Test that chain commands exist (even if they fail)""" print("\nšŸ” Testing chain commands exist...") commands = [ "wallet chain list", "wallet chain status", "wallet chain create test-chain 'Test Chain' http://localhost:8099 test-key", "wallet chain wallets ait-devnet", "wallet chain info ait-devnet test-wallet", "wallet chain balance ait-devnet test-wallet", "wallet chain migrate ait-devnet ait-testnet test-wallet" ] success_count = 0 for cmd in commands: stdout, stderr, code = run_cli_command(cmd, check=False) # We expect commands to exist (not show "No such command") even if they fail if "No such command" not in stderr and "Try 'aitbc --help'" not in stderr: success_count += 1 print(f" āœ… {cmd.split()[2]} command exists") else: print(f" āŒ {cmd.split()[2]} command doesn't exist") print(f"āœ… {success_count}/{len(commands)} chain commands exist") return success_count >= len(commands) - 1 # Allow for one failure def test_create_in_chain_command(): """Test that create-in-chain command exists""" print("\nšŸ” Testing create-in-chain command...") stdout, stderr, code = run_cli_command("wallet create-in-chain --help", check=False) if "Create a wallet in a specific chain" in stdout or "chain_id" in stdout: print("āœ… create-in-chain command exists") return True else: print("āŒ create-in-chain command doesn't exist") return False def test_daemon_commands(): """Test daemon commands""" print("\nšŸ” Testing daemon commands...") stdout, stderr, code = run_cli_command("wallet daemon --help") if code == 0 and "status" in stdout and "configure" in stdout: print("āœ… Daemon commands available") return True else: print("āŒ Daemon commands missing") return False def test_daemon_status(): """Test daemon status""" print("\nšŸ” Testing daemon status...") stdout, stderr, code = run_cli_command("wallet daemon status") if code == 0 and ("Wallet daemon is available" in stdout or "status" in stdout.lower()): print("āœ… Daemon status command works") return True else: print("āŒ Daemon status command failed") return False def test_use_daemon_flag(): """Test that --use-daemon flag is recognized""" print("\nšŸ” Testing --use-daemon flag...") # Test with a simple command that should recognize the flag stdout, stderr, code = run_cli_command("wallet --use-daemon --help", check=False) if code == 0 or "use-daemon" in stdout: print("āœ… --use-daemon flag recognized") return True else: print("āŒ --use-daemon flag not recognized") return False def main(): """Run all CLI structure tests""" print("šŸš€ Starting CLI Structure Tests") print("=" * 50) # Test results results = {} # Test basic CLI structure results['cli_help'] = test_cli_help() results['wallet_help'] = test_wallet_help() results['chain_help'] = test_chain_help() results['chain_commands'] = test_chain_commands_exist() results['create_in_chain'] = test_create_in_chain_command() results['daemon_commands'] = test_daemon_commands() results['daemon_status'] = test_daemon_status() results['use_daemon_flag'] = test_use_daemon_flag() # Summary print("\n" + "=" * 50) print("šŸ“Š CLI Structure Test Results:") print("=" * 50) passed = 0 total = len(results) for test_name, result in results.items(): status = "āœ… PASS" if result else "āŒ FAIL" print(f"{test_name.replace('_', ' ').title():<20}: {status}") if result: passed += 1 print(f"\nOverall: {passed}/{total} tests passed") if passed >= total - 1: # Allow for one failure print("šŸŽ‰ CLI structure is working correctly!") print("šŸ’” Note: Multi-chain daemon endpoints may need to be implemented for full functionality.") return True else: print("āš ļø Some CLI structure tests failed.") return False if __name__ == "__main__": success = main() sys.exit(0 if success else 1)