Esempio n. 1
0
        /// <summary>Creates a peer with extended puller behavior.</summary>
        public INetworkPeer CreatePeer(out ExtendedBlockPullerBehavior mockedBehavior, bool notSupportedVersion = false)
        {
            var peer = new Mock <INetworkPeer>();

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

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

            var            connectionParameters = new NetworkPeerConnectionParameters();
            VersionPayload version = connectionParameters.CreateVersion(new IPEndPoint(1, 1), Network.StratisMain, 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.Object);
        }
Esempio n. 2
0
        private ExtendedBlockPullerBehavior CreateBlockPullerBehavior()
        {
            var ibdState = new Mock <IInitialBlockDownloadState>();

            ibdState.Setup(x => x.IsInitialBlockDownload()).Returns(() => true);

            var behavior = new ExtendedBlockPullerBehavior(this.Puller, ibdState.Object, this.loggerFactory);

            return(behavior);
        }