-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mechanism): add stake info for log trigger (#5419)
- Loading branch information
1 parent
068764b
commit d6ff733
Showing
3 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 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()); | ||
} | ||
|
||
} |