Example #1
0
		public void CanEnumerateBlockCountRange()
		{
			var store = new BlockStore(@"data\blocks", Network.Main);
			var expectedBlock = store.Enumerate(false).Skip(4).First();
			var actualBlocks = store.Enumerate(false, 4, 2).ToArray();
			Assert.Equal(2, actualBlocks.Length);
			Assert.Equal(expectedBlock.Item.Header.GetHash(), actualBlocks[0].Item.Header.GetHash());
			Assert.True(actualBlocks[0].Item.CheckMerkleRoot());
		}
Example #2
0
        public void CanStoreBlocks()
        {
            BlockStore store = CreateBlockStore();

            var allBlocks = StoredBlock.EnumerateFile(TestDataLocations.DataBlockFolder("blk0001.dat")).Take(50).ToList();

            foreach (StoredBlock s in allBlocks)
            {
                store.Append(s.Item);
            }

            var storedBlocks = store.Enumerate(true).ToList();

            Assert.Equal(allBlocks.Count, storedBlocks.Count);

            foreach (StoredBlock s in allBlocks)
            {
                StoredBlock retrieved = store.Enumerate(true).First(b => b.Item.GetHash() == s.Item.GetHash());
                Assert.True(retrieved.Item.HeaderOnly);
            }
        }
Example #3
0
        public void BlockDirectoryScanSpeed()
        {
            //TestUtils.EnsureNew("BlockDirectoryScanSpeed");
            var completeScan = Bench(() =>
            {
                BlockStore store = new BlockStore(@"Z:\Bitcoin\blocks", Network.Main);
                //BlockStore other = new BlockStore(@"BlockDirectoryScanSpeed", Network.Main);
                foreach (var block in store.Enumerate(false))
                {
                }
            });

            //var headersOnlyScan = Bench(() =>
            //{
            //	BlockStore store = new BlockStore(@"E:\Bitcoin\blocks\", Network.Main);
            //	var count = store.Enumerate(true).Count();
            //});
        }
Example #4
0
        public void CanStoreBlocksInMultipleFiles()
        {
            BlockStore store = CreateBlockStore();

            store.MaxFileSize = 10; // Verify break all block in one respective file with extreme settings.

            var allBlocks = StoredBlock.EnumerateFile(TestDataLocations.DataBlockFolder("blk0001.dat"), network: Network.StratisMain).Take(10).ToList();

            foreach (StoredBlock s in allBlocks)
            {
                store.Append(s.Item);
            }

            var storedBlocks = store.Enumerate(true).ToList();

            Assert.Equal(allBlocks.Count, storedBlocks.Count);

            Assert.Equal(11, store.Folder.GetFiles().Length); //10 files + lock file
        }
Example #5
0
        public void BlockDirectoryScanSpeed()
        {
            //TestUtils.EnsureNew("BlockDirectoryScanSpeed");
            var completeScan = Bench(() =>
            {
                BlockStore store = new BlockStore(@"E:\Bitcoin\blocks\", Network.Main);
                //BlockStore other = new BlockStore(@"BlockDirectoryScanSpeed", Network.Main);
                foreach (var block in store.Enumerate(false, new DiskBlockPosRange(new DiskBlockPos(50, 0))))
                {
                    //other.Append(block.Item);
                }
            });

            var headersOnlyScan = Bench(() =>
            {
                BlockStore store = new BlockStore(@"E:\Bitcoin\blocks\", Network.Main);
                var count        = store.Enumerate(true).Count();
            });
        }
Example #6
0
		public void BlockDirectoryScanSpeed()
		{
			//TestUtils.EnsureNew("BlockDirectoryScanSpeed");
			var completeScan = Bench(() =>
			{
				BlockStore store = new BlockStore(@"Z:\Bitcoin\blocks", Network.Main);
				//BlockStore other = new BlockStore(@"BlockDirectoryScanSpeed", Network.Main);
				foreach(var block in store.Enumerate(false))
				{

				}
			});

			//var headersOnlyScan = Bench(() =>
			//{
			//	BlockStore store = new BlockStore(@"E:\Bitcoin\blocks\", Network.Main);
			//	var count = store.Enumerate(true).Count();
			//});
		}
Example #7
0
        public void CheckBlockProofOfStake()
        {
            var totalblocks = 5000;  // fill only a small portion so test wont be too long
            var mainStore   = new BlockStore(TestDataLocations.BlockFolderLocation, Network.StratisMain);

            // create the stores
            BlockStore store = CreateBlockStore();

            var index      = 0;
            var blockStore = new NoSqlBlockRepository();

            foreach (StoredBlock storedBlock in mainStore.Enumerate(false).Take(totalblocks))
            {
                store.Append(storedBlock.Item);
                blockStore.PutAsync(storedBlock.Item);
                index++;
            }

            // build the chain
            ConcurrentChain chain = store.GetChain();

            // fill the transaction store
            var trxStore = new NoSqlTransactionRepository();
            var mapStore = new BlockTransactionMapStore();

            foreach (ChainedBlock chainedBlock in chain.ToEnumerable(false).Take(totalblocks))
            {
                Block block = blockStore.GetBlock(chainedBlock.HashBlock);
                foreach (Transaction blockTransaction in block.Transactions)
                {
                    trxStore.Put(blockTransaction);
                    mapStore.PutAsync(blockTransaction.GetHash(), block.GetHash());
                }
            }

            RPCClient client = null;

            if (!pos_RPCClientTests.noClient)
            {
                client = new RPCClient(new NetworkCredential("rpcuser", "rpcpassword"),
                                       new Uri("http://127.0.0.1:" + Network.StratisMain.RPCPort), Network.StratisMain);
            }

            var stakeChain = new MemoryStakeChain(Network.StratisMain);

            // validate the stake trasnaction
            foreach (ChainedBlock item in chain.ToEnumerable(false).Take(totalblocks).ToList())
            {
                Block      block = blockStore.GetBlock(item.HashBlock);
                BlockStake blockStake;
                Assert.True(BlockValidator.CheckAndComputeStake(blockStore, trxStore, mapStore, stakeChain, chain, item, block, out blockStake));
                stakeChain.Set(item.HashBlock, blockStake);
                if (item.Height == 1125)
                {
                    var g = block.ToHex();
                }

                if (client != null)
                {
                    RPCBlock fetched = client.GetRPCBlockAsync(item.HashBlock).Result;
                    Assert.Equal(uint256.Parse(fetched.modifierv2), blockStake.StakeModifierV2);
                    Assert.Equal(uint256.Parse(fetched.proofhash), blockStake.HashProof);
                }
            }
        }
Example #8
0
        public void CanReIndex()
        {
            var source = new BlockStore(@"data\blocks", Network.Main);
            var store = CreateBlockStore("CanReIndexFolder");
            store.AppendAll(source.Enumerate(false).Take(100).Select(b => b.Item));

            var test = new IndexedBlockStore(new SQLiteNoSqlRepository("CanReIndex", true), store);
            var reIndexed = test.ReIndex();
            Assert.Equal(100, reIndexed);
            int i = 0;
            foreach(var b in store.Enumerate(true))
            {
                var result = test.Get(b.Item.GetHash());
                Assert.Equal(result.GetHash(), b.Item.GetHash());
                i++;
            }
            Assert.Equal(100, i);

            var last = source.Enumerate(false).Skip(100).FirstOrDefault();
            store.Append(last.Item);

            reIndexed = test.ReIndex();
            Assert.Equal(1, reIndexed);

            reIndexed = test.ReIndex();
            Assert.Equal(0, reIndexed);
        }
Example #9
0
		public void CanEnumerateBlockInAFileRange()
		{
			var store = new BlockStore(@"data\blocks", Network.Main);
			var result = store.Enumerate(new DiskBlockPosRange(new DiskBlockPos(0, 0), new DiskBlockPos(1, 0))).ToList();
			Assert.Equal(300, result.Count);
		}
 public void Load(string blockFolder)
 {
     var store = new BlockStore(blockFolder, this._Tester.Client.Configuration.Network);
     foreach (var block in store.Enumerate(false))
     {
         SubmitBlock(block.Item);
     }
 }