Program: 85867
Project: 85867
Buggy source:
@Test public void basicSpending() throws Exception {
  BigInteger v1=Utils.toNanoCoins(1,0);
  Transaction t1=sendMoneyToWallet(v1,null);
  assertEquals(BigInteger.ZERO,wallet.getBalance());
  assertEquals(v1,wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  assertEquals(1,wallet.getPoolSize(Pool.PENDING));
  assertEquals(0,wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
  sendMoneyToWallet(t1,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  assertEquals(v1,wallet.getBalance());
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.ALL));
  Address destination=new ECKey().toAddress(params);
  BigInteger v2=toNanoCoins(0,50);
  Wallet.SendRequest req=Wallet.SendRequest.to(destination,v2);
  req.fee=toNanoCoins(0,1);
  wallet.completeTx(req);
  Transaction t2=req.tx;
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.ALL));
  assertEquals(TransactionConfidence.Source.SELF,t2.getConfidence().getSource());
  assertEquals(1,t2.getInputs().size());
  assertEquals(myAddress,t2.getInputs().get(0).getScriptSig().getFromAddress());
  assertEquals(t2.getConfidence().getConfidenceType(),TransactionConfidence.ConfidenceType.NOT_SEEN_IN_CHAIN);
  assertEquals(2,t2.getOutputs().size());
  assertEquals(destination,t2.getOutputs().get(0).getScriptPubKey().getToAddress());
  assertEquals(wallet.getChangeAddress(),t2.getOutputs().get(1).getScriptPubKey().getToAddress());
  BigInteger v3=toNanoCoins(0,49);
  assertEquals(v3,t2.getOutputs().get(1).getValue());
  t2.getInputs().get(0).verify();
  final LinkedList<Transaction> txns=Lists.newLinkedList();
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onCoinsSent(    Wallet wallet,    Transaction tx,    BigInteger prevBalance,    BigInteger newBalance){
      txns.add(tx);
    }
  }
);
  t2.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{1,2,3,4})));
  t2.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{10,2,3,4})));
  wallet.commitTx(t2);
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.PENDING));
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.SPENT));
  assertEquals(2,wallet.getPoolSize(WalletTransaction.Pool.ALL));
  assertEquals(t2,txns.getFirst());
  assertEquals(1,txns.size());
  assertEquals(v3,wallet.getBalance());
  Transaction t3=wallet.createSend(new ECKey().toAddress(params),v3);
  assertNotNull(t3);
}

Fixed version (ground truth):
@Test public void basicSpending() throws Exception {
  BigInteger v1=Utils.toNanoCoins(1,0);
  Transaction t1=sendMoneyToWallet(v1,null);
  assertEquals(BigInteger.ZERO,wallet.getBalance());
  assertEquals(v1,wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  assertEquals(1,wallet.getPoolSize(Pool.PENDING));
  assertEquals(0,wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
  sendMoneyToWallet(t1,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  assertEquals(v1,wallet.getBalance());
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.ALL));
  Address destination=new ECKey().toAddress(params);
  BigInteger v2=toNanoCoins(0,50);
  Wallet.SendRequest req=Wallet.SendRequest.to(destination,v2);
  req.fee=toNanoCoins(0,1);
  wallet.completeTx(req);
  Transaction t2=req.tx;
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.ALL));
  assertEquals(TransactionConfidence.Source.SELF,t2.getConfidence().getSource());
  assertEquals(1,t2.getInputs().size());
  assertEquals(myAddress,t2.getInputs().get(0).getScriptSig().getFromAddress());
  assertEquals(t2.getConfidence().getConfidenceType(),TransactionConfidence.ConfidenceType.NOT_SEEN_IN_CHAIN);
  assertEquals(2,t2.getOutputs().size());
  assertEquals(destination,t2.getOutputs().get(0).getScriptPubKey().getToAddress());
  assertEquals(wallet.getChangeAddress(),t2.getOutputs().get(1).getScriptPubKey().getToAddress());
  BigInteger v3=toNanoCoins(0,49);
  assertEquals(v3,t2.getOutputs().get(1).getValue());
  t2.getInputs().get(0).verify();
  final LinkedList<Transaction> txns=Lists.newLinkedList();
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onCoinsSent(    Wallet wallet,    Transaction tx,    BigInteger prevBalance,    BigInteger newBalance){
      txns.add(tx);
    }
  }
);
  t2.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{1,2,3,4})));
  t2.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByAddress(new byte[]{10,2,3,4})));
  wallet.commitTx(t2);
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.PENDING));
  assertEquals(1,wallet.getPoolSize(WalletTransaction.Pool.SPENT));
  assertEquals(2,wallet.getPoolSize(WalletTransaction.Pool.ALL));
  assertEquals(t2,txns.getFirst());
  assertEquals(1,txns.size());
  assertEquals(v3,wallet.getBalance());
  Transaction t3=wallet.createSend(new ECKey().toAddress(params),v3);
  assertNotNull(t3);
  wallet.commitTx(t3);
  assertTrue(wallet.isConsistent());
  BlockPair bp=createFakeBlock(blockStore,t2,t3);
  wallet.receiveFromBlock(t2,bp.storedBlock,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  wallet.receiveFromBlock(t3,bp.storedBlock,AbstractBlockChain.NewBlockType.BEST_CHAIN);
  wallet.notifyNewBestBlock(bp.block);
  assertTrue(wallet.isConsistent());
}