public void can_handle_empty_argument() { _response = new List <Keccak>(); _requestor = new PooledTxsRequestor(_txPool); _requestor.RequestTransactions(Send, new List <Keccak>()); _response.Should().BeEmpty(); }
public void Setup() { _svc = Build.A.SerializationService().WithEth65().TestObject; NetworkDiagTracer.IsEnabled = true; _session = Substitute.For <ISession>(); Node node = new(TestItem.PublicKeyA, new IPEndPoint(IPAddress.Broadcast, 30303)); _session.Node.Returns(node); _syncManager = Substitute.For <ISyncServer>(); _transactionPool = Substitute.For <ITxPool>(); _pooledTxsRequestor = Substitute.For <IPooledTxsRequestor>(); _specProvider = Substitute.For <ISpecProvider>(); _genesisBlock = Build.A.Block.Genesis.TestObject; _syncManager.Head.Returns(_genesisBlock.Header); _syncManager.Genesis.Returns(_genesisBlock.Header); ITimerFactory timerFactory = Substitute.For <ITimerFactory>(); _handler = new Eth65ProtocolHandler( _session, _svc, new NodeStatsManager(timerFactory, LimboLogs.Instance), _syncManager, _transactionPool, _pooledTxsRequestor, Policy.FullGossip, _specProvider, LimboLogs.Instance); _handler.Init(); }
public ProtocolsManager( ISyncPeerPool syncPeerPool, ISyncServer syncServer, ITxPool txPool, IPooledTxsRequestor pooledTxsRequestor, IDiscoveryApp discoveryApp, IMessageSerializationService serializationService, IRlpxPeer localPeer, INodeStatsManager nodeStatsManager, IProtocolValidator protocolValidator, INetworkStorage peerStorage, ISpecProvider specProvider, ILogManager logManager) { _syncPool = syncPeerPool ?? throw new ArgumentNullException(nameof(syncPeerPool)); _syncServer = syncServer ?? throw new ArgumentNullException(nameof(syncServer)); _txPool = txPool ?? throw new ArgumentNullException(nameof(txPool)); _pooledTxsRequestor = pooledTxsRequestor ?? throw new ArgumentNullException(nameof(pooledTxsRequestor)); _discoveryApp = discoveryApp ?? throw new ArgumentNullException(nameof(discoveryApp)); _serializer = serializationService ?? throw new ArgumentNullException(nameof(serializationService)); _localPeer = localPeer ?? throw new ArgumentNullException(nameof(localPeer)); _stats = nodeStatsManager ?? throw new ArgumentNullException(nameof(nodeStatsManager)); _protocolValidator = protocolValidator ?? throw new ArgumentNullException(nameof(protocolValidator)); _peerStorage = peerStorage ?? throw new ArgumentNullException(nameof(peerStorage)); _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); _logManager = logManager ?? throw new ArgumentNullException(nameof(logManager)); _logger = _logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _protocolFactories = GetProtocolFactories(); localPeer.SessionCreated += SessionCreated; }
public Eth65ProtocolHandler(ISession session, IMessageSerializationService serializer, INodeStatsManager nodeStatsManager, ISyncServer syncServer, ITxPool txPool, IPooledTxsRequestor pooledTxsRequestor, ISpecProvider specProvider, ILogManager logManager) : base(session, serializer, nodeStatsManager, syncServer, txPool, specProvider, logManager) { _pooledTxsRequestor = pooledTxsRequestor; }
public void filter_properly_discovered_hashes() { _response = new List <Keccak>(); _requestor = new PooledTxsRequestor(_txPool); _request = new List <Keccak> { TestItem.KeccakA, TestItem.KeccakB, TestItem.KeccakC }; _expected = new List <Keccak> { TestItem.KeccakA, TestItem.KeccakB, TestItem.KeccakC }; _requestor.RequestTransactions(Send, _request); _response.Should().BeEquivalentTo(_expected); }
public void filter_properly_already_pending_hashes() { _response = new List <Keccak>(); _requestor = new PooledTxsRequestor(_txPool); _requestor.RequestTransactions(_doNothing, new List <Keccak> { TestItem.KeccakA, TestItem.KeccakB, TestItem.KeccakC }); _request = new List <Keccak> { TestItem.KeccakA, TestItem.KeccakB, TestItem.KeccakC }; _requestor.RequestTransactions(Send, _request); _response.Should().BeEmpty(); }
public Context() { _channel = Substitute.For <IChannel>(); _channelHandlerContext = Substitute.For <IChannelHandlerContext>(); _pipeline = Substitute.For <IChannelPipeline>(); _channelHandlerContext.Channel.Returns(_channel); _channel.Pipeline.Returns(_pipeline); _pipeline.Get <ZeroPacketSplitter>().Returns(new ZeroPacketSplitter(LimboLogs.Instance)); _packetSender = Substitute.For <IPacketSender>(); _syncServer = Substitute.For <ISyncServer>(); _syncServer = Substitute.For <ISyncServer>(); _syncServer.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header); _syncServer.Head.Returns(Build.A.BlockHeader.TestObject); _txPool = Substitute.For <ITxPool>(); _pooledTxsRequestor = Substitute.For <IPooledTxsRequestor>(); _discoveryApp = Substitute.For <IDiscoveryApp>(); _serializer = new MessageSerializationService(); _rlpxHost = Substitute.For <IRlpxHost>(); _rlpxHost.LocalPort.Returns(_localPort); _rlpxHost.LocalNodeId.Returns(TestItem.PublicKeyA); ITimerFactory timerFactory = Substitute.For <ITimerFactory>(); _nodeStatsManager = new NodeStatsManager(timerFactory, LimboLogs.Instance); _blockTree = Substitute.For <IBlockTree>(); _blockTree.ChainId.Returns(1ul); _blockTree.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header); _protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, LimboLogs.Instance); _peerStorage = Substitute.For <INetworkStorage>(); _syncPeerPool = Substitute.For <ISyncPeerPool>(); _gossipPolicy = Substitute.For <IGossipPolicy>(); _manager = new ProtocolsManager( _syncPeerPool, _syncServer, _txPool, _pooledTxsRequestor, _discoveryApp, _serializer, _rlpxHost, _nodeStatsManager, _protocolValidator, _peerStorage, MainnetSpecProvider.Instance, _gossipPolicy, LimboLogs.Instance); _serializer.Register(new HelloMessageSerializer()); _serializer.Register(new StatusMessageSerializer()); _serializer.Register(new DisconnectMessageSerializer()); }
public void filter_properly_hashes_present_in_hashCache() { _response = new List <Keccak>(); ITxPool txPool = Substitute.For <ITxPool>(); txPool.IsInHashCache(Arg.Any <Keccak>()).Returns(true); _requestor = new PooledTxsRequestor(txPool); _request = new List <Keccak> { TestItem.KeccakA, TestItem.KeccakB }; _expected = new List <Keccak> { }; _requestor.RequestTransactions(Send, _request); _response.Should().BeEquivalentTo(_expected); }
public Eth66ProtocolHandler(ISession session, IMessageSerializationService serializer, INodeStatsManager nodeStatsManager, ISyncServer syncServer, ITxPool txPool, IPooledTxsRequestor pooledTxsRequestor, ISpecProvider specProvider, ILogManager logManager) : base(session, serializer, nodeStatsManager, syncServer, txPool, pooledTxsRequestor, specProvider, logManager) { _headersRequests66 = new MessageQueue <GetBlockHeadersMessage, BlockHeader[]>(Send); _bodiesRequests66 = new MessageQueue <GetBlockBodiesMessage, BlockBody[]>(Send); _nodeDataRequests66 = new MessageQueue <GetNodeDataMessage, byte[][]>(Send); _receiptsRequests66 = new MessageQueue <GetReceiptsMessage, TxReceipt[][]>(Send); _pooledTxsRequestor = pooledTxsRequestor; }