public void CanBuildChainFromBlocks() { var store = new BlockStore(TestDataLocations.DataFolder(@"blocks"), Network.StratisMain); ConcurrentChain chain = store.GetChain(); Assert.True(chain.Height == 3999); }
public void CanBuildChainFromBlocks() { var store = new BlockStore(@"data\blocks", Network.Main); var chain = store.GetChain(); Assert.True(chain.Height == 599); }
public void BenchmarkCreateChainFromBlocks() { BlockStore store = new BlockStore(@"E:\Bitcoin\blocks\", Network.Main); ConcurrentChain chain = null; var fullBuild = Bench(() => { chain = store.GetChain(); }); }
public void BenchmarkCreateChainFromBlocks() { BlockStore store = new BlockStore(this.BlockStoreFolder, Network.Main); ConcurrentChain chain = null; var fullBuild = Bench(() => { chain = store.GetChain(); }); }
public void EnumerateAndCheckTipBlock() { var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.Main); // use the synchronize chain method to load all blocks and look for the tip (currently block 100k) var block100K = uint256.Parse("af380a53467b70bc5d1ee61441586398a0a5907bb4fad7855442575483effa54"); var chain = store.GetChain(); var lastblk = chain.GetBlock(block100K); Assert.Equal(block100K, lastblk.Header.GetHash()); Assert.Equal(100000, lastblk.Height); }
public void IndexTheFullChain() { var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.StratisMain); var indexStore = new IndexedBlockStore(new InMemoryNoSqlRepository(), store); var reindexed = indexStore.ReIndex(); Assert.Equal(103952, reindexed); ConcurrentChain chain = store.GetChain(); foreach (ChainedBlock item in chain.ToEnumerable(false)) { Block block = indexStore.Get(item.HashBlock); Assert.True(BlockValidator.CheckBlock(block)); } }
public static void CanCalculatePowPosCorrectly() { var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.Main); var chain = store.GetChain(); var stakeChain = new MemoryStakeChain(Network.Main); var indexStore = new IndexedBlockStore(new InMemoryNoSqlRepository(), store); var reindexed = indexStore.ReIndex(); Assert.Equal(reindexed, 103952); foreach (var chainedBlock in chain.EnumerateAfter(chain.Genesis)) { var block = indexStore.Get(chainedBlock.HashBlock); var blockstake = new BlockStake(block); stakeChain.Set(chainedBlock.HashBlock, blockstake); Assert.True(stakeChain.CheckPowPosAndTarget(chainedBlock, blockstake, Network.Main)); } }
public void CanCalculateDifficulty() { var histories = File.ReadAllLines("data/targethistory.csv"); var store = new BlockStore(@"download\blocks", Network.Main); // todo: load the chain with a heder only file ConcurrentChain chain = store.GetChain(); foreach (var history in histories) { var height = int.Parse(history.Split(',')[0]); var expectedTarget = new Target(BigInteger.Parse(history.Split(',')[1])); var block = chain.GetBlock(height).Header; Assert.Equal(expectedTarget, block.Bits); var target = chain.GetWorkRequired(Network.Main, height); Assert.Equal(expectedTarget, target); } }
public void CanCalculateDifficulty() { var histories = File.ReadAllLines(TestDataLocations.DataFolder(@"targethistory.csv")); var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.Main); // todo: load the chain with a header only file ConcurrentChain chain = store.GetChain(); foreach (var history in histories) { var height = int.Parse(history.Split(',')[0]); var expectedTarget = new Target(new BigInteger(history.Split(',')[1].Trim(), 10)); var block = chain.GetBlock(height).Header; Assert.Equal(expectedTarget, block.Bits); var target = chain.GetWorkRequired(Network.Main, height); Assert.Equal(expectedTarget, target); } }
public void CanCalculateDifficulty() { var histories = File.ReadAllLines(TestDataLocations.DataFolder(@"targethistory.csv")); var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.Main); // todo: load the chain with a header only file ConcurrentChain chain = store.GetChain(); var stakeChain = new MemoryStakeChain(Network.Main); var indexStore = new IndexedBlockStore(new InMemoryNoSqlRepository(), store); var reindexed = indexStore.ReIndex(); Assert.Equal(reindexed, 103952); 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.Main.Consensus); //var target = chain.GetWorkRequired(Network.Main, height); Assert.Equal(expectedTarget, target); } }
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); } } }
public void CanBuildChainFromBlocks() { var store = new BlockStore(@"data\blocks", Network.Main); var chain = store.GetChain(); Assert.True(chain.Height == 599); }
public void BenchmarkCreateChainFromBlocks() { BlockStore store = new BlockStore(@"E:\Bitcoin\blocks\", Network.Main); ConcurrentChain chain = null; var fullBuild = Bench(() => { chain = store.GetChain(); }); }