-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
t8n test #7744
Open
yerke26
wants to merge
19
commits into
master
Choose a base branch
from
feature/t8n-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
t8n test #7744
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9b032c3
create Evm.Test project
yerke26 d7404d0
refactoring for testing
yerke26 540c028
added t8nTests
yerke26 d1cc5f3
fix tests
yerke26 0ddc8f9
add testdata
yerke26 d461649
add testdata folder copyToOutput
yerke26 ea7a26c
move Evm.Test to Evm solution
yerke26 10cb77e
remove Evm.Test solution
yerke26 c59ae28
testdata folder CopyToOutputDirectory
yerke26 ef9e26a
refactoring
yerke26 3c823d3
fix tests
yerke26 573b05f
remove unnecessary files
yerke26 d8e092d
Merge branch 'master' into feature/t8n-test
yerke26 e260d9b
fix test
yerke26 f43d2eb
Use Custom ReceiptJsonConverter
yerke26 43f5b61
fix cmd options
yerke26 600c4b2
fix t8n
yerke26 38715b6
Merge branch 'master' into feature/t8n-test
yerke26 85a5592
change to dotnet 9.0
yerke26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/> | ||
<PackageReference Include="NUnit" Version="4.2.2"/> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Evm\Evm.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="testdata\**"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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,260 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Evm.T8n; | ||
using Evm.T8n.JsonTypes; | ||
using Nethermind.Logging; | ||
using Nethermind.Serialization.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Evm.Test; | ||
|
||
public class InputParams(string basedir, string alloc, string env, string txs, string stateFork, string? stateReward = null) | ||
{ | ||
public readonly string Alloc = Path.Combine(basedir, alloc); | ||
public readonly string Env = Path.Combine(basedir, env); | ||
public readonly string Txs = Path.Combine(basedir, txs); | ||
public readonly string StateFork = stateFork; | ||
public readonly string? StateReward = stateReward; | ||
} | ||
|
||
public class OutputParams(string? alloc = null, string? result = null, string? body = null) | ||
{ | ||
public readonly string? Alloc = alloc; | ||
public readonly string? Result = result; | ||
public readonly string? Body = body; | ||
} | ||
|
||
public class T8nTests | ||
{ | ||
private readonly EthereumJsonSerializer _ethereumJsonSerializer = new(); | ||
|
||
[Test] | ||
public void Test1() | ||
{ | ||
Execute( | ||
new InputParams("testdata/1/", "alloc.json", "env.json", "txs.json", "Frontier+1346"), | ||
new OutputParams(alloc: "stdout", result: "stdout"), | ||
expectedExitCode: 3); | ||
} | ||
|
||
[Test] | ||
public void Test2() | ||
{ | ||
Execute( | ||
new InputParams("testdata/1/", "alloc.json", "env.json", "txs.json", "Byzantium"), | ||
new OutputParams(alloc: "stdout", result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/1/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test3() | ||
{ | ||
Execute( | ||
new InputParams("testdata/3/", "alloc.json", "env.json", "txs.json", "Berlin"), | ||
new OutputParams(alloc: "stdout", result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/3/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test4() | ||
{ | ||
Execute( | ||
new InputParams("testdata/4/", "alloc.json", "env.json", "txs.json", "Berlin"), | ||
new OutputParams(alloc: "stdout", result: "stdout"), | ||
expectedExitCode: 4); | ||
} | ||
|
||
[Test] | ||
public void Test5() | ||
{ | ||
Execute( | ||
new("testdata/5/", "alloc.json", "env.json", "txs.json", "Byzantium", "0x80"), | ||
new OutputParams(alloc: "stdout", result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/5/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test6() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you name tests in some sensible way? I see it is based on |
||
{ | ||
Execute( | ||
new InputParams("testdata/13/", "alloc.json", "env.json", "txs.json", "London"), | ||
new OutputParams(body: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/13/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test7() | ||
{ | ||
Execute( | ||
new InputParams("testdata/13/", "alloc.json", "env.json", "signed_txs.rlp", "London"), | ||
new OutputParams(result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/13/exp2.json"); | ||
} | ||
|
||
[Test] | ||
public void Test8() | ||
{ | ||
Execute( | ||
new InputParams("testdata/14/", "alloc.json", "env.json", "txs.json", "London"), | ||
new OutputParams(result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/14/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test9() | ||
{ | ||
Execute( | ||
new InputParams("testdata/14/", "alloc.json", "env.uncles.json", "txs.json", "London"), | ||
new OutputParams(result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/14/exp2.json"); | ||
} | ||
|
||
[Test] | ||
public void Test10() | ||
{ | ||
Execute( | ||
new InputParams("testdata/14/", "alloc.json", "env.uncles.json", "txs.json", "Berlin"), | ||
new OutputParams(result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/14/exp_berlin.json"); | ||
} | ||
|
||
[Test] | ||
public void Test11() | ||
{ | ||
Execute( | ||
new InputParams("testdata/19/", "alloc.json", "env.json", "txs.json", "London"), | ||
new OutputParams(result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/19/exp_london.json"); | ||
} | ||
|
||
[Test] | ||
public void Test12() | ||
{ | ||
Execute( | ||
new InputParams("testdata/19/", "alloc.json", "env.json", "txs.json", "ArrowGlacier"), | ||
new OutputParams(result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/19/exp_arrowglacier.json"); | ||
} | ||
|
||
[Test] | ||
public void Test13() | ||
{ | ||
Execute( | ||
new InputParams("testdata/19/", "alloc.json", "env.json", "txs.json", "GrayGlacier"), | ||
new OutputParams(result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/19/exp_grayglacier.json"); | ||
} | ||
|
||
[Test] | ||
public void Test14() | ||
{ | ||
Execute( | ||
new InputParams("testdata/23/", "alloc.json", "env.json", "txs.json", "Berlin"), | ||
new OutputParams(result: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/23/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test15() | ||
{ | ||
Execute( | ||
new InputParams("testdata/24/", "alloc.json", "env.json", "txs.json", "Merge"), | ||
new OutputParams(result: "stdout", alloc: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/24/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test16() | ||
{ | ||
Execute( | ||
new InputParams("testdata/24/", "alloc.json", "env-missingrandom.json", "txs.json", "Merge"), | ||
new OutputParams(result: "stdout", alloc: "stdout"), | ||
expectedExitCode: 3); | ||
} | ||
|
||
[Test] | ||
public void Test17() | ||
{ | ||
Execute( | ||
new InputParams("testdata/26/", "alloc.json", "env.json", "txs.json", "Shanghai"), | ||
new OutputParams(result: "stdout", alloc: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/26/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test18() | ||
{ | ||
Execute( | ||
new InputParams("testdata/28/", "alloc.json", "env.json", "txs.rlp", "Cancun"), | ||
new OutputParams(result: "stdout", alloc: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/28/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test19() | ||
{ | ||
Execute( | ||
new InputParams("testdata/29/", "alloc.json", "env.json", "txs.json", "Cancun"), | ||
new OutputParams(result: "stdout", alloc: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/29/exp.json"); | ||
} | ||
|
||
[Test] | ||
public void Test20() | ||
{ | ||
Execute( | ||
new InputParams("testdata/30/", "alloc.json", "env.json", "txs_more.rlp", "Cancun"), | ||
new OutputParams(result: "stdout", alloc: "stdout"), | ||
expectedExitCode: 0, | ||
expectedOutputFile: "testdata/30/exp.json"); | ||
} | ||
|
||
private void Execute(InputParams inputParams, OutputParams outputParams, int expectedExitCode, string? expectedOutputFile = null) | ||
{ | ||
var arguments = new T8nCommandArguments | ||
{ | ||
InputAlloc = inputParams.Alloc, | ||
InputEnv = inputParams.Env, | ||
InputTxs = inputParams.Txs, | ||
OutputBody = outputParams.Body, | ||
StateFork = inputParams.StateFork, | ||
}; | ||
if (outputParams.Alloc is not null) arguments.OutputAlloc = outputParams.Alloc; | ||
if (outputParams.Result is not null) arguments.OutputResult = outputParams.Result; | ||
if (inputParams.StateReward is not null) arguments.StateReward = inputParams.StateReward; | ||
|
||
T8nOutput output = T8nTool.Run(arguments, NullLogManager.Instance); | ||
|
||
Assert.That(output.ExitCode, Is.EqualTo(expectedExitCode)); | ||
|
||
if (expectedOutputFile == null) return; | ||
|
||
var outputString = _ethereumJsonSerializer.Serialize(output, true); | ||
var fileContent = File.ReadAllText(expectedOutputFile); | ||
Assert.That(AreEqual(fileContent, outputString)); | ||
} | ||
|
||
private static bool AreEqual(string json1, string json2) | ||
{ | ||
var expected = JToken.Parse(json1); | ||
var actual = JToken.Parse(json2); | ||
return JToken.DeepEquals(actual, expected); | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { | ||
"balance": "0x5ffd4878be161d74", | ||
"code": "0x", | ||
"nonce": "0xac", | ||
"storage": {} | ||
}, | ||
"0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192":{ | ||
"balance": "0xfeedbead", | ||
"nonce" : "0x00" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", | ||
"currentDifficulty": "0x20000", | ||
"currentGasLimit": "0x750a163df65e8a", | ||
"currentNumber": "1", | ||
"currentTimestamp": "1000" | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we serialize
Address.Zero
for transactions that don't create contracts?This will also affect all the RPC method, are we sure we want to do it?
If we don't want to change RPC methods, but we want to change it here, you can inherit
ReceiptForRpc
and add this logic in the derived class.