Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public class GeneralStateTest : EthereumTest
public Hash256? CurrentBeaconRoot { get; set; }
public Hash256? CurrentWithdrawalsRoot { get; set; }
public ulong? CurrentExcessBlobGas { get; set; }
public UInt256? ParentBlobGasUsed { get; set; }
public UInt256? ParentExcessBlobGas { get; set; }

public Hash256? RequestsHash { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ public class GeneralStateTestEnvJson
public Hash256? CurrentBeaconRoot { get; set; }
public Hash256? CurrentWithdrawalsRoot { get; set; }
public ulong? CurrentExcessBlobGas { get; set; }
public UInt256? ParentBlobGasUsed { get; set; }
public UInt256? ParentExcessBlobGas { get; set; }
}
}
50 changes: 23 additions & 27 deletions src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Nethermind.Consensus.Validators;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.ExecutionRequest;
using Nethermind.Core.Extensions;
using Nethermind.Core.Specs;
using Nethermind.Core.Test.Modules;
Expand All @@ -21,6 +22,8 @@
using Nethermind.Specs;
using Nethermind.Specs.Forks;
using Nethermind.Specs.Test;
using Nethermind.State.Proofs;
using Nethermind.Trie;
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -61,6 +64,7 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
{
_logger.Info($"Running {test.Name} at {DateTime.UtcNow:HH:mm:ss.ffffff}");
Assert.That(test.LoadFailure, Is.Null, "test data loading failure");
Assert.That(test.Transaction, Is.Not.Null, "there is no transaction in the test");

EofValidator.Logger = _logger;

Expand All @@ -87,6 +91,7 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
IMainProcessingContext mainBlockProcessingContext = container.Resolve<IMainProcessingContext>();
IWorldState stateProvider = mainBlockProcessingContext.WorldState;
using IDisposable _ = stateProvider.BeginScope(null);
IBlockValidator blockValidator = container.Resolve<IBlockValidator>();
ITransactionProcessor transactionProcessor = mainBlockProcessingContext.TransactionProcessor;

InitializeTestState(test.Pre, stateProvider, specProvider);
Expand All @@ -101,6 +106,15 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
stateProvider.RecalculateStateRoot();
}

if (test.Transaction.ChainId is null)
{
test.Transaction.ChainId = test.ChainId;
}

IReleaseSpec? spec = specProvider.GetSpec((ForkActivation)test.CurrentNumber);
Transaction[] transactions = [test.Transaction];
Withdrawal[]? withdrawals = spec.WithdrawalsEnabled ? [] : null;

BlockHeader header = new(
test.PreviousHash,
Keccak.OfAnEmptySequenceRlp,
Expand All @@ -115,47 +129,29 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
StateRoot = test.PostHash,
IsPostMerge = test.CurrentRandom is not null,
MixHash = test.CurrentRandom,
WithdrawalsRoot = test.CurrentWithdrawalsRoot,
WithdrawalsRoot = test.CurrentWithdrawalsRoot ?? (spec.WithdrawalsEnabled ? PatriciaTree.EmptyTreeHash : null),
ParentBeaconBlockRoot = test.CurrentBeaconRoot,
ExcessBlobGas = test.CurrentExcessBlobGas ?? (test.Fork is Cancun ? 0ul : null),
BlobGasUsed = BlobGasCalculator.CalculateBlobGas(test.Transaction),
RequestsHash = test.RequestsHash
RequestsHash = test.RequestsHash ?? (spec.RequestsEnabled ? ExecutionRequestExtensions.EmptyRequestsHash : null),
TxRoot = TxTrie.CalculateRoot(transactions),
ReceiptsRoot = test.PostReceiptsRoot,
};

header.Hash = header.CalculateHash();
Block block = new(header, new BlockBody(transactions, [], withdrawals));

Stopwatch stopwatch = Stopwatch.StartNew();
IReleaseSpec? spec = specProvider.GetSpec((ForkActivation)test.CurrentNumber);

if (test.Transaction.ChainId is null)
test.Transaction.ChainId = test.ChainId;
if (test.ParentBlobGasUsed is not null && test.ParentExcessBlobGas is not null)
{
BlockHeader parent = new(
parentHash: Keccak.Zero,
unclesHash: Keccak.OfAnEmptySequenceRlp,
beneficiary: test.CurrentCoinbase,
difficulty: test.CurrentDifficulty,
number: test.CurrentNumber - 1,
gasLimit: test.CurrentGasLimit,
timestamp: test.CurrentTimestamp,
extraData: []
)
{
BlobGasUsed = (ulong)test.ParentBlobGasUsed,
ExcessBlobGas = (ulong)test.ParentExcessBlobGas,
};
header.ExcessBlobGas = BlobGasCalculator.CalculateExcessBlobGas(parent, spec);
}

ValidationResult txIsValid = new TxValidator(test.ChainId).IsWellFormed(test.Transaction, spec);
TransactionResult? txResult = null;
if (txIsValid)

if (blockValidator.ValidateOrphanedBlock(block, out string blockValidationError))
{
txResult = transactionProcessor.Execute(test.Transaction, new BlockExecutionContext(header, spec), txTracer);
}
else
{
_logger.Info($"Skipping invalid tx with error: {txIsValid.Error}");
_logger.Info($"Skipping invalid tx with error: {blockValidationError}");
}

stopwatch.Stop();
Expand Down
2 changes: 0 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ public static IEnumerable<GeneralStateTest> Convert(string name, string category
CurrentBeaconRoot = testJson.Env.CurrentBeaconRoot,
CurrentWithdrawalsRoot = testJson.Env.CurrentWithdrawalsRoot,
CurrentExcessBlobGas = testJson.Env.CurrentExcessBlobGas,
ParentBlobGasUsed = testJson.Env.ParentBlobGasUsed,
ParentExcessBlobGas = testJson.Env.ParentExcessBlobGas,
PostReceiptsRoot = stateJson.Logs,
PostHash = stateJson.Hash,
Pre = testJson.Pre.ToDictionary(p => p.Key, p => p.Value),
Expand Down