Skip to content

Commit 70637d1

Browse files
fixed magicMock
Signed-off-by: tech0priyanshu <priyanshuyadv101106@gmail.com>
1 parent 91ab9e8 commit 70637d1

5 files changed

Lines changed: 36 additions & 19 deletions

File tree

src/hiero_sdk_python/client/client.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, network: Network = None) -> None:
5959

6060
self.max_attempts: int = 10
6161
self.default_max_query_payment: Hbar = DEFAULT_MAX_QUERY_PAYMENT
62-
self.default_max_transaction_fee: Hbar = None
62+
self.default_max_transaction_fee: Hbar | None = None
6363

6464
self._min_backoff: float = DEFAULT_MIN_BACKOFF
6565
self._max_backoff: float = DEFAULT_MAX_BACKOFF
@@ -293,7 +293,20 @@ 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.
296306
307+
Returns:
308+
Client: The current client instance for method chaining.
309+
"""
297310
if isinstance(max_transaction_fee, bool) or not isinstance(
298311
max_transaction_fee,
299312
(int, float, Decimal, Hbar),

src/hiero_sdk_python/transaction/transaction.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ def freeze_with(self, client: Client):
304304
# For each node, set the node_account_id and build the transaction body
305305
# This allows the transaction to be submitted to any node in the network
306306

307+
# Use all nodes from client network
308+
# Resolve fee priority before building bodies:
309+
# 1. Explicit transaction fee (self.transaction_fee)
310+
# 2. Client default_max_transaction_fee
311+
# 3. Transaction class default (_default_transaction_fee)
312+
if self.transaction_fee is None:
313+
if client is not None and getattr(client, "default_max_transaction_fee", None) is not None:
314+
self.transaction_fee = client.default_max_transaction_fee
315+
else:
316+
self.transaction_fee = self._default_transaction_fee
317+
307318
if self.batch_key:
308319
# For Inner Transaction of batch transaction node_account_id=0.0.0
309320
self.node_account_id = AccountId(0, 0, 0)
@@ -323,17 +334,6 @@ def freeze_with(self, client: Client):
323334
self._transaction_body_bytes[node_account_id] = self.build_transaction_body().SerializeToString()
324335

325336
else:
326-
# Use all nodes from client network
327-
# Resolve fee priority before building bodies:
328-
# 1. Explicit transaction fee (self.transaction_fee)
329-
# 2. Client default_max_transaction_fee
330-
# 3. Transaction class default (_default_transaction_fee)
331-
if self.transaction_fee is None:
332-
if client is not None and getattr(client, "default_max_transaction_fee", None) is not None:
333-
self.transaction_fee = client.default_max_transaction_fee
334-
else:
335-
self.transaction_fee = self._default_transaction_fee
336-
337337
for node in client.network.nodes:
338338
self.node_account_id = node._account_id
339339
self._transaction_body_bytes[node._account_id] = self.build_transaction_body().SerializeToString()
@@ -796,6 +796,7 @@ def from_bytes(transaction_bytes: bytes):
796796

797797
def set_max_transaction_fee(self, max_transaction_fee):
798798
# Accept int, float, Decimal, or Hbar (but not bool)
799+
self._require_not_frozen()
799800

800801
if isinstance(max_transaction_fee, bool) or not isinstance(max_transaction_fee, (int, float, Decimal, Hbar)):
801802
raise TypeError(

tests/unit/fee_estimate_query_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def mock_client():
3232
client.mirror_network = "https://testnet.mirrornode.hedera.com"
3333
client.max_retries = 3
3434

35+
client.default_max_transaction_fee = Hbar(2)
3536
client.generate_transaction_id.return_value = TransactionId.generate(AccountId(0, 0, 1001))
3637
client.operator_account_id._to_proto.return_value = AccountId(0, 0, 1)._to_proto()
3738

tests/unit/file_append_transaction_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def test_freeze_with_generates_transaction_ids():
9595

9696
# Mock client and transaction_id
9797
mock_client = MagicMock()
98+
mock_client.default_max_transaction_fee = Hbar(1)
9899
mock_transaction_id = TransactionId(account_id=MagicMock(), valid_start=Timestamp(0, 1))
99100
file_tx.transaction_id = mock_transaction_id
100101

@@ -135,6 +136,7 @@ def test_multi_chunk_execution():
135136

136137
# Mock client and responses
137138
mock_client = MagicMock()
139+
mock_client.default_max_transaction_fee = Hbar(1)
138140
mock_receipt = MagicMock(spec=TransactionReceipt)
139141
mock_receipt.status = ResponseCode.SUCCESS
140142

tests/unit/transaction_freeze_and_bytes_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ def test_freeze_with_valid_parameters():
6666
@pytest.mark.parametrize(
6767
"valid_amount,expected",
6868
[
69-
(1, Hbar(1)),
70-
(0.1, Hbar(0.1)),
71-
(Decimal("0.1"), Hbar(Decimal("0.1"))),
72-
(Hbar(1), Hbar(1)),
73-
(Hbar(0), Hbar(0)),
69+
(1, 1_00_000_000),
70+
(0.1, 10_000_000),
71+
(Decimal("0.1"), 10_000_000),
72+
(Hbar(1), 1_00_000_000),
73+
(Hbar(0), 0.00000000),
7474
],
7575
)
7676
def test_set_max_transaction_fee_valid_param(valid_amount, expected):
@@ -735,7 +735,7 @@ def test_fee_resolution_transaction_precedence(mock_client):
735735

736736
tx.freeze_with(mock_client)
737737

738-
assert tx.transaction_fee == Hbar(10)
738+
assert tx.transaction_fee == 10_00_000_000
739739

740740

741741
def test_fee_resolution_client_default_used_when_transaction_missing(mock_client):
@@ -747,7 +747,7 @@ def test_fee_resolution_client_default_used_when_transaction_missing(mock_client
747747

748748
tx.freeze_with(mock_client)
749749

750-
assert tx.transaction_fee == Hbar(7)
750+
assert tx.transaction_fee == 7_00_000_000
751751

752752

753753
def test_fee_resolution_falls_back_to_transaction_default(mock_client):

0 commit comments

Comments
 (0)