diff --git a/src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs b/src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs index 098b7cc8682..da8142a513f 100644 --- a/src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs +++ b/src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs @@ -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; } diff --git a/src/Nethermind/Ethereum.Test.Base/GeneralStateTestEnvJson.cs b/src/Nethermind/Ethereum.Test.Base/GeneralStateTestEnvJson.cs index a82748257d9..384b5465b19 100644 --- a/src/Nethermind/Ethereum.Test.Base/GeneralStateTestEnvJson.cs +++ b/src/Nethermind/Ethereum.Test.Base/GeneralStateTestEnvJson.cs @@ -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; } } } diff --git a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs index e402b1716b7..dcf87b0aa5c 100644 --- a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs @@ -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; @@ -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; @@ -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; @@ -87,6 +91,7 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) IMainProcessingContext mainBlockProcessingContext = container.Resolve(); IWorldState stateProvider = mainBlockProcessingContext.WorldState; using IDisposable _ = stateProvider.BeginScope(null); + IBlockValidator blockValidator = container.Resolve(); ITransactionProcessor transactionProcessor = mainBlockProcessingContext.TransactionProcessor; InitializeTestState(test.Pre, stateProvider, specProvider); @@ -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, @@ -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(); diff --git a/src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs b/src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs index 4c7c5d6317e..0eda74a3459 100644 --- a/src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs +++ b/src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs @@ -277,8 +277,6 @@ public static IEnumerable 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),