@@ -331,3 +331,64 @@ def test_setters_are_chainable():
331331 result = q .set_max_attempts (2 ).set_max_backoff (1.0 ).set_high_volume_throttle (100 )
332332
333333 assert result is q
334+
335+
336+ def test_port_replacement_for_localhost_execute_single ():
337+ """Test localhost:38081 is replaced with :8084."""
338+ client_1 = MagicMock ()
339+ client_1 .network .get_mirror_rest_url .return_value = "http://localhost:38081/api/v1"
340+
341+ tx = (
342+ TransferTransaction ()
343+ .add_hbar_transfer (AccountId .from_string ("0.0.1001" ), Hbar (- 1 ))
344+ .add_hbar_transfer (AccountId .from_string ("0.0.1002" ), Hbar (1 ))
345+ )
346+
347+ query = FeeEstimateQuery ().set_transaction (tx ).set_mode (FeeEstimateMode .INTRINSIC )
348+
349+ with patch .object (query , "_execute_single" ) as mock_execute_single :
350+ query .execute (client_1 )
351+ called_url = mock_execute_single .call_args [0 ][0 ]
352+ assert ":8084" in called_url
353+ assert ":38081" not in called_url
354+
355+ client_2 = MagicMock ()
356+ client_2 .network .get_mirror_rest_url .return_value = "http://127.0.0.1:38081/api/v1"
357+
358+ with patch .object (query , "_execute_single" ) as mock_execute_single :
359+ query .execute (client_2 )
360+ called_url = mock_execute_single .call_args [0 ][0 ]
361+ assert ":8084" in called_url
362+ assert ":38081" not in called_url
363+
364+
365+ def test_port_replacement_for_localhost_execute_multiple ():
366+ """Test localhost:38081 is replaced with :8084 for chunked tx."""
367+ client_1 = MagicMock ()
368+ client_1 .network .get_mirror_rest_url .return_value = "http://localhost:38081/api/v1"
369+
370+ tx = (
371+ TopicMessageSubmitTransaction ()
372+ .set_topic_id (TopicId (0 , 0 , 4 ))
373+ .set_message ("A" * 2048 )
374+ .set_transaction_id (TransactionId .generate (AccountId (0 , 0 , 3 )))
375+ .set_node_account_id (AccountId (0 , 0 , 4 ))
376+ )
377+
378+ query = FeeEstimateQuery ().set_transaction (tx ).set_mode (FeeEstimateMode .INTRINSIC )
379+
380+ with patch .object (query , "_execute_chunked" , return_value = MagicMock ()) as mock_execute_chunked :
381+ query .execute (client_1 )
382+
383+ called_url = mock_execute_chunked .call_args [0 ][1 ]
384+ assert ":8084" in called_url
385+ assert ":38081" not in called_url
386+
387+ client_2 = MagicMock ()
388+ client_2 .network .get_mirror_rest_url .return_value = "http://127.0.0.1:38081/api/v1"
389+
390+ with patch .object (query , "_execute_chunked" , return_value = MagicMock ()) as mock_execute_chunked :
391+ query .execute (client_2 )
392+ called_url = mock_execute_chunked .call_args [0 ][1 ]
393+ assert ":8084" in called_url
394+ assert ":38081" not in called_url
0 commit comments