Skip to content

Commit 0a16fa2

Browse files
committed
fix the bug of testcase
1 parent 03d2a31 commit 0a16fa2

File tree

3 files changed

+17
-52
lines changed

3 files changed

+17
-52
lines changed

framework/src/test/java/org/tron/core/jsonrpc/ApiUtilTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import static org.tron.keystore.Wallet.generateRandomBytes;
55

66
import com.google.protobuf.ByteString;
7+
import org.junit.AfterClass;
78
import org.junit.Assert;
9+
import org.junit.BeforeClass;
810
import org.junit.Test;
911
import org.tron.common.utils.ByteArray;
1012
import org.tron.core.capsule.BlockCapsule;
13+
import org.tron.core.config.args.Args;
1114
import org.tron.core.services.jsonrpc.JsonRpcApiUtil;
1215
import org.tron.protos.Protocol.Block;
1316
import org.tron.protos.Protocol.BlockHeader;
@@ -16,6 +19,16 @@
1619

1720
public class ApiUtilTest {
1821

22+
@BeforeClass
23+
public static void init() {
24+
Args.setParam(new String[]{}, "config-localtest.conf");
25+
}
26+
27+
@AfterClass
28+
public static void clear() {
29+
Args.clearParam();
30+
}
31+
1932
@Test
2033
public void testGetBlockID() {
2134
byte[] mockedHash = generateRandomBytes(128);

framework/src/test/java/org/tron/core/net/BaseNet.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
package org.tron.core.net;
22

3-
import io.netty.bootstrap.Bootstrap;
4-
import io.netty.channel.Channel;
5-
import io.netty.channel.ChannelInitializer;
6-
import io.netty.channel.ChannelOption;
7-
import io.netty.channel.DefaultMessageSizeEstimator;
8-
import io.netty.channel.FixedRecvByteBufAllocator;
9-
import io.netty.channel.nio.NioEventLoopGroup;
10-
import io.netty.channel.socket.nio.NioSocketChannel;
11-
import io.netty.handler.codec.ByteToMessageDecoder;
12-
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
13-
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
14-
import io.netty.handler.timeout.ReadTimeoutHandler;
15-
import io.netty.handler.timeout.WriteTimeoutHandler;
16-
import java.io.File;
173
import java.io.IOException;
18-
import java.util.Collection;
194
import java.util.concurrent.ExecutorService;
205
import java.util.concurrent.Executors;
21-
import java.util.concurrent.TimeUnit;
226
import lombok.extern.slf4j.Slf4j;
237
import org.junit.AfterClass;
248
import org.junit.Assert;
@@ -29,13 +13,10 @@
2913
import org.tron.common.application.ApplicationFactory;
3014
import org.tron.common.application.TronApplicationContext;
3115
import org.tron.common.parameter.CommonParameter;
32-
import org.tron.common.utils.FileUtil;
3316
import org.tron.common.utils.PublicMethod;
34-
import org.tron.common.utils.ReflectUtils;
3517
import org.tron.core.Constant;
3618
import org.tron.core.config.DefaultConfig;
3719
import org.tron.core.config.args.Args;
38-
import org.tron.core.net.peer.PeerConnection;
3920

4021
@Slf4j
4122
public class BaseNet {
@@ -53,30 +34,6 @@ public class BaseNet {
5334

5435
private static ExecutorService executorService = Executors.newFixedThreadPool(1);
5536

56-
public static Channel connect(ByteToMessageDecoder decoder) throws InterruptedException {
57-
NioEventLoopGroup group = new NioEventLoopGroup(1);
58-
Bootstrap b = new Bootstrap();
59-
b.group(group).channel(NioSocketChannel.class)
60-
.handler(new ChannelInitializer<Channel>() {
61-
@Override
62-
protected void initChannel(Channel ch) throws Exception {
63-
ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(256 * 1024));
64-
ch.config().setOption(ChannelOption.SO_RCVBUF, 256 * 1024);
65-
ch.config().setOption(ChannelOption.SO_BACKLOG, 1024);
66-
ch.pipeline()
67-
.addLast("readTimeoutHandler", new ReadTimeoutHandler(600, TimeUnit.SECONDS))
68-
.addLast("writeTimeoutHandler", new WriteTimeoutHandler(600, TimeUnit.SECONDS));
69-
ch.pipeline().addLast("protoPender", new ProtobufVarint32LengthFieldPrepender());
70-
ch.pipeline().addLast("lengthDecode", new ProtobufVarint32FrameDecoder());
71-
ch.pipeline().addLast("handshakeHandler", decoder);
72-
ch.closeFuture();
73-
}
74-
}).option(ChannelOption.SO_KEEPALIVE, true)
75-
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 60000)
76-
.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT);
77-
return b.connect(Constant.LOCAL_HOST, port).sync().channel();
78-
}
79-
8037
@BeforeClass
8138
public static void init() throws Exception {
8239
executorService.execute(() -> {
@@ -123,11 +80,6 @@ public static void init() throws Exception {
12380

12481
@AfterClass
12582
public static void destroy() {
126-
Collection<PeerConnection> peerConnections = ReflectUtils
127-
.invokeMethod(tronNetDelegate, "getActivePeer");
128-
for (PeerConnection peer : peerConnections) {
129-
peer.getChannel().close();
130-
}
13183
Args.clearParam();
13284
context.destroy();
13385
}

framework/src/test/java/org/tron/core/services/http/GetRewardServletTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ public MockHttpServletRequest createRequest(String contentType) {
5858
@Before
5959
public void init() {
6060
manager.getDynamicPropertiesStore().saveChangeDelegation(1);
61-
byte[] sr = decodeFromBase58Check("27VZHn9PFZwNh7o2EporxmLkpe157iWZVkh");
61+
byte[] sr = decodeFromBase58Check("27bi7CD8d94AgXY3XFS9A9vx78Si5MqrECz");
6262
delegationStore.setBrokerage(0, sr, 10);
6363
delegationStore.setWitnessVote(0, sr, 100000000);
6464
}
6565

6666
@Test
6767
public void getRewardValueByJsonTest() {
6868
int expect = 138181;
69-
String jsonParam = "{\"address\": \"27VZHn9PFZwNh7o2EporxmLkpe157iWZVkh\"}";
69+
String jsonParam = "{\"address\": \"27bi7CD8d94AgXY3XFS9A9vx78Si5MqrECz\"}";
7070
MockHttpServletRequest request = createRequest("application/json");
7171
MockHttpServletResponse response = new MockHttpServletResponse();
7272
request.setContent(jsonParam.getBytes());
@@ -84,7 +84,7 @@ public void getRewardValueByJsonTest() {
8484
@Test
8585
public void getRewardByJsonUTF8Test() {
8686
int expect = 138181;
87-
String jsonParam = "{\"address\": \"27VZHn9PFZwNh7o2EporxmLkpe157iWZVkh\"}";
87+
String jsonParam = "{\"address\": \"27bi7CD8d94AgXY3XFS9A9vx78Si5MqrECz\"}";
8888
MockHttpServletRequest request = createRequest("application/json; charset=utf-8");
8989
MockHttpServletResponse response = new MockHttpServletResponse();
9090
request.setContent(jsonParam.getBytes());
@@ -105,7 +105,7 @@ public void getRewardValueTest() {
105105
MockHttpServletRequest request = createRequest("application/x-www-form-urlencoded");
106106
MockHttpServletResponse response = new MockHttpServletResponse();
107107
mortgageService.payStandbyWitness();
108-
request.addParameter("address", "27VZHn9PFZwNh7o2EporxmLkpe157iWZVkh");
108+
request.addParameter("address", "27bi7CD8d94AgXY3XFS9A9vx78Si5MqrECz");
109109
getRewardServlet.doPost(request, response);
110110
try {
111111
String contentAsString = response.getContentAsString();

0 commit comments

Comments
 (0)