|
5 | 5 | import static com.google.common.net.HttpHeaders.X_FORWARDED_FOR;
|
6 | 6 | import static org.assertj.core.api.Assertions.assertThat;
|
7 | 7 | import static org.hiero.mirror.web3.utils.Constants.MODULARIZED_HEADER;
|
| 8 | +import static org.springframework.web.util.WebUtils.ERROR_EXCEPTION_ATTRIBUTE; |
8 | 9 |
|
| 10 | +import com.hederahashgraph.api.proto.java.ResponseCodeEnum; |
9 | 11 | import java.nio.charset.StandardCharsets;
|
| 12 | +import java.util.LinkedList; |
| 13 | +import java.util.List; |
10 | 14 | import lombok.SneakyThrows;
|
11 | 15 | import org.apache.commons.io.IOUtils;
|
12 | 16 | import org.apache.commons.lang3.RandomStringUtils;
|
13 | 17 | import org.apache.commons.lang3.StringUtils;
|
14 | 18 | import org.hiero.mirror.web3.Web3Properties;
|
| 19 | +import org.hiero.mirror.web3.exception.MirrorEvmTransactionException; |
15 | 20 | import org.junit.jupiter.api.Test;
|
16 | 21 | import org.junit.jupiter.api.extension.ExtendWith;
|
| 22 | +import org.junit.jupiter.params.ParameterizedTest; |
| 23 | +import org.junit.jupiter.params.provider.NullAndEmptySource; |
17 | 24 | import org.springframework.boot.test.system.CapturedOutput;
|
18 | 25 | import org.springframework.boot.test.system.OutputCaptureExtension;
|
19 | 26 | import org.springframework.http.HttpStatus;
|
@@ -154,6 +161,110 @@ void postLargeUncompressibleContent(CapturedOutput output) {
|
154 | 161 | assertThat(output.getOut()).contains(content.substring(0, maxSize)).doesNotContain(content);
|
155 | 162 | }
|
156 | 163 |
|
| 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 | + |
157 | 268 | private void assertLog(CapturedOutput logOutput, String level, String pattern) {
|
158 | 269 | assertThat(logOutput).asString().hasLineCount(1).contains(level).containsPattern(pattern);
|
159 | 270 | }
|
|
0 commit comments