1+ package org .tron .common .logsfilter ;
2+
3+ import static org .tron .core .config .Parameter .ChainConstant .TRX_PRECISION ;
4+
5+ import com .google .protobuf .ByteString ;
6+ import org .junit .Assert ;
7+ import org .junit .Before ;
8+ import org .junit .Test ;
9+ import org .tron .common .logsfilter .capsule .TransactionLogTriggerCapsule ;
10+ import org .tron .common .utils .Sha256Hash ;
11+ import org .tron .core .capsule .BlockCapsule ;
12+ import org .tron .core .capsule .TransactionCapsule ;
13+ import org .tron .p2p .utils .ByteArray ;
14+ import org .tron .protos .Protocol ;
15+ import org .tron .protos .contract .BalanceContract ;
16+ import org .tron .protos .contract .Common ;
17+
18+ public class TransactionLogTriggerCapsuleTest {
19+
20+ private static final String OWNER_ADDRESS = "41548794500882809695a8a687866e76d4271a1abc" ;
21+ private static final String RECEIVER_ADDRESS = "41abd4b9367799eaa3197fecb144eb71de1e049150" ;
22+
23+ public TransactionCapsule transactionCapsule ;
24+ public BlockCapsule blockCapsule ;
25+
26+ @ Before
27+ public void setup () {
28+ blockCapsule = new BlockCapsule (1 , Sha256Hash .ZERO_HASH ,
29+ System .currentTimeMillis (), Sha256Hash .ZERO_HASH .getByteString ());
30+ }
31+
32+ @ Test
33+ public void testConstructorWithUnfreezeBalanceTrxCapsule () {
34+ BalanceContract .UnfreezeBalanceContract .Builder builder2 =
35+ BalanceContract .UnfreezeBalanceContract .newBuilder ()
36+ .setOwnerAddress (ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS )))
37+ .setReceiverAddress (ByteString .copyFrom (ByteArray .fromHexString (RECEIVER_ADDRESS )));
38+ transactionCapsule = new TransactionCapsule (builder2 .build (),
39+ Protocol .Transaction .Contract .ContractType .UnfreezeBalanceContract );
40+
41+ TransactionLogTriggerCapsule triggerCapsule =
42+ new TransactionLogTriggerCapsule (transactionCapsule , blockCapsule );
43+
44+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getFromAddress ());
45+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getToAddress ());
46+ }
47+
48+
49+ @ Test
50+ public void testConstructorWithFreezeBalanceV2TrxCapsule () {
51+ BalanceContract .FreezeBalanceV2Contract .Builder builder2 =
52+ BalanceContract .FreezeBalanceV2Contract .newBuilder ()
53+ .setOwnerAddress (ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS )))
54+ .setFrozenBalance (TRX_PRECISION + 100000 )
55+ .setResource (Common .ResourceCode .BANDWIDTH );
56+ transactionCapsule = new TransactionCapsule (builder2 .build (),
57+ Protocol .Transaction .Contract .ContractType .FreezeBalanceV2Contract );
58+
59+ TransactionLogTriggerCapsule triggerCapsule =
60+ new TransactionLogTriggerCapsule (transactionCapsule , blockCapsule );
61+
62+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getFromAddress ());
63+ Assert .assertEquals ("trx" , triggerCapsule .getTransactionLogTrigger ().getAssetName ());
64+ Assert .assertEquals (TRX_PRECISION + 100000 ,
65+ triggerCapsule .getTransactionLogTrigger ().getAssetAmount ());
66+ }
67+
68+ @ Test
69+ public void testConstructorWithUnfreezeBalanceV2TrxCapsule () {
70+ BalanceContract .UnfreezeBalanceV2Contract .Builder builder2 =
71+ BalanceContract .UnfreezeBalanceV2Contract .newBuilder ()
72+ .setOwnerAddress (ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS )))
73+ .setUnfreezeBalance (TRX_PRECISION + 4000 )
74+ .setResource (Common .ResourceCode .BANDWIDTH );
75+ transactionCapsule = new TransactionCapsule (builder2 .build (),
76+ Protocol .Transaction .Contract .ContractType .UnfreezeBalanceV2Contract );
77+
78+ TransactionLogTriggerCapsule triggerCapsule =
79+ new TransactionLogTriggerCapsule (transactionCapsule , blockCapsule );
80+
81+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getFromAddress ());
82+ Assert .assertEquals ("trx" , triggerCapsule .getTransactionLogTrigger ().getAssetName ());
83+ Assert .assertEquals (TRX_PRECISION + 4000 ,
84+ triggerCapsule .getTransactionLogTrigger ().getAssetAmount ());
85+ }
86+
87+
88+ @ Test
89+ public void testConstructorWithWithdrawExpireTrxCapsule () {
90+ BalanceContract .WithdrawExpireUnfreezeContract .Builder builder2 =
91+ BalanceContract .WithdrawExpireUnfreezeContract .newBuilder ()
92+ .setOwnerAddress (ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS )));
93+ transactionCapsule = new TransactionCapsule (builder2 .build (),
94+ Protocol .Transaction .Contract .ContractType .WithdrawExpireUnfreezeContract );
95+
96+ TransactionLogTriggerCapsule triggerCapsule =
97+ new TransactionLogTriggerCapsule (transactionCapsule , blockCapsule );
98+
99+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getFromAddress ());
100+ Assert .assertEquals ("trx" , triggerCapsule .getTransactionLogTrigger ().getAssetName ());
101+ Assert .assertEquals (0L , triggerCapsule .getTransactionLogTrigger ().getAssetAmount ());
102+ }
103+
104+
105+ @ Test
106+ public void testConstructorWithDelegateResourceTrxCapsule () {
107+ BalanceContract .DelegateResourceContract .Builder builder2 =
108+ BalanceContract .DelegateResourceContract .newBuilder ()
109+ .setOwnerAddress (ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS )))
110+ .setReceiverAddress (ByteString .copyFrom (ByteArray .fromHexString (RECEIVER_ADDRESS )))
111+ .setBalance (TRX_PRECISION + 2000 );
112+ transactionCapsule = new TransactionCapsule (builder2 .build (),
113+ Protocol .Transaction .Contract .ContractType .DelegateResourceContract );
114+
115+ TransactionLogTriggerCapsule triggerCapsule =
116+ new TransactionLogTriggerCapsule (transactionCapsule , blockCapsule );
117+
118+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getFromAddress ());
119+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getToAddress ());
120+ Assert .assertEquals ("trx" , triggerCapsule .getTransactionLogTrigger ().getAssetName ());
121+ Assert .assertEquals (TRX_PRECISION + 2000 ,
122+ triggerCapsule .getTransactionLogTrigger ().getAssetAmount ());
123+ }
124+
125+ @ Test
126+ public void testConstructorWithUnDelegateResourceTrxCapsule () {
127+ BalanceContract .UnDelegateResourceContract .Builder builder2 =
128+ BalanceContract .UnDelegateResourceContract .newBuilder ()
129+ .setOwnerAddress (ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS )))
130+ .setReceiverAddress (ByteString .copyFrom (ByteArray .fromHexString (RECEIVER_ADDRESS )))
131+ .setBalance (TRX_PRECISION + 10000 );
132+ transactionCapsule = new TransactionCapsule (builder2 .build (),
133+ Protocol .Transaction .Contract .ContractType .UnDelegateResourceContract );
134+
135+ TransactionLogTriggerCapsule triggerCapsule =
136+ new TransactionLogTriggerCapsule (transactionCapsule , blockCapsule );
137+
138+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getFromAddress ());
139+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getToAddress ());
140+ Assert .assertEquals ("trx" , triggerCapsule .getTransactionLogTrigger ().getAssetName ());
141+ Assert .assertEquals (TRX_PRECISION + 10000 ,
142+ triggerCapsule .getTransactionLogTrigger ().getAssetAmount ());
143+ }
144+
145+ @ Test
146+ public void testConstructorWithCancelAllUnfreezeTrxCapsule () {
147+ BalanceContract .CancelAllUnfreezeV2Contract .Builder builder2 =
148+ BalanceContract .CancelAllUnfreezeV2Contract .newBuilder ()
149+ .setOwnerAddress (ByteString .copyFrom (ByteArray .fromHexString (OWNER_ADDRESS )));
150+ transactionCapsule = new TransactionCapsule (builder2 .build (),
151+ Protocol .Transaction .Contract .ContractType .CancelAllUnfreezeV2Contract );
152+
153+ TransactionLogTriggerCapsule triggerCapsule =
154+ new TransactionLogTriggerCapsule (transactionCapsule , blockCapsule );
155+
156+ Assert .assertNotNull (triggerCapsule .getTransactionLogTrigger ().getFromAddress ());
157+ }
158+
159+ }
0 commit comments