Skip to content

Commit 2db4e34

Browse files
author
wangzihe
committed
renew P0 and P1, delete listaccount case
1 parent fdf0a16 commit 2db4e34

17 files changed

Lines changed: 538 additions & 165 deletions

src/test/java/stest/tron/wallet/Wallettest_p0/Wallettest_p0_001.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
import java.util.HashMap;
55
import java.util.Optional;
6-
6+
import stest.tron.wallet.common.client.Configuration;
7+
import io.grpc.ManagedChannel;
8+
import io.grpc.ManagedChannelBuilder;
79
import org.tron.api.GrpcAPI;
810
import org.tron.api.GrpcAPI.AccountList;
911
import org.tron.api.GrpcAPI.NodeList;
12+
import org.tron.api.WalletGrpc;
1013
import org.tron.common.crypto.Hash;
1114
import org.tron.common.utils.ByteArray;
1215
import lombok.extern.slf4j.Slf4j;
@@ -41,6 +44,9 @@ public class Wallettest_p0_001 {
4144
private static final Long F_DURATION = 3L;
4245
private static final Long ZUIDIXIAOFEI = 100000L;
4346

47+
private ManagedChannel channelFull = null;
48+
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
49+
private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);
4450

4551
public static void main(String[] args){
4652
logger.info("test man.");
@@ -51,8 +57,13 @@ public void beforeClass() {
5157
walletClient = new WalletClient(testKey002);
5258
walletClient.init(0);
5359

60+
channelFull = ManagedChannelBuilder.forTarget(fullnode)
61+
.usePlaintext(true)
62+
.build();
63+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
64+
5465
//check config-beta env
55-
Assert.assertTrue(checkENV());
66+
//Assert.assertTrue(checkENV());
5667

5768
boolean ret = walletClient.freezeBalance(10000000000L,F_DURATION);
5869
Assert.assertTrue(ret);
@@ -97,8 +108,11 @@ public void checkTrxCoinTrade() {
97108
Assert.assertTrue(ret);
98109

99110
//check transaction count
100-
Long transactionCnt = checkclient.getTotalTransaction().getNum();
101-
Assert.assertTrue(transactionCnt > 0 );
111+
//GrpcAPI.NumberMessage GetTotalTransaction = blockingStubFull.totalTransaction(GrpcAPI.EmptyMessage.newBuilder().build());
112+
//logger.info(Long.toString(GetTotalTransaction.getNum()));
113+
114+
//Long transactionCnt = GetTotalTransaction.getNum();
115+
//Assert.assertTrue(transactionCnt > 0 );
102116

103117
/*
104118
@@ -151,6 +165,8 @@ public void checkTrxCoinVote() {
151165

152166
//1 vote = 1 trx = 1000000 drop
153167
//check vote
168+
//GrpcAPI.WitnessList witnesslist = blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build());
169+
//Optional<GrpcAPI.WitnessList> witnessResult = Optional.ofNullable(witnesslist);
154170
Optional<GrpcAPI.WitnessList> witnessResult = walletClient.listWitnesses();
155171

156172
HashMap<String, String> witnesshash = new HashMap();
@@ -178,6 +194,7 @@ public void checkTrxCoinVote() {
178194
//get list again
179195
witnessResult = walletClient.listWitnesses();
180196

197+
181198
if (witnessResult.isPresent()) {
182199
WitnessList = witnessResult.get();
183200
WitnessList.getWitnessesList().forEach(witness -> {
@@ -194,7 +211,10 @@ public void checkTrxCoinVote() {
194211
//check env: nodelist;witnesslist;accountlist.
195212
public boolean checkENV(){
196213
//check account
197-
Optional<AccountList> accountResult = walletClient.listAccounts();
214+
//Optional<AccountList> accountResult = walletClient.listAccounts();
215+
216+
GrpcAPI.AccountList accountlist = blockingStubFull.listAccounts(GrpcAPI.EmptyMessage.newBuilder().build());
217+
Optional<GrpcAPI.AccountList> accountResult = Optional.ofNullable(accountlist);
198218

199219
if (accountResult.isPresent()) {
200220
AccountList accountList = accountResult.get();
@@ -257,7 +277,7 @@ public void checkAcc(){
257277
}
258278
}
259279

260-
@Test(enabled = false)
280+
@Test(enabled = true)
261281
public void checkNode() {
262282

263283
Optional<GrpcAPI.NodeList> result = walletClient.listNodes();

src/test/java/stest/tron/wallet/Wallettest_p0/Wallettest_p0_002.java

Lines changed: 135 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22

33
import com.google.protobuf.ByteString;
44
import com.googlecode.cqengine.query.simple.In;
5+
import io.grpc.ManagedChannel;
6+
import io.grpc.ManagedChannelBuilder;
57
import javafx.scene.AmbientLight;
68
import lombok.extern.slf4j.Slf4j;
79
import org.testng.annotations.*;
810
import org.testng.Assert;
911
import org.tron.api.GrpcAPI;
12+
import org.tron.api.WalletGrpc;
13+
import org.tron.common.crypto.ECKey;
1014
import org.tron.common.utils.ByteArray;
1115
import org.tron.protos.Contract;
1216
import org.tron.protos.Protocol;
17+
import stest.tron.wallet.common.client.Configuration;
1318
import stest.tron.wallet.common.client.WalletClient;
1419
import stest.tron.wallet.common.client.utils.Base58;
20+
import stest.tron.wallet.common.client.utils.TransactionUtils;
1521

22+
import java.math.BigInteger;
1623
import java.util.Optional;
1724

1825

@@ -38,8 +45,16 @@ public class Wallettest_p0_002 {
3845
private static final Long AMOUNT = 101L;
3946

4047
private static final long now = System.currentTimeMillis();
41-
private static final String name = "testAssetIssue_" + Long.toString(now);
48+
private static String name = "testAssetIssue_" + Long.toString(now);
4249
private static final long TotalSupply = now;
50+
String Description = "just-test";
51+
String Url = "https://github.com/tronprotocol/wallet-cli/";
52+
53+
private ManagedChannel channelFull = null;
54+
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
55+
//private String fullnode = "39.105.111.178:50051";
56+
private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);
57+
//private String search_fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1);
4358

4459
public static void main(String[] args) {
4560
logger.info("test man.");
@@ -52,47 +67,45 @@ public void beforeClass() {
5267
walletClient = new WalletClient(testKey002);
5368
walletClient.init(0);
5469

70+
channelFull = ManagedChannelBuilder.forTarget(fullnode)
71+
.usePlaintext(true)
72+
.build();
73+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
74+
5575
}
5676

57-
@Test(enabled = false)
77+
@Test(enabled = true)
5878
public void TestAssetIssue() {
59-
//long TotalSupply = 100000000L;
60-
int TrxNum = 1;
61-
int IcoNum = 100;
62-
long StartTime = 1522583680000L;
63-
long EndTime = 1525089280000L;
64-
int DecayRatio = 1;
65-
int VoteScore = 2;
66-
String Description = "just-test";
67-
String Url = "https://github.com/tronprotocol/wallet-cli/";
6879

69-
try {
70-
Contract.AssetIssueContract.Builder builder = Contract.AssetIssueContract.newBuilder();
71-
builder.setOwnerAddress(ByteString.copyFrom(walletClient.getAddress()));
72-
builder.setName(ByteString.copyFrom(name.getBytes()));
73-
builder.setTotalSupply(TotalSupply);
74-
builder.setTrxNum(TrxNum);
75-
builder.setNum(IcoNum);
76-
builder.setStartTime(StartTime);
77-
builder.setEndTime(EndTime);
78-
//builder.setDecayRatio(DecayRatio);
79-
builder.setVoteScore(VoteScore);
80-
builder.setDescription(ByteString.copyFrom(Description.getBytes()));
81-
builder.setUrl(ByteString.copyFrom(Url.getBytes()));
80+
ByteString addressBS1 = ByteString.copyFrom(FROM_ADDRESS);
81+
Protocol.Account request1 = Protocol.Account.newBuilder().setAddress(addressBS1).build();
82+
GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull
83+
.getAssetIssueByAccount(request1);
84+
Optional<GrpcAPI.AssetIssueList> queryAssetByAccount = Optional.ofNullable(assetIssueList1);
85+
if (queryAssetByAccount.get().getAssetIssueCount() == 0){
86+
try {
87+
Thread.sleep(16000);
88+
} catch (InterruptedException e) {
89+
e.printStackTrace();
90+
}
91+
//新建一笔通证
92+
Assert.assertTrue(CreateAssetIssue(FROM_ADDRESS,name,TotalSupply, 1,100,now +900000,now+10000000000L,
93+
1, Description, Url, testKey002));
94+
}
95+
else{
96+
logger.info("This account already create an assetisue");
97+
Optional<GrpcAPI.AssetIssueList> queryAssetByAccount1 = Optional.ofNullable(assetIssueList1);
98+
name = ByteArray.toStr(queryAssetByAccount1.get().getAssetIssue(0).getName().toByteArray());
8299

83-
Boolean ret = walletClient.createAssetIssue(builder.build());
84-
Assert.assertTrue(ret);
85-
} catch (Exception ex) {
86-
ex.printStackTrace();
87100
}
88101

89-
logger.info("this is TestAssetIssue test case");
90102
}
91103

92-
@Test(enabled = false)
104+
@Test(enabled = true)
93105
public void TestGetAssetIssueByName() {
94106
Contract.AssetIssueContract ret = walletClient.getAssetIssueByName(name);
95-
Assert.assertEquals(ret.getTotalSupply(), TotalSupply);
107+
Assert.assertTrue(ret.getOwnerAddress() != null);
108+
//Assert.assertEquals(ret.getTotalSupply(), TotalSupply);
96109

97110

98111
//logger.info(ByteArray.toStr(walletClient.getAssetIssueByName(name).getName().toByteArray()));
@@ -106,11 +119,21 @@ public void TestGetAssetIssueByName() {
106119
}
107120

108121

109-
@Test(enabled = false)
122+
@Test(enabled = true)
110123
public void TestTransferAsset() {
111124
//byte assertName[] = name.getBytes();
112125
//logger.info(Long.toString(walletClient.getAssetIssueByName(name).getTotalSupply()));
113126
Boolean ret = walletClient.transferAsset(TO_ADDRESS, name.getBytes(), AMOUNT);
127+
if (ret == false){
128+
try {
129+
Thread.sleep(16000);
130+
} catch (InterruptedException e) {
131+
e.printStackTrace();
132+
}
133+
ret = walletClient.transferAsset(TO_ADDRESS, name.getBytes(), AMOUNT);
134+
135+
}
136+
114137
//logger.info(Long.toString(walletClient.getAssetIssueByName(name).getTotalSupply()));
115138
Assert.assertTrue(ret);
116139
logger.info("this is TestTransferAsset");
@@ -119,18 +142,19 @@ public void TestTransferAsset() {
119142
}
120143

121144

122-
@Test(enabled = false)
145+
@Test(enabled = true)
123146
public void TestGetAssetIssueByAccount() {
124147
Optional<GrpcAPI.AssetIssueList> result = walletClient.getAssetIssueByAccount(FROM_ADDRESS);
148+
Assert.assertTrue(result.get().getAssetIssueCount() == 1);
125149

126-
GrpcAPI.AssetIssueList assetissuelist = result.get();
150+
//GrpcAPI.AssetIssueList assetissuelist = result.get();
127151
//logger.info(Integer.toString(result.get().getAssetIssue(0).getDecayRatio()));
128152
//logger.info(Long.toString(result.get().getAssetIssue(0).getTotalSupply()));
129153
//logger.info(ByteArray.toStr(result.get().getAssetIssue(result.get().getAssetIssueCount()-1).getName().toByteArray()));
130154
//logger.info(ByteArray.toStr(result.get().getAssetIssue(0).getName().toByteArray()));
131155
//logger.info(ByteArray.toStr(result.get().getAssetIssue(0).getName().toByteArray()));
132-
logger.info(Integer.toString(result.get().getAssetIssueCount()));
133-
156+
//logger.info(Integer.toString(result.get().getAssetIssueCount()));
157+
/*
134158
Boolean foundThisName = false;
135159
for (int j = 0; j < result.get().getAssetIssueCount(); j++) {
136160
logger.info(result.get().getAssetIssue(j).getName().toString());
@@ -143,20 +167,21 @@ public void TestGetAssetIssueByAccount() {
143167
}
144168
}
145169
Assert.assertTrue(foundThisName);
146-
logger.info("TestGetAssetIssueByAccount");
170+
logger.info("TestGetAssetIssueByAccount");*/
147171

148172
}
149173

150174

151175

152176

153-
@Test(enabled = false)
177+
@Test(enabled = true)
154178
public void TestGetAssetIssueList(){
155179
Optional<GrpcAPI.AssetIssueList> result = walletClient.getAssetIssueList();
156180
GrpcAPI.AssetIssueList getAssetIssueList = result.get();
157181
logger.info(Integer.toString(result.get().getAssetIssueCount()));
182+
Assert.assertTrue(result.get().getAssetIssueCount() > 0);
158183

159-
Boolean foundThisName = false;
184+
/* Boolean foundThisName = false;
160185
for (int j =0; j<result.get().getAssetIssueCount(); j++) {
161186
logger.info(ByteArray.toStr(result.get().getAssetIssue(j).getName().toByteArray()));
162187
if (result.get().getAssetIssue(j).getTotalSupply() == TotalSupply){
@@ -165,7 +190,7 @@ public void TestGetAssetIssueList(){
165190
}
166191
}
167192
Assert.assertTrue(foundThisName);
168-
logger.info("TestGetAssetIssueList");
193+
logger.info("TestGetAssetIssueList");*/
169194
}
170195

171196
@Test(enabled = false)
@@ -186,19 +211,85 @@ public void TestGetAssetIssueByTimestamp(){
186211

187212
}
188213

189-
@Test(enabled = false)
214+
@Test(enabled = true)
190215
public void TestParticipateAssetIssue(){
191216
Contract.ParticipateAssetIssueContract result = walletClient.participateAssetIssueContract(TO_ADDRESS, name.getBytes(),FROM_ADDRESS, AMOUNT);
192-
Assert.assertTrue(AMOUNT != 0);
193-
logger.info(Long.toString(result.getAmount()));
217+
218+
Assert.assertTrue(result.getAmount() == AMOUNT);
219+
//Assert.assertTrue(AMOUNT != 0);
220+
//logger.info(Long.toString(result.getAmount()));
194221
//logger.info(result.getAssetName());
195-
logger.info("This is TestParticipateAssetIssue.");
222+
//logger.info("This is TestParticipateAssetIssue.");
196223
}
197224

198225
@AfterClass
199226
public void afterClass() {
200227
logger.info("this is after class");
201228
}
202229

230+
public Boolean CreateAssetIssue(byte[] address, String name, Long TotalSupply, Integer TrxNum, Integer IcoNum, Long StartTime, Long EndTime,
231+
Integer VoteScore, String Description, String URL, String priKey){
232+
//long TotalSupply = 100000000L;
233+
//int TrxNum = 1;
234+
//int IcoNum = 100;
235+
//long StartTime = 1522583680000L;
236+
//long EndTime = 1525089280000L;
237+
//int DecayRatio = 1;
238+
//int VoteScore = 2;
239+
//String Description = "just-test";
240+
//String Url = "https://github.com/tronprotocol/wallet-cli/";
241+
ECKey temKey = null;
242+
try {
243+
BigInteger priK = new BigInteger(priKey, 16);
244+
temKey = ECKey.fromPrivate(priK);
245+
} catch (Exception ex) {
246+
ex.printStackTrace();
247+
}
248+
ECKey ecKey= temKey;
249+
//Protocol.Account search = queryAccount(ecKey, blockingStubFull);
250+
251+
try {
252+
Contract.AssetIssueContract.Builder builder = Contract.AssetIssueContract.newBuilder();
253+
builder.setOwnerAddress(ByteString.copyFrom(address));
254+
builder.setName(ByteString.copyFrom(name.getBytes()));
255+
builder.setTotalSupply(TotalSupply);
256+
builder.setTrxNum(TrxNum);
257+
builder.setNum(IcoNum);
258+
builder.setStartTime(StartTime);
259+
builder.setEndTime(EndTime);
260+
//builder.setDecayRatio(DecayRatio);
261+
builder.setVoteScore(VoteScore);
262+
builder.setDescription(ByteString.copyFrom(Description.getBytes()));
263+
builder.setUrl(ByteString.copyFrom(URL.getBytes()));
264+
265+
Protocol.Transaction transaction = blockingStubFull.createAssetIssue(builder.build());
266+
if (transaction == null || transaction.getRawData().getContractCount() == 0) {
267+
logger.info("transaction == null, create assetissue failed");
268+
return false;
269+
}
270+
transaction = signTransaction(ecKey,transaction);
271+
GrpcAPI.Return response = blockingStubFull.broadcastTransaction(transaction);
272+
if (response.getResult() == false){
273+
logger.info(ByteArray.toStr(response.getMessage().toByteArray()));
274+
return false;
275+
}
276+
else{
277+
logger.info(name);
278+
return true;
279+
}
280+
} catch (Exception ex) {
281+
ex.printStackTrace();
282+
return false;
283+
}
284+
}
285+
286+
private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction transaction) {
287+
if (ecKey == null || ecKey.getPrivKey() == null) {
288+
logger.warn("Warning: Can't sign,there is no private key !!");
289+
return null;
290+
}
291+
transaction = TransactionUtils.setTimestamp(transaction);
292+
return TransactionUtils.sign(transaction, ecKey);
293+
}
203294

204295
}

0 commit comments

Comments
 (0)