Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
- Fix unit test tet_query.py
- TLS Hostname Mismatch & Certificate Verification Failure for Nodes
- Workflow does not contain permissions for `pr-check-test-files` and `pr-check-codecov`
- 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`.

### Breaking Change

Expand Down
14 changes: 3 additions & 11 deletions src/hiero_sdk_python/hbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -41,13 +40,6 @@ def __init__(
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 +107,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 +168,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
21 changes: 21 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,22 @@ 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."""
from hiero_sdk_python.tokens.custom_fixed_fee import CustomFixedFee

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
9 changes: 2 additions & 7 deletions tests/unit/hbar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@ def test_constructor():

def test_constructor_in_tinybars():
"""Test creation directly in tinybars."""
hbar1 = Hbar(50, in_tinybars=True)
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