Skip to content

Commit 871e9c7

Browse files
authored
Fix AuRaMergeEngineModuleTests (#10872)
1 parent 82ab1a7 commit 871e9c7

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
using Nethermind.Consensus.AuRa.Config;
1212
using Nethermind.Consensus.AuRa.InitializationSteps;
1313
using Nethermind.Consensus.AuRa.Validators;
14-
using Nethermind.Consensus.Processing;
1514
using Nethermind.Consensus.Producers;
1615
using Nethermind.Consensus.Withdrawals;
1716
using Nethermind.Core;
1817
using Nethermind.Core.Crypto;
1918
using Nethermind.Core.Specs;
19+
using Nethermind.Core.Test.Builders;
2020
using Nethermind.Core.Test.Container;
2121
using Nethermind.Evm.TransactionProcessing;
2222
using Nethermind.Int256;
@@ -29,6 +29,7 @@
2929
using Nethermind.Specs.ChainSpecStyle;
3030
using Nethermind.Specs.Test;
3131
using Nethermind.Specs.Test.ChainSpecStyle;
32+
using Nethermind.TxPool;
3233
using NSubstitute;
3334
using NUnit.Framework;
3435

@@ -111,6 +112,12 @@ public override Task Can_apply_withdrawals_correctly((Withdrawal[][] Withdrawals
111112
public new Task getPayloadV1_does_not_wait_for_improvement_when_block_is_not_empty()
112113
=> base.getPayloadV1_does_not_wait_for_improvement_when_block_is_not_empty();
113114

115+
protected override BlockBuilder BuildNewBlock(Block head)
116+
=> base.BuildNewBlock(head).WithAura(0, []);
117+
118+
protected override BlockBuilder BuildOneMoreTerminalBlock(Block head, bool correctStateRoot = true)
119+
=> base.BuildOneMoreTerminalBlock(head, correctStateRoot).WithAura(0, []);
120+
114121
public class MergeAuRaTestBlockchain : MergeTestBlockchain
115122
{
116123
public MergeAuRaTestBlockchain(IMergeConfig? mergeConfig = null)
@@ -139,9 +146,16 @@ protected override ContainerBuilder ConfigureContainer(ContainerBuilder builder,
139146
})
140147

141148
// Aura uses `AuRaNethermindApi` for initialization, so need to do some additional things here
142-
// as normally, test blockchain don't use INethermindApi at all. Note: This test does not
143-
// seems to use aura block processor which means a lot of aura things is not available here.
149+
// as normally, test blockchain don't use INethermindApi at all.
144150
.AddModule(new AuRaModule(ChainSpec))
151+
152+
.AddDecorator<AuRaNethermindApi>((_, api) =>
153+
{
154+
api.EngineSigner = NullSigner.Instance;
155+
api.NonceManager = Substitute.For<INonceManager>();
156+
return api;
157+
})
158+
145159
.AddModule(new AuRaMergeModule())
146160
.AddSingleton<NethermindApi.Dependencies>()
147161
.AddSingleton<IReportingValidator>(NullReportingValidator.Instance)
@@ -154,9 +168,6 @@ protected override ContainerBuilder ConfigureContainer(ContainerBuilder builder,
154168
.AddSingleton<IBlockImprovementContextFactory, IBlockProducer, IMergeConfig>((blockProducer,
155169
mergeConfig) => new BlockImprovementContextFactory(blockProducer, TimeSpan.FromSeconds(mergeConfig.SecondsPerSlot)))
156170

157-
// AuRa was never configured correctly in test.
158-
.AddScoped<IBlockProcessor, BlockProcessor>()
159-
160171
.AddDecorator<AuRaNethermindApi>((_, api) =>
161172
{
162173
// Yes getting from `TestBlockchain` itself, since steps are not run
@@ -171,11 +182,16 @@ protected override ContainerBuilder ConfigureContainer(ContainerBuilder builder,
171182
protected override ChainSpec CreateChainSpec()
172183
{
173184
ChainSpec baseChainSpec = base.CreateChainSpec();
185+
AuRaChainSpecEngineParameters.AuRaValidatorJson validatorsJson = new()
186+
{
187+
List = [Address.Zero]
188+
};
174189
baseChainSpec.EngineChainSpecParametersProvider = new TestChainSpecParametersProvider(
175190
new AuRaChainSpecEngineParameters
176191
{
177192
WithdrawalContractAddress = new(_auraWithdrawalContractAddress),
178-
StepDuration = { { 0, 3 } }
193+
StepDuration = { { 0, 3 } },
194+
ValidatorsJson = validatorsJson
179195
});
180196
baseChainSpec.Parameters = new ChainParameters();
181197
return baseChainSpec;

src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
using Nethermind.Core.Test.Builders;
2323
using Nethermind.Core.Test.Container;
2424
using Nethermind.Crypto;
25-
using Nethermind.Evm;
2625
using Nethermind.Facade.Eth;
2726
using Nethermind.HealthChecks;
2827
using Nethermind.Int256;
@@ -843,7 +842,6 @@ public async Task forkchoiceUpdatedV1_should_not_accept_blocks_with_incorrect_tt
843842
resultWrapper.Data.PayloadStatus.LatestValidHash.Should().Be(Keccak.Zero);
844843
}
845844

846-
[Test]
847845
[CancelAfter(5000)]
848846
public async Task executePayloadV1_on_top_of_terminal_block(CancellationToken cancellationToken)
849847
{
@@ -852,19 +850,12 @@ public async Task executePayloadV1_on_top_of_terminal_block(CancellationToken ca
852850
TerminalTotalDifficulty = $"{1900000}"
853851
});
854852
IEngineRpcModule rpc = chain.EngineRpcModule;
855-
Block newBlock = Build.A.Block.WithNumber(chain.BlockTree.Head!.Number)
856-
.WithParent(chain.BlockTree.Head!)
857-
.WithNonce(0)
858-
.WithDifficulty(1000000)
859-
.WithTotalDifficulty(2000000L)
860-
.WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject;
853+
854+
Block newBlock = BuildNewBlock(chain.BlockTree.Head!).TestObject;
861855
newBlock.CalculateHash();
862-
Block oneMoreTerminalBlock = Build.A.Block.WithNumber(chain.BlockTree.Head!.Number)
863-
.WithParent(chain.BlockTree.Head!)
864-
.WithNonce(0)
865-
.WithDifficulty(900000)
866-
.WithTotalDifficulty(1900000L)
867-
.WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject;
856+
857+
Block oneMoreTerminalBlock = BuildOneMoreTerminalBlock(chain.BlockTree.Head!).TestObject;
858+
oneMoreTerminalBlock.CalculateHash();
868859

869860
using SemaphoreSlim bestBlockProcessed = new(0);
870861
chain.BlockTree.NewHeadBlock += (s, e) =>
@@ -875,7 +866,6 @@ public async Task executePayloadV1_on_top_of_terminal_block(CancellationToken ca
875866
await chain.BlockTree.SuggestBlockAsync(newBlock);
876867
await bestBlockProcessed.WaitAsync(cancellationToken);
877868

878-
oneMoreTerminalBlock.CalculateHash();
879869
await chain.BlockTree.SuggestBlockAsync(oneMoreTerminalBlock);
880870

881871
Block firstPoSBlock = Build.A.Block.WithParent(oneMoreTerminalBlock).
@@ -889,7 +879,6 @@ public async Task executePayloadV1_on_top_of_terminal_block(CancellationToken ca
889879
ExecutionPayload.Create(chain.BlockTree.BestSuggestedBody!).Should().BeEquivalentTo(executionPayload, o => o.IgnoringCyclicReferences());
890880
}
891881

892-
[Test]
893882
[CancelAfter(5000)]
894883
public async Task executePayloadV1_on_top_of_not_processed_invalid_terminal_block(CancellationToken cancellationToken)
895884
{
@@ -898,19 +887,12 @@ public async Task executePayloadV1_on_top_of_not_processed_invalid_terminal_bloc
898887
TerminalTotalDifficulty = $"{1900000}"
899888
});
900889
IEngineRpcModule rpc = chain.EngineRpcModule;
901-
Block newBlock = Build.A.Block.WithNumber(chain.BlockTree.Head!.Number)
902-
.WithParent(chain.BlockTree.Head!)
903-
.WithNonce(0)
904-
.WithDifficulty(1000000)
905-
.WithTotalDifficulty(2000000L)
906-
.WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject;
890+
891+
Block newBlock = BuildNewBlock(chain.BlockTree.Head!).TestObject;
907892
newBlock.CalculateHash();
908-
Block oneMoreTerminalBlock = Build.A.Block.WithNumber(chain.BlockTree.Head!.Number)
909-
.WithParent(chain.BlockTree.Head!)
910-
.WithNonce(0)
911-
.WithDifficulty(900000)
912-
.WithTotalDifficulty(1900000L)
913-
.WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bfba4ccf1702fabf02d8ad7a20b454edb6fd2f")).TestObject; //incorrect state root
893+
894+
Block oneMoreTerminalBlock = BuildOneMoreTerminalBlock(chain.BlockTree.Head!, correctStateRoot: false).TestObject;
895+
oneMoreTerminalBlock.CalculateHash();
914896

915897
using SemaphoreSlim bestBlockProcessed = new(0);
916898
chain.BlockTree.NewHeadBlock += (s, e) =>
@@ -921,7 +903,6 @@ public async Task executePayloadV1_on_top_of_not_processed_invalid_terminal_bloc
921903
await chain.BlockTree.SuggestBlockAsync(newBlock);
922904
await bestBlockProcessed.WaitAsync(cancellationToken);
923905

924-
oneMoreTerminalBlock.CalculateHash();
925906
await chain.BlockTree.SuggestBlockAsync(oneMoreTerminalBlock);
926907

927908
Block firstPoSBlock = Build.A.Block.WithParent(oneMoreTerminalBlock).
@@ -1719,4 +1700,20 @@ public async Task<int> ForkchoiceUpdated_should_validate_payload_attributes_fiel
17191700

17201701
return errorResponse.Error?.Code ?? ErrorCodes.None;
17211702
}
1703+
1704+
protected virtual BlockBuilder BuildNewBlock(Block head)
1705+
=> Build.A.Block.WithNumber(head.Number)
1706+
.WithParent(head)
1707+
.WithNonce(0)
1708+
.WithDifficulty(1000000)
1709+
.WithTotalDifficulty(2000000L)
1710+
.WithStateRoot(new Hash256("0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f"));
1711+
1712+
protected virtual BlockBuilder BuildOneMoreTerminalBlock(Block head, bool correctStateRoot = true)
1713+
=> Build.A.Block.WithNumber(head.Number)
1714+
.WithParent(head)
1715+
.WithNonce(0)
1716+
.WithDifficulty(900000)
1717+
.WithTotalDifficulty(1900000L)
1718+
.WithStateRoot(new Hash256(correctStateRoot ? "0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f" : "0x1ef7300d8961797263939a3d29bfba4ccf1702fabf02d8ad7a20b454edb6fd2f"));
17221719
}

0 commit comments

Comments
 (0)