@@ -26,7 +26,7 @@ import io.iohk.ethereum.ledger.{
26
26
OmmersTestSetup ,
27
27
TestSetupWithVmAndValidators
28
28
}
29
- import io .iohk .ethereum .mpt .{LeafNode , MerklePatriciaTrie }
29
+ import io .iohk .ethereum .mpt .{LeafNode , MerklePatriciaTrie , NullNode }
30
30
import io .iohk .ethereum .utils .BlockchainConfig
31
31
import org .scalatest .concurrent .ScalaFutures
32
32
import org .scalatest .flatspec .AnyFlatSpec
@@ -40,7 +40,7 @@ class ConsensusSpec extends AnyFlatSpec with Matchers with ScalaFutures {
40
40
implicit override val patienceConfig : PatienceConfig =
41
41
PatienceConfig (timeout = scaled(2 seconds), interval = scaled(1 second))
42
42
43
- " Importing blocks " should " ignore existing block" in new ImportBlockTestSetup {
43
+ " Consensus " should " ignore duplicated block" in new ImportBlockTestSetup {
44
44
val block1 : Block = getBlock()
45
45
val block2 : Block = getBlock()
46
46
@@ -55,7 +55,7 @@ class ConsensusSpec extends AnyFlatSpec with Matchers with ScalaFutures {
55
55
whenReady(consensus.evaluateBranchBlock(block2).runToFuture)(_ shouldEqual DuplicateBlock )
56
56
}
57
57
58
- it should " import a block to top of the main chain" in new ImportBlockTestSetup {
58
+ it should " import a block to the top of the main chain" in new ImportBlockTestSetup {
59
59
val block : Block = getBlock(6 , parent = bestBlock.header.hash)
60
60
val difficulty : BigInt = block.header.difficulty
61
61
val hash : ByteString = block.header.hash
@@ -112,7 +112,39 @@ class ConsensusSpec extends AnyFlatSpec with Matchers with ScalaFutures {
112
112
113
113
(blockQueue.removeSubtree _).expects(* )
114
114
115
- whenReady(consensus.evaluateBranchBlock(block).runToFuture)(_ shouldBe a[BlockImportFailed ])
115
+ whenReady(consensus.evaluateBranchBlock(block).runToFuture)(
116
+ _ shouldBe BlockImportFailed (" MPTError(io.iohk.ethereum.mpt.MerklePatriciaTrie$MPTException: Invalid Node)" )
117
+ )
118
+ }
119
+
120
+ it should " handle no best block available error when importing to top" in new ImportBlockTestSetup {
121
+ val block : Block = getBlock(6 , parent = bestBlock.header.hash)
122
+
123
+ setBlockExists(block, inChain = false , inQueue = false )
124
+ (blockchainReader.getBestBlock _).expects().returning(None )
125
+ setChainWeightForBlock(bestBlock, currentWeight)
126
+
127
+ whenReady(consensus.evaluateBranchBlock(block).runToFuture)(
128
+ _ shouldBe BlockImportFailed (" Couldn't find the current best block" )
129
+ )
130
+ }
131
+
132
+ it should " handle total difficulty error when importing to top" in new ImportBlockTestSetup {
133
+ val block : Block = getBlock(6 , parent = bestBlock.header.hash)
134
+
135
+ setBlockExists(block, inChain = false , inQueue = false )
136
+ setBestBlock(bestBlock)
137
+ (blockchain.getChainWeightByHash _).expects(* ).returning(None )
138
+
139
+ (blockchainReader.getBlockHeaderByHash _).expects(* ).returning(Some (block.header))
140
+
141
+ whenReady(consensus.evaluateBranchBlock(block).runToFuture) { result =>
142
+ result shouldBe a[BlockImportFailed ]
143
+ result
144
+ .asInstanceOf [BlockImportFailed ]
145
+ .error
146
+ .should(startWith(" Couldn't get total difficulty for current best block" ))
147
+ }
116
148
}
117
149
118
150
// scalastyle:off magic.number
0 commit comments