Skip to content

Commit

Permalink
fix revert error (#3218)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcindsobczak authored Jul 12, 2021
1 parent 3161505 commit 8eaabaa
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
60 changes: 60 additions & 0 deletions src/Nethermind/Nethermind.Evm.Test/TransactionSubstateTests.cs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//

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<byte> readOnlyMemory = new(data);
TransactionSubstate transactionSubstate = new(readOnlyMemory,
0,
new ArraySegment<Address>(),
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<byte> readOnlyMemory = new(data);
TransactionSubstate transactionSubstate = new(readOnlyMemory,
0,
new ArraySegment<Address>(),
new LogEntry[] {},
true,
true);
transactionSubstate.Error.Should().Be("Reverted 0x0506070809");
}
}
}
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Evm/TransactionSubstate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using Nethermind.Core;
using Nethermind.Core.Extensions;

Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 8eaabaa

Please sign in to comment.