Skip to content

Commit cdfd7b5

Browse files
Add tests that cover full exception message cases
Signed-off-by: Bilyana Gospodinova <[email protected]>
1 parent bf376d7 commit cdfd7b5

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

web3/src/main/java/org/hiero/mirror/web3/exception/MirrorEvmTransactionException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public String getFullMessage() {
8484
if (!StringUtils.isBlank(getDetail())) {
8585
exceptionMessageBuilder.append(", detail: ").append(getDetail());
8686
}
87-
if (!getChildTransactionErrors().isEmpty()) {
87+
if (getChildTransactionErrors() != null && !getChildTransactionErrors().isEmpty()) {
8888
exceptionMessageBuilder.append(", childTransactionErrors: ").append(getChildTransactionErrors());
8989
}
9090
exceptionMessageBuilder.append(", data: ").append(getData());

web3/src/test/java/org/hiero/mirror/web3/config/LoggingFilterTest.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
import static com.google.common.net.HttpHeaders.X_FORWARDED_FOR;
66
import static org.assertj.core.api.Assertions.assertThat;
77
import static org.hiero.mirror.web3.utils.Constants.MODULARIZED_HEADER;
8+
import static org.springframework.web.util.WebUtils.ERROR_EXCEPTION_ATTRIBUTE;
89

10+
import com.hederahashgraph.api.proto.java.ResponseCodeEnum;
911
import java.nio.charset.StandardCharsets;
12+
import java.util.LinkedList;
13+
import java.util.List;
1014
import lombok.SneakyThrows;
1115
import org.apache.commons.io.IOUtils;
1216
import org.apache.commons.lang3.RandomStringUtils;
1317
import org.apache.commons.lang3.StringUtils;
1418
import org.hiero.mirror.web3.Web3Properties;
19+
import org.hiero.mirror.web3.exception.MirrorEvmTransactionException;
1520
import org.junit.jupiter.api.Test;
1621
import org.junit.jupiter.api.extension.ExtendWith;
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.NullAndEmptySource;
1724
import org.springframework.boot.test.system.CapturedOutput;
1825
import org.springframework.boot.test.system.OutputCaptureExtension;
1926
import org.springframework.http.HttpStatus;
@@ -154,6 +161,110 @@ void postLargeUncompressibleContent(CapturedOutput output) {
154161
assertThat(output.getOut()).contains(content.substring(0, maxSize)).doesNotContain(content);
155162
}
156163

164+
@Test
165+
@SneakyThrows
166+
void getFullExceptionMessage(CapturedOutput output) {
167+
int maxSize = web3Properties.getMaxPayloadLogSize();
168+
var content = "abcdef0123456789";
169+
var request = new MockHttpServletRequest("POST", "/");
170+
request.setContent(content.getBytes(StandardCharsets.UTF_8));
171+
request.setAttribute(
172+
ERROR_EXCEPTION_ATTRIBUTE,
173+
new MirrorEvmTransactionException(
174+
ResponseCodeEnum.CONTRACT_REVERT_EXECUTED.name(),
175+
"detail",
176+
"0123456",
177+
null,
178+
true,
179+
List.of("childMessage")));
180+
response.setStatus(HttpStatus.OK.value());
181+
182+
loggingFilter.doFilter(request, response, (req, res) -> IOUtils.toString(req.getReader()));
183+
184+
assertThat(output.getOut())
185+
.contains(
186+
"Mirror EVM transaction error: CONTRACT_REVERT_EXECUTED, detail: detail, childTransactionErrors: [childMessage], data: 0123456 - abcdef0123456789");
187+
}
188+
189+
@ParameterizedTest
190+
@NullAndEmptySource
191+
@SneakyThrows
192+
void getFullExceptionMessageDetailEmpty(final String detail, CapturedOutput output) {
193+
int maxSize = web3Properties.getMaxPayloadLogSize();
194+
var content = "abcdef0123456789";
195+
var request = new MockHttpServletRequest("POST", "/");
196+
request.setContent(content.getBytes(StandardCharsets.UTF_8));
197+
request.setAttribute(
198+
ERROR_EXCEPTION_ATTRIBUTE,
199+
new MirrorEvmTransactionException(
200+
ResponseCodeEnum.CONTRACT_REVERT_EXECUTED.name(),
201+
detail,
202+
"0123456",
203+
null,
204+
true,
205+
List.of("childMessage")));
206+
response.setStatus(HttpStatus.OK.value());
207+
208+
loggingFilter.doFilter(request, response, (req, res) -> IOUtils.toString(req.getReader()));
209+
210+
assertThat(output.getOut())
211+
.contains(
212+
"Mirror EVM transaction error: CONTRACT_REVERT_EXECUTED, childTransactionErrors: [childMessage], data: 0123456 - abcdef0123456789");
213+
}
214+
215+
@ParameterizedTest
216+
@NullAndEmptySource
217+
@SneakyThrows
218+
void getFullExceptionMessageChildErrorsEmpty(final LinkedList<String> childErrors, CapturedOutput output) {
219+
int maxSize = web3Properties.getMaxPayloadLogSize();
220+
var content = "abcdef0123456789";
221+
var request = new MockHttpServletRequest("POST", "/");
222+
request.setContent(content.getBytes(StandardCharsets.UTF_8));
223+
request.setAttribute(
224+
ERROR_EXCEPTION_ATTRIBUTE,
225+
new MirrorEvmTransactionException(
226+
ResponseCodeEnum.CONTRACT_REVERT_EXECUTED.name(),
227+
"detail",
228+
"0123456",
229+
null,
230+
true,
231+
childErrors));
232+
response.setStatus(HttpStatus.OK.value());
233+
234+
loggingFilter.doFilter(request, response, (req, res) -> IOUtils.toString(req.getReader()));
235+
236+
assertThat(output.getOut())
237+
.contains(
238+
"Mirror EVM transaction error: CONTRACT_REVERT_EXECUTED, detail: detail, data: 0123456 - abcdef0123456789");
239+
}
240+
241+
@Test
242+
@SneakyThrows
243+
void getFullExceptionMessageWithCompressedContent(CapturedOutput output) {
244+
int maxSize = web3Properties.getMaxPayloadLogSize();
245+
var content = StringUtils.repeat("abcdefghij", maxSize / 10 + 1);
246+
var request = new MockHttpServletRequest("POST", "/");
247+
request.setContent(content.getBytes(StandardCharsets.UTF_8));
248+
request.setAttribute(
249+
ERROR_EXCEPTION_ATTRIBUTE,
250+
new MirrorEvmTransactionException(
251+
ResponseCodeEnum.CONTRACT_REVERT_EXECUTED.name(),
252+
"detail",
253+
"0123456",
254+
null,
255+
true,
256+
List.of("childMessage")));
257+
response.setStatus(HttpStatus.OK.value());
258+
259+
loggingFilter.doFilter(request, response, (req, res) -> IOUtils.toString(req.getReader()));
260+
261+
var compressed = "H4sIAAAAAAAA/0tMSk5JTUvPyMxKHGURzQIAy81t7zYBAAA=";
262+
assertThat(output.getOut())
263+
.contains(
264+
"Mirror EVM transaction error: CONTRACT_REVERT_EXECUTED, detail: detail, childTransactionErrors: [childMessage], data: 0123456 - "
265+
+ compressed);
266+
}
267+
157268
private void assertLog(CapturedOutput logOutput, String level, String pattern) {
158269
assertThat(logOutput).asString().hasLineCount(1).contains(level).containsPattern(pattern);
159270
}

0 commit comments

Comments
 (0)