コード例 #1
0
        public void MaxConnectionLimit()
        {
            using (var tester = new NodeServerTester())
            {
                tester.Server1.MaxConnections = 4;
                Node.Connect(tester.Network, tester.Server1.ExternalEndpoint).VersionHandshake();
                Node.Connect(tester.Network, tester.Server1.ExternalEndpoint).VersionHandshake();
                Node.Connect(tester.Network, tester.Server1.ExternalEndpoint).VersionHandshake();
                Node.Connect(tester.Network, tester.Server1.ExternalEndpoint).VersionHandshake();

                TestUtils.Eventually(() => tester.Server1.ConnectedNodes.Count == 4);

                var connect = Node.Connect(tester.Network, tester.Server1.ExternalEndpoint);
                try
                {
                    connect.VersionHandshake();
                }
                catch
                {
                }

                TestUtils.Eventually(() => tester.Server1.ConnectedNodes.Count == 4);
                TestUtils.Eventually(() => connect.IsConnected == false);
            }
        }
コード例 #2
0
 public void CantConnectToYourself()
 {
     using (var tester = new NodeServerTester())
     {
         tester.Server2.Nonce = tester.Server1.Nonce;
         Assert.Throws <InvalidOperationException>(() =>
         {
             tester.Node1.VersionHandshake();
         });
     }
 }
コード例 #3
0
 public void CanReceiveHandshake()
 {
     using (var tester = new NodeServerTester())
     {
         var toS2 = tester.Node1;
         toS2.VersionHandshake();
         Assert.Equal(NodeState.HandShaked, toS2.State);
         Thread.Sleep(100);                 //Let the time to Server2 to add the new node, else the test was failing sometimes.
         Assert.Equal(NodeState.HandShaked, tester.Node2.State);
         Assert.NotNull(toS2.TimeOffset);
     }
 }
コード例 #4
0
 public void ServerDisconnectCorrectlyFromDroppingClient()
 {
     using (var tester = new NodeServerTester())
     {
         var to2 = tester.Node1;
         to2.VersionHandshake();
         Assert.True(tester.Server1.IsConnectedTo(tester.Server2.ExternalEndpoint));
         Thread.Sleep(100);
         Assert.True(tester.Server2.IsConnectedTo(tester.Server1.ExternalEndpoint));
         to2.Disconnect();
         Thread.Sleep(100);
         Assert.False(tester.Server1.IsConnectedTo(tester.Server2.ExternalEndpoint));
         Thread.Sleep(100);
         Assert.False(tester.Server2.IsConnectedTo(tester.Server1.ExternalEndpoint));
     }
 }
コード例 #5
0
 public void CanRespondToPong()
 {
     using (var tester = new NodeServerTester())
     {
         var toS2 = tester.Node1;
         toS2.VersionHandshake();
         var ping = new PingPayload();
         CancellationTokenSource cancel = new CancellationTokenSource();
         cancel.CancelAfter(10000);
         using (var list = toS2.CreateListener())
         {
             toS2.SendMessageAsync(ping);
             while (true)
             {
                 var pong = list.ReceivePayload <PongPayload>(cancel.Token);
                 if (ping.Nonce == pong.Nonce)
                 {
                     break;
                 }
             }
         }
     }
 }
コード例 #6
0
        public void CanMaintainChainWithChainBehavior()
        {
            using (var builder = NodeBuilderEx.Create())
            {
                var node = builder.CreateNode(true).CreateNodeClient();
                builder.Nodes[0].Generate(600);
                var rpc   = builder.Nodes[0].CreateRPCClient();
                var chain = node.GetChain(rpc.GetBlockHash(500));
                Assert.True(chain.Height == 500);
                using (var tester = new NodeServerTester())
                {
                    var n1 = tester.Node1;
                    n1.Behaviors.Add(new ChainBehavior(chain));
                    n1.VersionHandshake();
                    Assert.True(n1.MyVersion.StartHeight == 500);
                    var n2 = tester.Node2;
                    Assert.True(n2.MyVersion.StartHeight == 0);
                    Assert.True(n2.PeerVersion.StartHeight == 500);
                    Assert.True(n1.State == NodeState.HandShaked);
                    Assert.True(n2.State == NodeState.HandShaked);
                    var behavior = new ChainBehavior(new ConcurrentChain(Network.RegTest));
                    n2.Behaviors.Add(behavior);
                    TestUtils.Eventually(() => behavior.Chain.Height == 500);
                    var chain2 = n2.GetChain(rpc.GetBlockHash(500));
                    Assert.True(chain2.Height == 500);
                    var chain1 = n1.GetChain(rpc.GetBlockHash(500));
                    Assert.True(chain1.Height == 500);
                    chain1 = n1.GetChain(rpc.GetBlockHash(499));
                    Assert.True(chain1.Height == 499);

                    //Should not broadcast above HighestValidatorPoW
                    n1.Behaviors.Find <ChainBehavior>().SharedState.HighestValidatedPoW = chain1.GetBlock(300);
                    chain1 = n2.GetChain(rpc.GetBlockHash(499));
                    Assert.True(chain1.Height == 300);
                }
            }
        }