Skip to content

Commit edfe80e

Browse files
committed
refactor(tck): convert contract.py aligned with new execute_validated after hiero-ledger#2611 merge
Signed-off-by: Abhijeet Saharan <abhijeetsaharan2236@gmail.com>
1 parent a5f94d6 commit edfe80e

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

tck/handlers/contract.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from hiero_sdk_python.Duration import Duration
66
from hiero_sdk_python.file.file_id import FileId
77
from hiero_sdk_python.response_code import ResponseCode
8-
from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt
98
from tck.errors import JsonRpcError
109
from tck.handlers.registry import rpc_method
1110
from tck.param.contract import CreateContractParams
@@ -14,6 +13,7 @@
1413
from tck.util.constants import DEFAULT_GRPC_TIMEOUT
1514
from tck.util.key_utils import get_key_from_string
1615
from tck.util.param_utils import decode_hex, to_int
16+
from tck.util.transaction_utils import execute_validated
1717

1818

1919
INT64_MIN = -(2**63)
@@ -99,11 +99,10 @@ def create_contract(params: CreateContractParams) -> CreateContractResponse:
9999
if params.commonTransactionParams is not None:
100100
params.commonTransactionParams.apply_common_params(transaction, client)
101101

102-
response = transaction.execute(client, wait_for_receipt=False)
103-
receipt: TransactionReceipt = response.get_receipt(client, validate_status=True)
102+
receipt = execute_validated(transaction, client)
104103

105104
contract_id = ""
106-
if receipt.status == ResponseCode.SUCCESS and receipt.contract_id is not None:
105+
if receipt.contract_id is not None:
107106
contract_id = str(receipt.contract_id)
108107

109108
return CreateContractResponse(contract_id, ResponseCode(receipt.status).name)

tests/tck/transaction_utils_test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
pytestmark = pytest.mark.unit
1515

1616

17-
class TestExecuteValidated:
18-
"""Test the execute_validated helper's success and failure paths."""
17+
class TestExecuteValidatedSuccess:
18+
"""Test the execute_validated helper's success path."""
1919

2020
def test_returns_receipt_on_success(self):
2121
"""Test that execute_validated returns the receipt when validation succeeds."""
@@ -34,6 +34,10 @@ def test_returns_receipt_on_success(self):
3434
mock_transaction.execute.assert_called_once_with(mock_client, wait_for_receipt=False)
3535
mock_response.get_receipt.assert_called_once_with(mock_client, validate_status=True)
3636

37+
38+
class TestExecuteValidatedErrors:
39+
"""Test the execute_validated helper's failure path."""
40+
3741
def test_raises_receipt_status_error_on_failure(self):
3842
"""Test that execute_validated propagates ReceiptStatusError without catching it."""
3943
mock_transaction_id = MagicMock()
@@ -50,5 +54,8 @@ def test_raises_receipt_status_error_on_failure(self):
5054
mock_transaction.execute.return_value = mock_response
5155
mock_client = MagicMock()
5256

53-
with pytest.raises(ReceiptStatusError):
57+
with pytest.raises(ReceiptStatusError) as exc_info:
5458
execute_validated(mock_transaction, mock_client)
59+
60+
if exc_info.value.status != ResponseCode.ACCOUNT_DELETED:
61+
raise AssertionError("Expected the raised error's status to be preserved")

0 commit comments

Comments
 (0)