mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-19 05:33:44 +01:00
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:
parent
cb5025b987
commit
bebc83f64c
@ -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;
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user