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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<AuRaNethermindApi>((_, api) =>
{
api.EngineSigner = NullSigner.Instance;
api.NonceManager = Substitute.For<INonceManager>();
return api;
})

.AddModule(new AuRaMergeModule())
.AddSingleton<NethermindApi.Dependencies>()
.AddSingleton<IReportingValidator>(NullReportingValidator.Instance)
Expand All @@ -154,9 +168,6 @@ protected override ContainerBuilder ConfigureContainer(ContainerBuilder builder,
.AddSingleton<IBlockImprovementContextFactory, IBlockProducer, IMergeConfig>((blockProducer,
mergeConfig) => new BlockImprovementContextFactory(blockProducer, TimeSpan.FromSeconds(mergeConfig.SecondsPerSlot)))

// AuRa was never configured correctly in test.
.AddScoped<IBlockProcessor, BlockProcessor>()

.AddDecorator<AuRaNethermindApi>((_, api) =>
{
// Yes getting from `TestBlockchain` itself, since steps are not run
Expand All @@ -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;
Expand Down
55 changes: 26 additions & 29 deletions src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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) =>
Expand All @@ -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).
Expand All @@ -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)
{
Expand All @@ -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) =>
Expand All @@ -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).
Expand Down Expand Up @@ -1719,4 +1700,20 @@ public async Task<int> 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"));
}
Loading