Skip to content

Commit

Permalink
Merge branch 'pectra' into feature/eip-7702
Browse files Browse the repository at this point in the history
  • Loading branch information
ak88 committed Aug 22, 2024
2 parents 021792d + c9e36a8 commit c7e9f61
Show file tree
Hide file tree
Showing 178 changed files with 4,495 additions and 602 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Ethereum.Test.Base;
using NUnit.Framework;

namespace Ethereum.Blockchain.Pyspec.Test;

[TestFixture]
[Parallelizable(ParallelScope.All)]
[Explicit("These tests are not ready yet")]
public class PragueBlockChainTests : BlockchainTestBase
{
[TestCaseSource(nameof(LoadTests))]
public async Task Test(BlockchainTest test) => await RunTest(test);

private static IEnumerable<BlockchainTest> LoadTests()
{
TestsSourceLoader loader = new(new LoadPyspecTestsStrategy(), $"fixtures/blockchain_tests/prague");
return loader.LoadTests().OfType<BlockchainTest>();
}
}
22 changes: 22 additions & 0 deletions src/Nethermind/Ethereum.Blockchain.Pyspec.Test/PragueStateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Linq;
using Ethereum.Test.Base;
using FluentAssertions;
using NUnit.Framework;

namespace Ethereum.Blockchain.Pyspec.Test;

[TestFixture]
[Parallelizable(ParallelScope.All)]
[Explicit("These tests are not ready yet")]
public class PragueStateTests : GeneralStateTestBase
{
[TestCaseSource(nameof(LoadTests))]
public void Test(GeneralStateTest test) => RunTest(test).Pass.Should().BeTrue();

private static IEnumerable<GeneralStateTest> LoadTests()
{
TestsSourceLoader loader = new(new LoadPyspecTestsStrategy(), $"fixtures/state_tests/prague");
return loader.LoadTests().Cast<GeneralStateTest>();
}
}
26 changes: 26 additions & 0 deletions src/Nethermind/Ethereum.Blockchain.Test/EIP6110Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using Ethereum.Test.Base;
using NUnit.Framework;

namespace Ethereum.Blockchain.Test
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class Eip6110Tests : GeneralStateTestBase
{
[TestCaseSource(nameof(LoadTests))]
public void Test(GeneralStateTest test)
{
Assert.True(RunTest(test).Pass);
}

public static IEnumerable<GeneralStateTest> LoadTests()
{
var loader = new TestsSourceLoader(new LoadGeneralStateTestsStrategy(), "stEIP6110");
return (IEnumerable<GeneralStateTest>)loader.LoadTests();
}
}
}
16 changes: 9 additions & 7 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,23 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
codeInfoRepository,
_logManager);

TransactionProcessor? txProcessor = new(
specProvider,
stateProvider,
virtualMachine,
codeInfoRepository,
_logManager);

IBlockProcessor blockProcessor = new BlockProcessor(
specProvider,
blockValidator,
rewardCalculator,
new BlockProcessor.BlockValidationTransactionsExecutor(
new TransactionProcessor(
specProvider,
stateProvider,
virtualMachine,
codeInfoRepository,
_logManager),
new BlockProcessor.BlockValidationTransactionsExecutor(txProcessor,
stateProvider),
stateProvider,
receiptStorage,
new BlockhashStore(specProvider, stateProvider),
txProcessor,
_logManager);

IBlockchainProcessor blockchainProcessor = new BlockchainProcessor(
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class GeneralStateTest : IEthereumTest
public UInt256? ParentBlobGasUsed { get; set; }
public UInt256? ParentExcessBlobGas { get; set; }

public Hash256? RequestsRoot { get; set; }

public override string ToString()
{
return $"{Path.GetFileName(Category)}.{Name}_{ForkName}";
Expand Down
3 changes: 2 additions & 1 deletion src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
header.ParentBeaconBlockRoot = test.CurrentBeaconRoot;
header.ExcessBlobGas = test.CurrentExcessBlobGas ?? (test.Fork is Cancun ? 0ul : null);
header.BlobGasUsed = BlobGasCalculator.CalculateBlobGas(test.Transaction);
header.RequestsRoot = test.RequestsRoot;

Stopwatch stopwatch = Stopwatch.StartNew();
IReleaseSpec? spec = specProvider.GetSpec((ForkActivation)test.CurrentNumber);
Expand Down Expand Up @@ -178,7 +179,7 @@ private static void InitializeTestState(GeneralStateTest test, WorldState stateP
}

stateProvider.CreateAccount(accountState.Key, accountState.Value.Balance);
stateProvider.InsertCode(accountState.Key, accountState.Value.Code, specProvider.GenesisSpec);
stateProvider.InsertCode(accountState.Key, accountState.Value.Code, specProvider.GenesisSpec, false);
stateProvider.SetNonce(accountState.Key, accountState.Value.Nonce);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public static IEnumerable<GeneralStateTest> Convert(string name, GeneralStateTes
}

List<GeneralStateTest> blockchainTests = new();
Console.WriteLine($"Loaded {testJson}");
foreach (KeyValuePair<string, PostStateJson[]> postStateBySpec in testJson.Post)
{
int iterationNumber = 0;
Expand Down Expand Up @@ -287,9 +288,11 @@ public static IEnumerable<GeneralStateTest> Convert(string json)
{
Dictionary<string, GeneralStateTestJson> testsInFile =
_serializer.Deserialize<Dictionary<string, GeneralStateTestJson>>(json);

List<GeneralStateTest> tests = new();
foreach (KeyValuePair<string, GeneralStateTestJson> namedTest in testsInFile)
{
Console.WriteLine($"Loading {namedTest.Key}\n {namedTest.Value.Post}");
tests.AddRange(Convert(namedTest.Key, namedTest.Value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ protected override BlockProcessor CreateBlockProcessor()
State,
ReceiptStorage,
new BlockhashStore(SpecProvider, State),
TxProcessor,
LogManager);

AbiParameterConverter.RegisterFactory(new AbiTypeFactory(new AbiTuple<UserOperationAbi>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void Process(AuRaBlockProcessor auRaBlockProcessor, int blockNumber, Hash256 sta
LimboLogs.Instance,
Substitute.For<IBlockTree>(),
new WithdrawalProcessor(stateProvider, LimboLogs.Instance),
transactionProcessor,
null,
txFilter,
contractRewriter: contractRewriter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
Expand All @@ -17,7 +16,6 @@
using Nethermind.Consensus.Validators;
using Nethermind.Core;
using Nethermind.Logging;
using Nethermind.Trie.Pruning;
using NUnit.Framework;

namespace Nethermind.AuRa.Test.Contract;
Expand Down Expand Up @@ -101,6 +99,7 @@ protected override BlockProcessor CreateBlockProcessor()
LimboLogs.Instance,
BlockTree,
NullWithdrawalProcessor.Instance,
TxProcessor,
null,
null,
GasLimitCalculator as AuRaContractGasLimitOverride);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using Nethermind.Core.Specs;
using Nethermind.Core.Test.Builders;
using Nethermind.Logging;
using Nethermind.Trie.Pruning;
using Nethermind.TxPool;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
Expand Down Expand Up @@ -157,8 +156,8 @@ protected override BlockProcessor CreateBlockProcessor()
LimboLogs.Instance,
BlockTree,
NullWithdrawalProcessor.Instance,
null
);
TxProcessor,
null);
}

protected override Task AddBlocksOnStart() => Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ protected override BlockProcessor CreateBlockProcessor()
LimboLogs.Instance,
BlockTree,
NullWithdrawalProcessor.Instance,
TxProcessor,
null,
PermissionBasedTxFilter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void Prepared_block_contains_author_field()
stateProvider,
NullReceiptStorage.Instance,
Substitute.For<IBlockhashStore>(),
transactionProcessor,
LimboLogs.Instance);

BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject;
Expand Down Expand Up @@ -79,6 +80,7 @@ public void Recovers_state_on_cancel()
stateProvider,
NullReceiptStorage.Instance,
Substitute.For<IBlockhashStore>(),
transactionProcessor,
LimboLogs.Instance);

BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithAuthor(TestItem.AddressD).TestObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void Test()
stateProvider,
NullReceiptStorage.Instance,
new BlockhashStore(specProvider, stateProvider),
txProcessor,
LimboLogs.Instance);
BlockchainProcessor blockchainProcessor = new(
blockTree,
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void Setup()
stateProvider,
NullReceiptStorage.Instance,
new BlockhashStore(MainnetSpecProvider.Instance, stateProvider),
transactionProcessor,
LimboLogs.Instance);
_blockchainProcessor = new BlockchainProcessor(
_blockTree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Nethermind.Consensus.Messages;
using Nethermind.Consensus.Validators;
using Nethermind.Core.ConsensusRequests;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
Expand Down Expand Up @@ -202,5 +203,52 @@ public void ValidateSuggestedBlock_SuggestedBlockIsInvalid_CorrectErrorIsSet(Blo

Assert.That(error, Does.StartWith(expectedError));
}

[Test]
public void ValidateBodyAgainstHeader_BlockHasInvalidRequestRoot_ReturnsFalse()
{
Block block = Build.A.Block
.WithConsensusRequests(new ConsensusRequest[] {
Build.Deposit.WithIndex(0).TestObject,
Build.WithdrawalRequest.TestObject
})
.TestObject;
block.Header.RequestsRoot = Keccak.OfAnEmptyString;

Assert.That(
BlockValidator.ValidateBodyAgainstHeader(block.Header, block.Body),
Is.False);
}

[Test]
public void ValidateBodyRequests_BlockHasReuests_InOrder_ReturnsTrue()
{
Block block = Build.A.Block
.WithConsensusRequests(new ConsensusRequest[] {
Build.Deposit.WithIndex(0).TestObject,
Build.WithdrawalRequest.TestObject
})
.TestObject;

Assert.That(
BlockValidator.ValidateRequestsOrder(block, out string? _),
Is.True);
}

[Test]
public void ValidateBodyRequests_BlockHasReuests_OutOfOrder_ReturnsFalse()
{
Block block = Build.A.Block
.WithConsensusRequests(new ConsensusRequest[] {
Build.WithdrawalRequest.TestObject,
Build.Deposit.WithIndex(0).TestObject
})
.TestObject;

Assert.That(
BlockValidator.ValidateRequestsOrder(block, out string? _),
Is.False);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public void Withdrawals_with_incorrect_withdrawals_root_are_invalid()
{
ISpecProvider specProvider = new CustomSpecProvider(((ForkActivation)0, Shanghai.Instance));
BlockValidator blockValidator = new(Always.Valid, Always.Valid, Always.Valid, specProvider, LimboLogs.Instance);
Withdrawal[] withdrawals = { TestItem.WithdrawalA_1Eth, TestItem.WithdrawalB_2Eth };
Hash256 withdrawalRoot = new WithdrawalTrie(withdrawals).RootHash;
Withdrawal[] withdrawals = [TestItem.WithdrawalA_1Eth, TestItem.WithdrawalB_2Eth];
bool isValid = blockValidator.ValidateSuggestedBlock(Build.A.Block.WithWithdrawals(withdrawals).WithWithdrawalsRoot(TestItem.KeccakD).TestObject);
Assert.False(isValid);
}
Expand All @@ -50,7 +49,7 @@ public void Empty_withdrawals_are_valid_post_shanghai()
{
ISpecProvider specProvider = new CustomSpecProvider(((ForkActivation)0, Shanghai.Instance));
BlockValidator blockValidator = new(Always.Valid, Always.Valid, Always.Valid, specProvider, LimboLogs.Instance);
Withdrawal[] withdrawals = { };
Withdrawal[] withdrawals = [];
Hash256 withdrawalRoot = new WithdrawalTrie(withdrawals).RootHash;
bool isValid = blockValidator.ValidateSuggestedBlock(Build.A.Block.WithWithdrawals(withdrawals).WithWithdrawalsRoot(withdrawalRoot).TestObject);
Assert.True(isValid);
Expand All @@ -61,7 +60,7 @@ public void Correct_withdrawals_block_post_shanghai()
{
ISpecProvider specProvider = new CustomSpecProvider(((ForkActivation)0, Shanghai.Instance));
BlockValidator blockValidator = new(Always.Valid, Always.Valid, Always.Valid, specProvider, LimboLogs.Instance);
Withdrawal[] withdrawals = { TestItem.WithdrawalA_1Eth, TestItem.WithdrawalB_2Eth };
Withdrawal[] withdrawals = [TestItem.WithdrawalA_1Eth, TestItem.WithdrawalB_2Eth];
Hash256 withdrawalRoot = new WithdrawalTrie(withdrawals).RootHash;
bool isValid = blockValidator.ValidateSuggestedBlock(Build.A.Block.WithWithdrawals(withdrawals).WithWithdrawalsRoot(withdrawalRoot).TestObject);
Assert.True(isValid);
Expand Down
Loading

0 comments on commit c7e9f61

Please sign in to comment.