11package org .tron .core .jsonrpc ;
22
3+ import static org .tron .core .services .jsonrpc .JsonRpcApiUtil .MAX_BLOCK_IDENTIFIER_LENGTH ;
34import static org .tron .core .services .jsonrpc .JsonRpcApiUtil .getByJsonBlockId ;
45import static org .tron .core .services .jsonrpc .TronJsonRpcImpl .LATEST_STR ;
56import static org .tron .core .services .jsonrpc .TronJsonRpcImpl .TAG_PENDING_SUPPORT_ERROR ;
@@ -1017,9 +1018,9 @@ public void testNewFilterFinalizedBlock() {
10171018 }
10181019 }
10191020
1020- private String generateLongHexString (int length ) {
1021+ private String generateLongHexString () {
10211022 StringBuilder longInput = new StringBuilder ();
1022- for (int i = 0 ; i < length ; i ++) {
1023+ for (int i = 0 ; i < MAX_BLOCK_IDENTIFIER_LENGTH + 1 ; i ++) {
10231024 longInput .append ("a" );
10241025 }
10251026 return longInput .toString ();
@@ -1037,8 +1038,7 @@ public void testGetBlockReceipts() {
10371038 }
10381039
10391040 try {
1040- // Test Exceeds MAX_BLOCK_IDENTIFIER_LENGTH (128)
1041- tronJsonRpc .getBlockReceipts (generateLongHexString (130 ));
1041+ tronJsonRpc .getBlockReceipts (generateLongHexString ());
10421042 Assert .fail ("Should throw JsonRpcInvalidParamsException for too long blockNumOrTag" );
10431043 } catch (Exception e ) {
10441044 Assert .assertTrue ("Should be JsonRpcInvalidParamsException" ,
@@ -1140,8 +1140,7 @@ public void testValidateBlockNumOrHashOrTag_EthGetBlockTransactionCountByNumber(
11401140 }
11411141
11421142 try {
1143- // Test Exceeds MAX_BLOCK_IDENTIFIER_LENGTH (128)
1144- tronJsonRpc .ethGetBlockTransactionCountByNumber (generateLongHexString (130 ));
1143+ tronJsonRpc .ethGetBlockTransactionCountByNumber (generateLongHexString ());
11451144 Assert .fail ("Should throw JsonRpcInvalidParamsException for too long input" );
11461145 } catch (Exception e ) {
11471146 Assert .assertTrue ("Should be JsonRpcInvalidParamsException" ,
@@ -1170,8 +1169,7 @@ public void testValidateBlockNumOrHashOrTag_EthGetBlockByNumber() {
11701169 }
11711170
11721171 try {
1173- // Test Exceeds MAX_BLOCK_IDENTIFIER_LENGTH (128)
1174- tronJsonRpc .ethGetBlockByNumber (generateLongHexString (130 ), false );
1172+ tronJsonRpc .ethGetBlockByNumber (generateLongHexString (), false );
11751173 Assert .fail ("Should throw JsonRpcInvalidParamsException for too long input" );
11761174 } catch (Exception e ) {
11771175 Assert .assertTrue ("Should be JsonRpcInvalidParamsException" ,
@@ -1200,8 +1198,7 @@ public void testValidateBlockNumOrHashOrTag_GetTrxBalance() {
12001198 }
12011199
12021200 try {
1203- // Test Exceeds MAX_BLOCK_IDENTIFIER_LENGTH (128)
1204- tronJsonRpc .getTrxBalance (OWNER_ADDRESS , generateLongHexString (130 ));
1201+ tronJsonRpc .getTrxBalance (OWNER_ADDRESS , generateLongHexString ());
12051202 Assert .fail ("Should throw JsonRpcInvalidParamsException for too long blockNumOrTag" );
12061203 } catch (Exception e ) {
12071204 Assert .assertTrue ("Should be JsonRpcInvalidParamsException" ,
@@ -1230,8 +1227,7 @@ public void testValidateBlockNumOrHashOrTag_getTransactionByBlockNumberAndIndex(
12301227 }
12311228
12321229 try {
1233- // Test Exceeds MAX_BLOCK_IDENTIFIER_LENGTH (128)
1234- tronJsonRpc .getTransactionByBlockNumberAndIndex (generateLongHexString (130 ), "0x0" );
1230+ tronJsonRpc .getTransactionByBlockNumberAndIndex (generateLongHexString (), "0x0" );
12351231 Assert .fail ("Should throw JsonRpcInvalidParamsException for too long blockNumOrTag" );
12361232 } catch (Exception e ) {
12371233 Assert .assertTrue ("Should be JsonRpcInvalidParamsException" ,
0 commit comments