Improve unit tests to verify the arguments to the onDeadTransaction event. Fixed a bug revealed by this.

Credit to miron@google.com for spotting the problem.
This commit is contained in:
Mike Hearn 2011-05-23 12:44:32 +00:00
parent cb5025b987
commit bebc83f64c
2 changed files with 10 additions and 6 deletions

View File

@ -802,13 +802,14 @@ public class Wallet implements Serializable {
isDead = true;
// This transaction was replaced by a double spend on the new chain. Did you just reverse
// your own transaction? I hope not!!
log.info(" ->dead, will not confirm now unless there's another re-org",
tx.getHashAsString());
log.info(" ->dead, will not confirm now unless there's another re-org", tx.getHashAsString());
TransactionOutput doubleSpent = input.getConnectedOutput(pool);
Transaction replacement = doubleSpent.getSpentBy().parentTransaction;
dead.put(tx.getHash(), tx);
// Inform the event listeners of the newly dead tx.
for (WalletEventListener listener : eventListeners) {
synchronized (listener) {
listener.onDeadTransaction(input.outpoint.fromTx, tx);
listener.onDeadTransaction(tx, replacement);
}
}
break;

View File

@ -222,11 +222,13 @@ public class ChainSplitTests {
// Check what happens when a re-org happens and one of our UNconfirmed transactions becomes invalidated by a
// double spend on the new best chain.
final boolean[] eventCalled = new boolean[1];
final Transaction[] eventDead = new Transaction[1];
final Transaction[] eventReplacement = new Transaction[1];
wallet.addEventListener(new WalletEventListener() {
@Override
public void onDeadTransaction(Transaction deadTx, Transaction replacementTx) {
eventCalled[0] = true;
eventDead[0] = deadTx;
eventReplacement[0] = replacementTx;
}
});
@ -255,7 +257,8 @@ public class ChainSplitTests {
chain.add(b4); // New best chain.
// Should have seen a double spend against the pending pool.
assertTrue(eventCalled[0]);
assertEquals(t1, eventDead[0]);
assertEquals(t2, eventReplacement[0]);
assertEquals(Utils.toNanoCoins(30, 0), wallet.getBalance());
// ... and back to our own parallel universe.