Skip to content

fix: consistent error handling for regenerate_hotkeypub and regenerate_coldkeypub#181

Open
Nicknamess96 wants to merge 1 commit intoopentensor:stagingfrom
Nicknamess96:fix/hotkeypub-error-handling-and-tests
Open

fix: consistent error handling for regenerate_hotkeypub and regenerate_coldkeypub#181
Nicknamess96 wants to merge 1 commit intoopentensor:stagingfrom
Nicknamess96:fix/hotkeypub-error-handling-and-tests

Conversation

@Nicknamess96
Copy link

Summary

  • regenerate_hotkeypub() and regenerate_coldkeypub() Python bindings now raise ValueError for invalid inputs (matching regenerate_coldkey() behavior) instead of generic KeyFileError
  • Added 6 tests covering edge cases: invalid ss58 address, missing args, public_key parameter, and file-not-found scenarios

Problem

regenerate_coldkey() correctly maps WalletError::InvalidInput and WalletError::KeyGeneration to PyValueError, but regenerate_hotkeypub() and regenerate_coldkeypub() mapped all errors generically to PyKeyFileError. This means callers catching ValueError for input validation would miss errors from these two methods.

Changes

src/python_bindings.rs:

  • regenerate_coldkeypub(): replaced generic .map_err(PyErr::new::<PyKeyFileError, _>) with match on InvalidInput/KeyGenerationPyValueError, other → PyKeyFileError
  • regenerate_hotkeypub(): same fix

tests/test_wallet.py:

  • test_regenerate_hotkeypub_invalid_ss58 — invalid address raises ValueError
  • test_regenerate_hotkeypub_no_args — no ss58 or public_key raises ValueError
  • test_regenerate_coldkeypub_invalid_ss58 — same for coldkeypub
  • test_regenerate_coldkeypub_no_args — same for coldkeypub
  • test_regenerate_hotkeypub_with_public_key — regenerate via public_key works
  • test_hotkeypub_file_not_found — accessing hotkeypub without file raises KeyFileError

Closes #155

…e_coldkeypub

Map InvalidInput and KeyGeneration errors to ValueError (matching
regenerate_coldkey behavior) instead of generic KeyFileError. Add
tests for invalid inputs, missing args, public_key param, and
file-not-found edge cases.

Closes opentensor#155

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@basfroman basfroman added run-bittensor-sdk-tests Runs Bittensor SDK tests. run-bittensor-cli-tests Runs BTCLI tests. labels Feb 27, 2026
@Nicknamess96
Copy link
Author

Friendly ping — this aligns the error handling in regenerate_hotkeypub and regenerate_coldkeypub to be consistent. Ready for review.

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

Labels

run-bittensor-cli-tests Runs BTCLI tests. run-bittensor-sdk-tests Runs Bittensor SDK tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants