Skip to content

Commit b39cbb1

Browse files
committed
it-test, assert that is not reorganising when parent block is not part of the chain
1 parent 4a7e5cc commit b39cbb1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/it/scala/io/iohk/ethereum/ledger/BlockImporterItSpec.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,29 @@ class BlockImporterItSpec
153153
blockchain.getBestBlock().get shouldEqual newBlock3
154154
}
155155

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 {
157+
val newcomerBlock4: Block =
158+
getBlock(genesisBlock.number + 4, difficulty = 104, parent = oldBlock3.header.hash)
159+
val newcomerWeight4Duplicate = oldWeight3.increase(newcomerBlock4.header)
160+
161+
//Block n5 with oldBlock4 as parent
162+
val newComerBlock5WithOldBlock4Parent: Block =
163+
getBlock(genesisBlock.number + 5, difficulty = 108, parent = oldBlock4.header.hash)
164+
165+
blockchain.save(oldBlock2, Nil, oldWeight2, saveAsBestBlock = true)
166+
blockchain.save(oldBlock3, Nil, oldWeight3, saveAsBestBlock = true)
167+
blockchain.save(oldBlock4, Nil, oldWeight4, saveAsBestBlock = true)
168+
// simulation of node restart
169+
blockchain.saveBestKnownBlocks(blockchain.getBestBlockNumber() - 1)
170+
blockchain.save(newcomerBlock4, Nil, newcomerWeight4Duplicate, saveAsBestBlock = true)
171+
172+
//this is not reorganising anymore until oldBlock4(not part of the chain anymore) // but resolveBranch is returning UnknownBranch
173+
blockImporter ! BlockFetcher.PickedBlocks(NonEmptyList.fromListUnsafe(List(newComerBlock5WithOldBlock4Parent)))
174+
175+
Thread.sleep(200)
176+
blockchain.getBestBlock().get shouldEqual newcomerBlock4
177+
}
178+
156179
it should "switch to a branch with a checkpoint" in {
157180

158181
val checkpoint = ObjectGenerators.fakeCheckpointGen(3, 3).sample.get

0 commit comments

Comments
 (0)