From de98029fff80f5f4da78f3de8e87a5932f65bd44 Mon Sep 17 00:00:00 2001 From: "Filip.Gumula" Date: Sat, 18 Nov 2023 20:39:27 +0100 Subject: [PATCH] Regex for removing unnecessary newlines, adjust tests. Signed-off-by: Neo --- .../besu/ethereum/trie/verkle/SimpleVerkleTrie.java | 2 +- .../besu/ethereum/trie/verkle/exporter/DotExporter.java | 2 +- .../hyperledger/besu/ethereum/trie/verkle/DotDisplayTest.java | 1 + src/test/resources/VerkleTrie.gv | 3 +-- src/test/resources/expectedTreeOneValueNoRepeatingEdges.txt | 3 +-- src/test/resources/expectedTreeOneValueRepeatingEdges.txt | 3 +-- src/test/resources/expectedTreeTwoValuesNoRepeatingEdges.txt | 3 +-- src/test/resources/expectedTreeTwoValuesRepeatingEdges.txt | 3 +-- 8 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/hyperledger/besu/ethereum/trie/verkle/SimpleVerkleTrie.java b/src/main/java/org/hyperledger/besu/ethereum/trie/verkle/SimpleVerkleTrie.java index 31c49b2..3b9e7e3 100644 --- a/src/main/java/org/hyperledger/besu/ethereum/trie/verkle/SimpleVerkleTrie.java +++ b/src/main/java/org/hyperledger/besu/ethereum/trie/verkle/SimpleVerkleTrie.java @@ -155,7 +155,7 @@ public void commit(final NodeUpdater nodeUpdater) { * @return The DOT representation of the Verkle Trie. */ public String toDotTree(Boolean showRepeatingEdges) { - return String.format("digraph VerkleTrie {\n%s}\n", getRoot().toDot(showRepeatingEdges)); + return String.format("digraph VerkleTrie {\n%s\n}", getRoot().toDot(showRepeatingEdges).replaceAll("^\\n+|\\n+$", "")); } /** diff --git a/src/main/java/org/hyperledger/besu/ethereum/trie/verkle/exporter/DotExporter.java b/src/main/java/org/hyperledger/besu/ethereum/trie/verkle/exporter/DotExporter.java index 02cdd77..082e859 100644 --- a/src/main/java/org/hyperledger/besu/ethereum/trie/verkle/exporter/DotExporter.java +++ b/src/main/java/org/hyperledger/besu/ethereum/trie/verkle/exporter/DotExporter.java @@ -73,7 +73,7 @@ public static void exportToDotFile(String verkleTrieDotString, String filePath) try (BufferedWriter writer = new BufferedWriter(new FileWriter(path.toString(), StandardCharsets.UTF_8))) { - writer.write(verkleTrieDotString + "\n"); + writer.write(verkleTrieDotString); } } catch (AccessDeniedException e) { diff --git a/src/test/java/org/hyperledger/besu/ethereum/trie/verkle/DotDisplayTest.java b/src/test/java/org/hyperledger/besu/ethereum/trie/verkle/DotDisplayTest.java index 4d862cf..caaa675 100644 --- a/src/test/java/org/hyperledger/besu/ethereum/trie/verkle/DotDisplayTest.java +++ b/src/test/java/org/hyperledger/besu/ethereum/trie/verkle/DotDisplayTest.java @@ -58,6 +58,7 @@ public void testToDotTrieOneValueNoRepeatingEdgesExport() throws IOException { final String fileName = "expectedTreeOneValueNoRepeatingEdges.txt"; final String expectedTree = getResources(fileName); final String actualTree = trie.toDotTree(); + System.out.println(actualTree); assertEquals(expectedTree, actualTree); } diff --git a/src/test/resources/VerkleTrie.gv b/src/test/resources/VerkleTrie.gv index 9e1ee36..67a9c05 100644 --- a/src/test/resources/VerkleTrie.gv +++ b/src/test/resources/VerkleTrie.gv @@ -516,5 +516,4 @@ NullNode0x[location="0x"] NullNode0x[location="0x"] NullNode0x[location="0x"] NullNode0x[location="0x"] -} - +} \ No newline at end of file diff --git a/src/test/resources/expectedTreeOneValueNoRepeatingEdges.txt b/src/test/resources/expectedTreeOneValueNoRepeatingEdges.txt index 9e1ee36..67a9c05 100644 --- a/src/test/resources/expectedTreeOneValueNoRepeatingEdges.txt +++ b/src/test/resources/expectedTreeOneValueNoRepeatingEdges.txt @@ -516,5 +516,4 @@ NullNode0x[location="0x"] NullNode0x[location="0x"] NullNode0x[location="0x"] NullNode0x[location="0x"] -} - +} \ No newline at end of file diff --git a/src/test/resources/expectedTreeOneValueRepeatingEdges.txt b/src/test/resources/expectedTreeOneValueRepeatingEdges.txt index 674ef96..c0c52a2 100644 --- a/src/test/resources/expectedTreeOneValueRepeatingEdges.txt +++ b/src/test/resources/expectedTreeOneValueRepeatingEdges.txt @@ -1024,5 +1024,4 @@ InternalNode0x -> NullNode0x NullNode0x[location="0x"] InternalNode0x -> NullNode0x NullNode0x[location="0x"] -} - +} \ No newline at end of file diff --git a/src/test/resources/expectedTreeTwoValuesNoRepeatingEdges.txt b/src/test/resources/expectedTreeTwoValuesNoRepeatingEdges.txt index 3fa5243..453e2ad 100644 --- a/src/test/resources/expectedTreeTwoValuesNoRepeatingEdges.txt +++ b/src/test/resources/expectedTreeTwoValuesNoRepeatingEdges.txt @@ -517,5 +517,4 @@ NullNode0x[location="0x"] NullNode0x[location="0x"] NullNode0x[location="0x"] NullNode0x[location="0x"] -} - +} \ No newline at end of file diff --git a/src/test/resources/expectedTreeTwoValuesRepeatingEdges.txt b/src/test/resources/expectedTreeTwoValuesRepeatingEdges.txt index f2e567a..5cc59b0 100644 --- a/src/test/resources/expectedTreeTwoValuesRepeatingEdges.txt +++ b/src/test/resources/expectedTreeTwoValuesRepeatingEdges.txt @@ -1024,5 +1024,4 @@ InternalNode0x -> NullNode0x NullNode0x[location="0x"] InternalNode0x -> NullNode0x NullNode0x[location="0x"] -} - +} \ No newline at end of file