3
3
import com .google .protobuf .ByteString ;
4
4
import io .grpc .ManagedChannel ;
5
5
import io .grpc .ManagedChannelBuilder ;
6
+ import java .util .HashMap ;
7
+ import java .util .Optional ;
8
+ import java .util .concurrent .TimeUnit ;
6
9
import lombok .extern .slf4j .Slf4j ;
7
10
import org .junit .Assert ;
8
11
import org .testng .annotations .AfterClass ;
9
12
import org .testng .annotations .BeforeClass ;
10
13
import org .testng .annotations .BeforeSuite ;
11
14
import org .testng .annotations .Test ;
12
- import org .tron .api .GrpcAPI .AccountResourceMessage ;
13
15
import org .tron .api .WalletGrpc ;
14
16
import org .tron .common .crypto .ECKey ;
15
17
import org .tron .common .utils .ByteArray ;
16
18
import org .tron .common .utils .Utils ;
17
19
import org .tron .core .Wallet ;
18
20
import org .tron .protos .Protocol ;
19
- import org .tron .protos .Protocol .TransactionInfo ;
20
- import org .tron .protos .contract .SmartContractOuterClass ;
21
21
import org .tron .protos .contract .SmartContractOuterClass .SmartContract ;
22
22
import stest .tron .wallet .common .client .Configuration ;
23
23
import stest .tron .wallet .common .client .Parameter .CommonConstant ;
24
24
import stest .tron .wallet .common .client .utils .Base58 ;
25
25
import stest .tron .wallet .common .client .utils .PublicMethed ;
26
26
27
- import java .util .HashMap ;
28
- import java .util .List ;
29
- import java .util .Optional ;
30
- import java .util .concurrent .TimeUnit ;
31
27
32
28
@ Slf4j
33
29
public class ContractTrcToken081 {
@@ -45,8 +41,8 @@ public class ContractTrcToken081 {
45
41
.get (0 );
46
42
private long maxFeeLimit = Configuration .getByPath ("testng.conf" )
47
43
.getLong ("defaultParameter.maxFeeLimit" );
48
- private byte [] TokenReceiver = null ;
49
- private byte [] TokenSender = null ;
44
+ private byte [] tokenReceiver = null ;
45
+ private byte [] tokenSender = null ;
50
46
51
47
private String description = Configuration .getByPath ("testng.conf" )
52
48
.getString ("defaultParameter.assetDescription" );
@@ -109,46 +105,46 @@ public void beforeClass() {
109
105
+ devAssetCountBefore );
110
106
111
107
String filePath = "./src/test/resources/soliditycode/contractTrcToken081.sol" ;
112
- String contractName = "TokenReceiver " ;
108
+ String contractName = "tokenReceiver " ;
113
109
HashMap retMap = PublicMethed .getBycodeAbi (filePath , contractName );
114
110
115
111
String code = retMap .get ("byteCode" ).toString ();
116
112
String abi = retMap .get ("abI" ).toString ();
117
113
118
114
String tokenId = assetAccountId .toStringUtf8 ();
119
115
120
- TokenReceiver = PublicMethed .deployContract (contractName , abi , code , "" , maxFeeLimit ,
116
+ tokenReceiver = PublicMethed .deployContract (contractName , abi , code , "" , maxFeeLimit ,
121
117
500000000L , 100 , null , dev001Key , dev001Address , blockingStubFull );
122
118
123
119
PublicMethed .waitProduceNextBlock (blockingStubFull );
124
120
SmartContract smartContract = PublicMethed
125
- .getContract (TokenReceiver , blockingStubFull );
121
+ .getContract (tokenReceiver , blockingStubFull );
126
122
Assert .assertNotNull (smartContract .getAbi ());
127
123
128
124
129
- contractName = "TokenSender " ;
125
+ contractName = "tokenSender " ;
130
126
retMap = PublicMethed .getBycodeAbi (filePath , contractName );
131
127
132
128
code = retMap .get ("byteCode" ).toString ();
133
129
abi = retMap .get ("abI" ).toString ();
134
- TokenSender = PublicMethed .deployContract (contractName , abi , code , "" , maxFeeLimit ,
135
- 500000000L , 100 , 10000L ,assetAccountId .toStringUtf8 (),
130
+ tokenSender = PublicMethed .deployContract (contractName , abi , code , "" , maxFeeLimit ,
131
+ 500000000L , 100 , 10000L , assetAccountId .toStringUtf8 (),
136
132
10L , null , dev001Key , dev001Address , blockingStubFull );
137
133
PublicMethed .waitProduceNextBlock (blockingStubFull );
138
- smartContract = PublicMethed .getContract (TokenSender ,
134
+ smartContract = PublicMethed .getContract (tokenSender ,
139
135
blockingStubFull );
140
136
Assert .assertNotNull (smartContract .getAbi ());
141
137
142
138
Long contractAssetCount = PublicMethed
143
- .getAssetIssueValue (TokenSender , assetAccountId , blockingStubFull );
144
- logger .info ("TokenSender has AssetId before: " + assetAccountId .toStringUtf8 () + ", Count: "
139
+ .getAssetIssueValue (tokenSender , assetAccountId , blockingStubFull );
140
+ logger .info ("tokenSender has AssetId before: " + assetAccountId .toStringUtf8 () + ", Count: "
145
141
+ contractAssetCount );
146
142
147
143
Long devAssetCountAfterDeploy = PublicMethed
148
144
.getAssetIssueValue (dev001Address , assetAccountId , blockingStubFull );
149
- logger .info ("after deploy tokenSender AssetId: " + assetAccountId .toStringUtf8 () + ", devAssetCountAfter: "
150
- + devAssetCountAfterDeploy );
151
- Assert .assertTrue (10 == devAssetCountBefore - devAssetCountAfterDeploy );
145
+ logger .info ("after deploy tokenSender AssetId: " + assetAccountId .toStringUtf8 ()
146
+ + ", devAssetCountAfter: " + devAssetCountAfterDeploy );
147
+ Assert .assertTrue (10 == devAssetCountBefore - devAssetCountAfterDeploy );
152
148
Assert .assertTrue (10 == contractAssetCount );
153
149
154
150
}
@@ -157,75 +153,77 @@ public void beforeClass() {
157
153
@ Test (enabled = true , description = "transfer 1 trc10 to contract by assembly" )
158
154
public void transferTokenToContract () {
159
155
Long senderAssetCountBefore = PublicMethed
160
- .getAssetIssueValue (TokenSender , assetAccountId , blockingStubFull );
161
- logger .info ("before trigger TokenSender has AssetId before: " + assetAccountId .toStringUtf8 () + ", Count: "
162
- + senderAssetCountBefore );
156
+ .getAssetIssueValue (tokenSender , assetAccountId , blockingStubFull );
157
+ logger .info ("before trigger tokenSender has AssetId before: " + assetAccountId .toStringUtf8 ()
158
+ + ", Count: " + senderAssetCountBefore );
163
159
164
160
Long receiverAssetCountBefore = PublicMethed
165
- .getAssetIssueValue (TokenReceiver , assetAccountId , blockingStubFull );
166
- logger .info ("before trigger tokenReceiver AssetId: " + assetAccountId .toStringUtf8 () + ", Count: "
167
- + receiverAssetCountBefore );
168
- String args = "\" " + Base58 .encode58Check (TokenReceiver ) + "\" " ;
161
+ .getAssetIssueValue (tokenReceiver , assetAccountId , blockingStubFull );
162
+ logger .info ("before trigger tokenReceiver AssetId: " + assetAccountId .toStringUtf8 ()
163
+ + ", Count: " + receiverAssetCountBefore );
164
+ String args = "\" " + Base58 .encode58Check (tokenReceiver ) + "\" " ;
169
165
logger .info ("args: " + args );
170
166
String triggerTxid = PublicMethed
171
- .triggerContract (TokenSender , "sendTRC10(address)" , args , false , 0 ,
172
- 1000000000L , assetAccountId .toStringUtf8 (), 0 , dev001Address , dev001Key , blockingStubFull );
167
+ .triggerContract (tokenSender , "sendTRC10(address)" , args , false , 0 , 1000000000L ,
168
+ assetAccountId .toStringUtf8 (), 0 , dev001Address , dev001Key , blockingStubFull );
173
169
174
170
PublicMethed .waitProduceNextBlock (blockingStubFull );
175
171
176
- Optional <Protocol .TransactionInfo > infoById = PublicMethed .getTransactionInfoById (triggerTxid , blockingStubFull );
172
+ Optional <Protocol .TransactionInfo > infoById =
173
+ PublicMethed .getTransactionInfoById (triggerTxid , blockingStubFull );
177
174
178
175
if (infoById .get ().getResultValue () != 0 ) {
179
176
Assert .fail ("transaction failed with message: " + infoById .get ().getResMessage ());
180
177
}
181
178
Long senderAssetCountAfter = PublicMethed
182
- .getAssetIssueValue (TokenSender , assetAccountId , blockingStubFull );
183
- logger .info ("TokenSender has AssetId After trigger: " + assetAccountId .toStringUtf8 () + ", Count: "
184
- + senderAssetCountAfter );
179
+ .getAssetIssueValue (tokenSender , assetAccountId , blockingStubFull );
180
+ logger .info ("tokenSender has AssetId After trigger: " + assetAccountId .toStringUtf8 ()
181
+ + ", Count: " + senderAssetCountAfter );
185
182
186
183
Long receiverAssetCountAfterTrigger = PublicMethed
187
- .getAssetIssueValue (TokenReceiver , assetAccountId , blockingStubFull );
184
+ .getAssetIssueValue (tokenReceiver , assetAccountId , blockingStubFull );
188
185
logger .info ("after trigger AssetId: " + assetAccountId .toStringUtf8 () + ", Count: "
189
186
+ receiverAssetCountAfterTrigger );
190
- Assert .assertTrue (1 == senderAssetCountBefore - senderAssetCountAfter );
191
- Assert .assertTrue (1 == receiverAssetCountAfterTrigger - receiverAssetCountBefore );
187
+ Assert .assertTrue (1 == senderAssetCountBefore - senderAssetCountAfter );
188
+ Assert .assertTrue (1 == receiverAssetCountAfterTrigger - receiverAssetCountBefore );
192
189
193
190
}
194
191
195
192
@ Test (enabled = true , description = "transfer 1 trc10 to normal address by assembly" )
196
193
public void transferTokenToNormalAddress () {
197
194
long senderAssetCountBefore = PublicMethed
198
- .getAssetIssueValue (TokenSender , assetAccountId , blockingStubFull );
199
- logger .info ("TokenSender has AssetId After trigger: " + assetAccountId .toStringUtf8 () + ", Count: "
200
- + senderAssetCountBefore );
195
+ .getAssetIssueValue (tokenSender , assetAccountId , blockingStubFull );
196
+ logger .info ("tokenSender has AssetId After trigger: " + assetAccountId .toStringUtf8 ()
197
+ + ", Count: " + senderAssetCountBefore );
201
198
202
199
long devAssetCountBeforeTrigger = PublicMethed
203
200
.getAssetIssueValue (dev001Address , assetAccountId , blockingStubFull );
204
- logger .info ("after trigger AssetId: " + assetAccountId .toStringUtf8 () + ", devAssetCountAfterTrigger: "
205
- + devAssetCountBeforeTrigger );
201
+ logger .info ("after trigger AssetId: " + assetAccountId .toStringUtf8 ()
202
+ + ", devAssetCountAfterTrigger: " + devAssetCountBeforeTrigger );
206
203
207
204
String args = "\" " + Base58 .encode58Check (dev001Address ) + "\" " ;
208
205
logger .info ("args: " + args );
209
206
String triggerTxid = PublicMethed
210
- .triggerContract (TokenSender , "sendTRC10(address)" , args , false , 0 ,
211
- 1000000000L , assetAccountId .toStringUtf8 (), 0 , dev001Address , dev001Key , blockingStubFull );
207
+ .triggerContract (tokenSender , "sendTRC10(address)" , args , false , 0 , 1000000000L ,
208
+ assetAccountId .toStringUtf8 (), 0 , dev001Address , dev001Key , blockingStubFull );
212
209
213
210
PublicMethed .waitProduceNextBlock (blockingStubFull );
214
211
215
- Optional <Protocol .TransactionInfo > infoById = PublicMethed .getTransactionInfoById (triggerTxid , blockingStubFull );
212
+ Optional <Protocol .TransactionInfo > infoById =
213
+ PublicMethed .getTransactionInfoById (triggerTxid , blockingStubFull );
216
214
217
215
if (infoById .get ().getResultValue () != 0 ) {
218
216
Assert .fail ("transaction failed with message: " + infoById .get ().getResMessage ());
219
217
}
220
218
long senderAssetCountAfter = PublicMethed
221
- .getAssetIssueValue (TokenSender , assetAccountId , blockingStubFull );
222
- logger .info ("TokenSender has AssetId After trigger: " + assetAccountId .toStringUtf8 () + ", Count: "
223
- + senderAssetCountAfter );
219
+ .getAssetIssueValue (tokenSender , assetAccountId , blockingStubFull );
220
+ logger .info ("tokenSender has AssetId After trigger: " + assetAccountId .toStringUtf8 ()
221
+ + ", Count: " + senderAssetCountAfter );
224
222
225
223
long devAssetCountAfterTrigger = PublicMethed
226
224
.getAssetIssueValue (dev001Address , assetAccountId , blockingStubFull );
227
- logger .info ("after trigger AssetId: " + assetAccountId .toStringUtf8 () + ", devAssetCountAfterTrigger: "
228
- + devAssetCountAfterTrigger );
225
+ logger .info ("after trigger AssetId: " + assetAccountId .toStringUtf8 ()
226
+ + ", devAssetCountAfterTrigger: " + devAssetCountAfterTrigger );
229
227
Assert .assertTrue (1 == senderAssetCountBefore - senderAssetCountAfter );
230
228
Assert .assertTrue (1 == devAssetCountAfterTrigger - devAssetCountBeforeTrigger );
231
229
}
0 commit comments