Skip to content

Conversation

@MonaaEid
Copy link
Contributor

Description:
This pull request removes the deprecated in_tinybars parameter from the Hbar class and updates related code and tests to use the unit parameter instead. It also deprecates the set_amount_in_tinybars method in favor of a more explicit approach, and updates documentation and warnings accordingly.

Deprecation and Removal of in_tinybars:

  • Removed the deprecated in_tinybars parameter from the Hbar class constructor and all related logic in src/hiero_sdk_python/hbar.py. All code should now use the unit parameter to specify tinybars.
  • Updated the from_tinybars class method in Hbar to use the unit parameter instead of in_tinybars.

Test Updates:

  • Updated unit tests in tests/unit/hbar_test.py to remove usage of in_tinybars and switch to the unit parameter.

Deprecation of Tinybar Setter Method:

  • Deprecated the set_amount_in_tinybars method in CustomFixedFee, adding a warning and updating the docstring to recommend using set_hbar_amount(Hbar.from_tinybars(amount)) instead.

Related issue(s):

Fixes #1167

Checklist

  • Removed the deprecated in_tinybars parameter from the Hbar class constructor.
  • Updated CHANGELOG.md
  • Documented (Code comments)
  • Tested (unit)

@codecov
Copy link

codecov bot commented Dec 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1188      +/-   ##
==========================================
+ Coverage   91.26%   91.28%   +0.02%     
==========================================
  Files         139      139              
  Lines        8447     8447              
==========================================
+ Hits         7709     7711       +2     
+ Misses        738      736       -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MonaaEid MonaaEid marked this pull request as ready for review December 21, 2025 23:53
Copilot AI review requested due to automatic review settings December 21, 2025 23:53
@coderabbitai
Copy link

coderabbitai bot commented Dec 21, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Removed the deprecated in_tinybars parameter from Hbar.__init__ and replaced internal uses with unit=HbarUnit.TINYBAR; marked CustomFixedFee.set_amount_in_tinybars as deprecated (runtime DeprecationWarning) and adjusted tests and changelog to match these API changes.

Changes

Cohort / File(s) Summary
Hbar constructor refactor
src/hiero_sdk_python/hbar.py
Removed the in_tinybars parameter from Hbar.__init__; constructor now accepts amount and unit only. Updated from_tinybars to call Hbar(..., unit=HbarUnit.TINYBAR) instead of using the deprecated flag.
Custom fee deprecation
src/hiero_sdk_python/tokens/custom_fixed_fee.py
Marked set_amount_in_tinybars as deprecated: added runtime DeprecationWarning, updated docstring, clear denominating_token_id (set to None) before setting amount, and return self.
Tests
tests/unit/hbar_test.py, tests/unit/custom_fee_test.py
Updated tests to use unit=HbarUnit.TINYBAR instead of in_tinybars; added test_set_amount_in_tinybars_deprecation that asserts a DeprecationWarning, verifies amount set and denominating_token_id cleared.
Changelog
CHANGELOG.md
Added entry documenting removal of the deprecated in_tinybars parameter and related test/implementation updates.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify all call sites (including examples and client code) were updated from in_tinybars to unit=HbarUnit.TINYBAR.
  • Check serialization/deserialization and factory methods (e.g., from_tinybars) for consistent tinybar handling.
  • Confirm deprecation warning text, emission type, and docstring follow project conventions.
  • Review tests to ensure they correctly assert the warning and the denominating_token_id behavior.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing the deprecated in_tinybars parameter from the codebase.
Description check ✅ Passed The description comprehensively explains what was changed, why, and provides implementation details directly related to the changeset.
Linked Issues check ✅ Passed The PR addresses all primary objectives from #1167: removes in_tinybars parameter from Hbar class, updates from_tinybars to use unit parameter, updates tests to use unit=HbarUnit.TINYBAR, and deprecates set_amount_in_tinybars with appropriate warnings.
Out of Scope Changes check ✅ Passed All changes are directly related to the in_tinybars refactoring scope: Hbar class updates, test modifications, and CustomFixedFee deprecation all align with issue #1167 objectives.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38cfc1a and 999c803.

📒 Files selected for processing (1)
  • CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
src/hiero_sdk_python/tokens/custom_fixed_fee.py (1)

90-113: Well-implemented deprecation with proper warning.

The deprecation is correctly implemented:

  • Uses DeprecationWarning with appropriate stacklevel=2
  • Provides clear migration guidance in both docstring and warning message
  • Maintains backward compatibility while signaling future removal

One minor improvement: the .. deprecated:: Sphinx directive on line 93 is missing a version number. Consider adding the version where this was deprecated for documentation clarity.

🔎 Add version to deprecation directive
-        .. deprecated:: 
+        .. deprecated:: 0.2.0
             Use :meth:`set_hbar_amount` with :meth:`Hbar.from_tinybars` instead.
             For example: ``set_hbar_amount(Hbar.from_tinybars(amount))``
src/hiero_sdk_python/hbar.py (2)

35-42: Stale docstring reference to removed parameter.

The docstring still mentions in_tinybars (deprecated) on line 41, but this parameter has been removed. The docstring should be updated to reflect the current API.

🔎 Update docstring
         """
         Create an Hbar instance with the given amount designated either in hbars or tinybars.

         Args:
             amount: The numeric amount of hbar or tinybar.
             unit: Unit of the provided amount.
-            in_tinybars (deprecated): If True, treat the amount as tinybars directly.
         """

9-10: Unused import.

The warnings module is imported but no longer used after removing the in_tinybars deprecation logic. This should be cleaned up.

🔎 Remove unused import
 import re
-import warnings
 from decimal import Decimal
tests/unit/hbar_test.py (1)

24-34: Tests correctly updated to use new unit parameter.

The tests properly verify the new API using unit=HbarUnit.TINYBAR instead of the removed in_tinybars parameter.

Note: test_constructor_in_tinybars (lines 24-28) is now functionally identical to the first case in test_constructor_with_unit (lines 32-34). Consider consolidating these tests or renaming test_constructor_in_tinybars to better reflect that it's testing the unit=HbarUnit.TINYBAR path.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b97935d and 146bda9.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • src/hiero_sdk_python/hbar.py (3 hunks)
  • src/hiero_sdk_python/tokens/custom_fixed_fee.py (3 hunks)
  • tests/unit/custom_fee_test.py (3 hunks)
  • tests/unit/hbar_test.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
tests/unit/hbar_test.py (2)
src/hiero_sdk_python/hbar.py (1)
  • Hbar (18-166)
src/hiero_sdk_python/hbar_unit.py (1)
  • HbarUnit (3-47)
tests/unit/custom_fee_test.py (1)
src/hiero_sdk_python/tokens/custom_fixed_fee.py (2)
  • CustomFixedFee (22-300)
  • set_amount_in_tinybars (90-113)
src/hiero_sdk_python/hbar.py (1)
src/hiero_sdk_python/hbar_unit.py (1)
  • HbarUnit (3-47)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Agent
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build-and-test (3.11)
  • GitHub Check: build-and-test (3.13)
  • GitHub Check: build-and-test (3.10)
  • GitHub Check: build-and-test (3.12)
  • GitHub Check: run-examples
  • GitHub Check: StepSecurity Harden-Runner
🔇 Additional comments (2)
src/hiero_sdk_python/hbar.py (1)

108-110: LGTM!

The from_tinybars method is correctly updated to use unit=HbarUnit.TINYBAR instead of the removed in_tinybars parameter.

tests/unit/hbar_test.py (1)

60-63: LGTM!

The fractional tinybar test correctly uses the new unit=HbarUnit.TINYBAR parameter.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request removes the deprecated in_tinybars parameter from the Hbar class constructor and updates all code and tests to use the unit parameter with HbarUnit.TINYBAR instead. Additionally, it deprecates the set_amount_in_tinybars() method in CustomFixedFee with an appropriate warning.

Key changes:

  • Removed the deprecated in_tinybars boolean parameter and related logic from the Hbar.__init__() method
  • Updated Hbar.from_tinybars() to use unit=HbarUnit.TINYBAR instead of the removed parameter
  • Added deprecation warning to CustomFixedFee.set_amount_in_tinybars() method recommending the use of set_hbar_amount(Hbar.from_tinybars(amount)) instead

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/hiero_sdk_python/hbar.py Removed in_tinybars parameter from constructor and updated from_tinybars() to use unit parameter
tests/unit/hbar_test.py Updated tests to replace in_tinybars=True with unit=HbarUnit.TINYBAR
src/hiero_sdk_python/tokens/custom_fixed_fee.py Added deprecation warning to set_amount_in_tinybars() method
tests/unit/custom_fee_test.py Added test to verify deprecation warning is properly raised
CHANGELOG.md Documented the removal of deprecated parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
src/hiero_sdk_python/hbar.py (1)

30-34: Fix PEP 8 style: missing spaces around = in type-annotated default.

PEP 8 recommends unit: HbarUnit = HbarUnit.HBAR (with spaces) when the parameter has a type annotation.

🔎 Fix spacing
     def __init__(
             self,
             amount: Union[int, float, Decimal],
-            unit: HbarUnit=HbarUnit.HBAR
+            unit: HbarUnit = HbarUnit.HBAR
         ) -> None:
tests/unit/hbar_test.py (1)

30-31: Update the misleading docstring.

The docstring says "Test creation directly in tinybars" but this test actually validates construction with multiple units (TINYBAR, MICROBAR, MILLIBAR, HBAR, KILOBAR, MEGABAR, GIGABAR).

🔎 Suggested fix
 def test_constructor_with_unit():
-    """Test creation directly in tinybars."""
+    """Test creation with various HbarUnit values."""
     hbar1 = Hbar(50, unit=HbarUnit.TINYBAR)
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 146bda9 and 38cfc1a.

📒 Files selected for processing (3)
  • src/hiero_sdk_python/hbar.py (3 hunks)
  • tests/unit/custom_fee_test.py (3 hunks)
  • tests/unit/hbar_test.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/hiero_sdk_python/hbar.py (1)
src/hiero_sdk_python/hbar_unit.py (1)
  • HbarUnit (3-47)
tests/unit/custom_fee_test.py (1)
src/hiero_sdk_python/tokens/custom_fixed_fee.py (2)
  • CustomFixedFee (22-300)
  • set_amount_in_tinybars (90-113)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: run-examples
  • GitHub Check: build-and-test (3.10)
  • GitHub Check: build-and-test (3.11)
  • GitHub Check: build-and-test (3.13)
  • GitHub Check: build-and-test (3.12)
  • GitHub Check: StepSecurity Harden-Runner
🔇 Additional comments (4)
tests/unit/custom_fee_test.py (2)

3-3: LGTM!

The warnings import is necessary for the new deprecation test and is appropriately placed.


259-274: LGTM!

The test correctly verifies:

  • A DeprecationWarning is raised with the expected message
  • The method still functions correctly after deprecation (amount=100, denominating_token_id=None)

The test follows best practices for deprecation testing.

tests/unit/hbar_test.py (1)

60-63: LGTM!

The test correctly validates that fractional tinybar values raise a ValueError when using unit=HbarUnit.TINYBAR.

src/hiero_sdk_python/hbar.py (1)

96-109: LGTM!

The method correctly migrates from the deprecated in_tinybars=True parameter to unit=HbarUnit.TINYBAR, maintaining the same functionality while aligning with the new API.

Copy link
Contributor

@exploreriii exploreriii left a comment

Choose a reason for hiding this comment

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

Hi @MonaaEid
This is fantastic

The hbarunit functionality was added in 0.1.9, with the deprecation message
We have now released 0.1.10 and hopefully soon can release 0.2.0, in which case it will be appropriate to merge in this on this upcoming release

Could you please emphasise it is a breaking change in the changelog :)

@exploreriii exploreriii marked this pull request as draft December 22, 2025 09:32
@exploreriii exploreriii marked this pull request as ready for review December 22, 2025 12:47
Copy link
Contributor

@exploreriii exploreriii left a comment

Choose a reason for hiding this comment

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

Hi @MonaaEid
Nicely done and thanks for picking up instances of the other methods that need to be deprecated :)

@exploreriii exploreriii merged commit 38b7ac7 into hiero-ledger:main Dec 22, 2025
18 checks passed
@MonaaEid
Copy link
Contributor Author

Hi @MonaaEid Nicely done and thanks for picking up instances of the other methods that need to be deprecated :)

Much appreciated!

prishajaiswal75 pushed a commit to prishajaiswal75/hiero-sdk-python that referenced this pull request Dec 22, 2025
Signed-off-by: MonaaEid <[email protected]>
Signed-off-by: MontyPokemon <[email protected]>
Signed-off-by: prishajaiswal75 <[email protected]>
@MonaaEid MonaaEid deleted the fix/1167-refactor-in-tinybars-usage branch December 23, 2025 13:02
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.

[Intermediate]: Refactor uses of in_tinybars to use unit=HbarUnit.TINYBAR

2 participants