public void Can_upgrade_maybe_parent() { BlockHeader parent = Build.A.BlockHeader.TestObject; BlockHeader parentWithTotalDiff = Build.A.BlockHeader.WithTotalDifficulty(1).TestObject; BlockHeader child = Build.A.BlockHeader.WithParent(parent).TestObject; parent.TotalDifficulty.Should().BeNull(); // just to avoid the testing rig change without this test being updated IBlockFinder blockFinder = Substitute.For <IBlockFinder>(); blockFinder.FindHeader(child.ParentHash, BlockTreeLookupOptions.TotalDifficultyNotNeeded).Returns(parent); blockFinder.FindHeader(child.ParentHash, BlockTreeLookupOptions.None).Returns(parentWithTotalDiff); blockFinder.FindParentHeader(child, BlockTreeLookupOptions.TotalDifficultyNotNeeded).Should().Be(parent); blockFinder.FindParentHeader(child, BlockTreeLookupOptions.None).TotalDifficulty.Should().Be((UInt256?)UInt256.One); }
private bool TryGetParentBlock(BlockHeader currentBlock, out BlockHeader parentHeader) { if (currentBlock.IsGenesis) { parentHeader = null; return(false); } parentHeader = _blockFinder.FindParentHeader(currentBlock, BlockTreeLookupOptions.TotalDifficultyNotNeeded); return(true); }