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

MerkleRoots() private method

private MerkleRoots ( ) : void
return void
        public void MerkleRoots()
        {
            // Test that merkle root verification takes place when a relevant transaction is present and doesn't when
            // there isn't any such tx present (as an optimization).
            var tx1 = TestUtils.CreateFakeTx(_unitTestParams,
                                             Utils.ToNanoCoins(1, 0),
                                             _wallet.Keychain[0].ToAddress(_unitTestParams));
            var b1 = TestUtils.CreateFakeBlock(_unitTestParams, _blockStore, tx1).Block;
            _chain.Add(b1);
            ResetBlockStore();
            var hash = b1.MerkleRoot;
            b1.MerkleRoot = Sha256Hash.ZeroHash;
            try
            {
                _chain.Add(b1);
                Assert.Fail();
            }
            catch (VerificationException)
            {
                // Expected.
                b1.MerkleRoot = hash;
            }
            // Now add a second block with no relevant transactions and then break it.
            var tx2 = TestUtils.CreateFakeTx(_unitTestParams, Utils.ToNanoCoins(1, 0),
                                             new EcKey().ToAddress(_unitTestParams));
            var b2 = TestUtils.CreateFakeBlock(_unitTestParams, _blockStore, tx2).Block;
            b2.MerkleRoot = Sha256Hash.ZeroHash;
            b2.Solve();
            _chain.Add(b2); // Broken block is accepted because its contents don't matter to us.
        }