4545import org .tron .core .services .interfaceJsonRpcOnSolidity .JsonRpcServiceOnSolidity ;
4646import org .tron .core .services .jsonrpc .FullNodeJsonRpcHttpService ;
4747import org .tron .core .services .jsonrpc .TronJsonRpc .FilterRequest ;
48+ import org .tron .core .services .jsonrpc .TronJsonRpc .LogFilterElement ;
4849import org .tron .core .services .jsonrpc .TronJsonRpcImpl ;
4950import org .tron .core .services .jsonrpc .filters .LogFilterWrapper ;
5051import org .tron .core .services .jsonrpc .types .BlockResult ;
@@ -109,11 +110,11 @@ public void init() {
109110 blockCapsule0 = BlockUtil .newGenesisBlockCapsule ();
110111 blockCapsule1 = new BlockCapsule (LATEST_BLOCK_NUM , Sha256Hash .wrap (ByteString .copyFrom (
111112 ByteArray .fromHexString (
112- "0304f784e4e7bae517bcab94c3e0c9214fb4ac7ff9d7d5a937d1f40031f87b81" ))), 1 ,
113+ "0304f784e4e7bae517bcab94c3e0c9214fb4ac7ff9d7d5a937d1f40031f87b81" ))), 1000000 ,
113114 ByteString .copyFromUtf8 ("testAddress" ));
114115 blockCapsule2 = new BlockCapsule (LATEST_SOLIDIFIED_BLOCK_NUM , Sha256Hash .wrap (
115116 ByteString .copyFrom (ByteArray .fromHexString (
116- "9938a342238077182498b464ac029222ae169360e540d1fd6aee7c2ae9575a06" ))), 1 ,
117+ "9938a342238077182498b464ac029222ae169360e540d1fd6aee7c2ae9575a06" ))), 2000000 ,
117118 ByteString .copyFromUtf8 ("testAddress" ));
118119
119120 TransferContract transferContract1 = TransferContract .newBuilder ().setAmount (1L )
@@ -135,13 +136,15 @@ public void init() {
135136
136137 transactionCapsule1 = new TransactionCapsule (transferContract1 , ContractType .TransferContract );
137138 transactionCapsule1 .setBlockNum (blockCapsule1 .getNum ());
139+ transactionCapsule1 .setTimestamp (blockCapsule1 .getTimeStamp ());
138140 TransactionCapsule transactionCapsule2 = new TransactionCapsule (transferContract2 ,
139141 ContractType .TransferContract );
140142 transactionCapsule2 .setBlockNum (blockCapsule1 .getNum ());
143+ transactionCapsule2 .setTimestamp (blockCapsule1 .getTimeStamp ());
141144 TransactionCapsule transactionCapsule3 = new TransactionCapsule (transferContract3 ,
142145 ContractType .TransferContract );
143146 transactionCapsule3 .setBlockNum (blockCapsule2 .getNum ());
144-
147+ transactionCapsule3 . setTimestamp ( blockCapsule2 . getTimeStamp ());
145148 blockCapsule1 .addTransaction (transactionCapsule1 );
146149 blockCapsule1 .addTransaction (transactionCapsule2 );
147150 blockCapsule2 .addTransaction (transactionCapsule3 );
@@ -181,6 +184,7 @@ public void init() {
181184 TransactionInfoCapsule transactionInfoCapsule = new TransactionInfoCapsule ();
182185 transactionInfoCapsule .setId (tx .getTransactionId ().getBytes ());
183186 transactionInfoCapsule .setBlockNumber (blockCapsule1 .getNum ());
187+ transactionInfoCapsule .setBlockTimeStamp (blockCapsule1 .getTimeStamp ());
184188 transactionInfoCapsule .addAllLog (logs );
185189 transactionRetCapsule1 .addTransactionInfo (transactionInfoCapsule .getInstance ());
186190 });
@@ -192,6 +196,7 @@ public void init() {
192196 TransactionInfoCapsule transactionInfoCapsule = new TransactionInfoCapsule ();
193197 transactionInfoCapsule .setId (tx .getTransactionId ().getBytes ());
194198 transactionInfoCapsule .setBlockNumber (blockCapsule2 .getNum ());
199+ transactionInfoCapsule .setBlockTimeStamp (blockCapsule2 .getTimeStamp ());
195200 transactionRetCapsule2 .addTransactionInfo (transactionInfoCapsule .getInstance ());
196201 });
197202 dbManager .getTransactionRetStore ()
@@ -969,6 +974,30 @@ public void testMethodBlockRange() {
969974 }
970975 }
971976
977+ @ Test
978+ public void testGetLogs () {
979+ try {
980+ LogFilterElement [] logs = tronJsonRpc .getLogs (
981+ new FilterRequest ("0x2710" , "0x2710" , null , null , null ));
982+ Assert .assertTrue (logs .length > 0 );
983+ LogFilterElement log = logs [0 ];
984+ Assert .assertEquals (ByteArray .toJsonHex (blockCapsule1 .getNum ()), log .getBlockNumber ());
985+ Assert .assertEquals (ByteArray .toJsonHex (blockCapsule1 .getBlockId ().toString ()),
986+ log .getBlockHash ());
987+ Assert .assertEquals ("0x0" , log .getLogIndex ());
988+ Assert .assertFalse (log .isRemoved ());
989+ Assert .assertEquals (1 , log .getTopics ().length );
990+ Assert .assertEquals (
991+ "0x0000000000000000000000000000000000000000000000000000746f70696331" ,
992+ log .getTopics ()[0 ]);
993+ Assert .assertEquals (ByteArray .toJsonHex ("data1" .getBytes ()), log .getData ());
994+ Assert .assertEquals (ByteArray .toJsonHex (blockCapsule1 .getTimeStamp () / 1000 ),
995+ log .getBlockTimestamp ());
996+ } catch (Exception e ) {
997+ Assert .fail ();
998+ }
999+ }
1000+
9721001 @ Test
9731002 public void testNewFilterFinalizedBlock () {
9741003
@@ -1026,6 +1055,10 @@ public void testGetBlockReceipts() {
10261055
10271056 Assert .assertEquals (
10281057 JSON .toJSONString (transactionReceipt ), JSON .toJSONString (transactionReceipt1 ));
1058+
1059+ Assert .assertTrue (transactionReceipt1 .getLogs ().length > 0 );
1060+ Assert .assertEquals (ByteArray .toJsonHex (blockCapsule1 .getTimeStamp () / 1000 ),
1061+ transactionReceipt1 .getLogs ()[0 ].getBlockTimestamp ());
10291062 }
10301063 } catch (JsonRpcInvalidParamsException | JsonRpcInternalException e ) {
10311064 throw new RuntimeException (e );
0 commit comments