Skip to content

Commit 87f9d57

Browse files
committed
fix(api): treat empty-string events list as absent in shielded scan APIs
1 parent 63fe9fd commit 87f9d57

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

framework/src/main/java/org/tron/core/services/RpcApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private StatusRuntimeException getRunTimeException(Exception e) {
294294

295295
private static boolean rejectIfEventsPresent(
296296
StreamObserver<?> responseObserver, ProtocolStringList events) {
297-
if (!events.isEmpty()) {
297+
if (events.stream().anyMatch(s -> !s.isEmpty())) {
298298
responseObserver.onError(Status.INVALID_ARGUMENT
299299
.withDescription("'events' field is deprecated and no longer supported")
300300
.asRuntimeException());

framework/src/main/java/org/tron/core/services/http/ScanShieldedTRC20NotesByIvkServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static String convertOutput(GrpcAPI.DecryptNotesTRC20 notes, boolean visi
3939
}
4040

4141
static void rejectIfEventsPresent(ProtocolStringList events) {
42-
if (!events.isEmpty()) {
42+
if (events.stream().anyMatch(s -> !s.isEmpty())) {
4343
throw new IllegalArgumentException(EVENTS_DEPRECATED_MSG);
4444
}
4545
}

framework/src/test/java/org/tron/core/services/http/ScanShieldedTRC20NotesServletTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,44 @@ public void testOvkGetRejectsDeprecatedEvents() throws Exception {
7474
Assert.assertTrue(response.getContentAsString().contains(EVENTS_DEPRECATED_MSG));
7575
}
7676

77+
@Test
78+
public void testIvkPostEmptyEventsPassesGuard() throws Exception {
79+
MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME);
80+
request.setContentType("application/json");
81+
request.setContent("{\"events\":[\"\"]}".getBytes(UTF_8));
82+
MockHttpServletResponse response = new MockHttpServletResponse();
83+
scanShieldedTRC20NotesByIvkServlet.doPost(request, response);
84+
Assert.assertNotEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
85+
}
86+
87+
@Test
88+
public void testOvkPostEmptyEventsPassesGuard() throws Exception {
89+
MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME);
90+
request.setContentType("application/json");
91+
request.setContent("{\"events\":[\"\"]}".getBytes(UTF_8));
92+
MockHttpServletResponse response = new MockHttpServletResponse();
93+
scanShieldedTRC20NotesByOvkServlet.doPost(request, response);
94+
Assert.assertNotEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
95+
}
96+
97+
@Test
98+
public void testIvkPostWithoutEventsPassesGuard() throws Exception {
99+
MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME);
100+
request.setContentType("application/json");
101+
request.setContent("{\"start_block_index\":0,\"end_block_index\":1}".getBytes(UTF_8));
102+
MockHttpServletResponse response = new MockHttpServletResponse();
103+
scanShieldedTRC20NotesByIvkServlet.doPost(request, response);
104+
Assert.assertNotEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
105+
}
106+
107+
@Test
108+
public void testOvkPostWithoutEventsPassesGuard() throws Exception {
109+
MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME);
110+
request.setContentType("application/json");
111+
request.setContent("{\"start_block_index\":0,\"end_block_index\":1}".getBytes(UTF_8));
112+
MockHttpServletResponse response = new MockHttpServletResponse();
113+
scanShieldedTRC20NotesByOvkServlet.doPost(request, response);
114+
Assert.assertNotEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
115+
}
116+
77117
}

0 commit comments

Comments
 (0)