feat: transaction record query include duplicates#1671
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughAdds include_duplicates support to TransactionRecordQuery (requesting and mapping duplicate records) and a public duplicates list to TransactionRecord; updates mapping/execution logic, tests, an example, and CHANGELOG entries. (22 words) Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant Query as TransactionRecordQuery
participant Service as TransactionGetRecordService
participant Mapper as _map_record_list
participant Record as TransactionRecord
Client->>Query: set_transaction_id(tx_id)
Client->>Query: set_include_duplicates(true)
Client->>Query: execute(client)
Query->>Service: send TransactionGetRecord (includeDuplicates=true)
Service-->>Query: response (transactionRecord + duplicateTransactionRecords)
Query->>Mapper: _map_record_list(proto_duplicate_records)
Mapper->>Record: TransactionRecord._from_proto(proto_dup, tx_id)
Record-->>Mapper: duplicate TransactionRecord
Mapper-->>Query: list of duplicates
Query->>Record: TransactionRecord._from_proto(primary_proto, tx_id, duplicates=list)
Record-->>Query: primary TransactionRecord (with duplicates)
Query-->>Client: return TransactionRecord
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: Siddhartha Ganguly <gangulysiddhartha22@gmail.com>
792dbc0 to
e9a1bdb
Compare
|
Hi @gangulysiddhartha22-cmyk, Thanks for PR, add an entry in CHANGELOG.md |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/unit/transaction_record_query_test.py (1)
89-124: 🧹 Nitpick | 🔵 TrivialConsider adding unit test for
executewithinclude_duplicates=True.The existing
test_transaction_record_query_executetests the basic flow, but there's no unit-level test verifying:
- The
duplicatesattribute exists on the returnedTransactionRecord- The behavior when
include_duplicates=Trueand duplicate records are returnedPer PRIORITY 1 guidelines, tests should assert public attributes exist to protect against breaking changes.
♻️ Suggested test addition
def test_transaction_record_query_execute_with_duplicates(transaction_id): """Test TransactionRecordQuery with include_duplicates=True returns duplicates.""" receipt = transaction_receipt_pb2.TransactionReceipt(status=ResponseCode.SUCCESS) main_record = transaction_record_pb2.TransactionRecord( receipt=receipt, transactionID=transaction_id._to_proto(), memo="Main record", ) duplicate_record = transaction_record_pb2.TransactionRecord( receipt=receipt, transactionID=transaction_id._to_proto(), memo="Duplicate record", ) response_sequences = [[ # Cost query response response_pb2.Response( transactionGetRecord=transaction_get_record_pb2.TransactionGetRecordResponse( header=response_header_pb2.ResponseHeader( nodeTransactionPrecheckCode=ResponseCode.OK, responseType=ResponseType.COST_ANSWER, cost=2 ) ) ), # Actual query response with duplicates response_pb2.Response( transactionGetRecord=transaction_get_record_pb2.TransactionGetRecordResponse( header=response_header_pb2.ResponseHeader( nodeTransactionPrecheckCode=ResponseCode.OK, responseType=ResponseType.ANSWER_ONLY, ), transactionRecord=main_record, duplicateTransactionRecords=[duplicate_record], ) ) ]] with mock_hedera_servers(response_sequences) as client: query = TransactionRecordQuery(transaction_id).set_include_duplicates(True) result = query.execute(client) # Assert duplicates attribute exists (PRIORITY 1) assert hasattr(result, 'duplicates'), "TransactionRecord should have 'duplicates' attribute" assert isinstance(result.duplicates, list)Based on learnings: "Assert public attributes exist (e.g.,
assert hasattr(obj, 'account_id'))."
22dd578 to
2b22818
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/unit/transaction_record_query_test.py (1)
89-155: 🛠️ Refactor suggestion | 🟠 MajorConsider adding a test for
execute()with duplicate records.The existing
test_transaction_record_query_executetests the basic flow but doesn't cover the newinclude_duplicatesfunctionality. Per PRIORITY 3 (comprehensive coverage), consider adding a test that:
- Sets
include_duplicates=True- Provides a response with
duplicateTransactionRecords- Verifies the returned
TransactionRecord.duplicateslist is populated♻️ Suggested test addition
def test_transaction_record_query_execute_with_duplicates(transaction_id): """Test TransactionRecordQuery returns duplicates when include_duplicates=True.""" receipt = transaction_receipt_pb2.TransactionReceipt(status=ResponseCode.SUCCESS) primary_record = transaction_record_pb2.TransactionRecord( receipt=receipt, memo="primary", transactionFee=100000 ) duplicate_record = transaction_record_pb2.TransactionRecord( receipt=receipt, memo="duplicate", transactionFee=100000 ) response_sequences = [[ # Cost query responses... response_pb2.Response( transactionGetRecord=transaction_get_record_pb2.TransactionGetRecordResponse( header=response_header_pb2.ResponseHeader( nodeTransactionPrecheckCode=ResponseCode.OK, responseType=ResponseType.COST_ANSWER, cost=2 ) ) ), response_pb2.Response( transactionGetRecord=transaction_get_record_pb2.TransactionGetRecordResponse( header=response_header_pb2.ResponseHeader( nodeTransactionPrecheckCode=ResponseCode.OK, responseType=ResponseType.COST_ANSWER, cost=2 ) ) ), response_pb2.Response( transactionGetRecord=transaction_get_record_pb2.TransactionGetRecordResponse( header=response_header_pb2.ResponseHeader( nodeTransactionPrecheckCode=ResponseCode.OK, responseType=ResponseType.ANSWER_ONLY, ), transactionRecord=primary_record, duplicateTransactionRecords=[duplicate_record] ) ) ]] with mock_hedera_servers(response_sequences) as client: query = TransactionRecordQuery(transaction_id, include_duplicates=True) result = query.execute(client) assert result.transaction_memo == "primary" assert hasattr(result, 'duplicates'), "duplicates attribute must exist" assert len(result.duplicates) == 1 assert result.duplicates[0].transaction_memo == "duplicate"
Signed-off-by: Siddhartha Ganguly <gangulysiddhartha22@gmail.com>
2b22818 to
fb9e91f
Compare
|
@AntonioCeppellini |
Hi @gangulysiddhartha22-cmyk this could be out of scope right now but i recommend to follow black formatting in the code you write :D. |
|
Makes sense to me applying Black formatting only to the files changed in the PR sounds like a good approach |
exploreriii
left a comment
There was a problem hiding this comment.
Hi @gangulysiddhartha22-cmyk
This is excellent!
Can you add an example please?
aceppaluni
left a comment
There was a problem hiding this comment.
@gangulysiddhartha22-cmyk This is great work, thank you for your contribution!!
Please only run Black on files changed in this PR, thank you.
Once suggested changes are implemented happy to re-review.
Thank you and happy contributing!!
|
@manishdait @exploreriii @AntonioCeppellini @aceppaluni |
…e-duplicates-1 Signed-off-by: Siddhartha Ganguly <gangulysiddhartha22@gmail.com>
2f8c6c1 to
3e7ce3a
Compare
8c5d8a4 to
0db3f82
Compare
0db3f82 to
4646c4d
Compare
4646c4d to
45c9ed5
Compare
45c9ed5 to
2363b5d
Compare
…e-duplicates-1 Signed-off-by: Siddhartha Ganguly <gangulysiddhartha22@gmail.com>
… example Signed-off-by: Siddhartha Ganguly <gangulysiddhartha22@gmail.com>
7900857 to
bc8fe96
Compare
|
Hi @gangulysiddhartha22-cmyk please click to resolve the conversations if you are able 👍 |
|
@exploreriii I've resolved all the conversations on my end. Let me know if there's anything left. Thanks! |
exploreriii
left a comment
There was a problem hiding this comment.
While we wait for @hiero-ledger/hiero-sdk-python-committers or @hiero-ledger/hiero-sdk-python-maintainers, could you please double check your code coverage meets our threshold requirement 👍
977cc97 to
7e00d6f
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/unit/transaction_record_query_test.py (1)
29-35: 🛠️ Refactor suggestion | 🟠 MajorUse identity check (
is) for fluent setter assertion.Line 35 uses
==to verify chaining, but fluent setter tests should useisto confirm the exact same instance is returned, consistent with the pattern used at Line 47 forset_include_duplicates.Proposed fix
- assert result == query # Should return self for chaining + assert result is query # Should return self for chainingAs per coding guidelines, "Assert fluent setters return
self(e.g.,assert tx.set_memo("test") is tx)."
7e00d6f to
b8ed7b0
Compare
b8ed7b0 to
17af695
Compare
Signed-off-by: Siddhartha Ganguly <gangulysiddhartha22@gmail.com>
17af695 to
6af8f83
Compare
|
@exploreriii I've added those extra unit tests for all type checks (invalid bool/transaction_id cases). Ready for review |
exploreriii
left a comment
There was a problem hiding this comment.
Hi @gangulysiddhartha22-cmyk
Note your unit tests are not passing, there is a bug somewhere in this PR will let you know if I find it
6977cf3 to
98bb924
Compare
98bb924 to
b2f3c7f
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hiero_sdk_python/query/transaction_record_query.py (1)
145-160:⚠️ Potential issue | 🟡 MinorDocstring refers to "transaction receipt query" — should say "transaction record query".
Lines 147 and 150 describe this as "the transaction receipt query" and "getting transaction receipts", but this is
TransactionRecordQuery, which retrieves transaction records (not receipts). This mismatch is misleading and could confuse maintainers.📝 Proposed fix
def _get_method(self, channel: _Channel) -> _Method: """ - Returns the appropriate gRPC method for the transaction receipt query. + Returns the appropriate gRPC method for the transaction record query. Implements the abstract method from Query to provide the specific - gRPC method for getting transaction receipts. + gRPC method for getting transaction records. Args: channel (_Channel): The channel containing service stubs
…e-duplicates-1 Signed-off-by: Siddhartha Ganguly <gangulysiddhartha22@gmail.com>
b2f3c7f to
51d94e0
Compare
Description:
Add support for the includeDuplicates flag
Related issue(s):
Fixes #1635
Notes for reviewer:
-No breaking changes
-Unit/Integration tests added
Checklist