public void OurPeerBecomesActiveAndDisconnectTest() { var p2pSession = InitializeNode(); //trigger p2p initialization var p2pProtocol = new P2PProtocolHandler(p2pSession, new MessageSerializationService(), p2pSession.RemoteNodeId, p2pSession.RemotePort ?? 0, _logManager, new PerfService(_logManager)); var p2pArgs = new P2PProtocolInitializedEventArgs(p2pProtocol) { P2PVersion = 4, Capabilities = new[] { new Capability(Protocol.Eth, 62), new Capability(Protocol.Eth, 63) }.ToList(), }; p2pSession.TriggerProtocolInitialized(p2pArgs); AssertTrue(() => _peerManager.ActivePeers.First().NodeStats.DidEventHappen(NodeStatsEventType.P2PInitialized), 5000); //Assert.IsTrue(); //trigger eth62 initialization var eth62 = new Eth62ProtocolHandler(p2pSession, new MessageSerializationService(), _synchronizationManager, _logManager, new PerfService(_logManager), _blockTree, _transactionPool, _timestamp); var args = new EthProtocolInitializedEventArgs(eth62) { ChainId = _synchronizationManager.ChainId }; p2pSession.TriggerProtocolInitialized(args); AssertTrue(() => _peerManager.ActivePeers.First().NodeStats.DidEventHappen(NodeStatsEventType.Eth62Initialized), 5000); //Assert.IsTrue(_peerManager.ActivePeers.First().NodeStats.DidEventHappen(NodeStatsEventType.Eth62Initialized)); AssertTrue(() => _peerManager.ActivePeers.First().SynchronizationPeer != null, 5000); //Assert.NotNull(_peerManager.ActivePeers.First().SynchronizationPeer); //verify active peer was added to synch manager _synchronizationManager.Received(1).AddPeer(Arg.Any <ISynchronizationPeer>()); //trigger disconnect p2pSession.TriggerPeerDisconnected(); //verify active peer was removed from synch manager AssertTrue(() => _peerManager.ActivePeers.Count == 0, 5000); Assert.AreEqual(1, _peerManager.CandidatePeers.Count); //Assert.AreEqual(0, _peerManager.ActivePeers.Count); _synchronizationManager.Received(1).RemovePeer(Arg.Any <ISynchronizationPeer>()); }
public void PeerBecomesActiveAndDisconnectTest() { var p2pSession = InitializeNode(); //trigger p2p initialization var p2pProtocol = new P2PProtocolHandler(p2pSession, new MessageSerializationService(), p2pSession.RemoteNodeId, p2pSession.RemotePort, _logger); var p2pArgs = new P2PProtocolInitializedEventArgs(p2pProtocol) { P2PVersion = 4, Capabilities = new[] { new Capability(Protocol.Eth, 62) }.ToList() }; p2pSession.TriggerProtocolInitialized(p2pArgs); Assert.IsTrue(_peerManager.ActivePeers.First().NodeStats.DidEventHappen(NodeStatsEvent.P2PInitialized)); //trigger eth62 initialization var eth62 = new Eth62ProtocolHandler(p2pSession, new MessageSerializationService(), _synchronizationManager, _logger); var args = new Eth62ProtocolInitializedEventArgs(eth62) { ChainId = _synchronizationManager.ChainId }; p2pSession.TriggerProtocolInitialized(args); Assert.IsTrue(_peerManager.ActivePeers.First().NodeStats.DidEventHappen(NodeStatsEvent.Eth62Initialized)); Assert.NotNull(_peerManager.ActivePeers.First().SynchronizationPeer); //verify active peer was added to synch manager _synchronizationManager.Received(1).AddPeer(Arg.Any <ISynchronizationPeer>()); //trigger disconnect p2pSession.TriggerPeerDisconnected(); Assert.AreEqual(0, _peerManager.NewPeers.Count); Assert.AreEqual(0, _peerManager.ActivePeers.Count); //verify active peer was removed from synch manager _synchronizationManager.Received(1).RemovePeer(Arg.Any <ISynchronizationPeer>()); }
public Context VerifySyncPeersRemoved() { _transactionPool.Received().RemovePeer(Arg.Any <PublicKey>()); _synchronizationManager.Received().RemovePeer(Arg.Any <ISynchronizationPeer>()); return(this); }