Exemple #1
0
 public void TestBadTransactions()
 {
     var block = new Block(_params, _blockBytes);
     // Re-arrange so the coinbase transaction is not first.
     var tx1 = block.Transactions[0];
     var tx2 = block.Transactions[1];
     block.Transactions[0] = tx2;
     block.Transactions[1] = tx1;
     try
     {
         block.Verify();
         Assert.Fail();
     }
     catch (VerificationException)
     {
         // We should get here.
     }
 }
Exemple #2
0
 public void TestBlockVerification()
 {
     var block = new Block(_params, _blockBytes);
     block.Verify();
     Assert.AreEqual("00000000a6e5eb79dcec11897af55e90cd571a4335383a3ccfbc12ec81085935", block.HashAsString);
 }
Exemple #3
0
 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.TargetDifficulty = 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);
 }