Skip to content

Commit 62624c0

Browse files
fixes
Signed-off-by: tech0priyanshu <priyanshuyadv101106@gmail.com>
1 parent 9fd035d commit 62624c0

2 files changed

Lines changed: 37 additions & 28 deletions

File tree

src/hiero_sdk_python/client/client.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -293,28 +293,7 @@ def set_max_transaction_fee(
293293
self,
294294
max_transaction_fee: int | float | Decimal | Hbar,
295295
) -> Client:
296-
"""
297-
Sets the default maximum Hbar fee allowed for any transaction executed by this client.
298-
299-
This value is used as the transaction fee during freeze_with() if the transaction
300-
itself does not have an explicit fee set. Individual transactions may override this
301-
default by calling Transaction.set_max_transaction_fee().
302-
303-
Args:
304-
max_transaction_fee (int | float | Decimal | Hbar):
305-
The maximum fee that any single transaction is allowed to cost.
306-
307-
Returns:
308-
Client: The current client instance for method chaining.
309-
"""
310-
if isinstance(max_transaction_fee, bool) or not isinstance(
311-
max_transaction_fee,
312-
(int, float, Decimal, Hbar),
313-
):
314-
raise TypeError(
315-
f"max_transaction_fee must be int, float, Decimal, or Hbar, got {type(max_transaction_fee).__name__}"
316-
)
317-
296+
"""Sets the default maximum Hbar fee allowed for any transaction executed by this client."""
318297
value = max_transaction_fee if isinstance(max_transaction_fee, Hbar) else Hbar(max_transaction_fee)
319298

320299
if value < Hbar(0):

tests/unit/transaction_freeze_and_bytes_test.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@ def test_freeze_with_valid_parameters():
6262
# Should return self for method chaining
6363
assert result is transaction
6464

65+
# Should have transaction body bytes set
66+
assert len(transaction._transaction_body_bytes) > 0
67+
assert node_id in transaction._transaction_body_bytes
68+
6569

6670
@pytest.mark.parametrize(
6771
"valid_amount,expected",
6872
[
69-
(1, 1_00_000_000),
73+
(1, 100_000_000),
7074
(0.1, 10_000_000),
7175
(Decimal("0.1"), 10_000_000),
72-
(Hbar(1), 1_00_000_000),
73-
(Hbar(0), 0.00000000),
76+
(Hbar(1), 100_000_000),
77+
(Hbar(0), 0),
7478
],
7579
)
7680
def test_set_max_transaction_fee_valid_param(valid_amount, expected):
@@ -733,9 +737,11 @@ def test_fee_resolution_transaction_precedence(mock_client):
733737
# client has different default
734738
mock_client.set_max_transaction_fee(Hbar(5))
735739

740+
before = tx.transaction_fee
736741
tx.freeze_with(mock_client)
737742

738-
assert tx.transaction_fee == 10_00_000_000
743+
assert tx.transaction_fee == 1_000_000_000
744+
assert tx.transaction_fee == before
739745

740746

741747
def test_fee_resolution_client_default_used_when_transaction_missing(mock_client):
@@ -747,7 +753,7 @@ def test_fee_resolution_client_default_used_when_transaction_missing(mock_client
747753

748754
tx.freeze_with(mock_client)
749755

750-
assert tx.transaction_fee == 7_00_000_000
756+
assert tx.transaction_fee == 700_000_000
751757

752758

753759
def test_fee_resolution_falls_back_to_transaction_default(mock_client):
@@ -759,4 +765,28 @@ def test_fee_resolution_falls_back_to_transaction_default(mock_client):
759765

760766
tx.freeze_with(mock_client)
761767

762-
assert tx.transaction_fee == 100000000 # Default fee for TransferTransaction
768+
assert tx.transaction_fee == 100_000_000 # Default fee for TransferTransaction
769+
770+
771+
def test_resolved_fee_serialized_into_transaction_body(mock_client):
772+
"""The resolved fee must reach the serialized proto transactionFee."""
773+
tx = TransferTransaction()
774+
775+
tx.set_max_transaction_fee(Hbar(2))
776+
777+
body = tx.build_base_scheduled_body()
778+
779+
assert body.transactionFee == Hbar(2).to_tinybars()
780+
781+
782+
def test_max_transaction_fee_survives_to_bytes_round_trip(mock_client):
783+
"""An explicitly set max fee must survive a to_bytes -> from_bytes round trip."""
784+
tx = TransferTransaction()
785+
786+
tx.set_max_transaction_fee(Hbar(2))
787+
788+
tx.freeze_with(mock_client) # Serlize to_bytes()
789+
data = tx.to_bytes()
790+
791+
restored = TransferTransaction.from_bytes(data) # Deserialize from_bytes().
792+
assert restored._transaction_fee == Hbar(2).to_tinybars()

0 commit comments

Comments
 (0)