Exemplo n.º 1
0
        public void EnumerateAndCheckTipBlock()
        {
            var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.PurpleMain);

            // use the synchronize chain method to load all blocks and look for the tip (currently block 100k)
            var             block100K = uint256.Parse("af380a53467b70bc5d1ee61441586398a0a5907bb4fad7855442575483effa54");
            ConcurrentChain chain     = store.GetPurpleChain();
            ChainedBlock    lastblk   = chain.GetBlock(block100K);

            Assert.Equal(block100K, lastblk.Header.GetHash());
            Assert.Equal(100000, lastblk.Height);
        }
Exemplo n.º 2
0
        public void CanCalculateDifficulty()
        {
            var histories = File.ReadAllLines(TestDataLocations.DataFolder(@"targethistory.csv"));

            var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.PurpleMain);
            // todo: load the chain with a header only file
            ConcurrentChain chain = store.GetPurpleChain();

            var stakeChain = new MemoryStakeChain(Network.PurpleMain);
            var indexStore = new IndexedBlockStore(new InMemoryNoSqlRepository(), store);
            var reindexed  = indexStore.ReIndex();

            Assert.Equal(103952, reindexed);

            var lastIndex = 0;

            foreach (var history in histories)
            {
                var height         = int.Parse(history.Split(',')[0]);
                var expectedTarget = new Target(new BigInteger(history.Split(',')[1].Trim(), 10));

                var chainedBlock = chain.GetBlock(height);
                for (int i = height; i > lastIndex; i--)
                {
                    var g     = chain.GetBlock(i);
                    var block = indexStore.Get(g.HashBlock);
                    stakeChain.Set(g.HashBlock, new BlockStake(block));
                }
                lastIndex = height;

                Assert.Equal(expectedTarget, chainedBlock.Header.Bits);
                var target = stakeChain.GetWorkRequired(chainedBlock, stakeChain.Get(chainedBlock.HashBlock), Network.PurpleMain.Consensus);
                //var target = chain.GetWorkRequired(Network.PurpleMain, height);
                Assert.Equal(expectedTarget, target);
            }
        }