Skip to content

Commit 38b7ac7

Browse files
authored
refactor: remove deprecated in_tinybars parameter (hiero-ledger#1188)
Signed-off-by: MonaaEid <[email protected]> Signed-off-by: MontyPokemon <[email protected]>
1 parent 838a112 commit 38b7ac7

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
104104
- TLS Hostname Mismatch & Certificate Verification Failure for Nodes
105105
- Workflow does not contain permissions for `pr-check-test-files` and `pr-check-codecov`
106106

107+
107108
### Breaking Change
108109

109-
-
110+
- 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`.
110111

111112
## [0.1.10] - 2025-12-03
112113

src/hiero_sdk_python/hbar.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,15 @@ class Hbar:
3030
def __init__(
3131
self,
3232
amount: Union[int, float, Decimal],
33-
unit: HbarUnit=HbarUnit.HBAR,
34-
in_tinybars: bool=False # Deperecated
33+
unit: HbarUnit=HbarUnit.HBAR
3534
) -> None:
3635
"""
3736
Create an Hbar instance with the given amount designated either in hbars or tinybars.
3837
3938
Args:
4039
amount: The numeric amount of hbar or tinybar.
4140
unit: Unit of the provided amount.
42-
in_tinybars (deprecated): If True, treat the amount as tinybars directly.
4341
"""
44-
if in_tinybars:
45-
warnings.warn(
46-
"The 'in_tinybars' parameter is deprecated and will be removed in a future release. "
47-
"Use `unit=HbarUnit.TINYBAR` instead.",
48-
DeprecationWarning
49-
)
50-
unit = HbarUnit.TINYBAR
5142

5243
if unit == HbarUnit.TINYBAR:
5344
if not isinstance(amount, int):
@@ -115,7 +106,7 @@ def from_tinybars(cls, tinybars: int) -> "Hbar":
115106
"""
116107
if not isinstance(tinybars, int):
117108
raise TypeError("tinybars must be an int.")
118-
return cls(tinybars, in_tinybars=True)
109+
return cls(tinybars, unit=HbarUnit.TINYBAR)
119110

120111
@classmethod
121112
def from_string(cls, amount: str, unit: HbarUnit = HbarUnit.HBAR) -> "Hbar":
@@ -176,4 +167,4 @@ def __ge__(self, other: object) -> bool:
176167

177168
Hbar.ZERO = Hbar(0)
178169
Hbar.MAX = Hbar(50_000_000_000)
179-
Hbar.MIN = Hbar(-50_000_000_000)
170+
Hbar.MIN = Hbar(-50_000_000_000)

src/hiero_sdk_python/tokens/custom_fixed_fee.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22
import typing
3+
import warnings
34
from hiero_sdk_python.tokens.custom_fee import CustomFee
45
from hiero_sdk_python.hbar import Hbar
56

@@ -89,6 +90,10 @@ def __str__(self) -> str:
8990
def set_amount_in_tinybars(self, amount: int) -> "CustomFixedFee":
9091
"""Sets the fee amount in tinybars.
9192
93+
.. deprecated::
94+
Use :meth:`set_hbar_amount` with :meth:`Hbar.from_tinybars` instead.
95+
For example: ``set_hbar_amount(Hbar.from_tinybars(amount))``
96+
9297
Clears any previously set denominating token ID, implying the fee is in HBAR.
9398
9499
Args:
@@ -97,6 +102,13 @@ def set_amount_in_tinybars(self, amount: int) -> "CustomFixedFee":
97102
Returns:
98103
CustomFixedFee: This CustomFixedFee instance for chaining.
99104
"""
105+
warnings.warn(
106+
"set_amount_in_tinybars() is deprecated and will be removed in a future release. "
107+
"Use set_hbar_amount(Hbar.from_tinybars(amount)) instead.",
108+
DeprecationWarning,
109+
stacklevel=2
110+
)
111+
self.denominating_token_id = None
100112
self.amount = amount
101113
return self
102114

tests/unit/custom_fee_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from hiero_sdk_python.client.client import Client
22
import pytest
3+
import warnings
34
from unittest import mock
45
from hiero_sdk_python.tokens.custom_fee import CustomFee
56
from hiero_sdk_python.tokens.custom_fixed_fee import CustomFixedFee
@@ -9,6 +10,7 @@
910
from hiero_sdk_python.account.account_id import AccountId
1011
from hiero_sdk_python.tokens.token_id import TokenId
1112

13+
1214
pytestmark = pytest.mark.unit
1315

1416
def test_custom_fixed_fee_proto_round_trip():
@@ -253,3 +255,20 @@ def WhichOneof(self, name):
253255
return "unknown_fee"
254256
with pytest.raises(ValueError):
255257
CustomFee._from_proto(FakeProto())
258+
259+
def test_set_amount_in_tinybars_deprecation():
260+
"""Test that set_amount_in_tinybars shows deprecation warning."""
261+
fee = CustomFixedFee()
262+
263+
# Test that deprecation warning is raised
264+
with warnings.catch_warnings(record=True) as w:
265+
warnings.simplefilter("always")
266+
fee.set_amount_in_tinybars(100)
267+
268+
assert len(w) == 1
269+
assert issubclass(w[0].category, DeprecationWarning)
270+
assert "set_amount_in_tinybars() is deprecated" in str(w[0].message)
271+
272+
# Verify the method still works correctly
273+
assert fee.amount == 100
274+
assert fee.denominating_token_id is None

tests/unit/hbar_test.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@ def test_constructor():
2121
assert hbar3.to_tinybars() == 50_000_000
2222
assert hbar3.to_hbars() == 0.5
2323

24-
def test_constructor_in_tinybars():
25-
"""Test creation directly in tinybars."""
26-
hbar1 = Hbar(50, in_tinybars=True)
24+
def test_constructor_with_tinybar_unit():
25+
"""Test creation with unit set to HbarUnit.TINYBAR."""
26+
hbar1 = Hbar(50, unit=HbarUnit.TINYBAR)
2727
assert hbar1.to_tinybars() == 50
2828
assert hbar1.to_hbars() == 0.0000005
2929

30-
# If in_tinybars is False (Default)
31-
hbar2 = Hbar(50, in_tinybars=False)
32-
assert hbar2.to_tinybars() == 5_000_000_000
33-
assert hbar2.to_hbars() == 50
34-
3530
def test_constructor_with_unit():
3631
"""Test creation directly in tinybars."""
3732
hbar1 = Hbar(50, unit=HbarUnit.TINYBAR)
@@ -65,7 +60,7 @@ def test_constructor_with_unit():
6560
def test_constructor_fractional_tinybar():
6661
"""Test creation with fractional tinybars."""
6762
with pytest.raises(ValueError, match="Fractional tinybar value not allowed"):
68-
Hbar(0.1, in_tinybars=True)
63+
Hbar(0.1, unit=HbarUnit.TINYBAR)
6964

7065
def test_constructor_invalid_type():
7166
"""Test creation of Hbar with invalid type."""

0 commit comments

Comments
 (0)