Skip to content

Commit e1ef127

Browse files
committed
feat(net): solve the unit test problem
1 parent 6286784 commit e1ef127

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

framework/src/test/java/org/tron/core/net/messagehandler/BlockMsgHandlerTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.google.common.collect.ImmutableList;
44
import com.google.protobuf.ByteString;
5+
import java.lang.reflect.Field;
6+
import java.net.InetSocketAddress;
57
import java.util.List;
68
import org.junit.After;
79
import org.junit.Assert;
@@ -18,6 +20,7 @@
1820
import org.tron.core.net.message.adv.BlockMessage;
1921
import org.tron.core.net.peer.Item;
2022
import org.tron.core.net.peer.PeerConnection;
23+
import org.tron.p2p.connection.Channel;
2124
import org.tron.protos.Protocol.Inventory.InventoryType;
2225
import org.tron.protos.Protocol.Transaction;
2326

@@ -31,12 +34,18 @@ public class BlockMsgHandlerTest {
3134
* init context.
3235
*/
3336
@Before
34-
public void init() {
37+
public void init() throws Exception {
3538
Args.setParam(new String[]{"--output-directory", "output-directory", "--debug"},
3639
Constant.TEST_CONF);
3740
context = new TronApplicationContext(DefaultConfig.class);
3841
handler = context.getBean(BlockMsgHandler.class);
3942
peer = context.getBean(PeerConnection.class);
43+
Channel c1 = new Channel();
44+
InetSocketAddress a1 = new InetSocketAddress("100.1.1.1", 100);
45+
Field field = c1.getClass().getDeclaredField("inetAddress");
46+
field.setAccessible(true);
47+
field.set(c1, a1.getAddress());
48+
peer.setChannel(c1);
4049
}
4150

4251
@Test

0 commit comments

Comments
 (0)