public void TestDoubleSpendOnFork()
{
// Check what happens when a re-org happens and one of our confirmed transactions becomes invalidated by a
// double spend on the new best chain.
var eventCalled = false;
_wallet.DeadTransaction += (sender, e) => eventCalled = true;
var b1 = _unitTestParams.GenesisBlock.CreateNextBlock(_coinbaseTo);
_chain.Add(b1);
var t1 = _wallet.CreateSend(_someOtherGuy, Utils.ToNanoCoins(10, 0));
var yetAnotherGuy = new EcKey().ToAddress(_unitTestParams);
var t2 = _wallet.CreateSend(yetAnotherGuy, Utils.ToNanoCoins(20, 0));
_wallet.ConfirmSend(t1);
// Receive t1 as confirmed by the network.
var b2 = b1.CreateNextBlock(new EcKey().ToAddress(_unitTestParams));
b2.AddTransaction(t1);
b2.Solve();
_chain.Add(b2);
// Now we make a double spend become active after a re-org.
var b3 = b1.CreateNextBlock(new EcKey().ToAddress(_unitTestParams));
b3.AddTransaction(t2);
b3.Solve();
_chain.Add(b3); // Side chain.
var b4 = b3.CreateNextBlock(new EcKey().ToAddress(_unitTestParams));
_chain.Add(b4); // New best chain.
// Should have seen a double spend.
Assert.IsTrue(eventCalled);
Assert.AreEqual(Utils.ToNanoCoins(30, 0), _wallet.GetBalance());
}