@Test
public void testSendingAndBalances() throws Exception {

    DeterministicHierarchy h = new DeterministicHierarchy(masterKey);
    WalletPocketHD account1 = new WalletPocketHD(h.get(BTC.getBip44Path(0), false, true), BTC, null, null);
    WalletPocketHD account2 = new WalletPocketHD(h.get(BTC.getBip44Path(1), false, true), BTC, null, null);
    WalletPocketHD account3 = new WalletPocketHD(h.get(BTC.getBip44Path(2), false, true), BTC, null, null);
    Transaction tx = new Transaction(BTC);
    tx.addOutput(BTC.oneCoin().toCoin(), account1.getReceiveAddress());
    tx.getConfidence().setSource(Source.SELF);
    account1.addNewTransactionIfNeeded(tx);
    assertEquals(BTC.value("1"), account1.getBalance());
    assertEquals(BTC.value("0"), account2.getBalance());
    assertEquals(BTC.value("0"), account3.getBalance());
    Sha256Hash txId = send(BTC.value("0.05"), account1, account2);
    assertEquals(BTC.value("0.94"), account1.getBalance());
    assertEquals(BTC.value("0"), account2.getBalance());
    assertEquals(BTC.value("0"), account3.getBalance());
    setTrustedTransaction(account1, txId);
    setTrustedTransaction(account2, txId);
    assertEquals(BTC.value("0.94"), account1.getBalance());
    assertEquals(BTC.value("0.05"), account2.getBalance());
    txId = send(BTC.value("0.07"), account1, account3);
    setTrustedTransaction(account1, txId);
    setTrustedTransaction(account3, txId);
    assertEquals(BTC.value("0.86"), account1.getBalance());
    assertEquals(BTC.value("0.05"), account2.getBalance());
    assertEquals(BTC.value("0.07"), account3.getBalance());
    txId = send(BTC.value("0.03"), account2, account3);
    setTrustedTransaction(account2, txId);
    setTrustedTransaction(account3, txId);
    assertEquals(BTC.value("0.86"), account1.getBalance());
    assertEquals(BTC.value("0.01"), account2.getBalance());
    assertEquals(BTC.value("0.1"), account3.getBalance());
}