Beispiel #1
0
        public void CanCreateBigSlimChain()
        {
            var main = new ConcurrentChain(LoadMainChain(), Network.Main);
            var c    = new SlimChain(main.GetBlock(0).HashBlock);

            foreach (var item in main.EnumerateToTip(main.GetBlock(0).HashBlock))
            {
                c.TrySetTip(item.HashBlock, item.Previous?.HashBlock);
            }
            Assert.Equal(main.Height, c.Height);
            Assert.Equal(main.Tip.HashBlock, c.Tip);
            // Can up the capacity without errors
            c.SetCapacity(main.Height + 3000);
            Assert.Equal(main.Height, c.Height);
            Assert.Equal(main.Tip.HashBlock, c.Tip);
            Assert.Equal(main.GetBlock(main.Tip.HashBlock).HashBlock, c.GetBlock(c.Tip).Hash);
        }
Beispiel #2
0
        public void ChainedBlockVerifySkipListForGetAncestor()
        {
            int skipListLength = 300000;

            // Want a chain of exact length so subtract the genesis block.
            ConcurrentChain chain = this.CreateChain(skipListLength - 1);

            // Also want a copy in array form so can quickly verify indexing.
            ChainedBlock[] chainArray = new ChainedBlock[skipListLength];

            // Check skip height and build out array copy.
            foreach (ChainedBlock block in chain.EnumerateToTip(chain.Genesis))
            {
                if (block.Height > 0)
                {
                    Assert.True(block.Skip.Height < block.Height);
                }
                else
                {
                    Assert.Null(block.Skip);
                }
                chainArray[block.Height] = block;
            }

            // Do some random verification of GetAncestor().
            Random random         = new Random();
            int    randCheckCount = 1000;

            for (int i = 0; i < randCheckCount; i++)
            {
                int from = random.Next(chain.Tip.Height - 1);
                int to   = random.Next(from + 1);

                Assert.Equal(chainArray[chain.Tip.Height - 1].GetAncestor(from), chainArray[from]);
                Assert.Equal(chainArray[from].GetAncestor(to), chainArray[to]);
                Assert.Equal(chainArray[from].GetAncestor(0), chainArray[0]);
            }
        }