Skip to content

Commit eeea2e9

Browse files
author
wangzihe
committed
Add some http interface case
1 parent b3dcafa commit eeea2e9

File tree

4 files changed

+216
-9
lines changed

4 files changed

+216
-9
lines changed

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

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class HttpMethed {
2929
static String transactionSignString;
3030
static JSONObject responseContent;
3131
static JSONObject signResponseContent;
32+
static JSONObject transactionApprovedListContent;
3233

3334
/**
3435
* constructor.
@@ -104,6 +105,73 @@ public static HttpResponse voteWitnessAccount(String httpNode, byte[] ownerAddre
104105
return response;
105106
}
106107

108+
/**
109+
* constructor.
110+
*/
111+
public static HttpResponse createAccount(String httpNode, byte[] ownerAddress,
112+
byte[] accountAddress, String fromKey) {
113+
try {
114+
final String requestUrl = "http://" + httpNode + "/wallet/createaccount";
115+
JsonObject userBaseObj2 = new JsonObject();
116+
userBaseObj2.addProperty("account_address", ByteArray.toHexString(accountAddress));
117+
userBaseObj2.addProperty("owner_address", ByteArray.toHexString(ownerAddress));
118+
response = createConnect(requestUrl, userBaseObj2);
119+
transactionString = EntityUtils.toString(response.getEntity());
120+
transactionSignString = gettransactionsign(httpNode,transactionString,fromKey);
121+
response = broadcastTransaction(httpNode,transactionSignString);
122+
} catch (Exception e) {
123+
e.printStackTrace();
124+
httppost.releaseConnection();
125+
return null;
126+
}
127+
return response;
128+
}
129+
130+
/**
131+
* constructor.
132+
*/
133+
public static HttpResponse createWitness(String httpNode, byte[] ownerAddress, String url) {
134+
try {
135+
final String requestUrl = "http://" + httpNode + "/wallet/createwitness";
136+
JsonObject userBaseObj2 = new JsonObject();
137+
userBaseObj2.addProperty("url", str2hex(url));
138+
userBaseObj2.addProperty("owner_address", ByteArray.toHexString(ownerAddress));
139+
response = createConnect(requestUrl, userBaseObj2);
140+
logger.info(userBaseObj2.toString());
141+
//transactionString = EntityUtils.toString(response.getEntity());
142+
//transactionSignString = gettransactionsign(httpNode,transactionString,fromKey);
143+
//response = broadcastTransaction(httpNode,transactionSignString);
144+
} catch (Exception e) {
145+
e.printStackTrace();
146+
httppost.releaseConnection();
147+
return null;
148+
}
149+
return response;
150+
}
151+
152+
/**
153+
* constructor.
154+
*/
155+
public static HttpResponse withdrawBalance(String httpNode, byte[] witnessAddress) {
156+
try {
157+
final String requestUrl = "http://" + httpNode + "/wallet/withdrawbalance";
158+
JsonObject userBaseObj2 = new JsonObject();
159+
userBaseObj2.addProperty("owner_address", ByteArray.toHexString(witnessAddress));
160+
response = createConnect(requestUrl, userBaseObj2);
161+
logger.info(userBaseObj2.toString());
162+
//transactionString = EntityUtils.toString(response.getEntity());
163+
//transactionSignString = gettransactionsign(httpNode,transactionString,fromKey);
164+
//response = broadcastTransaction(httpNode,transactionSignString);
165+
} catch (Exception e) {
166+
e.printStackTrace();
167+
httppost.releaseConnection();
168+
return null;
169+
}
170+
return response;
171+
}
172+
173+
174+
107175
/**
108176
* constructor.
109177
*/
@@ -141,12 +209,20 @@ public static HttpResponse sendCoin(String httpNode, byte[] fromAddress, byte[]
141209
response = createConnect(requestUrl, userBaseObj2);
142210
transactionSignString = EntityUtils.toString(response.getEntity());
143211
HttpResponse getSignWeightResponse;
212+
HttpResponse getTransactionApprovedListResponse;
213+
144214
for (String key: managerKeys) {
145215
transactionSignString = gettransactionsign(httpNode,transactionSignString,key);
146216
getSignWeightResponse = getSignWeight(httpNode,transactionSignString);
147217
signResponseContent = parseResponseContent(getSignWeightResponse);
218+
logger.info("-----------sign information-----------------");
219+
printJsonContent(signResponseContent);
220+
getSignWeightResponse = getTransactionApprovedList(httpNode,transactionSignString);
221+
signResponseContent = parseResponseContent(getSignWeightResponse);
222+
logger.info("-----------get Transaction Approved List-----------------");
148223
printJsonContent(signResponseContent);
149224

225+
150226
}
151227
response = broadcastTransaction(httpNode,transactionSignString);
152228
} catch (Exception e) {
@@ -560,6 +636,34 @@ public static HttpResponse participateAssetIssue(String httpNode, byte[] toAddre
560636
return response;
561637
}
562638

639+
/**
640+
* constructor.
641+
*/
642+
public static HttpResponse updateAssetIssue(String httpNode, byte[] ownerAddress,
643+
String description, String url,Long newLimit, Long newPublicLimit, String fromKey) {
644+
try {
645+
final String requestUrl = "http://" + httpNode + "/wallet/updateasset";
646+
JsonObject userBaseObj2 = new JsonObject();
647+
userBaseObj2.addProperty("owner_address", ByteArray.toHexString(ownerAddress));
648+
userBaseObj2.addProperty("url", str2hex(url));
649+
userBaseObj2.addProperty("description", str2hex(description));
650+
userBaseObj2.addProperty("new_limit", newLimit);
651+
userBaseObj2.addProperty("new_public_limit", newPublicLimit);
652+
response = createConnect(requestUrl, userBaseObj2);
653+
transactionString = EntityUtils.toString(response.getEntity());
654+
logger.info(transactionString);
655+
transactionSignString = gettransactionsign(httpNode,transactionString,fromKey);
656+
logger.info(transactionSignString);
657+
response = broadcastTransaction(httpNode,transactionSignString);
658+
} catch (Exception e) {
659+
e.printStackTrace();
660+
httppost.releaseConnection();
661+
return null;
662+
}
663+
return response;
664+
}
665+
666+
563667
/**
564668
* constructor.
565669
*/
@@ -763,6 +867,35 @@ public static HttpResponse getSignWeight(String httpNode,String transactionSignS
763867
return response;
764868
}
765869

870+
/**
871+
* constructor.
872+
*/
873+
public static HttpResponse getTransactionApprovedList(String httpNode,
874+
String transactionSignString) {
875+
try {
876+
String requestUrl = "http://" + httpNode + "/wallet/getapprovedlist";
877+
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
878+
connectionTimeout);
879+
httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, soTimeout);
880+
httppost = new HttpPost(requestUrl);
881+
httppost.setHeader("Content-type", "application/json; charset=utf-8");
882+
httppost.setHeader("Connection", "Close");
883+
if (transactionSignString != null) {
884+
StringEntity entity = new StringEntity(transactionSignString, Charset.forName("UTF-8"));
885+
entity.setContentEncoding("UTF-8");
886+
entity.setContentType("application/json");
887+
httppost.setEntity(entity);
888+
}
889+
response = httpClient.execute(httppost);
890+
} catch (Exception e) {
891+
e.printStackTrace();
892+
httppost.releaseConnection();
893+
return null;
894+
}
895+
httppost.releaseConnection();
896+
return response;
897+
}
898+
766899

767900

768901
/**

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

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ public class HttpTestAccount003 {
3333
.getString("witness.key2");
3434
private final byte[] witness2Address = PublicMethed.getFinalAddress(witnessKey002);
3535

36-
3736
ECKey ecKey1 = new ECKey(Utils.getRandom());
38-
byte[] updateAccountAddress = ecKey1.getAddress();
39-
String updateAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
37+
byte[] newAccountAddress = ecKey1.getAddress();
38+
String newAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
39+
4040

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");
4146
Long amount = 50000000L;
4247
private static String updateAccountName = "updateAccount_"
4348
+ Long.toString(System.currentTimeMillis());
@@ -92,9 +97,8 @@ public void test2VoteWitnessAccount() {
9297
voteElement.addProperty("vote_count",12);
9398
voteKeys.add(voteElement);
9499

95-
//voteKeys.getAsString();
96-
97-
response = HttpMethed.voteWitnessAccount(httpnode,updateAccountAddress,voteKeys,updateAccountKey);
100+
response = HttpMethed.voteWitnessAccount(httpnode,updateAccountAddress,voteKeys,
101+
updateAccountKey);
98102
Assert.assertTrue(HttpMethed.verificationResult(response));
99103

100104
response = HttpMethed.getAccount(httpnode, updateAccountAddress);
@@ -128,7 +132,52 @@ public void test4UpdateWitness() {
128132
response = HttpMethed.listwitnesses(httpnode);
129133
responseContent = HttpMethed.parseResponseContent(response);
130134
HttpMethed.printJsonContent(responseContent);
131-
logger.info("result is " + responseContent.getString("witnesses").indexOf(updateUrl));
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+
132181
}
133182

134183

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/HttpTestMutiSign001.java

Lines changed: 0 additions & 2 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);

0 commit comments

Comments
 (0)