Skip to content

Conversation

@MkDev11
Copy link
Contributor

@MkDev11 MkDev11 commented Dec 10, 2025

feat: Add Proxy List, Reject Commands and Remove --all Flag

Summary

This PR implements the missing proxy commands as outlined in issue #742.

Closes #742

Changes

New Commands

btcli proxy list

Lists all proxies configured for an account by querying the chain's Proxy.Proxies storage.

# List proxies for your wallet
btcli proxy list

# List proxies for a specific address
btcli proxy list --address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY

# JSON output
btcli proxy list --json-output

Output includes:

  • Delegate address
  • Proxy type
  • Delay (in blocks)
  • Total deposit

btcli proxy reject

Rejects a previously announced proxy call by calling the Proxy.reject_announcement extrinsic. This allows the real account (proxied account) to cancel an announced transaction before it can be executed.

btcli proxy reject --delegate 5GDelegate... --call-hash 0x1234abcd

Parameters:

  • --delegate: The SS58 address of the delegate who made the announcement
  • --call-hash: The hash of the announced call to reject

Modified Commands

btcli proxy remove --all

Added --all flag to remove all proxies at once by calling the Proxy.remove_proxies extrinsic.

# Remove a single proxy (existing behavior)
btcli proxy remove --delegate 5GDelegate... --proxy-type Transfer

# Remove ALL proxies at once (new)
btcli proxy remove --all

Note: --all and --delegate are mutually exclusive.

Implementation Details

Files Changed

  • bittensor_cli/cli.py - Added CLI command handlers for proxy_list, proxy_reject, and updated proxy_remove
  • bittensor_cli/src/commands/proxy.py - Added core async functions:
    • list_proxies() - Queries chain storage
    • reject_announcement() - Submits reject_announcement extrinsic
    • remove_all_proxies() - Submits remove_proxies extrinsic

Substrate Proxy Pallet Extrinsics Used

Command Extrinsic Parameters
proxy list Storage query: Proxy.Proxies [address]
proxy reject Proxy.reject_announcement delegate, call_hash
proxy remove --all Proxy.remove_proxies (none)

Testing

Unit Tests Added (18 new tests)

list_proxies tests:

  • test_list_proxies_success - Verifies correct chain query and table display
  • test_list_proxies_json_output - Verifies JSON output format
  • test_list_proxies_empty - Handles empty proxy list gracefully
  • test_list_proxies_error_handling - Handles query errors

remove_all_proxies tests:

  • test_remove_all_proxies_success - Verifies extrinsic composition and success
  • test_remove_all_proxies_with_prompt_declined - User can cancel operation
  • test_remove_all_proxies_unlock_failure - Handles wallet unlock failure

reject_announcement tests:

  • test_reject_announcement_success - Verifies extrinsic composition and success
  • test_reject_announcement_json_output - Verifies JSON output format
  • test_reject_announcement_with_prompt_declined - User can cancel operation
  • test_reject_announcement_failure - Handles extrinsic failure

CLI integration tests:

  • test_proxy_remove_all_and_delegate_mutually_exclusive - Validates flag exclusivity
  • test_proxy_remove_requires_delegate_or_all - Validates required parameters
  • test_proxy_remove_with_all_flag_calls_remove_all_proxies - Verifies correct function called
  • test_proxy_remove_with_delegate_calls_remove_proxy - Verifies existing behavior preserved
  • test_proxy_list_with_address - Verifies address parameter handling
  • test_proxy_list_without_address_uses_wallet - Verifies wallet fallback
  • test_proxy_reject_calls_reject_announcement - Verifies correct function called

Running Tests

# Run all new proxy tests
python -m pytest tests/unit_tests/test_cli.py -v -k "list_proxies or remove_all or reject_announcement or proxy_remove or proxy_list or proxy_reject"

Lint Check

ruff check bittensor_cli/src/commands/proxy.py tests/unit_tests/test_cli.py
# All checks passed!

Checklist

  • Implements proxy list command
  • Implements proxy reject command
  • Implements proxy remove --all flag
  • All commands support --json-output
  • All commands support --no-prompt for scripting
  • Comprehensive unit tests added
  • Lint checks pass
  • Follows existing code patterns and style

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

@thewhaleking
Copy link
Contributor

@thewhaleking Can you plz check the PR and give me your feedback?

PRs need to be opened against the staging branch.

@MkDev11 MkDev11 changed the base branch from main to staging December 10, 2025 23:12
Copy link
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good overall. Please just fix that json_output comment. I'll test thoroughly later today, and if it's good will merge.

@MkDev11 MkDev11 requested a review from thewhaleking December 11, 2025 15:48
Copy link
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good overall. just fix the top level imports issue, and this should include e2e test (can be slotted into the other test_proxy.py tests, rather than needing to make a brand-new dedicated test)

@MkDev11
Copy link
Contributor Author

MkDev11 commented Dec 15, 2025

looks good overall. just fix the top level imports issue, and this should include e2e test (can be slotted into the other test_proxy.py tests, rather than needing to make a brand-new dedicated test)

Okay, fixed the issue and included e2e test.

@MkDev11 MkDev11 requested a review from thewhaleking December 15, 2025 13:34
Copy link
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your merge conflict resolution completely overwrites #748

Implements the missing proxy commands as outlined in issue opentensor#742:

- Add 'btcli proxy list' command to query and display all proxies for an account
- Add 'btcli proxy reject' command to reject announced proxy transactions
- Add '--all' flag to 'btcli proxy remove' to remove all proxies at once

All proxy functions properly use confirm_action with decline/quiet parameters
to support the --no flag feature from PR opentensor#748.

Includes comprehensive unit tests (22 tests) covering:
- Success cases, JSON output, error handling
- Prompt declined scenarios, wallet unlock failures
- CLI command routing tests
@MkDev11 MkDev11 force-pushed the feat/proxy-additions-742 branch from 481c0d4 to ca75bab Compare December 17, 2025 18:18
@MkDev11 MkDev11 requested a review from thewhaleking December 17, 2025 21:48
- Add decline parameter for naming consistency
- Pull announcements from ProxyAnnouncements table
- Mark as executed after successful rejection
- Allow delegate to default to wallet's coldkey
- Support interactive selection when multiple announcements exist
- Make list_proxies more robust by normalizing proxy data keys
- Add JSON output for all error paths in proxy_reject CLI
@MkDev11 MkDev11 requested a review from thewhaleking December 18, 2025 18:40
@MkDev11
Copy link
Contributor Author

MkDev11 commented Dec 18, 2025

@thewhaleking I think that the team will likely be mostly off next week, I hope this can be the last PR for now.

Copy link
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failing tests

- Fix test_list_proxies_* tests to mock subtensor.query() instead of
  substrate.query since list_proxies uses the former
- Fix test_reject_announcement_with_prompt_declined to assert False
  instead of None (function returns bool, not None)
- Fix test_proxy_reject_calls_reject_announcement to mock
  ProxyAnnouncements.get_db to avoid sqlite3 database access in CI
@MkDev11 MkDev11 requested a review from thewhaleking December 19, 2025 10:45
Copy link
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had to unresolve a bunch of your resolved comments because you, for some reason I cannot quite determine, have just gone and re-added them back in.

@MkDev11
Copy link
Contributor Author

MkDev11 commented Dec 19, 2025

I've had to unresolve a bunch of your resolved comments because you, for some reason I cannot quite determine, have just gone and re-added them back in.

The imports got re-added inside the test functions during a merge conflict resolution. I've now moved them all to top-level as originally requested. The fix has been pushed and all tests are passing locally.

@MkDev11 MkDev11 requested a review from thewhaleking December 19, 2025 11:23
@MkDev11
Copy link
Contributor Author

MkDev11 commented Dec 19, 2025

All test have passed now. Please let me know the result on your side.

@MkDev11
Copy link
Contributor Author

MkDev11 commented Dec 22, 2025

@thewhaleking Any chance you could review the update? I'd love to get this one wrapped up before the holidays if possible.

@thewhaleking
Copy link
Contributor

@thewhaleking Any chance you could review the update? I'd love to get this one wrapped up before the holidays if possible.

I'll take a look when I get a chance, but it's a very large PR.

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.

Proxy Additions

2 participants