diff --git a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs index ebfc467bff4f..0dfdd84e54f1 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs @@ -11,12 +11,12 @@ using Nethermind.Consensus.AuRa.Config; using Nethermind.Consensus.AuRa.InitializationSteps; using Nethermind.Consensus.AuRa.Validators; -using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; using Nethermind.Consensus.Withdrawals; using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Specs; +using Nethermind.Core.Test.Builders; using Nethermind.Core.Test.Container; using Nethermind.Evm.TransactionProcessing; using Nethermind.Int256; @@ -29,6 +29,7 @@ using Nethermind.Specs.ChainSpecStyle; using Nethermind.Specs.Test; using Nethermind.Specs.Test.ChainSpecStyle; +using Nethermind.TxPool; using NSubstitute; using NUnit.Framework; @@ -111,6 +112,12 @@ public override Task Can_apply_withdrawals_correctly((Withdrawal[][] Withdrawals public new Task getPayloadV1_does_not_wait_for_improvement_when_block_is_not_empty() => base.getPayloadV1_does_not_wait_for_improvement_when_block_is_not_empty(); + protected override BlockBuilder BuildNewBlock(Block head) + => base.BuildNewBlock(head).WithAura(0, []); + + protected override BlockBuilder BuildOneMoreTerminalBlock(Block head, bool correctStateRoot = true) + => base.BuildOneMoreTerminalBlock(head, correctStateRoot).WithAura(0, []); + public class MergeAuRaTestBlockchain : MergeTestBlockchain { public MergeAuRaTestBlockchain(IMergeConfig? mergeConfig = null) @@ -139,9 +146,16 @@ protected override ContainerBuilder ConfigureContainer(ContainerBuilder builder, }) // Aura uses `AuRaNethermindApi` for initialization, so need to do some additional things here - // as normally, test blockchain don't use INethermindApi at all. Note: This test does not - // seems to use aura block processor which means a lot of aura things is not available here. + // as normally, test blockchain don't use INethermindApi at all. .AddModule(new AuRaModule(ChainSpec)) + + .AddDecorator((_, api) => + { + api.EngineSigner = NullSigner.Instance; + api.NonceManager = Substitute.For(); + return api; + }) + .AddModule(new AuRaMergeModule()) .AddSingleton() .AddSingleton(NullReportingValidator.Instance) @@ -154,9 +168,6 @@ protected override ContainerBuilder ConfigureContainer(ContainerBuilder builder, .AddSingleton((blockProducer, mergeConfig) => new BlockImprovementContextFactory(blockProducer, TimeSpan.FromSeconds(mergeConfig.SecondsPerSlot))) - // AuRa was never configured correctly in test. - .AddScoped() - .AddDecorator((_, api) => { // Yes getting from `TestBlockchain` itself, since steps are not run @@ -171,11 +182,16 @@ protected override ContainerBuilder ConfigureContainer(ContainerBuilder builder, protected override ChainSpec CreateChainSpec() { ChainSpec baseChainSpec = base.CreateChainSpec(); + AuRaChainSpecEngineParameters.AuRaValidatorJson validatorsJson = new() + { + List = [Address.Zero] + }; baseChainSpec.EngineChainSpecParametersProvider = new TestChainSpecParametersProvider( new AuRaChainSpecEngineParameters { WithdrawalContractAddress = new(_auraWithdrawalContractAddress), - StepDuration = { { 0, 3 } } + StepDuration = { { 0, 3 } }, + ValidatorsJson = validatorsJson }); baseChainSpec.Parameters = new ChainParameters(); return baseChainSpec; diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs index 8179adfee29b..05ba56953cd9 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs @@ -22,7 +22,6 @@ using Nethermind.Core.Test.Builders; using Nethermind.Core.Test.Container; using Nethermind.Crypto; -using Nethermind.Evm; using Nethermind.Facade.Eth; using Nethermind.HealthChecks; using Nethermind.Int256; @@ -843,7 +842,6 @@ public async Task forkchoiceUpdatedV1_should_not_accept_blocks_with_incorrect_tt resultWrapper.Data.PayloadStatus.LatestValidHash.Should().Be(Keccak.Zero); } - [Test] [CancelAfter(5000)] public async Task executePayloadV1_on_top_of_terminal_block(CancellationToken cancellationToken) { @@ -852,19 +850,12 @@ public async Task executePayloadV1_on_top_of_terminal_block(CancellationToken ca TerminalTotalDifficulty = $"{1900000}" }); IEngineRpcModule rpc = chain.EngineRpcModule; - Block newBlock = Build.A.Block.WithNumber(chain.BlockTree.Head!.Number) - .WithParent(chain.BlockTree.Head!) - .WithNonce(0) - .WithDifficulty(1000000) - .WithTotalDifficulty(2000000L) - .WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject; + + Block newBlock = BuildNewBlock(chain.BlockTree.Head!).TestObject; newBlock.CalculateHash(); - Block oneMoreTerminalBlock = Build.A.Block.WithNumber(chain.BlockTree.Head!.Number) - .WithParent(chain.BlockTree.Head!) - .WithNonce(0) - .WithDifficulty(900000) - .WithTotalDifficulty(1900000L) - .WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject; + + Block oneMoreTerminalBlock = BuildOneMoreTerminalBlock(chain.BlockTree.Head!).TestObject; + oneMoreTerminalBlock.CalculateHash(); using SemaphoreSlim bestBlockProcessed = new(0); chain.BlockTree.NewHeadBlock += (s, e) => @@ -875,7 +866,6 @@ public async Task executePayloadV1_on_top_of_terminal_block(CancellationToken ca await chain.BlockTree.SuggestBlockAsync(newBlock); await bestBlockProcessed.WaitAsync(cancellationToken); - oneMoreTerminalBlock.CalculateHash(); await chain.BlockTree.SuggestBlockAsync(oneMoreTerminalBlock); Block firstPoSBlock = Build.A.Block.WithParent(oneMoreTerminalBlock). @@ -889,7 +879,6 @@ public async Task executePayloadV1_on_top_of_terminal_block(CancellationToken ca ExecutionPayload.Create(chain.BlockTree.BestSuggestedBody!).Should().BeEquivalentTo(executionPayload, o => o.IgnoringCyclicReferences()); } - [Test] [CancelAfter(5000)] public async Task executePayloadV1_on_top_of_not_processed_invalid_terminal_block(CancellationToken cancellationToken) { @@ -898,19 +887,12 @@ public async Task executePayloadV1_on_top_of_not_processed_invalid_terminal_bloc TerminalTotalDifficulty = $"{1900000}" }); IEngineRpcModule rpc = chain.EngineRpcModule; - Block newBlock = Build.A.Block.WithNumber(chain.BlockTree.Head!.Number) - .WithParent(chain.BlockTree.Head!) - .WithNonce(0) - .WithDifficulty(1000000) - .WithTotalDifficulty(2000000L) - .WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject; + + Block newBlock = BuildNewBlock(chain.BlockTree.Head!).TestObject; newBlock.CalculateHash(); - Block oneMoreTerminalBlock = Build.A.Block.WithNumber(chain.BlockTree.Head!.Number) - .WithParent(chain.BlockTree.Head!) - .WithNonce(0) - .WithDifficulty(900000) - .WithTotalDifficulty(1900000L) - .WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bfba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject; //incorrect state root + + Block oneMoreTerminalBlock = BuildOneMoreTerminalBlock(chain.BlockTree.Head!, correctStateRoot: false).TestObject; + oneMoreTerminalBlock.CalculateHash(); using SemaphoreSlim bestBlockProcessed = new(0); chain.BlockTree.NewHeadBlock += (s, e) => @@ -921,7 +903,6 @@ public async Task executePayloadV1_on_top_of_not_processed_invalid_terminal_bloc await chain.BlockTree.SuggestBlockAsync(newBlock); await bestBlockProcessed.WaitAsync(cancellationToken); - oneMoreTerminalBlock.CalculateHash(); await chain.BlockTree.SuggestBlockAsync(oneMoreTerminalBlock); Block firstPoSBlock = Build.A.Block.WithParent(oneMoreTerminalBlock). @@ -1719,4 +1700,20 @@ public async Task ForkchoiceUpdated_should_validate_payload_attributes_fiel return errorResponse.Error?.Code ?? ErrorCodes.None; } + + protected virtual BlockBuilder BuildNewBlock(Block head) + => Build.A.Block.WithNumber(head.Number) + .WithParent(head) + .WithNonce(0) + .WithDifficulty(1000000) + .WithTotalDifficulty(2000000L) + .WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f")); + + protected virtual BlockBuilder BuildOneMoreTerminalBlock(Block head, bool correctStateRoot = true) + => Build.A.Block.WithNumber(head.Number) + .WithParent(head) + .WithNonce(0) + .WithDifficulty(900000) + .WithTotalDifficulty(1900000L) + .WithStateRoot(new Hash256(correctStateRoot ? "0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f" : "0x1ef7300d8961797263939a3d29bfba4ccf1702fabf02d8ad7a20b454edb6fd2f")); }