-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(mechanism): optimize address parsing of stake interfaces #5419
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
Merged
halibobo1205
merged 15 commits into
tronprotocol:develop
from
CarlChaoCarl:feature/optimize_transaction_address_parsing_v2
Sep 4, 2023
+250
−0
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
87f9cea
feat(mechanism): optimize new transaction address parsing
e406639
feat(mechanism): optimize new transaction address parsing
5b1490b
feat(mechanism): optimize new transaction address parsing
9d61a7a
Merge branch 'develop' of https://github.com/CarlChaoCarl/java-tron i…
1f9da68
feat(mechanism): optimize new transaction address parsing
26e852a
feat(mechanism): optimize new transaction address parsing
7a5c58b
feat(mechanism): optimize new transaction address parsing
ab5bb17
Merge branch 'tronprotocol:develop' into feature/optimize_transaction…
CarlChaoCarl 4d1fd04
Merge branch 'tronprotocol:develop' into feature/optimize_transaction…
CarlChaoCarl 3e3ebe9
feat(mechanism): add unit test for optimize of new transaction addres…
737c36e
feat(mechanism): add fields for optimize of new transaction address p…
082abc7
feat(mechanism): add fields for optimize of new transaction address p…
52ecd18
Merge branch 'tronprotocol:develop' into feature/optimize_transaction…
CarlChaoCarl cd65c89
feat(mechanism): add fields for optimize of new transaction address p…
eaaa323
feat(mechanism): add fields for optimize of new transaction address p…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
framework/src/test/java/org/tron/common/logsfilter/TransactionLogTriggerCapsuleTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| package org.tron.common.logsfilter; | ||
|
|
||
| import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION; | ||
|
|
||
| import com.google.protobuf.ByteString; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.tron.common.logsfilter.capsule.TransactionLogTriggerCapsule; | ||
| import org.tron.common.utils.Sha256Hash; | ||
| import org.tron.core.capsule.BlockCapsule; | ||
| import org.tron.core.capsule.TransactionCapsule; | ||
| import org.tron.p2p.utils.ByteArray; | ||
| import org.tron.protos.Protocol; | ||
| import org.tron.protos.contract.BalanceContract; | ||
| import org.tron.protos.contract.Common; | ||
|
|
||
| public class TransactionLogTriggerCapsuleTest { | ||
|
|
||
| private static final String OWNER_ADDRESS = "41548794500882809695a8a687866e76d4271a1abc"; | ||
| private static final String RECEIVER_ADDRESS = "41abd4b9367799eaa3197fecb144eb71de1e049150"; | ||
|
|
||
| public TransactionCapsule transactionCapsule; | ||
| public BlockCapsule blockCapsule; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| blockCapsule = new BlockCapsule(1, Sha256Hash.ZERO_HASH, | ||
| System.currentTimeMillis(), Sha256Hash.ZERO_HASH.getByteString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorWithUnfreezeBalanceTrxCapsule() { | ||
| BalanceContract.UnfreezeBalanceContract.Builder builder2 = | ||
| BalanceContract.UnfreezeBalanceContract.newBuilder() | ||
| .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))) | ||
| .setReceiverAddress(ByteString.copyFrom(ByteArray.fromHexString(RECEIVER_ADDRESS))); | ||
| transactionCapsule = new TransactionCapsule(builder2.build(), | ||
| Protocol.Transaction.Contract.ContractType.UnfreezeBalanceContract); | ||
|
|
||
| TransactionLogTriggerCapsule triggerCapsule = | ||
| new TransactionLogTriggerCapsule(transactionCapsule, blockCapsule); | ||
|
|
||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getFromAddress()); | ||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getToAddress()); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testConstructorWithFreezeBalanceV2TrxCapsule() { | ||
| BalanceContract.FreezeBalanceV2Contract.Builder builder2 = | ||
| BalanceContract.FreezeBalanceV2Contract.newBuilder() | ||
| .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))) | ||
| .setFrozenBalance(TRX_PRECISION + 100000) | ||
| .setResource(Common.ResourceCode.BANDWIDTH); | ||
| transactionCapsule = new TransactionCapsule(builder2.build(), | ||
| Protocol.Transaction.Contract.ContractType.FreezeBalanceV2Contract); | ||
|
|
||
| TransactionLogTriggerCapsule triggerCapsule = | ||
| new TransactionLogTriggerCapsule(transactionCapsule, blockCapsule); | ||
|
|
||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getFromAddress()); | ||
| Assert.assertEquals("trx", triggerCapsule.getTransactionLogTrigger().getAssetName()); | ||
| Assert.assertEquals(TRX_PRECISION + 100000, | ||
| triggerCapsule.getTransactionLogTrigger().getAssetAmount()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorWithUnfreezeBalanceV2TrxCapsule() { | ||
| BalanceContract.UnfreezeBalanceV2Contract.Builder builder2 = | ||
| BalanceContract.UnfreezeBalanceV2Contract.newBuilder() | ||
| .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))) | ||
| .setUnfreezeBalance(TRX_PRECISION + 4000) | ||
| .setResource(Common.ResourceCode.BANDWIDTH); | ||
| transactionCapsule = new TransactionCapsule(builder2.build(), | ||
| Protocol.Transaction.Contract.ContractType.UnfreezeBalanceV2Contract); | ||
|
|
||
| TransactionLogTriggerCapsule triggerCapsule = | ||
| new TransactionLogTriggerCapsule(transactionCapsule, blockCapsule); | ||
|
|
||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getFromAddress()); | ||
| Assert.assertEquals("trx", triggerCapsule.getTransactionLogTrigger().getAssetName()); | ||
| Assert.assertEquals(TRX_PRECISION + 4000, | ||
| triggerCapsule.getTransactionLogTrigger().getAssetAmount()); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testConstructorWithWithdrawExpireTrxCapsule() { | ||
| BalanceContract.WithdrawExpireUnfreezeContract.Builder builder2 = | ||
| BalanceContract.WithdrawExpireUnfreezeContract.newBuilder() | ||
| .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))); | ||
| transactionCapsule = new TransactionCapsule(builder2.build(), | ||
| Protocol.Transaction.Contract.ContractType.WithdrawExpireUnfreezeContract); | ||
|
|
||
| TransactionLogTriggerCapsule triggerCapsule = | ||
| new TransactionLogTriggerCapsule(transactionCapsule, blockCapsule); | ||
|
|
||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getFromAddress()); | ||
| Assert.assertEquals("trx", triggerCapsule.getTransactionLogTrigger().getAssetName()); | ||
| Assert.assertEquals(0L, triggerCapsule.getTransactionLogTrigger().getAssetAmount()); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testConstructorWithDelegateResourceTrxCapsule() { | ||
| BalanceContract.DelegateResourceContract.Builder builder2 = | ||
| BalanceContract.DelegateResourceContract.newBuilder() | ||
| .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))) | ||
| .setReceiverAddress(ByteString.copyFrom(ByteArray.fromHexString(RECEIVER_ADDRESS))) | ||
| .setBalance(TRX_PRECISION + 2000); | ||
| transactionCapsule = new TransactionCapsule(builder2.build(), | ||
| Protocol.Transaction.Contract.ContractType.DelegateResourceContract); | ||
|
|
||
| TransactionLogTriggerCapsule triggerCapsule = | ||
| new TransactionLogTriggerCapsule(transactionCapsule, blockCapsule); | ||
|
|
||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getFromAddress()); | ||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getToAddress()); | ||
| Assert.assertEquals("trx", triggerCapsule.getTransactionLogTrigger().getAssetName()); | ||
| Assert.assertEquals(TRX_PRECISION + 2000, | ||
| triggerCapsule.getTransactionLogTrigger().getAssetAmount()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorWithUnDelegateResourceTrxCapsule() { | ||
| BalanceContract.UnDelegateResourceContract.Builder builder2 = | ||
| BalanceContract.UnDelegateResourceContract.newBuilder() | ||
| .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))) | ||
| .setReceiverAddress(ByteString.copyFrom(ByteArray.fromHexString(RECEIVER_ADDRESS))) | ||
| .setBalance(TRX_PRECISION + 10000); | ||
| transactionCapsule = new TransactionCapsule(builder2.build(), | ||
| Protocol.Transaction.Contract.ContractType.UnDelegateResourceContract); | ||
|
|
||
| TransactionLogTriggerCapsule triggerCapsule = | ||
| new TransactionLogTriggerCapsule(transactionCapsule, blockCapsule); | ||
|
|
||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getFromAddress()); | ||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getToAddress()); | ||
| Assert.assertEquals("trx", triggerCapsule.getTransactionLogTrigger().getAssetName()); | ||
| Assert.assertEquals(TRX_PRECISION + 10000, | ||
| triggerCapsule.getTransactionLogTrigger().getAssetAmount()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorWithCancelAllUnfreezeTrxCapsule() { | ||
| BalanceContract.CancelAllUnfreezeV2Contract.Builder builder2 = | ||
| BalanceContract.CancelAllUnfreezeV2Contract.newBuilder() | ||
| .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))); | ||
| transactionCapsule = new TransactionCapsule(builder2.build(), | ||
| Protocol.Transaction.Contract.ContractType.CancelAllUnfreezeV2Contract); | ||
|
|
||
| TransactionLogTriggerCapsule triggerCapsule = | ||
| new TransactionLogTriggerCapsule(transactionCapsule, blockCapsule); | ||
|
|
||
| Assert.assertNotNull(triggerCapsule.getTransactionLogTrigger().getFromAddress()); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this need to be added?
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.
OK, I get it