mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
Simplify the MockTransactionBroadcaster a bit and update the docs.
This commit is contained in:
parent
bcc8055b7e
commit
6e999c6054
@ -30,8 +30,9 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* A mock transaction broadcaster can be used in unit tests as a stand-in for a PeerGroup. It catches any transactions
|
||||
* broadcast through it and makes them available via the {@link #broadcasts} member. Reading from that
|
||||
* {@link LinkedBlockingQueue} will block the thread until a transaction is available.
|
||||
* broadcast through it and makes them available via the {@link #waitForTransaction()} method. Using that will cause
|
||||
* the broadcast to be seen as if it never propagated though, so you may instead use {@link #waitForTxFuture()} and then
|
||||
* set the returned future when you want the "broadcast" to be completed.
|
||||
*/
|
||||
public class MockTransactionBroadcaster implements TransactionBroadcaster {
|
||||
private final ReentrantLock lock = Threading.lock("mock tx broadcaster");
|
||||
@ -49,12 +50,14 @@ public class MockTransactionBroadcaster implements TransactionBroadcaster {
|
||||
|
||||
private final LinkedBlockingQueue<TxFuturePair> broadcasts = new LinkedBlockingQueue<TxFuturePair>();
|
||||
|
||||
/** Sets this mock broadcaster on the given wallet. */
|
||||
public MockTransactionBroadcaster(Wallet wallet) {
|
||||
// This code achieves nothing directly, but it sets up the broadcaster/peergroup > wallet lock ordering
|
||||
// so inversions can be caught.
|
||||
lock.lock();
|
||||
try {
|
||||
this.wallet = wallet;
|
||||
wallet.setTransactionBroadcaster(this);
|
||||
wallet.getPendingTransactions();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
|
@ -2187,7 +2187,6 @@ public class WalletTest extends TestWithWallet {
|
||||
Utils.setMockClock();
|
||||
// Watch out for wallet-initiated broadcasts.
|
||||
MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet);
|
||||
wallet.setTransactionBroadcaster(broadcaster);
|
||||
wallet.setKeyRotationEnabled(true);
|
||||
// Send three cents to two different keys, then add a key and mark the initial keys as compromised.
|
||||
ECKey key1 = new ECKey();
|
||||
@ -2251,7 +2250,7 @@ public class WalletTest extends TestWithWallet {
|
||||
assertArrayEquals(address.getHash160(), tx.getOutput(0).getScriptPubKey().getPubKeyHash());
|
||||
}
|
||||
|
||||
//@Test - this test is slow, disable for now.
|
||||
//@Test //- this test is slow, disable for now.
|
||||
public void fragmentedReKeying() throws Exception {
|
||||
// Send lots of small coins and check the fee is correct.
|
||||
ECKey key = new ECKey();
|
||||
@ -2264,7 +2263,6 @@ public class WalletTest extends TestWithWallet {
|
||||
}
|
||||
|
||||
MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet);
|
||||
wallet.setTransactionBroadcaster(broadcaster);
|
||||
wallet.setKeyRotationEnabled(true);
|
||||
|
||||
Date compromise = Utils.now();
|
||||
|
Loading…
x
Reference in New Issue
Block a user