BitSharper.Test.BlockTest.TestProofOfWork C# (CSharp) Method

TestProofOfWork() private method

private TestProofOfWork ( ) : void
return void
        public void TestProofOfWork()
        {
            // This params accepts any difficulty target.
            var @params = NetworkParameters.UnitTests();
            var block = new Block(@params, _blockBytes);
            block.Nonce = 12346;
            try
            {
                block.Verify();
                Assert.Fail();
            }
            catch (VerificationException)
            {
                // Expected.
            }
            // Blocks contain their own difficulty target. The BlockChain verification mechanism is what stops real blocks
            // from containing artificially weak difficulties.
            block.DifficultyTarget = Block.EasiestDifficultyTarget;
            // Now it should pass.
            block.Verify();
            // Break the nonce again at the lower difficulty level so we can try solving for it.
            block.Nonce = 1;
            try
            {
                block.Verify();
                Assert.Fail();
            }
            catch (VerificationException)
            {
                // Expected to fail as the nonce is no longer correct.
            }
            // Should find an acceptable nonce.
            block.Solve();
            block.Verify();
            Assert.AreEqual(block.Nonce, 2U);
        }