@@ -6,12 +6,15 @@ import cats.data.NonEmptyList
66import io .iohk .ethereum .blockchain .sync .regular .BlockImporter .NewCheckpoint
77import io .iohk .ethereum .blockchain .sync .regular .{BlockFetcher , BlockImporter }
88import io .iohk .ethereum .checkpointing .CheckpointingTestHelpers
9+ import io .iohk .ethereum .consensus .{GetBlockHeaderByHash , GetNBlocksBack }
910import io .iohk .ethereum .consensus .blocks .CheckpointBlockGenerator
11+ import io .iohk .ethereum .consensus .ethash .validators .{OmmersValidator , StdOmmersValidator }
12+ import io .iohk .ethereum .consensus .validators .Validators
1013import io .iohk .ethereum .domain ._
1114import io .iohk .ethereum .mpt .MerklePatriciaTrie
1215import io .iohk .ethereum .utils .Config .SyncConfig
1316import io .iohk .ethereum .utils .Config
14- import io .iohk .ethereum .{Fixtures , ObjectGenerators , crypto }
17+ import io .iohk .ethereum .{Fixtures , Mocks , ObjectGenerators , crypto }
1518import io .iohk .ethereum .ledger .Ledger .BlockResult
1619import monix .execution .Scheduler
1720import org .scalamock .scalatest .MockFactory
@@ -62,6 +65,18 @@ class BlockImporterItSpec
6265 ethCompatibleStorage = true
6366 )
6467
68+ override protected lazy val successValidators : Validators = new Mocks .MockValidatorsAlwaysSucceed {
69+ override val ommersValidator : OmmersValidator = (
70+ parentHash : ByteString ,
71+ blockNumber : BigInt ,
72+ ommers : Seq [BlockHeader ],
73+ getBlockHeaderByHash : GetBlockHeaderByHash ,
74+ getNBlocksBack : GetNBlocksBack
75+ ) =>
76+ new StdOmmersValidator (blockchainConfig, blockHeaderValidator)
77+ .validate(parentHash, blockNumber, ommers, getBlockHeaderByHash, getNBlocksBack)
78+ }
79+
6580 override lazy val ledger = new TestLedgerImpl (successValidators) {
6681 override private [ledger] lazy val blockExecution =
6782 new BlockExecution (blockchain, blockchainConfig, consensus.blockPreparator, blockValidation) {
@@ -153,14 +168,19 @@ class BlockImporterItSpec
153168 blockchain.getBestBlock().get shouldEqual newBlock3
154169 }
155170
156- it should " return Unknown branch, don't start reorganisation in case of PickedBlocks with block that has a parent who is not present in the chain " in {
171+ it should " return Unknown branch, don't start reorganisation(therefore no block/ommer validation) in case of PickedBlocks with block that has a parent who is not present in the chain(or ommer not in chain) " in {
157172 val newcomerBlock4 : Block =
158173 getBlock(genesisBlock.number + 4 , difficulty = 104 , parent = oldBlock3.header.hash)
159174 val newcomerWeight4Duplicate = oldWeight3.increase(newcomerBlock4.header)
160175
161176 // Block n5 with oldBlock4 as parent
162177 val newComerBlock5WithOldBlock4Parent : Block =
163- getBlock(genesisBlock.number + 5 , difficulty = 108 , parent = oldBlock4.header.hash)
178+ getBlock(
179+ genesisBlock.number + 5 ,
180+ difficulty = 108 ,
181+ parent = oldBlock4.header.hash,
182+ ommers = Seq (oldBlock4.header)
183+ )
164184
165185 blockchain.save(oldBlock2, Nil , oldWeight2, saveAsBestBlock = true )
166186 blockchain.save(oldBlock3, Nil , oldWeight3, saveAsBestBlock = true )
@@ -169,7 +189,7 @@ class BlockImporterItSpec
169189 blockchain.saveBestKnownBlocks(blockchain.getBestBlockNumber() - 1 )
170190 blockchain.save(newcomerBlock4, Nil , newcomerWeight4Duplicate, saveAsBestBlock = true )
171191
172- // this is not reorganising anymore until oldBlock4(not part of the chain anymore) // but resolveBranch is returning UnknownBranch
192+ // not reorganising anymore until oldBlock4(not part of the chain anymore), no block/ommer validation when not part of the chain, resolveBranch is returning UnknownBranch
173193 blockImporter ! BlockFetcher .PickedBlocks (NonEmptyList .fromListUnsafe(List (newComerBlock5WithOldBlock4Parent)))
174194
175195 Thread .sleep(200 )
0 commit comments