public void CanValidateChain() { var main = new ChainIndexer(this.network).Load(this.LoadMainChain()); foreach (ChainedHeader h in main.EnumerateToTip(main.Genesis)) { Assert.True(h.Validate(this.network)); } }
public void ChainedHeaderVerifySkipListForGetAncestor() { int skipListLength = 300000; // Want a chain of exact length so subtract the genesis block. ChainIndexer chainIndexer = this.CreateChain(skipListLength - 1); // Also want a copy in array form so can quickly verify indexing. var chainArray = new ChainedHeader[skipListLength]; // Check skip height and build out array copy. foreach (ChainedHeader block in chainIndexer.EnumerateToTip(chainIndexer.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(). var random = new Random(); int randCheckCount = 1000; for (int i = 0; i < randCheckCount; i++) { int from = random.Next(chainIndexer.Tip.Height - 1); int to = random.Next(from + 1); Assert.Equal(chainArray[chainIndexer.Tip.Height - 1].GetAncestor(from), chainArray[from]); Assert.Equal(chainArray[from].GetAncestor(to), chainArray[to]); Assert.Equal(chainArray[from].GetAncestor(0), chainArray[0]); } }