Skip to content

Commit f9a4544

Browse files
Merge pull request #6219 from lxcmyf/feature/sensitive_information_optimization
feat(test): optimize unit testing configuration
2 parents 93dfc33 + 34393f6 commit f9a4544

File tree

5 files changed

+9
-586
lines changed

5 files changed

+9
-586
lines changed

framework/src/test/java/org/tron/common/utils/client/WalletClient.java

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -96,65 +96,6 @@ public WalletClient(final ECKey ecKey) {
9696
this.ecKey = ecKey;
9797
}
9898

99-
/**
100-
* constructor.
101-
*/
102-
103-
public static boolean init(int itype) {
104-
Config config = Configuration.getByPath("testng.conf");
105-
dbPath = config.getString("CityDb.DbPath");
106-
txtPath = System.getProperty("user.dir") + '/' + config.getString("CityDb.TxtPath");
107-
108-
String fullNodepathname = "";
109-
110-
if (1000 == itype) {
111-
fullNodepathname = "checkfullnode.ip.list";
112-
} else {
113-
fullNodepathname = "fullnode.ip.list";
114-
}
115-
String fullNode = "";
116-
String solidityNode = "";
117-
if (config.hasPath("soliditynode.ip.list")) {
118-
solidityNode = config.getStringList("soliditynode.ip.list").get(0);
119-
}
120-
if (config.hasPath(fullNodepathname)) {
121-
fullNode = config.getStringList(fullNodepathname).get(itype);
122-
}
123-
if (config.hasPath("net.type") && "mainnet".equalsIgnoreCase(config.getString("net.type"))) {
124-
WalletClient.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
125-
} else {
126-
WalletClient.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_TESTNET);
127-
}
128-
rpcCli = new GrpcClient(fullNode, solidityNode);
129-
return true;
130-
}
131-
132-
/**
133-
* constructor.
134-
*/
135-
136-
public static GrpcClient init() {
137-
//Config config = org.tron.core.config.Configuration.getByPath("config.conf");
138-
Config config = Configuration.getByPath("testng.conf");
139-
dbPath = config.getString("CityDb.DbPath");
140-
txtPath = System.getProperty("user.dir") + "/" + config.getString("CityDb.TxtPath");
141-
142-
String fullNode = "";
143-
String solidityNode = "";
144-
if (config.hasPath("soliditynode.ip.list")) {
145-
solidityNode = config.getStringList("soliditynode.ip.list").get(0);
146-
}
147-
if (config.hasPath("fullnode.ip.list")) {
148-
fullNode = config.getStringList("fullnode.ip.list").get(0);
149-
}
150-
if (config.hasPath("net.type") && "mainnet".equalsIgnoreCase(config.getString("net.type"))) {
151-
WalletClient.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
152-
} else {
153-
WalletClient.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_TESTNET);
154-
}
155-
return new GrpcClient(fullNode, solidityNode);
156-
}
157-
15899
public static byte getAddressPreFixByte() {
159100
return addressPreFixByte;
160101
}

framework/src/test/java/org/tron/common/utils/client/utils/HttpMethed.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ public class HttpMethed {
3636
static HttpClient httpClient;
3737
static HttpPost httppost;
3838
static HttpResponse response;
39-
static Integer connectionTimeout =
40-
Configuration.getByPath("testng.conf").getInt("defaultParameter.httpConnectionTimeout");
41-
static Integer soTimeout =
42-
Configuration.getByPath("testng.conf").getInt("defaultParameter.httpSoTimeout");
39+
static Integer connectionTimeout = 19000;
40+
static Integer soTimeout = 18000;
4341
static String transactionString;
4442
static String transactionSignString;
4543
static JSONObject responseContent;
@@ -48,8 +46,7 @@ public class HttpMethed {
4846
public static volatile Integer witnessNum;
4947

5048
/** constructor. */
51-
private static volatile String httpnode =
52-
Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1);
49+
private static volatile String httpnode = "127.0.0.1:50052";
5350

5451
/** constructor. */
5552
public static Integer getWitnessNum() {
@@ -1171,7 +1168,7 @@ public static String gettransactionsign(
11711168
String httpNode, String transactionString, String privateKey) {
11721169
try {
11731170
transactionSignString = TransactionUtils.getTransactionSign(transactionString, privateKey,
1174-
false);
1171+
false);
11751172
} catch (Exception e) {
11761173
e.printStackTrace();
11771174
httppost.releaseConnection();
@@ -3446,7 +3443,7 @@ public static Boolean getSpendResult(
34463443
String jsonString = responseContent.toJSONString();
34473444
if (jsonString.contains("result")
34483445
&& (responseContent.getString("result").equals("true")
3449-
&& responseContent.getString("message").equals("Input note has been spent"))) {
3446+
&& responseContent.getString("message").equals("Input note has been spent"))) {
34503447
return Boolean.TRUE;
34513448
} else {
34523449
return Boolean.FALSE;
@@ -3501,7 +3498,7 @@ public static Boolean getSpendResultFromSolidity(
35013498
String jsonString = responseContent.toJSONString();
35023499
if (jsonString.contains("result")
35033500
&& (responseContent.getString("result").equals("true")
3504-
&& responseContent.getString("message").equals("Input note has been spent"))) {
3501+
&& responseContent.getString("message").equals("Input note has been spent"))) {
35053502
return Boolean.TRUE;
35063503
} else {
35073504
return Boolean.FALSE;
@@ -3552,7 +3549,7 @@ public static Boolean getSpendResultFromPbft(
35523549
String jsonString = responseContent.toJSONString();
35533550
if (jsonString.contains("result")
35543551
&& (responseContent.getString("result").equals("true")
3555-
&& responseContent.getString("message").equals("Input note has been spent"))) {
3552+
&& responseContent.getString("message").equals("Input note has been spent"))) {
35563553
return Boolean.TRUE;
35573554
} else {
35583555
return Boolean.FALSE;

framework/src/test/java/org/tron/core/services/NodeInfoServiceTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@
44

55
import com.alibaba.fastjson.JSON;
66
import com.google.protobuf.ByteString;
7-
import io.grpc.ManagedChannelBuilder;
87
import java.net.InetSocketAddress;
98
import lombok.extern.slf4j.Slf4j;
109
import org.junit.Assert;
1110
import org.mockito.Mockito;
12-
import org.tron.api.GrpcAPI.EmptyMessage;
13-
import org.tron.api.WalletGrpc;
14-
import org.tron.api.WalletGrpc.WalletBlockingStub;
1511
import org.tron.common.application.TronApplicationContext;
1612
import org.tron.common.entity.NodeInfo;
1713
import org.tron.common.utils.Sha256Hash;
18-
import org.tron.common.utils.client.Configuration;
1914
import org.tron.core.capsule.BlockCapsule;
2015
import org.tron.core.net.P2pEventHandlerImpl;
21-
import org.tron.core.net.peer.PeerManager;
2216
import org.tron.p2p.connection.Channel;
2317
import org.tron.program.Version;
2418

@@ -29,8 +23,6 @@ public class NodeInfoServiceTest {
2923
private NodeInfoService nodeInfoService;
3024
private WitnessProductBlockService witnessProductBlockService;
3125
private P2pEventHandlerImpl p2pEventHandler;
32-
private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list")
33-
.get(0);
3426

3527
public NodeInfoServiceTest(TronApplicationContext context) {
3628
nodeInfoService = context.getBean("nodeInfoService", NodeInfoService.class);
@@ -60,12 +52,4 @@ public void test() {
6052
logger.info("{}", JSON.toJSONString(nodeInfo));
6153
}
6254

63-
public void testGrpc() {
64-
WalletBlockingStub walletStub = WalletGrpc
65-
.newBlockingStub(ManagedChannelBuilder.forTarget(fullnode)
66-
.usePlaintext()
67-
.build());
68-
logger.info("getNodeInfo: {}", walletStub.getNodeInfo(EmptyMessage.getDefaultInstance()));
69-
}
70-
7155
}

framework/src/test/resources/config-localtest.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ genesis.block = {
225225

226226
witnesses = [
227227
{
228-
address: TN3zfjYUmMFK3ZsHSsrdJoNRtGkQmZLBLz
228+
address: TEDapYSVvAZ3aYH7w8N9tMEEFKaNKUD5Bp
229229
url = "http://Test.org",
230230
voteCount = 106
231231
},
@@ -262,7 +262,7 @@ genesis.block = {
262262
//localWitnessAccountAddress = TN3zfjYUmMFK3ZsHSsrdJoNRtGkQmZLBLz
263263

264264
localwitness = [
265-
f4df789d3210ac881cb900464dd30409453044d2777060a0c391cbdf4c6a4f57
265+
1234567890123456789012345678901234567890123456789012345678901234
266266
]
267267

268268

0 commit comments

Comments
 (0)