Skip to content

Conversation

@leonace924
Copy link
Contributor

@leonace924 leonace924 commented Dec 22, 2025

Summary

Refactors stake child set to be simpler and more consistent, adds a parent hotkey override in the CLI, and adds e2e coverage.

Changes

  • set_children refactor: Simplified bittensor_cli/src/commands/stake/children_hotkeys.py:set_children() into a single loop over target netuids (dict_output keyed by netuid).
  • Parent hotkey override: Added --parent-hotkey to:
    • btcli stake child set and plumbed it through to children_hotkeys.set_children(..., hotkey=...) .
  • Proportions guardrail: Added a check in set_children to reject when (\sum proportions > 1.0) (prints an error; when --json-output is set, returns a JSON error payload).
  • E2E tests: Added CLI-driven tests for set_children to tests/e2e_tests/test_children_hotkeys.py:
    • test_set_children
    • test_set_children_multiple_proportions

Before vs After

Before:

  • Complex branching for single vs multi-netuid cases.
  • Hardcoded parent hotkey (always derived from wallet).
  • Inconsistent output patterns across code paths.

After:

  • Single loop over computed netuids with consistent dict_output structure.
  • Optional hotkey parameter (CLI: --parent-hotkey) to manage children for a different parent hotkey SS58.
  • Proportions sum guard with consistent console + JSON output.

Test Coverage

Added 7 comprehensive e2e tests in tests/e2e_tests/test_children_hotkeys.py:

stake child get Tests:

  1. test_get_children_json_output - Tests getting children with --json-output flag, verifies JSON structure and validates response format
  2. test_get_children_non_json_output - Tests getting children without JSON flag, verifies table format output

stake child set Tests:

  1. test_set_children_single_child - Tests setting a single child hotkey with 50% proportion, verifies completion_block and set_block in response
  2. test_set_children_multiple_proportions - Tests setting multiple children (Bob 30%, Charlie 40%) with different proportions, verifies both are set correctly

Test Commands Verified

Added e2e tests in tests/e2e_tests/test_children_hotkeys.py:

  • btcli stake child get --netuid <netuid>
  • btcli stake child get --all-netuids
  • btcli stake child set --children <address> --proportions <proportion> --netuid <netuid>
  • btcli stake child set with multiple children and proportions

Files Changed

  • bittensor_cli/src/commands/stake/children_hotkeys.py
  • bittensor_cli/cli.py
  • tests/e2e_tests/test_children_hotkeys.py

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

@leonace924
Copy link
Contributor Author

@thewhaleking would you review my updates for set_children as we discussed?
I refactored the code and add e2e testing

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.

tests are failing

@leonace924
Copy link
Contributor Author

Hi @ibraheem-abe would you review my test for test_set_children_multiple_proportions?
I tried to follow your latest test update but I am failing at that function...

@leonace924
Copy link
Contributor Author

@thewhaleking I fixed the conflict and this is ready for review

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.

2 participants