Skip to content

Conversation

@leonace924
Copy link
Contributor

@leonace924 leonace924 commented Dec 23, 2025

Summary

This PR adds functionality to remove all proxies associated with an account in a single operation. Previously, users had to remove proxies one by one using the --delegate flag.
Now, users can use the --all flag to remove all proxies at once.

Changes

Core Functionality (bittensor_cli/src/commands/proxy.py)

  • Added remove_proxies() function (lines 312-360):
    • Executes the remove_proxies extrinsic call on the chain
    • Removes all proxies associated with the account in a single transaction
    • Includes proper confirmation prompts with warning messages (requires typing "REMOVE" to confirm)
    • Supports JSON output mode for programmatic use
    • Handles wallet unlocking and error cases gracefully
    • Uses the Proxy.remove_proxies substrate call

CLI Integration (bittensor_cli/cli.py)

  • Enhanced proxy_remove() command (lines 9449-9590):
    • Added --all flag option to remove all proxies
    • Made delegate parameter optional (required only when --all is not used)
    • Added comprehensive validation logic:
      • Ensures either --delegate or --all is provided
      • Validates --delegate is required when --all is not used
      • Provides clear error messages for both regular and JSON output modes
    • Added warning message when --delegate is provided alongside --all flag (delegate is ignored)
    • Updated help text and documentation examples
    • Routes to remove_proxies() when --all flag is used, otherwise uses existing remove_proxy() function
    • Maintains backward compatibility with existing single proxy removal workflow

Features

Single Proxy Removal (Existing Functionality)

btcli proxy remove --delegate 5GDel... --proxy-type Transfer --delay 0

Bulk Proxy Removal (New Functionality)

btcli proxy remove --all

Usage Examples

Remove all proxies with confirmation:

btcli proxy remove --all
# User must type "REMOVE" to confirm

Remove all proxies without prompts:

btcli proxy remove --all --no-prompt

Remove all proxies with JSON output:

btcli proxy remove --all --json-output

Testing

End-to-End Tests (tests/e2e_tests/test_proxy.py)

  1. test_remove_all_proxies() (lines 689-844):

    • Tests removing all proxies using the --all flag
    • Verifies multiple proxies can be added and then removed in bulk
    • Confirms proxies are actually removed by attempting to use them
    • Tests with different proxy types (Transfer, Staking)
  2. test_remove_proxy_validation() (lines 847-924):

    • Tests validation logic for proxy remove command
    • Verifies error handling when neither --delegate nor --all is provided
    • Tests that --all works even when no proxies exist
    • Validates error messages in both regular and JSON output modes
  3. test_remove_proxy() (lines 927-1140):

    • Tests removing a single proxy without --all flag
    • Verifies single proxy removal works correctly
    • Confirms proxy is removed by attempting to use it
    • Ensures backward compatibility

Unit Tests (tests/unit_tests/test_cli.py)

  1. test_proxy_remove_requires_delegate_or_all() (lines 816-843):

    • Tests validation when neither --delegate nor --all is provided
    • Verifies correct error message is displayed
  2. test_proxy_remove_requires_delegate_or_all_json() (lines 846-876):

    • Tests validation with JSON output mode
    • Verifies JSON error response structure
  3. test_proxy_remove_with_all_flag() (lines 879-929):

    • Tests that --all flag correctly calls remove_proxies()
    • Verifies warning message when --delegate is provided with --all
    • Ensures correct function routing

All tests pass successfully and cover both success and failure scenarios, including edge cases.

User Experience Improvements

  • Safety: When using --all flag, users must type "REMOVE" to confirm the destructive operation
  • Validation: Clear error messages when required parameters are missing (supports both regular and JSON output)
  • Flexibility: Users can still remove individual proxies using --delegate flag
  • Warning: Users are warned if they provide --delegate alongside --all flag (delegate is ignored)
  • Consistency: Error handling follows the same patterns as other CLI commands

Implementation Details

Validation Flow

  1. Initial validation: Checks if either --delegate or --all is provided
  2. Route determination:
    • If --all is True → calls remove_proxies()
    • If --delegate is provided → calls remove_proxy()
  3. Secondary validation: When --all is False, ensures --delegate is provided

Error Handling

  • Regular mode: Uses print_error() for user-friendly messages
  • JSON mode: Returns structured JSON with success, message, and extrinsic_identifier fields
  • Consistent error format across all validation paths

Backward Compatibility

This change is fully backward compatible. Existing functionality for removing individual proxies remains unchanged. The --all flag is an additional option that doesn't affect existing workflows. All existing tests continue to pass.

Related Files

  • bittensor_cli/src/commands/proxy.py - Core proxy management functions (added remove_proxies())
  • bittensor_cli/cli.py - CLI command integration (enhanced proxy_remove())
  • tests/e2e_tests/test_proxy.py - Comprehensive end-to-end test suite
  • tests/unit_tests/test_cli.py - Unit tests for CLI validation logic

Screenshot

{5D4F4ACF-3397-4C78-A9BB-4B8009B345E6} {410D3F45-58DD-42E5-8C69-D11F05DEA305}

Contribution by Gittensor, learn more at https://gittensor.io/

@leonace924
Copy link
Contributor Author

leonace924 commented Dec 23, 2025

Hi @thewhaleking , would you review my PR?
This PR is purely for --all option

cc: @ibraheem-abe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant