Skip to content

Commit c138e55

Browse files
authored
Merge pull request tronprotocol#2010 from tronprotocol/add_http_stest_case
Add http stest case
2 parents ac50c5a + 8bbfd8f commit c138e55

20 files changed

+1775
-76
lines changed

src/test/java/stest/tron/wallet/common/client/utils/HttpMethed.java

Lines changed: 401 additions & 2 deletions
Large diffs are not rendered by default.
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
package stest.tron.wallet.dailybuild.http;
2+
3+
import com.alibaba.fastjson.JSONArray;
4+
import com.alibaba.fastjson.JSONObject;
5+
import com.google.gson.JsonArray;
6+
import com.google.gson.JsonObject;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.apache.http.HttpResponse;
9+
import org.junit.Assert;
10+
import org.testng.annotations.AfterClass;
11+
import org.testng.annotations.Test;
12+
import org.tron.common.crypto.ECKey;
13+
import org.tron.common.utils.ByteArray;
14+
import org.tron.common.utils.Utils;
15+
import stest.tron.wallet.common.client.Configuration;
16+
import stest.tron.wallet.common.client.utils.HttpMethed;
17+
import stest.tron.wallet.common.client.utils.PublicMethed;
18+
19+
@Slf4j
20+
public class HttpTestAccount003 {
21+
22+
private final String testKey002 = Configuration.getByPath("testng.conf")
23+
.getString("foundationAccount.key1");
24+
private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002);
25+
private JSONObject responseContent;
26+
private HttpResponse response;
27+
private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list")
28+
.get(0);
29+
private final String witnessKey001 = Configuration.getByPath("testng.conf")
30+
.getString("witness.key1");
31+
private final byte[] witness1Address = PublicMethed.getFinalAddress(witnessKey001);
32+
private final String witnessKey002 = Configuration.getByPath("testng.conf")
33+
.getString("witness.key2");
34+
private final byte[] witness2Address = PublicMethed.getFinalAddress(witnessKey002);
35+
36+
ECKey ecKey1 = new ECKey(Utils.getRandom());
37+
byte[] newAccountAddress = ecKey1.getAddress();
38+
String newAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
39+
40+
41+
ECKey ecKey2 = new ECKey(Utils.getRandom());
42+
byte[] updateAccountAddress = ecKey2.getAddress();
43+
String updateAccountKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes());
44+
private final Long createWitnessAmount = Configuration.getByPath("testng.conf")
45+
.getLong("defaultParameter.createWitnessAmount");
46+
Long amount = 50000000L;
47+
private static String updateAccountName = "updateAccount_"
48+
+ Long.toString(System.currentTimeMillis());
49+
private static String updateUrl = "http://www.update.url" + Long.toString(System.currentTimeMillis());
50+
51+
JsonArray voteKeys = new JsonArray();
52+
JsonObject voteElement = new JsonObject();
53+
54+
55+
56+
/**
57+
* constructor.
58+
*/
59+
@Test(enabled = true, description = "Update account by http")
60+
public void test1UpdateAccount() {
61+
response = HttpMethed.sendCoin(httpnode, fromAddress, updateAccountAddress, amount, testKey002);
62+
Assert.assertTrue(HttpMethed.verificationResult(response));
63+
64+
HttpMethed.waitToProduceOneBlock(httpnode);
65+
66+
response = HttpMethed.updateAccount(httpnode, updateAccountAddress,updateAccountName,
67+
updateAccountKey);
68+
Assert.assertTrue(HttpMethed.verificationResult(response));
69+
70+
71+
response = HttpMethed.getAccount(httpnode, updateAccountAddress);
72+
responseContent = HttpMethed.parseResponseContent(response);
73+
HttpMethed.printJsonContent(responseContent);
74+
Assert.assertTrue(responseContent.getString("account_name")
75+
.equalsIgnoreCase(HttpMethed.str2hex(updateAccountName)));
76+
77+
Assert.assertFalse(responseContent.getString("active_permission").isEmpty());
78+
}
79+
80+
/**
81+
* constructor.
82+
*/
83+
@Test(enabled = true, description = "Vote witness account by http")
84+
public void test2VoteWitnessAccount() {
85+
//Freeze balance
86+
response = HttpMethed.freezeBalance(httpnode,updateAccountAddress,40000000L,0,
87+
0,updateAccountKey);
88+
Assert.assertTrue(HttpMethed.verificationResult(response));
89+
90+
voteElement.addProperty("vote_address",ByteArray.toHexString(witness1Address));
91+
voteElement.addProperty("vote_count",11);
92+
voteKeys.add(voteElement);
93+
94+
voteElement.remove("vote_address");
95+
voteElement.remove("vote_count");
96+
voteElement.addProperty("vote_address",ByteArray.toHexString(witness2Address));
97+
voteElement.addProperty("vote_count",12);
98+
voteKeys.add(voteElement);
99+
100+
response = HttpMethed.voteWitnessAccount(httpnode,updateAccountAddress,voteKeys,
101+
updateAccountKey);
102+
Assert.assertTrue(HttpMethed.verificationResult(response));
103+
104+
response = HttpMethed.getAccount(httpnode, updateAccountAddress);
105+
responseContent = HttpMethed.parseResponseContent(response);
106+
HttpMethed.printJsonContent(responseContent);
107+
Assert.assertTrue(!responseContent.getString("votes").isEmpty());
108+
}
109+
110+
/**
111+
* constructor.
112+
*/
113+
@Test(enabled = true, description = "List witnesses by http")
114+
public void test3ListWitness() {
115+
response = HttpMethed.listwitnesses(httpnode);
116+
responseContent = HttpMethed.parseResponseContent(response);
117+
HttpMethed.printJsonContent(responseContent);
118+
JSONArray jsonArray = JSONArray.parseArray(responseContent.getString("witnesses"));
119+
Assert.assertTrue(jsonArray.size() >= 2);
120+
}
121+
122+
/**
123+
* constructor.
124+
*/
125+
@Test(enabled = true, description = "Update witness by http")
126+
public void test4UpdateWitness() {
127+
response = HttpMethed.updateWitness(httpnode,witness1Address,updateUrl,witnessKey001);
128+
Assert.assertTrue(HttpMethed.verificationResult(response));
129+
130+
HttpMethed.waitToProduceOneBlock(httpnode);
131+
132+
response = HttpMethed.listwitnesses(httpnode);
133+
responseContent = HttpMethed.parseResponseContent(response);
134+
HttpMethed.printJsonContent(responseContent);
135+
Assert.assertTrue(responseContent.getString("witnesses").indexOf(updateUrl) != -1);
136+
//logger.info("result is " + responseContent.getString("witnesses").indexOf(updateUrl));
137+
}
138+
139+
/**
140+
* constructor.
141+
*/
142+
@Test(enabled = true, description = "Create account by http")
143+
public void test5CreateAccount() {
144+
PublicMethed.printAddress(newAccountKey);
145+
response = HttpMethed.createAccount(httpnode,fromAddress,newAccountAddress,testKey002);
146+
Assert.assertTrue(HttpMethed.verificationResult(response));
147+
148+
response = HttpMethed.getAccount(httpnode, newAccountAddress);
149+
responseContent = HttpMethed.parseResponseContent(response);
150+
HttpMethed.printJsonContent(responseContent);
151+
Assert.assertTrue(responseContent.getLong("create_time") > 3);
152+
}
153+
154+
/**
155+
* constructor.
156+
*/
157+
@Test(enabled = true, description = "Create witness by http")
158+
public void test6CreateWitness() {
159+
response = HttpMethed.sendCoin(httpnode,fromAddress,newAccountAddress,createWitnessAmount,testKey002);
160+
Assert.assertTrue(HttpMethed.verificationResult(response));
161+
162+
PublicMethed.printAddress(newAccountKey);
163+
HttpMethed.waitToProduceOneBlock(httpnode);
164+
165+
response = HttpMethed.createWitness(httpnode,newAccountAddress,updateUrl);
166+
responseContent = HttpMethed.parseResponseContent(response);
167+
HttpMethed.printJsonContent(responseContent);
168+
Assert.assertTrue(!responseContent.getString("txID").isEmpty());
169+
}
170+
171+
/**
172+
* constructor.
173+
*/
174+
@Test(enabled = true, description = "Withdraw by http")
175+
public void test7Withdraw() {
176+
response = HttpMethed.withdrawBalance(httpnode,witness1Address);
177+
responseContent = HttpMethed.parseResponseContent(response);
178+
HttpMethed.printJsonContent(responseContent);
179+
Assert.assertTrue(responseContent.getString("Error").indexOf("is a guard representative") != -1);
180+
181+
}
182+
183+
184+
185+
186+
187+
/**
188+
* constructor.
189+
*/
190+
@AfterClass
191+
public void shutdown() throws InterruptedException {
192+
HttpMethed.disConnect();
193+
}
194+
}

src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAsset001.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class HttpTestAsset001 {
4444
private static String name = "testAssetIssue002_" + Long.toString(now);
4545
private static final long totalSupply = now;
4646
private static String assetIssueId;
47+
private static String updateDescription = "Description_update_" + Long.toString(now);
48+
private static String updateUrl = "Url_update_" + Long.toString(now);
4749

4850
/**
4951
* constructor.
@@ -124,6 +126,31 @@ public void test5ParticipateAssetIssue() {
124126

125127
}
126128

129+
/**
130+
* constructor.
131+
*/
132+
@Test(enabled = true, description = "Update asset issue by http")
133+
public void test6UpdateAssetIssue() {
134+
response = HttpMethed.updateAssetIssue(httpnode,assetAddress,updateDescription,updateUrl,
135+
290L,390L,assetKey);
136+
Assert.assertTrue(HttpMethed.verificationResult(response));
137+
138+
HttpMethed.waitToProduceOneBlock(httpnode);
139+
response = HttpMethed.getAssetIssueById(httpnode,assetIssueId);
140+
getAssetIssueByIdContent = HttpMethed.parseResponseContent(response);
141+
HttpMethed.printJsonContent(getAssetIssueByIdContent);
142+
143+
144+
Assert.assertTrue(getAssetIssueByIdContent
145+
.getLong("public_free_asset_net_limit") == 390L);
146+
Assert.assertTrue(getAssetIssueByIdContent
147+
.getLong("free_asset_net_limit") == 290L);
148+
Assert.assertTrue(getAssetIssueByIdContent
149+
.getString("description").equalsIgnoreCase(HttpMethed.str2hex(updateDescription)));
150+
Assert.assertTrue(getAssetIssueByIdContent
151+
.getString("url").equalsIgnoreCase(HttpMethed.str2hex(updateUrl)));
152+
}
153+
127154

128155
/**
129156
* constructor.

src/test/java/stest/tron/wallet/dailybuild/http/HttpTestBlock001.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ public void get5BlockById() {
9797
Assert.assertEquals(blockId,responseContent.get("blockID").toString());
9898
}
9999

100+
/**
101+
* constructor.
102+
*/
103+
@Test(enabled = true, description = "List nodes by http")
104+
public void get6ListNodes() {
105+
response = HttpMethed.listNodes(httpnode);
106+
responseContent = HttpMethed.parseResponseContent(response);
107+
HttpMethed.printJsonContent(responseContent);
108+
JSONArray jsonArray = JSONArray.parseArray(responseContent.get("nodes").toString());
109+
Assert.assertTrue(jsonArray.size() >= 2);
110+
}
111+
112+
100113
/**
101114
* constructor.
102115
*/

src/test/java/stest/tron/wallet/dailybuild/http/HttpTestExchange001.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public void test1CreateExchange() {
6262
response = HttpMethed.sendCoin(httpnode,fromAddress,asset2Address,amount,testKey002);
6363
Assert.assertTrue(HttpMethed.verificationResult(response));
6464

65+
HttpMethed.waitToProduceOneBlock(httpnode);
66+
6567
//Create an asset issue
6668
response = HttpMethed.assetIssue(httpnode,exchangeOwnerAddress,name,name,totalSupply,1,1,
6769
System.currentTimeMillis() + 5000,System.currentTimeMillis() + 50000000,
@@ -72,6 +74,8 @@ public void test1CreateExchange() {
7274
2,3,description,url,1000L, 1000L,asset2Key);
7375
Assert.assertTrue(HttpMethed.verificationResult(response));
7476

77+
HttpMethed.waitToProduceOneBlock(httpnode);
78+
7579
response = HttpMethed.getAccount(httpnode,exchangeOwnerAddress);
7680
responseContent = HttpMethed.parseResponseContent(response);
7781
assetIssueId1 = responseContent.getString("asset_issued_ID");
@@ -82,6 +86,8 @@ public void test1CreateExchange() {
8286
assetIssueId2 = responseContent.getString("asset_issued_ID");
8387
Assert.assertTrue(Integer.parseInt(assetIssueId2) > 1000000);
8488

89+
HttpMethed.waitToProduceOneBlock(httpnode);
90+
8591
response = HttpMethed.transferAsset(httpnode,asset2Address,exchangeOwnerAddress,assetIssueId2,
8692
10000000000L,asset2Key);
8793
Assert.assertTrue(HttpMethed.verificationResult(response));
@@ -100,6 +106,7 @@ public void test1CreateExchange() {
100106
*/
101107
@Test(enabled = true, description = "List exchanges by http")
102108
public void test2ListExchange() {
109+
HttpMethed.waitToProduceOneBlock(httpnode);
103110
response = HttpMethed.listExchanges(httpnode);
104111
responseContent = HttpMethed.parseResponseContent(response);
105112
HttpMethed.printJsonContent(responseContent);
@@ -133,6 +140,7 @@ public void test4InjectExchange() {
133140
response = HttpMethed.exchangeInject(httpnode,exchangeOwnerAddress,exchangeId,assetIssueId1,
134141
300L,exchangeOwnerKey);
135142
Assert.assertTrue(HttpMethed.verificationResult(response));
143+
HttpMethed.waitToProduceOneBlock(httpnode);
136144
response = HttpMethed.getExchangeById(httpnode,exchangeId);
137145
responseContent = HttpMethed.parseResponseContent(response);
138146
afterInjectBalance = responseContent.getLong("first_token_balance");
@@ -153,6 +161,7 @@ public void test5WithdrawExchange() {
153161
response = HttpMethed.exchangeWithdraw(httpnode,exchangeOwnerAddress,exchangeId,assetIssueId1,
154162
170L,exchangeOwnerKey);
155163
Assert.assertTrue(HttpMethed.verificationResult(response));
164+
HttpMethed.waitToProduceOneBlock(httpnode);
156165
response = HttpMethed.getExchangeById(httpnode,exchangeId);
157166
responseContent = HttpMethed.parseResponseContent(response);
158167
afterWithdrawBalance = responseContent.getLong("first_token_balance");
@@ -169,9 +178,10 @@ public void test5WithdrawExchange() {
169178
@Test(enabled = true, description = "Transaction exchange by http")
170179
public void test6TransactionExchange() {
171180
//Transaction exchange.
172-
response = HttpMethed.exchangeTransaction(httpnode,exchangeOwnerAddress,exchangeId,assetIssueId1,
173-
100L,1L,exchangeOwnerKey);
181+
response = HttpMethed.exchangeTransaction(httpnode,exchangeOwnerAddress,exchangeId,
182+
assetIssueId1, 100L,1L,exchangeOwnerKey);
174183
Assert.assertTrue(HttpMethed.verificationResult(response));
184+
HttpMethed.waitToProduceOneBlock(httpnode);
175185
response = HttpMethed.getExchangeById(httpnode,exchangeId);
176186
responseContent = HttpMethed.parseResponseContent(response);
177187
afterTransactionBalance = responseContent.getLong("first_token_balance");
@@ -182,6 +192,18 @@ public void test6TransactionExchange() {
182192
}
183193

184194

195+
/**
196+
* constructor.
197+
*/
198+
@Test(enabled = true, description = "Get asset issue list by name by http")
199+
public void test7GetAssetIssueListByName() {
200+
response = HttpMethed.getAssetIssueListByName(httpnode,name);
201+
responseContent = HttpMethed.parseResponseContent(response);
202+
HttpMethed.printJsonContent(responseContent);
203+
JSONArray jsonArray = JSONArray.parseArray(responseContent.get("assetIssue").toString());
204+
Assert.assertTrue(jsonArray.size() >= 2);
205+
}
206+
185207

186208

187209

src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMutiSign001.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ public void test1AccountPermissionUpDate() {
6666
keys.add(manager1Wight);
6767
keys.add(manager2Wight);
6868

69-
70-
7169
ownerObject.addProperty("type", 0);
7270
ownerObject.addProperty("permission_name", "owner");
7371
ownerObject.addProperty("threshold", 2);
@@ -85,20 +83,11 @@ public void test1AccountPermissionUpDate() {
8583
Assert.assertTrue(HttpMethed.verificationResult(response));
8684
}
8785

88-
89-
/**
90-
* constructor.
91-
*/
92-
@Test(enabled = true, description = "Get sign weight by http")
93-
public void test2GetSignWeight() {
94-
95-
}
96-
9786
/**
9887
* constructor.
9988
*/
10089
@Test(enabled = true, description = "Add transaction sign by http")
101-
public void test3AddTransactionSign() {
90+
public void test2AddTransactionSign() {
10291

10392
HttpMethed.waitToProduceOneBlock(httpnode);
10493
String[] permissionKeyString = new String[2];

0 commit comments

Comments
 (0)