@@ -25,7 +25,7 @@ import io.iohk.ethereum.network.p2p.messages.CommonMessages.Status.StatusEnc
25
25
import io .iohk .ethereum .network .p2p .messages .PV62 .GetBlockHeaders .GetBlockHeadersEnc
26
26
import io .iohk .ethereum .network .p2p .messages .PV62 ._
27
27
import io .iohk .ethereum .network .p2p .messages .{PV64 , ProtocolVersions }
28
- import io .iohk .ethereum .network .p2p .messages .WireProtocol .Disconnect .Reasons
28
+ import io .iohk .ethereum .network .p2p .messages .WireProtocol .Disconnect .{ DisconnectEnc , Reasons }
29
29
import io .iohk .ethereum .network .p2p .messages .WireProtocol .Hello .HelloEnc
30
30
import io .iohk .ethereum .network .p2p .messages .WireProtocol .Pong .PongEnc
31
31
import io .iohk .ethereum .network .p2p .messages .WireProtocol ._
@@ -160,6 +160,35 @@ class PeerActorSpec
160
160
knownNodesManager.expectNoMessage()
161
161
}
162
162
163
+ it should " fail handshake with peer that has a wrong genesis hash" in new TestSetup {
164
+ val uri = new URI (s " enode:// ${Hex .toHexString(remoteNodeId.toArray[Byte ])}@localhost:9000 " )
165
+ val completeUri = new URI (s " enode:// ${Hex .toHexString(remoteNodeId.toArray[Byte ])}@127.0.0.1:9000?discport=9000 " )
166
+ peer ! PeerActor .ConnectTo (uri)
167
+ peer ! PeerActor .ConnectTo (uri)
168
+
169
+ rlpxConnection.expectMsgClass(classOf [RLPxConnectionHandler .ConnectTo ])
170
+ rlpxConnection.reply(RLPxConnectionHandler .ConnectionEstablished (remoteNodeId))
171
+
172
+ // Hello exchange
173
+ val remoteHello = Hello (4 , " test-client" , Seq (Eth63Capability ), 9000 , ByteString (" unused" ))
174
+ rlpxConnection.expectMsgPF() { case RLPxConnectionHandler .SendMessage (_ : HelloEnc ) => () }
175
+ rlpxConnection.send(peer, RLPxConnectionHandler .MessageReceived (remoteHello))
176
+
177
+ val remoteStatus = Status (
178
+ protocolVersion = ProtocolVersions .PV63 ,
179
+ networkId = peerConf.networkId,
180
+ totalDifficulty = daoForkBlockChainTotalDifficulty + 100000 , // remote is after the fork
181
+ bestHash = ByteString (" blockhash" ),
182
+ genesisHash = genesisHash.drop(2 )
183
+ )
184
+
185
+ // Node status exchange
186
+ rlpxConnection.expectMsgPF() { case RLPxConnectionHandler .SendMessage (_ : StatusEnc ) => () }
187
+ rlpxConnection.send(peer, RLPxConnectionHandler .MessageReceived (remoteStatus))
188
+
189
+ rlpxConnection.expectMsgPF() { case RLPxConnectionHandler .SendMessage (_ : DisconnectEnc ) => () }
190
+ }
191
+
163
192
it should " successfully connect to ETC peer with protocol 64" in new TestSetup {
164
193
override def protocol : Version = ProtocolVersions .PV64
165
194
val uri = new URI (s " enode:// ${Hex .toHexString(remoteNodeId.toArray[Byte ])}@localhost:9000 " )
0 commit comments