Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 3 additions & 12 deletions src/hiero_sdk_python/hbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,15 @@ 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.

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):
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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)
12 changes: 12 additions & 0 deletions src/hiero_sdk_python/tokens/custom_fixed_fee.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/custom_fee_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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():
Expand Down Expand Up @@ -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
13 changes: 4 additions & 9 deletions tests/unit/hbar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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."""
Expand Down