@@ -6,12 +6,15 @@ import cats.data.NonEmptyList
6
6
import io .iohk .ethereum .blockchain .sync .regular .BlockImporter .NewCheckpoint
7
7
import io .iohk .ethereum .blockchain .sync .regular .{BlockFetcher , BlockImporter }
8
8
import io .iohk .ethereum .checkpointing .CheckpointingTestHelpers
9
+ import io .iohk .ethereum .consensus .{GetBlockHeaderByHash , GetNBlocksBack }
9
10
import io .iohk .ethereum .consensus .blocks .CheckpointBlockGenerator
11
+ import io .iohk .ethereum .consensus .ethash .validators .{OmmersValidator , StdOmmersValidator }
12
+ import io .iohk .ethereum .consensus .validators .Validators
10
13
import io .iohk .ethereum .domain ._
11
14
import io .iohk .ethereum .mpt .MerklePatriciaTrie
12
15
import io .iohk .ethereum .utils .Config .SyncConfig
13
16
import io .iohk .ethereum .utils .Config
14
- import io .iohk .ethereum .{Fixtures , ObjectGenerators , crypto }
17
+ import io .iohk .ethereum .{Fixtures , Mocks , ObjectGenerators , crypto }
15
18
import io .iohk .ethereum .ledger .Ledger .BlockResult
16
19
import monix .execution .Scheduler
17
20
import org .scalamock .scalatest .MockFactory
@@ -62,6 +65,18 @@ class BlockImporterItSpec
62
65
ethCompatibleStorage = true
63
66
)
64
67
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
+
65
80
override lazy val ledger = new TestLedgerImpl (successValidators) {
66
81
override private [ledger] lazy val blockExecution =
67
82
new BlockExecution (blockchain, blockchainConfig, consensus.blockPreparator, blockValidation) {
@@ -153,14 +168,19 @@ class BlockImporterItSpec
153
168
blockchain.getBestBlock().get shouldEqual newBlock3
154
169
}
155
170
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 {
157
172
val newcomerBlock4 : Block =
158
173
getBlock(genesisBlock.number + 4 , difficulty = 104 , parent = oldBlock3.header.hash)
159
174
val newcomerWeight4Duplicate = oldWeight3.increase(newcomerBlock4.header)
160
175
161
176
// Block n5 with oldBlock4 as parent
162
177
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
+ )
164
184
165
185
blockchain.save(oldBlock2, Nil , oldWeight2, saveAsBestBlock = true )
166
186
blockchain.save(oldBlock3, Nil , oldWeight3, saveAsBestBlock = true )
@@ -169,7 +189,7 @@ class BlockImporterItSpec
169
189
blockchain.saveBestKnownBlocks(blockchain.getBestBlockNumber() - 1 )
170
190
blockchain.save(newcomerBlock4, Nil , newcomerWeight4Duplicate, saveAsBestBlock = true )
171
191
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
173
193
blockImporter ! BlockFetcher .PickedBlocks (NonEmptyList .fromListUnsafe(List (newComerBlock5WithOldBlock4Parent)))
174
194
175
195
Thread .sleep(200 )
0 commit comments