diff --git a/CHANGELOG.md b/CHANGELOG.md index 29600703b..818823fef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,9 +103,10 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1. - TLS Hostname Mismatch & Certificate Verification Failure for Nodes - Workflow does not contain permissions for `pr-check-test-files` and `pr-check-codecov` + ### Breaking Change -- +- Remove deprecated 'in_tinybars' parameter and update related tests `/src/hiero_sdk_python/hbar.py`, `/tests/unit/hbar_test.py` and `/src/hiero_sdk_python/tokens/custom_fixed_fee.py`. ## [0.1.10] - 2025-12-03 diff --git a/src/hiero_sdk_python/hbar.py b/src/hiero_sdk_python/hbar.py index d7a6e08a6..7af36b5de 100644 --- a/src/hiero_sdk_python/hbar.py +++ b/src/hiero_sdk_python/hbar.py @@ -30,8 +30,7 @@ class Hbar: def __init__( self, amount: Union[int, float, Decimal], - unit: HbarUnit=HbarUnit.HBAR, - in_tinybars: bool=False # Deperecated + unit: HbarUnit=HbarUnit.HBAR ) -> None: """ Create an Hbar instance with the given amount designated either in hbars or tinybars. @@ -39,15 +38,7 @@ def __init__( 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. """ - if in_tinybars: - warnings.warn( - "The 'in_tinybars' parameter is deprecated and will be removed in a future release. " - "Use `unit=HbarUnit.TINYBAR` instead.", - DeprecationWarning - ) - unit = HbarUnit.TINYBAR if unit == HbarUnit.TINYBAR: if not isinstance(amount, int): @@ -115,7 +106,7 @@ def from_tinybars(cls, tinybars: int) -> "Hbar": """ if not isinstance(tinybars, int): raise TypeError("tinybars must be an int.") - return cls(tinybars, in_tinybars=True) + return cls(tinybars, unit=HbarUnit.TINYBAR) @classmethod def from_string(cls, amount: str, unit: HbarUnit = HbarUnit.HBAR) -> "Hbar": @@ -176,4 +167,4 @@ def __ge__(self, other: object) -> bool: Hbar.ZERO = Hbar(0) Hbar.MAX = Hbar(50_000_000_000) -Hbar.MIN = Hbar(-50_000_000_000) +Hbar.MIN = Hbar(-50_000_000_000) \ No newline at end of file diff --git a/src/hiero_sdk_python/tokens/custom_fixed_fee.py b/src/hiero_sdk_python/tokens/custom_fixed_fee.py index e1c59e52f..5408db151 100644 --- a/src/hiero_sdk_python/tokens/custom_fixed_fee.py +++ b/src/hiero_sdk_python/tokens/custom_fixed_fee.py @@ -1,5 +1,6 @@ from __future__ import annotations import typing +import warnings from hiero_sdk_python.tokens.custom_fee import CustomFee from hiero_sdk_python.hbar import Hbar @@ -89,6 +90,10 @@ def __str__(self) -> str: def set_amount_in_tinybars(self, amount: int) -> "CustomFixedFee": """Sets the fee amount in tinybars. + .. deprecated:: + Use :meth:`set_hbar_amount` with :meth:`Hbar.from_tinybars` instead. + For example: ``set_hbar_amount(Hbar.from_tinybars(amount))`` + Clears any previously set denominating token ID, implying the fee is in HBAR. Args: @@ -97,6 +102,13 @@ def set_amount_in_tinybars(self, amount: int) -> "CustomFixedFee": Returns: CustomFixedFee: This CustomFixedFee instance for chaining. """ + warnings.warn( + "set_amount_in_tinybars() is deprecated and will be removed in a future release. " + "Use set_hbar_amount(Hbar.from_tinybars(amount)) instead.", + DeprecationWarning, + stacklevel=2 + ) + self.denominating_token_id = None self.amount = amount return self diff --git a/tests/unit/custom_fee_test.py b/tests/unit/custom_fee_test.py index 165be69ad..59639b2c2 100644 --- a/tests/unit/custom_fee_test.py +++ b/tests/unit/custom_fee_test.py @@ -1,5 +1,6 @@ from hiero_sdk_python.client.client import Client import pytest +import warnings from unittest import mock from hiero_sdk_python.tokens.custom_fee import CustomFee from hiero_sdk_python.tokens.custom_fixed_fee import CustomFixedFee @@ -9,6 +10,7 @@ from hiero_sdk_python.account.account_id import AccountId from hiero_sdk_python.tokens.token_id import TokenId + pytestmark = pytest.mark.unit def test_custom_fixed_fee_proto_round_trip(): @@ -253,3 +255,20 @@ def WhichOneof(self, name): return "unknown_fee" with pytest.raises(ValueError): CustomFee._from_proto(FakeProto()) + +def test_set_amount_in_tinybars_deprecation(): + """Test that set_amount_in_tinybars shows deprecation warning.""" + fee = CustomFixedFee() + + # Test that deprecation warning is raised + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + fee.set_amount_in_tinybars(100) + + assert len(w) == 1 + assert issubclass(w[0].category, DeprecationWarning) + assert "set_amount_in_tinybars() is deprecated" in str(w[0].message) + + # Verify the method still works correctly + assert fee.amount == 100 + assert fee.denominating_token_id is None diff --git a/tests/unit/hbar_test.py b/tests/unit/hbar_test.py index 610c6b1d5..253e3cbfc 100644 --- a/tests/unit/hbar_test.py +++ b/tests/unit/hbar_test.py @@ -21,17 +21,12 @@ def test_constructor(): assert hbar3.to_tinybars() == 50_000_000 assert hbar3.to_hbars() == 0.5 -def test_constructor_in_tinybars(): - """Test creation directly in tinybars.""" - hbar1 = Hbar(50, in_tinybars=True) +def test_constructor_with_tinybar_unit(): + """Test creation with unit set to HbarUnit.TINYBAR.""" + hbar1 = Hbar(50, unit=HbarUnit.TINYBAR) assert hbar1.to_tinybars() == 50 assert hbar1.to_hbars() == 0.0000005 - # If in_tinybars is False (Default) - hbar2 = Hbar(50, in_tinybars=False) - assert hbar2.to_tinybars() == 5_000_000_000 - assert hbar2.to_hbars() == 50 - def test_constructor_with_unit(): """Test creation directly in tinybars.""" hbar1 = Hbar(50, unit=HbarUnit.TINYBAR) @@ -65,7 +60,7 @@ def test_constructor_with_unit(): def test_constructor_fractional_tinybar(): """Test creation with fractional tinybars.""" with pytest.raises(ValueError, match="Fractional tinybar value not allowed"): - Hbar(0.1, in_tinybars=True) + Hbar(0.1, unit=HbarUnit.TINYBAR) def test_constructor_invalid_type(): """Test creation of Hbar with invalid type."""