From 9a987554e778d5e5864925c78f346cb4e4ebc4a2 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Mon, 25 Sep 2023 16:27:56 -0500 Subject: [PATCH 1/5] Fix t8n encoding issue When sending a stack in json fields strip out the newlines and tabs. Signed-off-by: Danno Ferrin --- ethereum/evmtool/build.gradle | 1 + .../besu/evmtool/T8nServerSubCommand.java | 2 +- .../besu/evmtool/T8nServerSubCommandTest.java | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java diff --git a/ethereum/evmtool/build.gradle b/ethereum/evmtool/build.gradle index c5604d7a52c..f92f6d3f937 100644 --- a/ethereum/evmtool/build.gradle +++ b/ethereum/evmtool/build.gradle @@ -62,6 +62,7 @@ dependencies { testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + testImplementation 'org.mockito:mockito-junit-jupiter' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nServerSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nServerSubCommand.java index eec78ee50d1..8b636b9a8c0 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nServerSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nServerSubCommand.java @@ -178,7 +178,7 @@ public void disposeTracer(final OperationTracer tracer) { t.printStackTrace(ps); ObjectNode json = objectMapper.createObjectNode(); json.put("error", t.getMessage()); - json.put("stacktrace", baos.toString(StandardCharsets.UTF_8)); + json.put("stacktrace", baos.toString(StandardCharsets.UTF_8).replaceAll("\\s", " ")); t.printStackTrace(System.out); diff --git a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java new file mode 100644 index 00000000000..d167e57470a --- /dev/null +++ b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java @@ -0,0 +1,46 @@ +package org.hyperledger.besu.evmtool; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.vertx.core.http.HttpServerRequest; +import io.vertx.core.http.HttpServerResponse; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Answers; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class T8nServerSubCommandTest { + + @Mock HttpServerRequest httpServerRequest; + + @Mock(answer = Answers.RETURNS_SELF) + HttpServerResponse httpServerResponse; + + @Test + void exceptionEncodedProperlyInJSON() { + T8nServerSubCommand subject = new T8nServerSubCommand(); + ObjectMapper objectMapper = new ObjectMapper(); + + when(httpServerRequest.response()).thenReturn(httpServerResponse); + + // Should trigger a NPE within the try block. + subject.handleT8nRequest(httpServerRequest, objectMapper, null, null); + + ArgumentCaptor responseCodeCaptor = ArgumentCaptor.forClass(Integer.class); + ArgumentCaptor responseStringCaptor = ArgumentCaptor.forClass(String.class); + + verify(httpServerResponse).setStatusCode(responseCodeCaptor.capture()); + verify(httpServerResponse).end(responseStringCaptor.capture()); + + System.out.println(responseCodeCaptor.getValue()); + System.out.println(responseStringCaptor.getValue()); + assertThat(responseCodeCaptor.getValue()).isEqualTo(500); + assertThat(responseStringCaptor.getValue()).doesNotContain("\\t"); + } +} From 31baed182d4b4b363d1fe785045425d41d530f84 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Mon, 25 Sep 2023 18:01:14 -0500 Subject: [PATCH 2/5] remove system.out and changelong Signed-off-by: Danno Ferrin --- CHANGELOG.md | 1 + .../org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa78e26a4eb..a8460b40af6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ ### Bug Fixes - do not create ignorable storage on revert storage-variables subcommand [#5830](https://github.com/hyperledger/besu/pull/5830) - fix duplicate key errors in EthScheduler-Transactions [#5857](https://github.com/hyperledger/besu/pull/5857) +- Don't put control characters, escaped or otherwise, in t8n stacktraces [#5910](https://github.com/hyperledger/besu/pull/5910) ### Download Links diff --git a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java index d167e57470a..9f0ef4952ff 100644 --- a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java +++ b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java @@ -38,8 +38,6 @@ void exceptionEncodedProperlyInJSON() { verify(httpServerResponse).setStatusCode(responseCodeCaptor.capture()); verify(httpServerResponse).end(responseStringCaptor.capture()); - System.out.println(responseCodeCaptor.getValue()); - System.out.println(responseStringCaptor.getValue()); assertThat(responseCodeCaptor.getValue()).isEqualTo(500); assertThat(responseStringCaptor.getValue()).doesNotContain("\\t"); } From 67dabfd4ea4d994b5e4e986ff53683c8822d9bf5 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Wed, 27 Sep 2023 23:52:19 -0500 Subject: [PATCH 3/5] Update ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java Co-authored-by: garyschulte Signed-off-by: Danno Ferrin --- .../besu/evmtool/T8nServerSubCommandTest.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java index 9f0ef4952ff..03c63d6a4a8 100644 --- a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java +++ b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java @@ -1,4 +1,16 @@ -package org.hyperledger.besu.evmtool; +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package org.hyperledger.besu.evmtool; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; From ba821ec2da3e6c04391f94d722e5b422abd88c97 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Fri, 29 Sep 2023 22:19:36 -0600 Subject: [PATCH 4/5] spotless Signed-off-by: Danno Ferrin --- .../org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java index 03c63d6a4a8..db956cfd6c8 100644 --- a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java +++ b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java @@ -10,7 +10,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ - package org.hyperledger.besu.evmtool; +package org.hyperledger.besu.evmtool; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; From b7b4e25ab3a5fe503a3c5b4f9f7541dbac870847 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Fri, 29 Sep 2023 22:57:15 -0600 Subject: [PATCH 5/5] spdx Signed-off-by: Danno Ferrin --- .../org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java index db956cfd6c8..2f658eeb323 100644 --- a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java +++ b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/T8nServerSubCommandTest.java @@ -9,6 +9,8 @@ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 */ package org.hyperledger.besu.evmtool;