// [Fact(Skip = "true")] public async Task PeerClientChannelFactory_should_put_the_correct_handlers_on_the_inbound_pipeline() { var testingChannel = new EmbeddedChannel("test".ToChannelId(), true, _factory.InheritedHandlers.ToArray()); var senderId = PeerIdHelper.GetPeerId("sender"); var correlationId = CorrelationId.GenerateCorrelationId(); var protocolMessage = new PingRequest().ToProtocolMessage(senderId, correlationId); var signature = ByteUtil.GenerateRandomByteArray(new FfiWrapper().SignatureLength); var signedMessage = protocolMessage.Sign(signature); _keySigner.Verify(Arg.Is <ISignature>(s => s.SignatureBytes.SequenceEqual(signature)), Arg.Any <byte[]>(), default) .ReturnsForAnyArgs(true); var observer = new ProtocolMessageObserver(0, Substitute.For <ILogger>()); var messageStream = ((ObservableServiceHandler)_factory.InheritedHandlers.Last()).MessageStream; using (messageStream.Subscribe(observer)) { testingChannel.WriteInbound(signedMessage); _correlationManager.DidNotReceiveWithAnyArgs().TryMatchResponse(protocolMessage); await _gossipManager.DidNotReceiveWithAnyArgs().BroadcastAsync(null); _keySigner.ReceivedWithAnyArgs(1).Verify(null, null, null); _testScheduler.Start(); observer.Received.Count.Should().Be(1); observer.Received.Single().Payload.CorrelationId.ToCorrelationId().Id.Should().Be(correlationId.Id); } }
public async Task BroadcastCandidate_should_not_broadcast_candidates_from_other_nodes() { var notMyCandidate = DeltaHelper.GetCandidateDelta(_hashProvider, producerId: PeerIdHelper.GetPeerId("not me")); _hub.BroadcastCandidate(notMyCandidate); await _broadcastManager.DidNotReceiveWithAnyArgs().BroadcastAsync(default).ConfigureAwait(false);
public async Task PeerServerChannelFactory_should_put_the_correct_handlers_on_the_inbound_pipeline() { var testingChannel = new EmbeddedChannel("test".ToChannelId(), true, _factory.InheritedHandlers.ToArray()); var protocolMessage = new PingRequest().ToProtocolMessage(_senderId, _correlationId); var signedMessage = protocolMessage.ToSignedProtocolMessage(signature: _signature); var observer = new ProtocolMessageObserver(0, Substitute.For <ILogger>()); var messageStream = GetObservableServiceHandler().MessageStream; using (messageStream.Subscribe(observer)) { testingChannel.WriteInbound(signedMessage); _correlationManager.DidNotReceiveWithAnyArgs().TryMatchResponse(protocolMessage); await _gossipManager.DidNotReceiveWithAnyArgs().BroadcastAsync(null); _keySigner.ReceivedWithAnyArgs(1).Verify(null, null, null); _testScheduler.Start(); observer.Received.Count.Should().Be(1); observer.Received.Single().Payload.CorrelationId.ToCorrelationId().Id.Should().Be(signedMessage.CorrelationId.ToCorrelationId().Id); } }
public void Can_Send_Error_To_Invalid_Transaction() { _transactionValidator.ValidateTransaction(Arg.Any <TransactionBroadcast>(), _peerSettings.NetworkType) .Returns(false); _transactionReceivedEvent.OnTransactionReceived(new TransactionBroadcast() .ToProtocolMessage(PeerIdHelper.GetPeerId(), CorrelationId.GenerateCorrelationId())).Should() .Be(ResponseCode.Error); _broadcastManager.DidNotReceiveWithAnyArgs().BroadcastAsync(default);
public void Can_Send_Error_To_Invalid_Transaction() { _transactionValidator.ValidateTransaction(Arg.Any <PublicEntry>()) .Returns(false); _transactionReceivedEvent.OnTransactionReceived(new TransactionBroadcast { PublicEntry = new PublicEntry { SenderAddress = new byte[32].ToByteString() } } .ToProtocolMessage(PeerIdHelper.GetPeerId(), CorrelationId.GenerateCorrelationId())).Should() .Be(ResponseCode.Error); _broadcastManager.DidNotReceiveWithAnyArgs()?.BroadcastAsync(default);