@@ -214,7 +214,7 @@ class BlockchainSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyCh
214
214
}
215
215
216
216
it should " return correct best block number after saving and rolling back blocks" in new TestSetup {
217
- forAll(posIntGen (min = 1 , max = maxNumberBlocksToImport)) { numberBlocksToImport =>
217
+ forAll(intGen (min = 1 , max = maxNumberBlocksToImport)) { numberBlocksToImport =>
218
218
val testSetup = newSetup()
219
219
import testSetup ._
220
220
@@ -237,8 +237,9 @@ class BlockchainSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyCh
237
237
blockchainReaderWithStubPersisting.getBestBlockNumber() shouldBe blocksToImport.last.number
238
238
239
239
// Rollback blocks
240
- val numberBlocksToRollback = intGen(0 , numberBlocksToImport).sample.get
241
- val (_, blocksToRollback) = blocksToImport.splitAt(numberBlocksToRollback)
240
+ val numberBlocksToKeep = intGen(0 , numberBlocksToImport).sample.get
241
+
242
+ val (_, blocksToRollback) = blocksToImport.splitAt(numberBlocksToKeep)
242
243
243
244
// Randomly select the block rollback to persist (empty means no persistence)
244
245
val blockRollbackToPersist =
@@ -254,38 +255,13 @@ class BlockchainSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyCh
254
255
blockchainWithStubPersisting.removeBlock(block.hash)
255
256
}
256
257
257
- val expectedPersistedBestBlock = calculatePersistedBestBlock(
258
- blockImportToPersist.map(_.number),
259
- blockRollbackToPersist.map(_.number),
260
- blocksToRollback.map(_.number)
261
- )
262
- blockchainReaderWithStubPersisting.getBestBlockNumber() shouldBe expectedPersistedBestBlock
258
+ blockchainReaderWithStubPersisting.getBestBlockNumber() shouldBe numberBlocksToKeep
263
259
}
264
260
}
265
261
266
262
trait TestSetup extends MockFactory {
267
263
val maxNumberBlocksToImport : Int = 30
268
264
269
- def calculatePersistedBestBlock (
270
- blockImportPersisted : Option [BigInt ],
271
- blockRollbackPersisted : Option [BigInt ],
272
- blocksRolledback : Seq [BigInt ]
273
- ): BigInt =
274
- (blocksRolledback, blockImportPersisted) match {
275
- case (Nil , Some (bi)) =>
276
- // No blocks rolledback, last persist was the persist during import
277
- bi
278
- case (nonEmptyRolledbackBlocks, Some (bi)) =>
279
- // Last forced persist during apply/rollback
280
- val maxForcedPersist = blockRollbackPersisted.fold(bi)(br => (br - 1 ).max(bi))
281
-
282
- // The above number would have been decreased by any rollbacked blocks
283
- (nonEmptyRolledbackBlocks.head - 1 ).min(maxForcedPersist)
284
- case (_, None ) =>
285
- // If persisted rollback, then it was decreased by the future rollbacks, if not no persistance was ever done
286
- blockRollbackPersisted.fold(0 : BigInt )(_ => blocksRolledback.head - 1 )
287
- }
288
-
289
265
trait StubPersistingBlockchainSetup {
290
266
def stubStateStorage : StateStorage
291
267
def blockchainStoragesWithStubPersisting : BlockchainStorages
0 commit comments