コード例 #1
0
 public SignalsTest()
 {
     this.blockConnectedSignaler = new Mock<ISignaler<ChainedHeaderBlock>>();
     this.blockDisconnectedSignaler = new Mock<ISignaler<ChainedHeaderBlock>>();
     this.transactionSignaler = new Mock<ISignaler<Transaction>>();
     this.signals = new Bitcoin.Signals.Signals(this.blockConnectedSignaler.Object, this.blockDisconnectedSignaler.Object, this.transactionSignaler.Object);
 }
コード例 #2
0
ファイル: AsyncProviderTest.cs プロジェクト: georgepinca/src
        public AsyncProviderTest()
        {
            var mockLogger        = new Mock <ILogger>();
            var mockLoggerFactory = new Mock <ILoggerFactory>();

            mockLoggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(mockLogger.Object);

            var signals      = new Bitcoin.Signals.Signals(mockLoggerFactory.Object, null);
            var nodeLifetime = new Mock <INodeLifetime>().Object;

            this.asyncProvider = new AsyncProvider(mockLoggerFactory.Object, signals, nodeLifetime);
        }
コード例 #3
0
        internal Mock <INetworkPeer> GetNetworkPeerWithConnection()
        {
            var networkPeer = new Mock <INetworkPeer>();

            var signals       = new Bitcoin.Signals.Signals(this.loggerFactory, null);
            var asyncProvider = new AsyncProvider(this.loggerFactory, this.signals, new NodeLifetime());

            var connection = new NetworkPeerConnection(this.Network, networkPeer.Object, new TcpClient(), 0, (message, token) => Task.CompletedTask,
                                                       this.dateTimeProvider, this.loggerFactory, new PayloadProvider().DiscoverPayloads(), asyncProvider);

            networkPeer.Setup(n => n.Connection)
            .Returns(connection);

            networkPeer.Setup(n => n.PeerEndPoint)
            .Returns(new System.Net.IPEndPoint(IPAddress.Loopback, 9999));

            networkPeer.Setup(n => n.RemoteSocketAddress)
            .Returns(IPAddress.Loopback.EnsureIPv6());
            networkPeer.Setup(n => n.RemoteSocketPort)
            .Returns(9999);

            networkPeer.Setup(n => n.RemoteSocketEndpoint)
            .Returns(new System.Net.IPEndPoint(IPAddress.Loopback.EnsureIPv6(), 9999));

            networkPeer.Setup(n => n.State)
            .Returns(NetworkPeerState.Connected);

            var behavior = new Mock <IConnectionManagerBehavior>();

            networkPeer.Setup(n => n.Behavior <IConnectionManagerBehavior>())
            .Returns(behavior.Object);

            this.peerAddressManager.AddPeer(networkPeer.Object.PeerEndPoint, networkPeer.Object.PeerEndPoint.Address);
            this.connectionManager.AddConnectedPeer(networkPeer.Object);

            return(networkPeer);
        }
コード例 #4
0
        /// <summary>Creates a peer with extended puller behavior.</summary>
        public Mock <INetworkPeer> CreatePeerMock(out ExtendedBlockPullerBehavior mockedBehavior, bool notSupportedVersion = false)
        {
            var peer = new Mock <INetworkPeer>();

            var signals       = new Bitcoin.Signals.Signals(this.loggerFactory, null);
            var asyncProvider = new AsyncProvider(this.loggerFactory, signals, new NodeLifetime());

            var connection = new NetworkPeerConnection(new StraxMain(), peer.Object, new TcpClient(), this.currentPeerId, (message, token) => Task.CompletedTask,
                                                       new DateTimeProvider(), this.loggerFactory, new PayloadProvider(), asyncProvider);

            this.currentPeerId++;
            peer.SetupGet(networkPeer => networkPeer.Connection).Returns(connection);

            var            connectionParameters = new NetworkPeerConnectionParameters();
            VersionPayload version = connectionParameters.CreateVersion(new IPEndPoint(1, 1), new IPEndPoint(1, 1), new StraxMain(), new DateTimeProvider().GetTimeOffset());

            if (notSupportedVersion)
            {
                version.Version = ProtocolVersion.NOBLKS_VERSION_START;
            }
            else
            {
                version.Services = NetworkPeerServices.Network;
            }

            peer.SetupGet(x => x.PeerVersion).Returns(version);
            peer.SetupGet(x => x.State).Returns(NetworkPeerState.HandShaked);
            peer.SetupGet(x => x.MessageReceived).Returns(new AsyncExecutionEvent <INetworkPeer, IncomingMessage>());

            ExtendedBlockPullerBehavior behavior = this.CreateBlockPullerBehavior();

            behavior.Attach(peer.Object);
            peer.Setup(x => x.Behavior <IBlockPullerBehavior>()).Returns(() => behavior);

            mockedBehavior = behavior;
            return(peer);
        }
コード例 #5
0
        private Mock <INetworkPeer> CreatePeerMock()
        {
            var peer = new Mock <INetworkPeer>();

            var signals       = new Bitcoin.Signals.Signals(this.loggerFactory, null);
            var asyncProvider = new AsyncProvider(this.loggerFactory, signals, new NodeLifetime());

            var connection = new NetworkPeerConnection(KnownNetworks.StraxMain, peer.Object, new TcpClient(), 0, (message, token) => Task.CompletedTask,
                                                       new DateTimeProvider(), this.loggerFactory, new PayloadProvider(), asyncProvider);

            peer.SetupGet(networkPeer => networkPeer.Connection).Returns(connection);

            var            connectionParameters = new NetworkPeerConnectionParameters();
            VersionPayload version = connectionParameters.CreateVersion(new IPEndPoint(1, 1), new IPEndPoint(1, 1), KnownNetworks.StraxMain, new DateTimeProvider().GetTimeOffset());

            version.Services = NetworkPeerServices.Network;

            peer.SetupGet(x => x.PeerVersion).Returns(version);
            peer.SetupGet(x => x.State).Returns(NetworkPeerState.HandShaked);

            this.StateChanged    = new AsyncExecutionEvent <INetworkPeer, NetworkPeerState>();
            this.MessageReceived = new AsyncExecutionEvent <INetworkPeer, IncomingMessage>();

            peer.Setup(x => x.StateChanged).Returns(() => this.StateChanged);
            peer.Setup(x => x.MessageReceived).Returns(() => this.MessageReceived);

            var connectionManagerBehaviorMock = new Mock <IConnectionManagerBehavior>();

            connectionManagerBehaviorMock.Setup(x => x.Whitelisted).Returns(this.IsPeerWhitelisted);

            peer.Setup(x => x.Behavior <IConnectionManagerBehavior>()).Returns(() => connectionManagerBehaviorMock.Object);

            peer.SetupGet(x => x.PeerEndPoint).Returns(new IPEndPoint(1, 1));

            return(peer);
        }
コード例 #6
0
 public SignalsTest()
 {
     this.blockSignaler       = new Mock <ISignaler <Block> >();
     this.transactionSignaler = new Mock <ISignaler <Transaction> >();
     this.signals             = new Bitcoin.Signals.Signals(this.blockSignaler.Object, this.transactionSignaler.Object);
 }