BitSharper.Test.ChainSplitTests.TestForking3 C# (CSharp) Method

TestForking3() private method

private TestForking3 ( ) : void
return void
        public void TestForking3()
        {
            // Check that we can handle our own spends being rolled back by a fork.
            var b1 = _unitTestParams.GenesisBlock.CreateNextBlock(_coinbaseTo);
            _chain.Add(b1);
            Assert.AreEqual("50.00", Utils.BitcoinValueToFriendlyString(_wallet.GetBalance()));
            var dest = new EcKey().ToAddress(_unitTestParams);
            var spend = _wallet.CreateSend(dest, Utils.ToNanoCoins(10, 0));
            _wallet.ConfirmSend(spend);
            // Waiting for confirmation ...
            Assert.AreEqual(0UL, _wallet.GetBalance());
            var b2 = b1.CreateNextBlock(_someOtherGuy);
            b2.AddTransaction(spend);
            b2.Solve();
            _chain.Add(b2);
            Assert.AreEqual(Utils.ToNanoCoins(40, 0), _wallet.GetBalance());
            // genesis -> b1 (receive coins) -> b2 (spend coins)
            //                               \-> b3 -> b4
            var b3 = b1.CreateNextBlock(_someOtherGuy);
            var b4 = b3.CreateNextBlock(_someOtherGuy);
            _chain.Add(b3);
            _chain.Add(b4);
            // b4 causes a re-org that should make our spend go inactive. Because the inputs are already spent our
            // available balance drops to zero again.
            Assert.AreEqual(0UL, _wallet.GetBalance(Wallet.BalanceType.Available));
            // We estimate that it'll make it back into the block chain (we know we won't double spend).
            // assertEquals(Utils.toNanoCoins(40, 0), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
        }