From 8eaabaa80a9fd80336a3e609a176147b8e97f84d Mon Sep 17 00:00:00 2001
From: Marcin Sobczak <77129288+marcindsobczak@users.noreply.github.com>
Date: Mon, 12 Jul 2021 22:31:57 +0100
Subject: [PATCH] fix revert error (#3218)
---
.../TransactionSubstateTests.cs | 60 +++++++++++++++++++
.../Nethermind.Evm/TransactionSubstate.cs | 6 +-
2 files changed, 63 insertions(+), 3 deletions(-)
create mode 100644 src/Nethermind/Nethermind.Evm.Test/TransactionSubstateTests.cs
diff --git a/src/Nethermind/Nethermind.Evm.Test/TransactionSubstateTests.cs b/src/Nethermind/Nethermind.Evm.Test/TransactionSubstateTests.cs
new file mode 100644
index 00000000000..6e50045779f
--- /dev/null
+++ b/src/Nethermind/Nethermind.Evm.Test/TransactionSubstateTests.cs
@@ -0,0 +1,60 @@
+// Copyright (c) 2021 Demerzel Solutions Limited
+// This file is part of the Nethermind library.
+//
+// The Nethermind library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The Nethermind library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the Nethermind. If not, see .
+//
+
+using System;
+using FluentAssertions;
+using Nethermind.Core;
+using NUnit.Framework;
+
+namespace Nethermind.Evm.Test
+{
+ public class TransactionSubstateTests
+ {
+ [Test]
+ public void should_return_proper_revert_error_when_there_is_no_exception()
+ {
+ byte[] data = {0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x20,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5,
+ 0x05, 0x06, 0x07, 0x08, 0x09};
+ ReadOnlyMemory readOnlyMemory = new(data);
+ TransactionSubstate transactionSubstate = new(readOnlyMemory,
+ 0,
+ new ArraySegment(),
+ new LogEntry[] {},
+ true,
+ true);
+ transactionSubstate.Error.Should().Be("Reverted 0x0506070809");
+ }
+
+ [Test]
+ public void should_return_proper_revert_error_when_there_is_exception()
+ {
+ byte[] data = {0x05, 0x06, 0x07, 0x08, 0x09};
+ ReadOnlyMemory readOnlyMemory = new(data);
+ TransactionSubstate transactionSubstate = new(readOnlyMemory,
+ 0,
+ new ArraySegment(),
+ new LogEntry[] {},
+ true,
+ true);
+ transactionSubstate.Error.Should().Be("Reverted 0x0506070809");
+ }
+ }
+}
diff --git a/src/Nethermind/Nethermind.Evm/TransactionSubstate.cs b/src/Nethermind/Nethermind.Evm/TransactionSubstate.cs
index a99356c9fee..f46ad77fb25 100644
--- a/src/Nethermind/Nethermind.Evm/TransactionSubstate.cs
+++ b/src/Nethermind/Nethermind.Evm/TransactionSubstate.cs
@@ -17,7 +17,6 @@
using System;
using System.Collections.Generic;
using System.Numerics;
-using System.Text;
using Nethermind.Core;
using Nethermind.Core.Extensions;
@@ -65,13 +64,14 @@ public TransactionSubstate(
{
BigInteger start = Output.Span.Slice(4, 32).ToUnsignedBigInteger();
BigInteger length = Output.Slice((int) start + 4, 32).Span.ToUnsignedBigInteger();
- Error = "revert: " + Encoding.ASCII.GetString(Output.Slice((int) start + 32 + 4, (int) length).Span);
+ Error = string.Concat("Reverted ",
+ Output.Slice((int)start + 32 + 4, (int)length).ToArray().ToHexString(true));
}
catch (Exception)
{
try
{
- Error = "revert: " + Output.ToArray().ToHexString(true);
+ Error = string.Concat("Reverted ", Output.ToArray().ToHexString(true));
}
catch
{