public void Balance()
{
// Receive 5 coins then half a coin.
var v1 = Utils.ToNanoCoins(5, 0);
var v2 = Utils.ToNanoCoins(0, 50);
var t1 = TestUtils.CreateFakeTx(_params, v1, _myAddress);
var t2 = TestUtils.CreateFakeTx(_params, v2, _myAddress);
var b1 = TestUtils.CreateFakeBlock(_params, _blockStore, t1).StoredBlock;
var b2 = TestUtils.CreateFakeBlock(_params, _blockStore, t2).StoredBlock;
var expected = Utils.ToNanoCoins(5, 50);
_wallet.Receive(t1, b1, BlockChain.NewBlockType.BestChain);
_wallet.Receive(t2, b2, BlockChain.NewBlockType.BestChain);
Assert.AreEqual(expected, _wallet.GetBalance());
// Now spend one coin.
var v3 = Utils.ToNanoCoins(1, 0);
var spend = _wallet.CreateSend(new EcKey().ToAddress(_params), v3);
_wallet.ConfirmSend(spend);
// Available and estimated balances should not be the same. We don't check the exact available balance here
// because it depends on the coin selection algorithm.
Assert.AreEqual(Utils.ToNanoCoins(4, 50), _wallet.GetBalance(Wallet.BalanceType.Estimated));
Assert.IsFalse(_wallet.GetBalance(Wallet.BalanceType.Available).Equals(
_wallet.GetBalance(Wallet.BalanceType.Estimated)));
// Now confirm the transaction by including it into a block.
var b3 = TestUtils.CreateFakeBlock(_params, _blockStore, spend).StoredBlock;
_wallet.Receive(spend, b3, BlockChain.NewBlockType.BestChain);
// Change is confirmed. We started with 5.50 so we should have 4.50 left.
var v4 = Utils.ToNanoCoins(4, 50);
Assert.AreEqual(v4, _wallet.GetBalance(Wallet.BalanceType.Available));
}