Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
- Add automated bot to recommend next issues to contributors after their first PR merge (#1380)
- Added dry-run support and refactored `.github/workflows/bot-workflows.yml` to use dedicated script `.github/scripts/bot-workflows.js` for improved maintainability and testability. (`#1288`)
- Added `/working` command to reset the inactivity timer on issues and PRs. ([#1552](https://github.com/hiero-ledger/hiero-sdk-python/issues/1552))
- Added `set_node_account_ids()` to `TransactionResponse.get_receipt()` for correct handling of pre-consensus failures. ([#1686](https://github.com/hiero-ledger/hiero-sdk-python/issues/1686))
Comment thread
exploreriii marked this conversation as resolved.
Outdated

### Changed

Expand Down
2 changes: 1 addition & 1 deletion src/hiero_sdk_python/transaction/transaction_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def get_receipt(self, client):
"""
# TODO: Decide how to avoid circular imports
from hiero_sdk_python.query.transaction_get_receipt_query import TransactionGetReceiptQuery
# TODO: Implement set_node_account_ids() to get failure reason for preHandle failures
receipt = (
TransactionGetReceiptQuery()
.set_transaction_id(self.transaction_id)
.set_node_account_ids([self.node_id])
Comment thread
exploreriii marked this conversation as resolved.
.execute(client)
)

Expand Down
76 changes: 76 additions & 0 deletions tests/unit/test_transaction_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""
Tests for TransactionResponse behavior.
"""

import pytest

from hiero_sdk_python.account.account_id import AccountId
from hiero_sdk_python.response_code import ResponseCode
from hiero_sdk_python.transaction.transaction_response import TransactionResponse
from hiero_sdk_python.hapi.services import (
response_header_pb2,
response_pb2,
transaction_get_receipt_pb2,
transaction_receipt_pb2,
)

from tests.unit.mock_server import mock_hedera_servers

pytestmark = pytest.mark.unit


def test_transaction_response_fields(transaction_id):
"""asserting response is correctly populated"""
resp = TransactionResponse()
resp.transaction_id = transaction_id
resp.node_id = AccountId(0, 0, 3)

assert resp.transaction_id == transaction_id
assert resp.node_id == AccountId(0, 0, 3)
Comment thread
coderabbitai[bot] marked this conversation as resolved.


def test_transaction_response_get_receipt_is_pinned_to_submitting_node(transaction_id):
"""
mock_hedera_servers assigns:
- server[0] -> node 0.0.3
- server[1] -> node 0.0.4

We make node 0.0.3 return a NON-retryable precheck error, and node 0.0.4 return SUCCESS.
If TransactionResponse.get_receipt() does not pin, it will likely hit 0.0.3 and fail.
If it pins to self.node_id (0.0.4), it will succeed.
"""
bad_node_response = response_pb2.Response(
transactionGetReceipt=transaction_get_receipt_pb2.TransactionGetReceiptResponse(
header=response_header_pb2.ResponseHeader(
nodeTransactionPrecheckCode=ResponseCode.INVALID_TRANSACTION
),
receipt=transaction_receipt_pb2.TransactionReceipt(
status=ResponseCode.UNKNOWN
),
)
)

good_node_response = response_pb2.Response(
transactionGetReceipt=transaction_get_receipt_pb2.TransactionGetReceiptResponse(
header=response_header_pb2.ResponseHeader(
nodeTransactionPrecheckCode=ResponseCode.OK
),
receipt=transaction_receipt_pb2.TransactionReceipt(
status=ResponseCode.SUCCESS
),
)
)

response_sequences = [
[bad_node_response], # node 0.0.3
[good_node_response], # node 0.0.4
]

with mock_hedera_servers(response_sequences) as client:
resp = TransactionResponse()
resp.transaction_id = transaction_id
resp.node_id = AccountId(0, 0, 4) # submitting node (server[1])

receipt = resp.get_receipt(client)

assert receipt.status == ResponseCode.SUCCESS
Comment thread
manishdait marked this conversation as resolved.
Comment thread
manishdait marked this conversation as resolved.
Comment thread
exploreriii marked this conversation as resolved.
Loading