@@ -190,7 +190,8 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
190190 }
191191 }
192192
193- it should " send status with fork id when peer supports ETH64" in new LocalPeerETH64Setup with RemotePeerETH64Setup {
193+ it should " connect correctly after validating fork id when peer supports ETH64" in new LocalPeerETH64Setup
194+ with RemotePeerETH64Setup {
194195
195196 val newChainWeight = ChainWeight .zero.increase(genesisBlock.header).increase(firstBlock.header)
196197
@@ -223,6 +224,45 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
223224 }
224225 }
225226
227+ it should " disconnect from a useless peer after validating fork id when peer supports ETH64" in new LocalPeerETH64Setup
228+ with RemotePeerETH64Setup {
229+
230+ val newChainWeight = ChainWeight .zero.increase(genesisBlock.header).increase(firstBlock.header)
231+
232+ blockchainWriter.save(firstBlock, Nil , newChainWeight, saveAsBestBlock = true )
233+
234+ val newLocalStatusMsg =
235+ localStatusMsg
236+ .copy(
237+ bestHash = firstBlock.header.hash,
238+ totalDifficulty = newChainWeight.totalDifficulty,
239+ forkId = ForkId (0xfc64ec04L, Some (1150000 ))
240+ )
241+
242+ initHandshakerWithoutResolver.nextMessage.map(_.messageToSend) shouldBe Right (localHello : HelloEnc )
243+
244+ val newRemoteStatusMsg =
245+ remoteStatusMsg
246+ .copy(
247+ forkId = ForkId (1 , None ) // ForkId that is incompatible with our chain
248+ )
249+
250+ val handshakerAfterHelloOpt = initHandshakerWithoutResolver.applyMessage(remoteHello)
251+ assert(handshakerAfterHelloOpt.isDefined)
252+
253+ handshakerAfterHelloOpt.get.nextMessage.map(_.messageToSend.underlyingMsg) shouldBe Right (newLocalStatusMsg)
254+
255+ val handshakerAfterStatusOpt = handshakerAfterHelloOpt.get.applyMessage(newRemoteStatusMsg)
256+ assert(handshakerAfterStatusOpt.isDefined)
257+
258+ handshakerAfterStatusOpt.get.nextMessage match {
259+ case Left (HandshakeFailure (Disconnect .Reasons .UselessPeer )) => succeed
260+ case other =>
261+ fail(s " Invalid handshaker state: $other" )
262+ }
263+
264+ }
265+
226266 it should " fail if a timeout happened during hello exchange" in new TestSetup {
227267 val handshakerAfterTimeout = initHandshakerWithoutResolver.processTimeout
228268 handshakerAfterTimeout.nextMessage.map(_.messageToSend) shouldBe Left (
@@ -447,7 +487,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
447487 totalDifficulty = 0 ,
448488 bestHash = genesisBlock.header.hash,
449489 genesisHash = genesisBlock.header.hash,
450- forkId = ForkId (2L , Some (3L ))
490+ forkId = ForkId (0xfc64ec04L , Some (1150000 ))
451491 )
452492
453493 val remoteStatus : RemoteStatus = RemoteStatus (remoteStatusMsg)
0 commit comments