Пример #1
0
        public void BlockDownloadFromNetwork()
        {
            using (var server = new NodeServer(Network.Main))
            {
                var originalNode = server.GetLocalNode();
                var original     = originalNode.BuildChain();
                Assert.True(originalNode.FullVersion.StartHeight <= original.Height);

                int simultaneous = 3;
                var chaines      = Enumerable.Range(0, simultaneous).Select(i => original.Clone()).ToArray();
                var time         = Benchmark.Bench(() =>
                {
                    Parallel.For(0, simultaneous, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = simultaneous
                    }, i =>
                    {
                        var chain     = chaines[i];
                        var node      = new NodeServer(Network.Main).GetLocalNode();
                        var localTime = Benchmark.Bench(() =>
                        {
                            chain.PushChange(new ChainChange()
                            {
                                ChangeType       = ChainChangeType.BackStep,
                                HeightOrBackstep = 100
                            }, null);
                            var blocks = node.GetBlocks(chain).ToList();
                            Assert.True(blocks.Count == 100 || blocks.Count == 101);
                        });
                    });
                });
                Console.WriteLine(time);
            }
        }
Пример #2
0
 public void CanGetTransactionsFromMemPool()
 {
     using (var server = new NodeServer(Network.TestNet, ProtocolVersion.PROTOCOL_VERSION))
     {
         var node         = server.GetLocalNode();
         var transactions = node.GetMempoolTransactions();
         Assert.True(transactions.Length > 0);
     }
 }
Пример #3
0
 public void CanHandshake()
 {
     using (var server = new NodeServer(Network.TestNet, ProtocolVersion.PROTOCOL_VERSION))
     {
         var seed = server.GetLocalNode();
         Assert.True(seed.State == NodeState.Connected);
         seed.VersionHandshake();
         Assert.True(seed.State == NodeState.HandShaked);
         seed.Disconnect();
         Assert.True(seed.State == NodeState.Offline);
     }
 }
Пример #4
0
 public void CanDownloadHeaders()
 {
     using (var server = new NodeServer(Network.TestNet))
     {
         var node = server.GetLocalNode();
         node.VersionHandshake();
         var begin  = node.Counter.Snapshot();
         var result = node.BuildChain();
         var end    = node.Counter.Snapshot();
         var diff   = end - begin;
         Assert.True(node.FullVersion.StartHeight <= result.Height);
     }
 }
Пример #5
0
 public void CanDownloadBlocks()
 {
     using (var server = new NodeServer(Network.TestNet))
     {
         var node  = server.GetLocalNode();
         var chain = node.BuildChain();
         chain.SetTip(chain.GetBlock(9));
         var blocks = node.GetBlocks(chain).ToList();
         foreach (var block in blocks)
         {
             Assert.True(block.CheckMerkleRoot());
         }
         Assert.Equal(10, blocks.Count);
     }
 }
Пример #6
0
        public void CanDownloadBlock()
        {
            using (var server = new NodeServer(Network.TestNet))
            {
                var node = server.GetLocalNode();
                node.VersionHandshake();
                node.SendMessage(new GetDataPayload(new InventoryVector()
                {
                    Hash = new uint256("00000000278d16a190be56f541b3fda44c3168b43dcc05d9c664e6f27ffe2c78"),
                    Type = InventoryType.MSG_BLOCK
                }));

                var block = node.RecieveMessage <BlockPayload>();
                Assert.True(block.Object.CheckMerkleRoot());
            }
        }
Пример #7
0
        public void CanDownloadLastBlocks()
        {
            using (var server = new NodeServer(Network.TestNet))
            {
                var node  = server.GetLocalNode();
                var chain = node.BuildChain();

                Assert.True(node.FullVersion.StartHeight <= chain.Height);

                var subChain = chain.CreateSubChain(chain.ToEnumerable(true).Skip(99).First(), true, chain.Tip, true);

                var begin  = node.Counter.Snapshot();
                var blocks = node.GetBlocks(subChain).Select(_ => 1).ToList();
                var end    = node.Counter.Snapshot();
                var diff   = end - begin;
                Assert.True(diff.Start == begin.Taken);
                Assert.True(diff.Taken == end.Taken);
                Assert.True(diff.TotalReadenBytes == end.TotalReadenBytes - begin.TotalReadenBytes);
                Assert.True(diff.TotalWrittenBytes == end.TotalWrittenBytes - begin.TotalWrittenBytes);

                Assert.True(blocks.Count == 100);
            }
        }