BitSharper.Test.BlockChainTest.TestDifficultyTransitions C# (CSharp) Method

TestDifficultyTransitions() private method

private TestDifficultyTransitions ( ) : void
return void
        public void TestDifficultyTransitions()
        {
            // Add a bunch of blocks in a loop until we reach a difficulty transition point. The unit test params have an
            // artificially shortened period.
            var prev = _unitTestParams.GenesisBlock;
            Block.FakeClock = UnixTime.ToUnixTime(DateTime.UtcNow);
            for (var i = 0; i < _unitTestParams.Interval - 1; i++)
            {
                var newBlock = prev.CreateNextBlock(_coinbaseTo, (uint) Block.FakeClock);
                Assert.IsTrue(_chain.Add(newBlock));
                prev = newBlock;
                // The fake chain should seem to be "fast" for the purposes of difficulty calculations.
                Block.FakeClock += 2;
            }
            // Now add another block that has no difficulty adjustment, it should be rejected.
            try
            {
                _chain.Add(prev.CreateNextBlock(_coinbaseTo));
                Assert.Fail();
            }
            catch (VerificationException)
            {
            }
            // Create a new block with the right difficulty target given our blistering speed relative to the huge amount
            // of time it's supposed to take (set in the unit test network parameters).
            var b = prev.CreateNextBlock(_coinbaseTo, (uint) Block.FakeClock);
            b.DifficultyTarget = 0x201FFFFF;
            b.Solve();
            Assert.IsTrue(_chain.Add(b));
        }