11package org .tron .core .net .node ;
22
3+ import com .google .protobuf .ByteString ;
4+ import java .util .List ;
35import lombok .extern .slf4j .Slf4j ;
6+ import org .apache .commons .codec .binary .Hex ;
47import org .apache .commons .collections4 .MapUtils ;
58import org .junit .*;
9+ import org .testng .collections .Lists ;
610import org .tron .common .application .TronApplicationContext ;
711import org .tron .common .application .Application ;
812import org .tron .common .application .ApplicationFactory ;
1418import org .tron .common .utils .FileUtil ;
1519import org .tron .common .utils .ReflectUtils ;
1620import org .tron .core .Constant ;
21+ import org .tron .core .capsule .TransactionCapsule ;
1722import org .tron .core .config .DefaultConfig ;
1823import org .tron .core .config .args .Args ;
1924import org .tron .core .db .ByteArrayWrapper ;
2025import org .tron .core .db .Manager ;
2126import org .tron .core .exception .TraitorPeerException ;
2227import org .tron .core .net .message .TransactionMessage ;
28+ import org .tron .core .net .message .TransactionsMessage ;
2329import org .tron .core .net .node .override .HandshakeHandlerTest ;
2430import org .tron .core .net .node .override .PeerClientTest ;
2531import org .tron .core .net .node .override .TronChannelInitializerTest ;
2632import org .tron .core .net .peer .PeerConnection ;
2733import org .tron .core .services .RpcApiService ;
2834import org .tron .core .services .WitnessService ;
35+ import org .tron .protos .Contract .TransferContract ;
2936import org .tron .protos .Protocol ;
3037import org .tron .protos .Protocol .Inventory .InventoryType ;
3138
3239import java .io .File ;
3340import java .util .Collection ;
3441import java .util .Map ;
3542import java .util .concurrent .ExecutorService ;
43+ import org .tron .protos .Protocol .Transaction .Contract .ContractType ;
3644
3745
3846@ Slf4j
@@ -66,11 +74,25 @@ private static Boolean deleteFolder(File index) {
6674 }
6775
6876 @ Test
69- public void testHandleTransactionMessage () throws TraitorPeerException {
70- PeerConnection peer = new PeerConnection ();
71- Protocol .Transaction transaction = Protocol .Transaction .getDefaultInstance ();
77+ public void testHandleTransactionMessage () throws Exception {
78+
79+ TransferContract tc =
80+ TransferContract .newBuilder ()
81+ .setAmount (10 )
82+ .setOwnerAddress (ByteString .copyFromUtf8 ("aaa" ))
83+ .setToAddress (ByteString .copyFromUtf8 ("bbb" ))
84+ .build ();
85+
86+ TransactionCapsule trx = new TransactionCapsule (tc , ContractType .TransferContract );
87+
88+ Protocol .Transaction transaction = trx .getInstance ();
89+
7290 TransactionMessage transactionMessage = new TransactionMessage (transaction );
91+ List list = Lists .newArrayList ();
92+ list .add (transaction );
93+ TransactionsMessage transactionsMessage = new TransactionsMessage (list );
7394
95+ PeerConnection peer = new PeerConnection ();
7496 //没有向peer广播请求过交易信息
7597 peer .getAdvObjWeRequested ().clear ();
7698 peer .setSyncFlag (true );
@@ -80,7 +102,8 @@ public void testHandleTransactionMessage() throws TraitorPeerException {
80102 //向peer广播请求过交易信息
81103 peer .getAdvObjWeRequested ().put (new Item (transactionMessage .getMessageId (), InventoryType .TRX ), System .currentTimeMillis ());
82104 peer .setSyncFlag (true );
83- node .onMessage (peer , transactionMessage );
105+ logger .info (" {} " , transactionMessage .getMessageId () );
106+ node .onMessage (peer , transactionsMessage );
84107 //Assert.assertEquals(peer.getAdvObjWeRequested().isEmpty(), true);
85108 //ConcurrentHashMap<Sha256Hash, InventoryType> advObjToSpread = ReflectUtils.getFieldValue(nodeImpl, "advObjToSpread");
86109 //Assert.assertEquals(advObjToSpread.contains(transactionMessage.getMessageId()), true);
0 commit comments