public void EnumerateAndCheckTipBlock() { var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.StratisMain); // 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.GetStratisChain(); ChainedBlock lastblk = chain.GetBlock(block100K); Assert.Equal(block100K, lastblk.Header.GetHash()); Assert.Equal(100000, lastblk.Height); }
public void CanCalculateDifficulty() { var histories = File.ReadAllLines(TestDataLocations.DataFolder(@"targethistory.csv")); var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.StratisMain); // todo: load the chain with a header only file ConcurrentChain chain = store.GetStratisChain(); var stakeChain = new MemoryStakeChain(Network.StratisMain); 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.StratisMain.Consensus); //var target = chain.GetWorkRequired(Network.Main, height); Assert.Equal(expectedTarget, target); } }