Repository navigation
feat: Implemet from_protobuf for the token_lifecycle transaction #2791
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
base: main
Are you sure you want to change the base?
Changes from all commits
be7a10d
dd75685
87cc026
958449e
4a06dc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,3 +197,35 @@ def test_token_fee_schedule_update_clears_fees(env): | |
|
|
||
| token_info_cleared = TokenInfoQuery().set_token_id(token_id).execute(env.client) | ||
| assert len(token_info_cleared.custom_fees) == 0 | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_update_token_fee_schedule_from_bytes(env): | ||
| """Test token update fee schedule transaction can be executed from bytes.""" | ||
| fee_schedule_key = env.operator_key | ||
| token_id = create_fungible_token(env, opts=[lambda tx: tx.set_fee_schedule_key(fee_schedule_key)]) | ||
| assert token_id is not None | ||
|
|
||
| new_fee = CustomFixedFee( | ||
| amount=25, | ||
| fee_collector_account_id=env.operator_id, | ||
| ) | ||
| original_tx = ( | ||
| TokenFeeScheduleUpdateTransaction() | ||
| .set_token_id(token_id) | ||
| .set_custom_fees([new_fee]) | ||
| .freeze_with(env.client) | ||
| .sign(fee_schedule_key) | ||
| ) | ||
|
|
||
| copy_tx = TokenFeeScheduleUpdateTransaction.from_bytes(original_tx.to_bytes()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert the reconstructed fields before execution.
Before execution, assert As per path instructions, “Suggest additional assertions that would strengthen correctness.” This also targets the PR's field-for-field restoration objective. Source: Path instructions |
||
|
|
||
| receipt = copy_tx.execute(env.client) | ||
| assert receipt.status == ResponseCode.SUCCESS, f"Fee schedule update failed: {ResponseCode(receipt.status).name}" | ||
|
|
||
| token_info = TokenInfoQuery().set_token_id(token_id).execute(env.client) | ||
| assert token_info.custom_fees and len(token_info.custom_fees) == 1, ( | ||
| "Custom fee must be present and should have length 1" | ||
| ) | ||
| retrieved_fee = token_info.custom_fees[0] | ||
| assert isinstance(retrieved_fee, CustomFixedFee) and retrieved_fee.amount == 25, "Custom fee amount must be 25" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,3 +263,39 @@ def test_token_update_nfts_transaction_fails_for_nonexistent_serial(env): | |
| assert receipt.status == ResponseCode.INVALID_NFT_ID, ( | ||
| f"NFT update should fail with INVALID_NFT_ID, got status: {ResponseCode(receipt.status).name}" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_update_nfts_from_bytes(env): | ||
| """Test token update nfts transaction can be executed from bytes.""" | ||
| supply_private_key = PrivateKey.generate_ed25519() | ||
| metadata_private_key = PrivateKey.generate_ed25519() | ||
|
|
||
| nft_id = create_nft_token( | ||
| env, [lambda tx: tx.set_supply_key(supply_private_key), lambda tx: tx.set_metadata_key(metadata_private_key)] | ||
| ) | ||
|
|
||
| mint_metadata = b"Hello, Hedera" | ||
| mint_tx = TokenMintTransaction(token_id=nft_id, metadata=mint_metadata) | ||
| receipt = mint_tx.freeze_with(env.client).sign(supply_private_key).execute(env.client) | ||
|
|
||
| assert receipt.status == ResponseCode.SUCCESS, ( | ||
| f"NFT minting failed with status: {ResponseCode(receipt.status).name}" | ||
| ) | ||
|
|
||
| serials = receipt.serial_numbers | ||
| nft_info = TokenNftInfoQuery(NftId(nft_id, serials[0])).execute(env.client) | ||
| assert nft_info.metadata == mint_metadata, f"Initial metadata mismatch for serial {serials[0]}" | ||
|
|
||
| updated_metadata = b"Hello, Hiero" | ||
| original_update_tx = TokenUpdateNftsTransaction(token_id=nft_id, serial_numbers=serials, metadata=updated_metadata) | ||
| original_update_tx.transaction_fee = Hbar(3).to_tinybars() | ||
| original_update_tx.freeze_with(env.client).sign(metadata_private_key) | ||
|
|
||
| copy_update_tx = TokenUpdateNftsTransaction.from_bytes(original_update_tx.to_bytes()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert the restored NFT update fields. The restored transaction retains the original signed body bytes. Execution can submit those bytes even if After Line 295, compare those three attributes with As per path instructions, “Suggest additional assertions that would strengthen correctness.” Source: Path instructions |
||
| receipt = copy_update_tx.execute(env.client) | ||
|
|
||
| assert receipt.status == ResponseCode.SUCCESS, f"NFT update failed with status: {ResponseCode(receipt.status).name}" | ||
|
|
||
| nft_info = TokenNftInfoQuery(NftId(nft_id, serials[0])).execute(env.client) | ||
| assert nft_info.metadata == updated_metadata, f"Updated metadata mismatch for serial {serials[0]}" | ||
Uh oh!
There was an error while loading. Please reload this page.