2222using Nethermind . Core . Test . Builders ;
2323using Nethermind . Core . Test . Container ;
2424using Nethermind . Crypto ;
25- using Nethermind . Evm ;
2625using Nethermind . Facade . Eth ;
2726using Nethermind . HealthChecks ;
2827using 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