-
Notifications
You must be signed in to change notification settings - Fork 144
feat: Transform custom_fee_fixed example to end-to-end test #1148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Transform custom_fee_fixed example to end-to-end test #1148
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughReplaced a static demo with an end-to-end Hedera testnet example: dotenv-driven client setup, token creation using a CustomFixedFee, transaction submission, receipt/record retrieval, TokenInfoQuery verification, and improved error handling/cleanup. Changes
Sequence Diagram(s)sequenceDiagram
participant User as Main
participant Client as Hedera Client (local)
participant Network as Hedera Testnet
participant TokenSvc as Token Registry
Note over User: Load environment (.env) OPERATOR_ID / OPERATOR_KEY / NETWORK
User->>Client: setup_client() — create configured client with operator
User->>User: build CustomFixedFee and TokenCreateTransaction (metadata, treasury, keys)
User->>Client: freeze transaction & sign with operator/admin keys
Client->>Network: submit TokenCreateTransaction
Network->>Network: process transaction
Network->>TokenSvc: persist token with custom fee config
Network-->>Client: return Receipt / Record (tokenId, status)
User->>Client: TokenInfoQuery(tokenId)
Client->>Network: query token info
Network->>TokenSvc: lookup token & fees
TokenSvc-->>Network: return token metadata & custom fees
Network-->>Client: return TokenInfo
User->>User: validate & print TokenInfo
User->>Client: close client (cleanup)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
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: Adityarya11 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1148 +/- ##
=======================================
Coverage 91.19% 91.19%
=======================================
Files 139 139
Lines 8446 8446
=======================================
Hits 7702 7702
Misses 744 744 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR transforms the examples/tokens/custom_fee_fixed.py from a static object demonstration into a functional end-to-end example that interacts with the Hedera network.
Key changes:
- Added client setup with operator credentials loaded from environment variables
- Implemented
TokenCreateTransactionto create a token with aCustomFixedFeeon the network - Added
TokenInfoQueryto verify the custom fee was correctly attached to the created token
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| examples/tokens/custom_fee_fixed.py | Transformed from static demo to full E2E example with network interaction, including client setup, token creation with fixed fee, and verification query |
| CHANGELOG.md | Added entry documenting the transformation of the custom_fee_fixed.py example |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
examples/tokens/custom_fee_fixed.py (1)
111-115: Consider more specific exception handling.The broad
Exceptioncatch is acceptable for example scripts but could be more specific. Consider catchingReceiptStatusErroror similar SDK-specific exceptions for better error reporting.🔎 View suggested improvement:
- except Exception as e: - print(f"Transaction failed: {e}") + except (ValueError, RuntimeError) as e: + print(f"Transaction failed: {e}")However, the current approach with broad exception handling and
finallyblock for cleanup is reasonable for an example script.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CHANGELOG.md(1 hunks)examples/tokens/custom_fee_fixed.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.14.8)
examples/tokens/custom_fee_fixed.py
45-45: Abstract raise to an inner function
(TRY301)
45-45: Avoid specifying long messages outside the exception class
(TRY003)
52-52: Consider moving this statement to an else block
(TRY300)
111-111: Do not catch blind exception: Exception
(BLE001)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: build-and-test (3.12)
- GitHub Check: build-and-test (3.11)
- GitHub Check: build-and-test (3.13)
- GitHub Check: build-and-test (3.10)
- GitHub Check: run-examples
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: StepSecurity Harden-Runner
🔇 Additional comments (6)
examples/tokens/custom_fee_fixed.py (6)
7-28: LGTM! Clean imports and environment setup.The imports are well-organized, and the environment loading with a sensible default network follows good practices for example scripts.
59-77: LGTM! Clear fee configuration.The CustomFixedFee is properly configured with explicit parameters, and the print statements provide helpful context about what the fee does.
79-92: LGTM! Complete token creation setup.The transaction is properly configured with all necessary parameters, follows the builder pattern correctly, and includes the custom fee as intended.
100-109: LGTM! Proper verification of custom fees.The TokenInfoQuery correctly retrieves and validates that the custom fee was attached to the token on the network. The iteration through retrieved fees provides clear confirmation.
117-118: LGTM! Standard Python entry point.The main execution guard follows Python conventions correctly.
94-97: The code is correct. The Python SDK'sexecute()method directly returns a receipt object, soreceipt = transaction.execute(client)followed by accessingreceipt.token_idis the proper pattern for hiero-sdk-python, which is the SDK used in this repository.
exploreriii
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Adityarya11 great! Couple small details
Signed-off-by: Adityarya11 <[email protected]>
bb90363 to
d9850b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
examples/tokens/custom_fee_fixed.py (2)
93-117: Consider catching more specific exceptions.Line 115 catches the broad
Exceptiontype, which may hide unexpected errors. Consider catching more specific exceptions likeReceiptStatusErroror network-related exceptions to provide more targeted error handling.🔎 View suggested refinement:
try: receipt = transaction.execute(client) # Check if the status is explicitly SUCCESS if receipt.status != ResponseCode.SUCCESS: print(f"Transaction failed with status: {ResponseCode(receipt.status).name}") token_id = receipt.token_id print(f"Token created successfully with ID: {token_id}") print("\n--- Verifying Fee on Network ---") token_info = TokenInfoQuery().set_token_id(token_id).execute(client) retrieved_fees = token_info.custom_fees if retrieved_fees: print(f"Success! Found {len(retrieved_fees)} custom fee(s) on token.") for fee in retrieved_fees: print(f"Fee Collector: {fee.fee_collector_account_id}") print(f"Fee Details: {fee}") else: print("Error: No custom fees found on the token.") - except Exception as e: + except (ReceiptStatusError, ValueError, RuntimeError) as e: print(f"Transaction failed: {e}") sys.exit(1)
65-119: Consider using a context manager for the client.While the
finallyblock ensures the client is closed, using a context manager (withstatement) would provide a more Pythonic approach and automatically handle cleanup.🔎 View alternative pattern:
def custom_fixed_fee_example(): """ Demonstrates how to create a token with a Custom Fixed Fee. """ client, operator_id, operator_key = setup_client() with client: print("\n--- Creating Custom Fixed Fee ---") fixed_fee = CustomFixedFee( amount=Hbar(1).to_tinybars(), fee_collector_account_id=operator_id, all_collectors_are_exempt=False ) # ... rest of the functionNote: This pattern requires that the
Clientclass implements the context manager protocol (__enter__and__exit__methods).
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
CHANGELOG.md(1 hunks)examples/tokens/custom_fee_fixed.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
examples/tokens/custom_fee_fixed.py (6)
src/hiero_sdk_python/query/token_info_query.py (1)
TokenInfoQuery(11-131)src/hiero_sdk_python/response_code.py (1)
ResponseCode(4-387)src/hiero_sdk_python/tokens/supply_type.py (1)
SupplyType(11-19)src/hiero_sdk_python/tokens/custom_fixed_fee.py (1)
CustomFixedFee(21-288)src/hiero_sdk_python/tokens/token_create_transaction.py (1)
TokenCreateTransaction(207-585)src/hiero_sdk_python/tokens/token_type.py (1)
TokenType(11-14)
🪛 Ruff (0.14.8)
examples/tokens/custom_fee_fixed.py
44-44: Abstract raise to an inner function
(TRY301)
44-44: Avoid specifying long messages outside the exception class
(TRY003)
51-51: Consider moving this statement to an else block
(TRY300)
115-115: Do not catch blind exception: Exception
(BLE001)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: run-examples
- GitHub Check: build-and-test (3.10)
- GitHub Check: build-and-test (3.11)
- GitHub Check: build-and-test (3.12)
- GitHub Check: build-and-test (3.13)
- GitHub Check: StepSecurity Harden-Runner
🔇 Additional comments (5)
CHANGELOG.md (1)
77-77: LGTM! Changelog entry accurately documents the transformation.The entry clearly describes that the example was transformed from a static object demo to an end-to-end network-interacting example, which aligns with the PR objectives.
examples/tokens/custom_fee_fixed.py (4)
7-22: LGTM! Import style is now consistent.All imports consistently use the full path pattern (
from hiero_sdk_python.X import Y), which addresses previous feedback about mixing import styles.
27-56: Client setup is well-structured with clear error messages.The function properly initializes the network and client, handles missing environment variables gracefully, and provides helpful error messages. The commented-out TLS configuration addresses previous concerns about hardcoded disabling.
58-91: Excellent end-to-end token creation workflow.The example clearly demonstrates creating a token with a custom fixed fee, including proper fee definition, comprehensive token configuration, and correct transaction signing. The code is well-commented and follows the suggested structure from issue #1085.
121-122: LGTM! Standard main guard pattern.The entry point is clean and follows Python conventions.
exploreriii
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works very nicely well done !
|
Please rebase and can merge this :) |
|
Please rebase and we can merge |
Signed-off-by: notsogod <[email protected]>
…dger#1148) Signed-off-by: Adityarya11 <[email protected]> Signed-off-by: notsogod <[email protected]> Signed-off-by: prajeeta pal <[email protected]>
Description:
Updates
examples/tokens/custom_fee_fixed.pyto be a functional end-to-end example that interacts with the Hedera network, rather than a static object demo.setup_client()with required TLS configuration.TokenCreateTransactionto deploy a token with aCustomFixedFee.TokenInfoQueryto verify the fee was correctly attached to the created token on the network.Fixes #1085
Checklist
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.