-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: lukasz.rozmej <[email protected]>
- Loading branch information
1 parent
879d52f
commit 55a6ec2
Showing
26 changed files
with
439 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/Nethermind/Nethermind.Evm.Test/Tracing/GethLike4byteTracerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Evm.Precompiles; | ||
using Nethermind.Evm.Tracing.GethStyle.Custom.Native.Tracers; | ||
using NUnit.Framework; | ||
namespace Nethermind.Evm.Test.Tracing; | ||
|
||
[TestFixture] | ||
public class GethLike4byteTracerTests : GethLikeNativeTracerTestsBase | ||
{ | ||
[TestCaseSource(nameof(FourByteTracerTests))] | ||
public Dictionary<string, int>? four_byte_tracer_executes_correctly(byte[] code, byte[]? input) => | ||
(Dictionary<string, int>)ExecuteAndTrace(Native4ByteTracer.FourByteTracer, code, input).CustomTracerResult?.Value; | ||
|
||
private static IEnumerable FourByteTracerTests | ||
{ | ||
get | ||
{ | ||
byte[] sampleInput = Prepare.EvmCode | ||
.PushData(SampleHexData2) | ||
.STOP() | ||
.Done; | ||
byte[] callEvmCode = Prepare.EvmCode | ||
.CallWithInput(TestItem.AddressA, 50000, sampleInput) | ||
.CallWithInput(TestItem.AddressA, 50000, sampleInput) | ||
.CallWithInput(TestItem.AddressA, 50000, new byte[6]) | ||
.STOP() | ||
.Done; | ||
yield return new TestCaseData(callEvmCode, null) | ||
{ | ||
TestName = "Tracing CALL execution", | ||
ExpectedResult = new Dictionary<string, int> | ||
{ | ||
{ "62b15678-1", 2 }, | ||
{ "00000000-2", 1 } | ||
} | ||
}; | ||
|
||
byte[] delegateCallEvmCode = Prepare.EvmCode | ||
.DelegateCall(TestItem.AddressC, 50000) | ||
.STOP() | ||
.Done; | ||
var singleCall4ByteIds = new Dictionary<string, int> | ||
{ | ||
{ "62b15678-1", 1 } | ||
}; | ||
yield return new TestCaseData(delegateCallEvmCode, sampleInput) | ||
{ | ||
TestName = "Tracing DELEGATECALL execution", | ||
ExpectedResult = singleCall4ByteIds | ||
}; | ||
|
||
byte[] staticCallEvmCode = Prepare.EvmCode | ||
.StaticCall(TestItem.AddressC, 50000) | ||
.STOP() | ||
.Done; | ||
yield return new TestCaseData(staticCallEvmCode, sampleInput) | ||
{ | ||
TestName = "Tracing STATICCALL execution", | ||
ExpectedResult = singleCall4ByteIds | ||
}; | ||
|
||
byte[] callCodeEvmCode = Prepare.EvmCode | ||
.CallCode(TestItem.AddressC, 50000) | ||
.STOP() | ||
.Done; | ||
yield return new TestCaseData(callCodeEvmCode, sampleInput) | ||
{ | ||
TestName = "Tracing CALLCODE execution", | ||
ExpectedResult = singleCall4ByteIds | ||
}; | ||
|
||
byte[] callEvmCodeLessThan3Bytes = Prepare.EvmCode | ||
.CallWithInput(TestItem.AddressA, 50000, Prepare.EvmCode.STOP().Done) | ||
.CallWithInput(TestItem.AddressA, 50000, new byte[3]) | ||
.STOP() | ||
.Done; | ||
yield return new TestCaseData(callEvmCodeLessThan3Bytes, null) | ||
{ | ||
TestName = "Tracing CALL execution with input less than 4 bytes", | ||
ExpectedResult = new Dictionary<string, int>() | ||
}; | ||
|
||
byte[] callEvmCodePrecompile = Prepare.EvmCode | ||
.CallWithInput(IdentityPrecompile.Address, 50000, sampleInput) | ||
.STOP() | ||
.Done; | ||
yield return new TestCaseData(callEvmCodePrecompile, null) | ||
{ | ||
TestName = "Tracing CALL execution with precompile", | ||
ExpectedResult = new Dictionary<string, int>() | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Nethermind/Nethermind.Evm.Test/Tracing/GethLikeNativeTracerFactoryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using Nethermind.Evm.Tracing.GethStyle; | ||
using Nethermind.Evm.Tracing.GethStyle.Custom.Native; | ||
using Nethermind.Evm.Tracing.GethStyle.Custom.Native.Tracers; | ||
using NUnit.Framework; | ||
namespace Nethermind.Evm.Test.Tracing; | ||
|
||
public class GethLikeNativeTracerFactoryTests | ||
{ | ||
[Test] | ||
public void CreateTracer_NativeTracerExists() | ||
{ | ||
var options = new GethTraceOptions { Tracer = Native4ByteTracer.FourByteTracer }; | ||
|
||
GethLikeNativeTxTracer? nativeTracer = GethLikeNativeTracerFactory.CreateTracer(options); | ||
|
||
Assert.True(nativeTracer is Native4ByteTracer); | ||
} | ||
|
||
[Test] | ||
public void CreateTracer_NativeTracerDoesNotExist() | ||
{ | ||
var options = new GethTraceOptions { Tracer = "nonExistentTracer" }; | ||
|
||
Assert.Throws<ArgumentException>(() => GethLikeNativeTracerFactory.CreateTracer(options)); | ||
} | ||
|
||
[Test] | ||
public void IsNativeTracer_TracerNameExists() | ||
{ | ||
var isNativeTracer = GethLikeNativeTracerFactory.IsNativeTracer(Native4ByteTracer.FourByteTracer); | ||
|
||
Assert.True(isNativeTracer); | ||
} | ||
|
||
[Test] | ||
public void IsNativeTracer_TracerNameDoesNotExist() | ||
{ | ||
var isNativeTracer = GethLikeNativeTracerFactory.IsNativeTracer("nonExistentTracer"); | ||
|
||
Assert.False(isNativeTracer); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Nethermind/Nethermind.Evm.Test/Tracing/GethLikeNativeTracerTestsBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core; | ||
using Nethermind.Evm.Tracing.GethStyle; | ||
using Nethermind.Evm.Tracing.GethStyle.Custom.Native; | ||
using Nethermind.Int256; | ||
|
||
namespace Nethermind.Evm.Test.Tracing; | ||
|
||
public class GethLikeNativeTracerTestsBase : VirtualMachineTestsBase | ||
{ | ||
protected GethLikeTxTrace ExecuteAndTrace(string tracerName, byte[] code, byte[]? input = default, UInt256 value = default) | ||
{ | ||
GethLikeNativeTxTracer tracer = GethLikeNativeTracerFactory.CreateTracer(GethTraceOptions.Default with { Tracer = tracerName }); | ||
(Block block, Transaction transaction) = input is null ? PrepareTx(Activation, 100000, code) : PrepareTx(Activation, 100000, code, input, value); | ||
_processor.Execute(transaction, block.Header, tracer); | ||
return tracer.BuildResult(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.