Skip to content

Commit 9255ba2

Browse files
committed
fix(test): fix jsonRpc test
1 parent 877fb62 commit 9255ba2

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

framework/src/main/java/org/tron/core/services/jsonrpc/JsonRpcApiUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class JsonRpcApiUtil {
6060
* Maximum allowed length for block identifiers to prevent DDoS attacks.
6161
* Supports block hashes (66 chars) + safety enough buffer.
6262
*/
63-
private static final int MAX_BLOCK_IDENTIFIER_LENGTH = 512;
63+
public static final int MAX_BLOCK_IDENTIFIER_LENGTH = 512;
6464

6565
public static byte[] convertToTronAddress(byte[] address) {
6666
byte[] newAddress = new byte[21];

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.tron.core.jsonrpc;
22

3+
import static org.tron.core.services.jsonrpc.JsonRpcApiUtil.MAX_BLOCK_IDENTIFIER_LENGTH;
34
import static org.tron.core.services.jsonrpc.JsonRpcApiUtil.getByJsonBlockId;
45
import static org.tron.core.services.jsonrpc.TronJsonRpcImpl.LATEST_STR;
56
import 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

Comments
 (0)