mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
Move some testing utilities to a new testing subpackage and rename TextUtils to reflect what it actually does.
This commit is contained in:
parent
98fc5827f2
commit
e1d6707626
@ -47,7 +47,7 @@ public abstract class PeerSocketHandler extends AbstractTimeoutHandler implement
|
|||||||
// If we close() before we know our writeTarget, set this to true to call writeTarget.closeConnection() right away.
|
// If we close() before we know our writeTarget, set this to true to call writeTarget.closeConnection() right away.
|
||||||
private boolean closePending = false;
|
private boolean closePending = false;
|
||||||
// writeTarget will be thread-safe, and may call into PeerGroup, which calls us, so we should call it unlocked
|
// writeTarget will be thread-safe, and may call into PeerGroup, which calls us, so we should call it unlocked
|
||||||
@VisibleForTesting MessageWriteTarget writeTarget = null;
|
@VisibleForTesting protected MessageWriteTarget writeTarget = null;
|
||||||
|
|
||||||
// The ByteBuffers passed to us from the writeTarget are static in size, and usually smaller than some messages we
|
// The ByteBuffers passed to us from the writeTarget are static in size, and usually smaller than some messages we
|
||||||
// will receive. For SPV clients, this should be rare (ie we're mostly dealing with small transactions), but for
|
// will receive. For SPV clients, this should be rare (ie we're mostly dealing with small transactions), but for
|
||||||
|
@ -14,19 +14,18 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.google.bitcoin.utils;
|
package com.google.bitcoin.testing;
|
||||||
|
|
||||||
import com.google.bitcoin.core.*;
|
import com.google.bitcoin.core.*;
|
||||||
import com.google.bitcoin.store.BlockStore;
|
import com.google.bitcoin.store.BlockStore;
|
||||||
import com.google.bitcoin.store.BlockStoreException;
|
import com.google.bitcoin.store.BlockStoreException;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class TestUtils {
|
public class FakeTxBuilder {
|
||||||
public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, BigInteger nanocoins, Address to, Address changeOutput)
|
public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, BigInteger nanocoins, Address to, Address changeOutput)
|
||||||
throws IOException, ProtocolException {
|
throws IOException, ProtocolException {
|
||||||
// Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
|
// Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
|
@ -1,5 +1,6 @@
|
|||||||
package com.google.bitcoin.core;
|
package com.google.bitcoin.testing;
|
||||||
|
|
||||||
|
import com.google.bitcoin.core.*;
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -9,11 +10,11 @@ import java.util.concurrent.ArrayBlockingQueue;
|
|||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An extension of {@link PeerSocketHandler} that keeps inbound messages in a queue for later processing
|
* An extension of {@link com.google.bitcoin.core.PeerSocketHandler} that keeps inbound messages in a queue for later processing
|
||||||
*/
|
*/
|
||||||
public abstract class InboundMessageQueuer extends PeerSocketHandler {
|
public abstract class InboundMessageQueuer extends PeerSocketHandler {
|
||||||
final BlockingQueue<Message> inboundMessages = new ArrayBlockingQueue<Message>(1000);
|
public final BlockingQueue<Message> inboundMessages = new ArrayBlockingQueue<Message>(1000);
|
||||||
final Map<Long, SettableFuture<Void>> mapPingFutures = new HashMap<Long, SettableFuture<Void>>();
|
public final Map<Long, SettableFuture<Void>> mapPingFutures = new HashMap<Long, SettableFuture<Void>>();
|
||||||
|
|
||||||
public Peer peer;
|
public Peer peer;
|
||||||
public BloomFilter lastReceivedFilter;
|
public BloomFilter lastReceivedFilter;
|
||||||
@ -33,7 +34,7 @@ public abstract class InboundMessageQueuer extends PeerSocketHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected void processMessage(Message m) throws Exception {
|
protected void processMessage(Message m) throws Exception {
|
||||||
if (m instanceof Ping) {
|
if (m instanceof Ping) {
|
||||||
SettableFuture<Void> future = mapPingFutures.get(((Ping)m).getNonce());
|
SettableFuture<Void> future = mapPingFutures.get(((Ping) m).getNonce());
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.set(null);
|
future.set(null);
|
||||||
return;
|
return;
|
@ -14,12 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.google.bitcoin.utils;
|
package com.google.bitcoin.testing;
|
||||||
|
|
||||||
import com.google.bitcoin.core.Transaction;
|
import com.google.bitcoin.core.Transaction;
|
||||||
import com.google.bitcoin.core.TransactionBroadcaster;
|
import com.google.bitcoin.core.TransactionBroadcaster;
|
||||||
import com.google.bitcoin.core.VerificationException;
|
import com.google.bitcoin.core.VerificationException;
|
||||||
import com.google.bitcoin.core.Wallet;
|
import com.google.bitcoin.core.Wallet;
|
||||||
|
import com.google.bitcoin.utils.Threading;
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
@ -15,8 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.google.bitcoin.core;
|
package com.google.bitcoin.testing;
|
||||||
|
|
||||||
|
import com.google.bitcoin.core.*;
|
||||||
import com.google.bitcoin.net.*;
|
import com.google.bitcoin.net.*;
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.store.BlockStore;
|
import com.google.bitcoin.store.BlockStore;
|
||||||
@ -37,7 +38,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class that makes it easy to work with mock NetworkConnections.
|
* Utility class that makes it easy to work with mock NetworkConnections.
|
||||||
@ -56,7 +57,7 @@ public class TestWithNetworkConnections {
|
|||||||
private final ClientConnectionManager channels;
|
private final ClientConnectionManager channels;
|
||||||
protected final BlockingQueue<InboundMessageQueuer> newPeerWriteTargetQueue = new LinkedBlockingQueue<InboundMessageQueuer>();
|
protected final BlockingQueue<InboundMessageQueuer> newPeerWriteTargetQueue = new LinkedBlockingQueue<InboundMessageQueuer>();
|
||||||
|
|
||||||
enum ClientType {
|
public enum ClientType {
|
||||||
NIO_CLIENT_MANAGER,
|
NIO_CLIENT_MANAGER,
|
||||||
BLOCKING_CLIENT_MANAGER,
|
BLOCKING_CLIENT_MANAGER,
|
||||||
NIO_CLIENT,
|
NIO_CLIENT,
|
||||||
@ -168,8 +169,8 @@ public class TestWithNetworkConnections {
|
|||||||
writeTarget.sendMessage(versionMessage);
|
writeTarget.sendMessage(versionMessage);
|
||||||
writeTarget.sendMessage(new VersionAck());
|
writeTarget.sendMessage(new VersionAck());
|
||||||
try {
|
try {
|
||||||
assertTrue(writeTarget.nextMessageBlocking() instanceof VersionMessage);
|
checkState(writeTarget.nextMessageBlocking() instanceof VersionMessage);
|
||||||
assertTrue(writeTarget.nextMessageBlocking() instanceof VersionAck);
|
checkState(writeTarget.nextMessageBlocking() instanceof VersionAck);
|
||||||
synchronized (doneConnecting) {
|
synchronized (doneConnecting) {
|
||||||
doneConnecting.set(true);
|
doneConnecting.set(true);
|
||||||
}
|
}
|
@ -14,19 +14,21 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.google.bitcoin.utils;
|
package com.google.bitcoin.testing;
|
||||||
|
|
||||||
import com.google.bitcoin.core.*;
|
import com.google.bitcoin.core.*;
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.store.BlockStore;
|
import com.google.bitcoin.store.BlockStore;
|
||||||
import com.google.bitcoin.store.MemoryBlockStore;
|
import com.google.bitcoin.store.MemoryBlockStore;
|
||||||
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
|
import com.google.bitcoin.utils.BriefLogFormatter;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import static com.google.bitcoin.utils.TestUtils.createFakeBlock;
|
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeBlock;
|
||||||
import static com.google.bitcoin.utils.TestUtils.createFakeTx;
|
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeTx;
|
||||||
|
|
||||||
// TODO: This needs to be somewhat rewritten - the "sendMoneyToWallet" methods aren't sending via the block chain object
|
// TODO: This needs to be somewhat rewritten - the "sendMoneyToWallet" methods aren't sending via the block chain object
|
||||||
|
|
||||||
@ -69,7 +71,7 @@ public class TestWithWallet {
|
|||||||
if (wallet.isPendingTransactionRelevant(tx))
|
if (wallet.isPendingTransactionRelevant(tx))
|
||||||
wallet.receivePending(tx, null);
|
wallet.receivePending(tx, null);
|
||||||
} else {
|
} else {
|
||||||
TestUtils.BlockPair bp = createFakeBlock(blockStore, tx);
|
FakeTxBuilder.BlockPair bp = createFakeBlock(blockStore, tx);
|
||||||
wallet.receiveFromBlock(tx, bp.storedBlock, type, 0);
|
wallet.receiveFromBlock(tx, bp.storedBlock, type, 0);
|
||||||
if (type == AbstractBlockChain.NewBlockType.BEST_CHAIN)
|
if (type == AbstractBlockChain.NewBlockType.BEST_CHAIN)
|
||||||
wallet.notifyNewBestBlock(bp.storedBlock);
|
wallet.notifyNewBestBlock(bp.storedBlock);
|
@ -22,8 +22,8 @@ import com.google.bitcoin.params.TestNet2Params;
|
|||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.store.BlockStore;
|
import com.google.bitcoin.store.BlockStore;
|
||||||
import com.google.bitcoin.store.MemoryBlockStore;
|
import com.google.bitcoin.store.MemoryBlockStore;
|
||||||
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
import com.google.bitcoin.utils.BriefLogFormatter;
|
import com.google.bitcoin.utils.BriefLogFormatter;
|
||||||
import com.google.bitcoin.utils.TestUtils;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -33,8 +33,8 @@ import java.math.BigInteger;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static com.google.bitcoin.utils.TestUtils.createFakeBlock;
|
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeBlock;
|
||||||
import static com.google.bitcoin.utils.TestUtils.createFakeTx;
|
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeTx;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
// Handling of chain splits/reorgs are in ChainSplitTests.
|
// Handling of chain splits/reorgs are in ChainSplitTests.
|
||||||
@ -272,7 +272,7 @@ public class BlockChainTest {
|
|||||||
wallet.addKey(key);
|
wallet.addKey(key);
|
||||||
Address addr = key.toAddress(unitTestParams);
|
Address addr = key.toAddress(unitTestParams);
|
||||||
// Create a tx that gives us some coins, and another that spends it to someone else in the same block.
|
// Create a tx that gives us some coins, and another that spends it to someone else in the same block.
|
||||||
Transaction t1 = TestUtils.createFakeTx(unitTestParams, Utils.toNanoCoins(1, 0), addr);
|
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, Utils.toNanoCoins(1, 0), addr);
|
||||||
Transaction t2 = new Transaction(unitTestParams);
|
Transaction t2 = new Transaction(unitTestParams);
|
||||||
t2.addInput(t1.getOutputs().get(0));
|
t2.addInput(t1.getOutputs().get(0));
|
||||||
t2.addOutput(Utils.toNanoCoins(2, 0), somebodyElse);
|
t2.addOutput(Utils.toNanoCoins(2, 0), somebodyElse);
|
||||||
|
@ -19,8 +19,8 @@ package com.google.bitcoin.core;
|
|||||||
import com.google.bitcoin.core.TransactionConfidence.ConfidenceType;
|
import com.google.bitcoin.core.TransactionConfidence.ConfidenceType;
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.store.MemoryBlockStore;
|
import com.google.bitcoin.store.MemoryBlockStore;
|
||||||
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
import com.google.bitcoin.utils.BriefLogFormatter;
|
import com.google.bitcoin.utils.BriefLogFormatter;
|
||||||
import com.google.bitcoin.utils.TestUtils;
|
|
||||||
import com.google.bitcoin.utils.Threading;
|
import com.google.bitcoin.utils.Threading;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -540,8 +540,8 @@ public class ChainSplitTest {
|
|||||||
// This covers issue 468.
|
// This covers issue 468.
|
||||||
|
|
||||||
// Receive some money to the wallet.
|
// Receive some money to the wallet.
|
||||||
Transaction t1 = TestUtils.createFakeTx(unitTestParams, Utils.COIN, coinsTo);
|
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, Utils.COIN, coinsTo);
|
||||||
final Block b1 = TestUtils.makeSolvedTestBlock(unitTestParams.genesisBlock, t1);
|
final Block b1 = FakeTxBuilder.makeSolvedTestBlock(unitTestParams.genesisBlock, t1);
|
||||||
chain.add(b1);
|
chain.add(b1);
|
||||||
|
|
||||||
// Send a couple of payments one after the other (so the second depends on the change output of the first).
|
// Send a couple of payments one after the other (so the second depends on the change output of the first).
|
||||||
@ -550,7 +550,7 @@ public class ChainSplitTest {
|
|||||||
wallet.commitTx(t2);
|
wallet.commitTx(t2);
|
||||||
Transaction t3 = checkNotNull(wallet.createSend(new ECKey().toAddress(unitTestParams), Utils.CENT));
|
Transaction t3 = checkNotNull(wallet.createSend(new ECKey().toAddress(unitTestParams), Utils.CENT));
|
||||||
wallet.commitTx(t3);
|
wallet.commitTx(t3);
|
||||||
chain.add(TestUtils.makeSolvedTestBlock(b1, t2, t3));
|
chain.add(FakeTxBuilder.makeSolvedTestBlock(b1, t2, t3));
|
||||||
|
|
||||||
final BigInteger coins0point98 = Utils.COIN.subtract(Utils.CENT).subtract(Utils.CENT);
|
final BigInteger coins0point98 = Utils.COIN.subtract(Utils.CENT).subtract(Utils.CENT);
|
||||||
assertEquals(coins0point98, wallet.getBalance());
|
assertEquals(coins0point98, wallet.getBalance());
|
||||||
@ -559,8 +559,8 @@ public class ChainSplitTest {
|
|||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
wallet.saveToFileStream(bos);
|
wallet.saveToFileStream(bos);
|
||||||
wallet = Wallet.loadFromFileStream(new ByteArrayInputStream(bos.toByteArray()));
|
wallet = Wallet.loadFromFileStream(new ByteArrayInputStream(bos.toByteArray()));
|
||||||
final Block b2 = TestUtils.makeSolvedTestBlock(b1, t2, t3);
|
final Block b2 = FakeTxBuilder.makeSolvedTestBlock(b1, t2, t3);
|
||||||
final Block b3 = TestUtils.makeSolvedTestBlock(b2);
|
final Block b3 = FakeTxBuilder.makeSolvedTestBlock(b2);
|
||||||
chain.add(b2);
|
chain.add(b2);
|
||||||
chain.add(b3);
|
chain.add(b3);
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ package com.google.bitcoin.core;
|
|||||||
import com.google.bitcoin.core.TransactionConfidence.ConfidenceType;
|
import com.google.bitcoin.core.TransactionConfidence.ConfidenceType;
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.store.MemoryBlockStore;
|
import com.google.bitcoin.store.MemoryBlockStore;
|
||||||
|
import com.google.bitcoin.testing.InboundMessageQueuer;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
|
@ -28,8 +28,8 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static com.google.bitcoin.utils.TestUtils.createFakeBlock;
|
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeBlock;
|
||||||
import static com.google.bitcoin.utils.TestUtils.createFakeTx;
|
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeTx;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class LazyParseByteCacheTest {
|
public class LazyParseByteCacheTest {
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
package com.google.bitcoin.core;
|
package com.google.bitcoin.core;
|
||||||
|
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
import com.google.bitcoin.utils.BriefLogFormatter;
|
import com.google.bitcoin.utils.BriefLogFormatter;
|
||||||
import com.google.bitcoin.utils.TestUtils;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ public class MemoryPoolTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
BriefLogFormatter.init();
|
BriefLogFormatter.init();
|
||||||
tx1 = TestUtils.createFakeTx(params, Utils.toNanoCoins(1, 0), new ECKey().toAddress(params));
|
tx1 = FakeTxBuilder.createFakeTx(params, Utils.toNanoCoins(1, 0), new ECKey().toAddress(params));
|
||||||
tx2 = new Transaction(params, tx1.bitcoinSerialize());
|
tx2 = new Transaction(params, tx1.bitcoinSerialize());
|
||||||
|
|
||||||
address1 = new PeerAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
address1 = new PeerAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
|
||||||
|
@ -21,7 +21,8 @@ import com.google.bitcoin.net.discovery.PeerDiscovery;
|
|||||||
import com.google.bitcoin.net.discovery.PeerDiscoveryException;
|
import com.google.bitcoin.net.discovery.PeerDiscoveryException;
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.store.MemoryBlockStore;
|
import com.google.bitcoin.store.MemoryBlockStore;
|
||||||
import com.google.bitcoin.utils.TestUtils;
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
|
import com.google.bitcoin.testing.InboundMessageQueuer;
|
||||||
import com.google.bitcoin.utils.Threading;
|
import com.google.bitcoin.utils.Threading;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@ -177,7 +178,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||||||
assertEquals(tmp, expectedPeers);
|
assertEquals(tmp, expectedPeers);
|
||||||
|
|
||||||
BigInteger value = Utils.toNanoCoins(1, 0);
|
BigInteger value = Utils.toNanoCoins(1, 0);
|
||||||
Transaction t1 = TestUtils.createFakeTx(unitTestParams, value, address);
|
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, value, address);
|
||||||
InventoryMessage inv = new InventoryMessage(unitTestParams);
|
InventoryMessage inv = new InventoryMessage(unitTestParams);
|
||||||
inv.addTransaction(t1);
|
inv.addTransaction(t1);
|
||||||
|
|
||||||
@ -212,10 +213,10 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||||||
|
|
||||||
// Set up a little block chain. We heard about b1 but not b2 (it is pending download). b3 is solved whilst we
|
// Set up a little block chain. We heard about b1 but not b2 (it is pending download). b3 is solved whilst we
|
||||||
// are downloading the chain.
|
// are downloading the chain.
|
||||||
Block b1 = TestUtils.createFakeBlock(blockStore).block;
|
Block b1 = FakeTxBuilder.createFakeBlock(blockStore).block;
|
||||||
blockChain.add(b1);
|
blockChain.add(b1);
|
||||||
Block b2 = TestUtils.makeSolvedTestBlock(b1);
|
Block b2 = FakeTxBuilder.makeSolvedTestBlock(b1);
|
||||||
Block b3 = TestUtils.makeSolvedTestBlock(b2);
|
Block b3 = FakeTxBuilder.makeSolvedTestBlock(b2);
|
||||||
|
|
||||||
// Peer 1 and 2 receives an inv advertising a newly solved block.
|
// Peer 1 and 2 receives an inv advertising a newly solved block.
|
||||||
InventoryMessage inv = new InventoryMessage(params);
|
InventoryMessage inv = new InventoryMessage(params);
|
||||||
@ -254,9 +255,9 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||||||
InboundMessageQueuer p1 = connectPeer(1);
|
InboundMessageQueuer p1 = connectPeer(1);
|
||||||
|
|
||||||
// Set up a little block chain.
|
// Set up a little block chain.
|
||||||
Block b1 = TestUtils.createFakeBlock(blockStore).block;
|
Block b1 = FakeTxBuilder.createFakeBlock(blockStore).block;
|
||||||
Block b2 = TestUtils.makeSolvedTestBlock(b1);
|
Block b2 = FakeTxBuilder.makeSolvedTestBlock(b1);
|
||||||
Block b3 = TestUtils.makeSolvedTestBlock(b2);
|
Block b3 = FakeTxBuilder.makeSolvedTestBlock(b2);
|
||||||
|
|
||||||
// Expect a zero hash getblocks on p1. This is how the process starts.
|
// Expect a zero hash getblocks on p1. This is how the process starts.
|
||||||
peerGroup.startBlockChainDownload(new AbstractPeerEventListener() {
|
peerGroup.startBlockChainDownload(new AbstractPeerEventListener() {
|
||||||
@ -299,7 +300,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||||||
InboundMessageQueuer p2 = connectPeer(2);
|
InboundMessageQueuer p2 = connectPeer(2);
|
||||||
InboundMessageQueuer p3 = connectPeer(3);
|
InboundMessageQueuer p3 = connectPeer(3);
|
||||||
|
|
||||||
Transaction tx = TestUtils.createFakeTx(params, Utils.toNanoCoins(20, 0), address);
|
Transaction tx = FakeTxBuilder.createFakeTx(params, Utils.toNanoCoins(20, 0), address);
|
||||||
InventoryMessage inv = new InventoryMessage(params);
|
InventoryMessage inv = new InventoryMessage(params);
|
||||||
inv.addTransaction(tx);
|
inv.addTransaction(tx);
|
||||||
|
|
||||||
@ -534,7 +535,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||||||
InboundMessageQueuer p1 = connectPeer(1);
|
InboundMessageQueuer p1 = connectPeer(1);
|
||||||
InboundMessageQueuer p2 = connectPeer(2);
|
InboundMessageQueuer p2 = connectPeer(2);
|
||||||
// Create a pay to pubkey tx.
|
// Create a pay to pubkey tx.
|
||||||
Transaction tx = TestUtils.createFakeTx(params, Utils.COIN, key);
|
Transaction tx = FakeTxBuilder.createFakeTx(params, Utils.COIN, key);
|
||||||
Transaction tx2 = new Transaction(params);
|
Transaction tx2 = new Transaction(params);
|
||||||
tx2.addInput(tx.getOutput(0));
|
tx2.addInput(tx.getOutput(0));
|
||||||
TransactionOutPoint outpoint = tx2.getInput(0).getOutpoint();
|
TransactionOutPoint outpoint = tx2.getInput(0).getOutpoint();
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
package com.google.bitcoin.core;
|
package com.google.bitcoin.core;
|
||||||
|
|
||||||
import com.google.bitcoin.params.TestNet3Params;
|
import com.google.bitcoin.params.TestNet3Params;
|
||||||
import com.google.bitcoin.utils.TestUtils;
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
|
import com.google.bitcoin.testing.InboundMessageQueuer;
|
||||||
|
import com.google.bitcoin.testing.TestWithNetworkConnections;
|
||||||
import com.google.bitcoin.utils.Threading;
|
import com.google.bitcoin.utils.Threading;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@ -46,7 +48,7 @@ import java.util.concurrent.Future;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static com.google.bitcoin.utils.TestUtils.*;
|
import static com.google.bitcoin.testing.FakeTxBuilder.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@RunWith(value = Parameterized.class)
|
@RunWith(value = Parameterized.class)
|
||||||
@ -541,9 +543,9 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
// -> [t7]
|
// -> [t7]
|
||||||
// -> [t8]
|
// -> [t8]
|
||||||
// The ones in brackets are assumed to be in the chain and are represented only by hashes.
|
// The ones in brackets are assumed to be in the chain and are represented only by hashes.
|
||||||
Transaction t2 = TestUtils.createFakeTx(unitTestParams, Utils.toNanoCoins(1, 0), to);
|
Transaction t2 = FakeTxBuilder.createFakeTx(unitTestParams, Utils.toNanoCoins(1, 0), to);
|
||||||
Sha256Hash t5 = t2.getInput(0).getOutpoint().getHash();
|
Sha256Hash t5 = t2.getInput(0).getOutpoint().getHash();
|
||||||
Transaction t4 = TestUtils.createFakeTx(unitTestParams, Utils.toNanoCoins(1, 0), new ECKey());
|
Transaction t4 = FakeTxBuilder.createFakeTx(unitTestParams, Utils.toNanoCoins(1, 0), new ECKey());
|
||||||
Sha256Hash t6 = t4.getInput(0).getOutpoint().getHash();
|
Sha256Hash t6 = t4.getInput(0).getOutpoint().getHash();
|
||||||
t4.addOutput(Utils.toNanoCoins(1, 0), new ECKey());
|
t4.addOutput(Utils.toNanoCoins(1, 0), new ECKey());
|
||||||
Transaction t3 = new Transaction(unitTestParams);
|
Transaction t3 = new Transaction(unitTestParams);
|
||||||
@ -557,10 +559,10 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
Sha256Hash anotherHash = new Sha256Hash("3b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6");
|
Sha256Hash anotherHash = new Sha256Hash("3b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6");
|
||||||
t1.addInput(new TransactionInput(unitTestParams, t1, new byte[]{}, new TransactionOutPoint(unitTestParams, 1, anotherHash)));
|
t1.addInput(new TransactionInput(unitTestParams, t1, new byte[]{}, new TransactionOutPoint(unitTestParams, 1, anotherHash)));
|
||||||
t1.addOutput(Utils.toNanoCoins(1, 0), to);
|
t1.addOutput(Utils.toNanoCoins(1, 0), to);
|
||||||
t1 = TestUtils.roundTripTransaction(unitTestParams, t1);
|
t1 = FakeTxBuilder.roundTripTransaction(unitTestParams, t1);
|
||||||
t2 = TestUtils.roundTripTransaction(unitTestParams, t2);
|
t2 = FakeTxBuilder.roundTripTransaction(unitTestParams, t2);
|
||||||
t3 = TestUtils.roundTripTransaction(unitTestParams, t3);
|
t3 = FakeTxBuilder.roundTripTransaction(unitTestParams, t3);
|
||||||
t4 = TestUtils.roundTripTransaction(unitTestParams, t4);
|
t4 = FakeTxBuilder.roundTripTransaction(unitTestParams, t4);
|
||||||
|
|
||||||
// Announce the first one. Wait for it to be downloaded.
|
// Announce the first one. Wait for it to be downloaded.
|
||||||
InventoryMessage inv = new InventoryMessage(unitTestParams);
|
InventoryMessage inv = new InventoryMessage(unitTestParams);
|
||||||
@ -663,7 +665,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Send a normal relevant transaction, it's received correctly.
|
// Send a normal relevant transaction, it's received correctly.
|
||||||
Transaction t1 = TestUtils.createFakeTx(unitTestParams, Utils.toNanoCoins(1, 0), key);
|
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, Utils.toNanoCoins(1, 0), key);
|
||||||
inbound(writeTarget, t1);
|
inbound(writeTarget, t1);
|
||||||
GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
|
GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
|
||||||
if (useNotFound) {
|
if (useNotFound) {
|
||||||
@ -676,7 +678,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
assertNotNull(vtx[0]);
|
assertNotNull(vtx[0]);
|
||||||
vtx[0] = null;
|
vtx[0] = null;
|
||||||
// Send a timelocked transaction, nothing happens.
|
// Send a timelocked transaction, nothing happens.
|
||||||
Transaction t2 = TestUtils.createFakeTx(unitTestParams, Utils.toNanoCoins(2, 0), key);
|
Transaction t2 = FakeTxBuilder.createFakeTx(unitTestParams, Utils.toNanoCoins(2, 0), key);
|
||||||
t2.setLockTime(999999);
|
t2.setLockTime(999999);
|
||||||
inbound(writeTarget, t2);
|
inbound(writeTarget, t2);
|
||||||
Threading.waitForUserCode();
|
Threading.waitForUserCode();
|
||||||
|
@ -20,6 +20,8 @@ import com.google.bitcoin.net.BlockingClientManager;
|
|||||||
import com.google.bitcoin.net.NioClientManager;
|
import com.google.bitcoin.net.NioClientManager;
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.store.BlockStore;
|
import com.google.bitcoin.store.BlockStore;
|
||||||
|
import com.google.bitcoin.testing.InboundMessageQueuer;
|
||||||
|
import com.google.bitcoin.testing.TestWithNetworkConnections;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
@ -19,7 +19,8 @@ package com.google.bitcoin.core;
|
|||||||
|
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.store.MemoryBlockStore;
|
import com.google.bitcoin.store.MemoryBlockStore;
|
||||||
import com.google.bitcoin.utils.TestUtils;
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
|
import com.google.bitcoin.testing.InboundMessageQueuer;
|
||||||
import com.google.bitcoin.utils.Threading;
|
import com.google.bitcoin.utils.Threading;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -106,7 +107,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
|
|||||||
connectPeer(2);
|
connectPeer(2);
|
||||||
|
|
||||||
// Send ourselves a bit of money.
|
// Send ourselves a bit of money.
|
||||||
Block b1 = TestUtils.makeSolvedTestBlock(blockStore, address);
|
Block b1 = FakeTxBuilder.makeSolvedTestBlock(blockStore, address);
|
||||||
inbound(p1, b1);
|
inbound(p1, b1);
|
||||||
assertNull(outbound(p1));
|
assertNull(outbound(p1));
|
||||||
assertEquals(Utils.toNanoCoins(50, 0), wallet.getBalance());
|
assertEquals(Utils.toNanoCoins(50, 0), wallet.getBalance());
|
||||||
@ -140,7 +141,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
|
|||||||
InboundMessageQueuer p2 = connectPeer(2);
|
InboundMessageQueuer p2 = connectPeer(2);
|
||||||
|
|
||||||
// Send ourselves a bit of money.
|
// Send ourselves a bit of money.
|
||||||
Block b1 = TestUtils.makeSolvedTestBlock(blockStore, address);
|
Block b1 = FakeTxBuilder.makeSolvedTestBlock(blockStore, address);
|
||||||
inbound(p1, b1);
|
inbound(p1, b1);
|
||||||
pingAndWait(p1);
|
pingAndWait(p1);
|
||||||
assertNull(outbound(p1));
|
assertNull(outbound(p1));
|
||||||
@ -178,7 +179,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
|
|||||||
assertEquals(transactions[0], sendResult.tx);
|
assertEquals(transactions[0], sendResult.tx);
|
||||||
assertEquals(1, transactions[0].getConfidence().numBroadcastPeers());
|
assertEquals(1, transactions[0].getConfidence().numBroadcastPeers());
|
||||||
// Confirm it.
|
// Confirm it.
|
||||||
Block b2 = TestUtils.createFakeBlock(blockStore, t1).block;
|
Block b2 = FakeTxBuilder.createFakeBlock(blockStore, t1).block;
|
||||||
inbound(p1, b2);
|
inbound(p1, b2);
|
||||||
pingAndWait(p1);
|
pingAndWait(p1);
|
||||||
assertNull(outbound(p1));
|
assertNull(outbound(p1));
|
||||||
|
@ -24,9 +24,9 @@ import com.google.bitcoin.crypto.KeyCrypterException;
|
|||||||
import com.google.bitcoin.crypto.KeyCrypterScrypt;
|
import com.google.bitcoin.crypto.KeyCrypterScrypt;
|
||||||
import com.google.bitcoin.crypto.TransactionSignature;
|
import com.google.bitcoin.crypto.TransactionSignature;
|
||||||
import com.google.bitcoin.store.WalletProtobufSerializer;
|
import com.google.bitcoin.store.WalletProtobufSerializer;
|
||||||
import com.google.bitcoin.utils.MockTransactionBroadcaster;
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
import com.google.bitcoin.utils.TestUtils;
|
import com.google.bitcoin.testing.MockTransactionBroadcaster;
|
||||||
import com.google.bitcoin.utils.TestWithWallet;
|
import com.google.bitcoin.testing.TestWithWallet;
|
||||||
import com.google.bitcoin.utils.Threading;
|
import com.google.bitcoin.utils.Threading;
|
||||||
import com.google.bitcoin.wallet.*;
|
import com.google.bitcoin.wallet.*;
|
||||||
import com.google.bitcoin.wallet.WalletTransaction.Pool;
|
import com.google.bitcoin.wallet.WalletTransaction.Pool;
|
||||||
@ -54,7 +54,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static com.google.bitcoin.core.Utils.*;
|
import static com.google.bitcoin.core.Utils.*;
|
||||||
import static com.google.bitcoin.utils.TestUtils.*;
|
import static com.google.bitcoin.testing.FakeTxBuilder.*;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@ -771,7 +771,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
send1.getConfidence().getConfidenceType());
|
send1.getConfidence().getConfidenceType());
|
||||||
assertEquals(send2, received.getOutput(0).getSpentBy().getParentTransaction());
|
assertEquals(send2, received.getOutput(0).getSpentBy().getParentTransaction());
|
||||||
|
|
||||||
TestUtils.DoubleSpends doubleSpends = TestUtils.createFakeDoubleSpendTxns(params, myAddress);
|
FakeTxBuilder.DoubleSpends doubleSpends = FakeTxBuilder.createFakeDoubleSpendTxns(params, myAddress);
|
||||||
// t1 spends to our wallet. t2 double spends somewhere else.
|
// t1 spends to our wallet. t2 double spends somewhere else.
|
||||||
wallet.receivePending(doubleSpends.t1, null);
|
wallet.receivePending(doubleSpends.t1, null);
|
||||||
assertEquals(TransactionConfidence.ConfidenceType.PENDING,
|
assertEquals(TransactionConfidence.ConfidenceType.PENDING,
|
||||||
|
@ -18,7 +18,7 @@ package com.google.bitcoin.protocols.channels;
|
|||||||
|
|
||||||
import com.google.bitcoin.core.*;
|
import com.google.bitcoin.core.*;
|
||||||
import com.google.bitcoin.store.WalletProtobufSerializer;
|
import com.google.bitcoin.store.WalletProtobufSerializer;
|
||||||
import com.google.bitcoin.utils.TestWithWallet;
|
import com.google.bitcoin.testing.TestWithWallet;
|
||||||
import com.google.bitcoin.utils.Threading;
|
import com.google.bitcoin.utils.Threading;
|
||||||
import com.google.bitcoin.wallet.WalletFiles;
|
import com.google.bitcoin.wallet.WalletFiles;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@ -40,7 +40,7 @@ import java.util.concurrent.*;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static com.google.bitcoin.protocols.channels.PaymentChannelCloseException.CloseReason;
|
import static com.google.bitcoin.protocols.channels.PaymentChannelCloseException.CloseReason;
|
||||||
import static com.google.bitcoin.utils.TestUtils.createFakeBlock;
|
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeBlock;
|
||||||
import static org.bitcoin.paymentchannel.Protos.TwoWayChannelMessage.MessageType;
|
import static org.bitcoin.paymentchannel.Protos.TwoWayChannelMessage.MessageType;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ package com.google.bitcoin.protocols.channels;
|
|||||||
import com.google.bitcoin.core.*;
|
import com.google.bitcoin.core.*;
|
||||||
import com.google.bitcoin.script.Script;
|
import com.google.bitcoin.script.Script;
|
||||||
import com.google.bitcoin.script.ScriptBuilder;
|
import com.google.bitcoin.script.ScriptBuilder;
|
||||||
import com.google.bitcoin.utils.TestWithWallet;
|
import com.google.bitcoin.testing.TestWithWallet;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
@ -34,8 +34,8 @@ import java.util.concurrent.BlockingQueue;
|
|||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
import static com.google.bitcoin.utils.TestUtils.createFakeTx;
|
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeTx;
|
||||||
import static com.google.bitcoin.utils.TestUtils.makeSolvedTestBlock;
|
import static com.google.bitcoin.testing.FakeTxBuilder.makeSolvedTestBlock;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class PaymentChannelStateTest extends TestWithWallet {
|
public class PaymentChannelStateTest extends TestWithWallet {
|
||||||
|
@ -23,8 +23,8 @@ import com.google.bitcoin.core.TransactionConfidence.ConfidenceType;
|
|||||||
import com.google.bitcoin.params.MainNetParams;
|
import com.google.bitcoin.params.MainNetParams;
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.script.ScriptBuilder;
|
import com.google.bitcoin.script.ScriptBuilder;
|
||||||
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
import com.google.bitcoin.utils.BriefLogFormatter;
|
import com.google.bitcoin.utils.BriefLogFormatter;
|
||||||
import com.google.bitcoin.utils.TestUtils;
|
|
||||||
import com.google.bitcoin.utils.Threading;
|
import com.google.bitcoin.utils.Threading;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import org.bitcoinj.wallet.Protos;
|
import org.bitcoinj.wallet.Protos;
|
||||||
@ -40,7 +40,7 @@ import java.util.Date;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.google.bitcoin.utils.TestUtils.createFakeTx;
|
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeTx;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class WalletProtobufSerializerTest {
|
public class WalletProtobufSerializerTest {
|
||||||
@ -125,7 +125,7 @@ public class WalletProtobufSerializerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void doubleSpend() throws Exception {
|
public void doubleSpend() throws Exception {
|
||||||
// Check that we can serialize double spends correctly, as this is a slightly tricky case.
|
// Check that we can serialize double spends correctly, as this is a slightly tricky case.
|
||||||
TestUtils.DoubleSpends doubleSpends = TestUtils.createFakeDoubleSpendTxns(params, myAddress);
|
FakeTxBuilder.DoubleSpends doubleSpends = FakeTxBuilder.createFakeDoubleSpendTxns(params, myAddress);
|
||||||
// t1 spends to our wallet.
|
// t1 spends to our wallet.
|
||||||
myWallet.receivePending(doubleSpends.t1, null);
|
myWallet.receivePending(doubleSpends.t1, null);
|
||||||
// t2 rolls back t1 and spends somewhere else.
|
// t2 rolls back t1 and spends somewhere else.
|
||||||
|
@ -19,8 +19,8 @@ package com.google.bitcoin.wallet;
|
|||||||
import com.google.bitcoin.core.*;
|
import com.google.bitcoin.core.*;
|
||||||
import com.google.bitcoin.params.RegTestParams;
|
import com.google.bitcoin.params.RegTestParams;
|
||||||
import com.google.bitcoin.params.UnitTestParams;
|
import com.google.bitcoin.params.UnitTestParams;
|
||||||
import com.google.bitcoin.utils.TestUtils;
|
import com.google.bitcoin.testing.FakeTxBuilder;
|
||||||
import com.google.bitcoin.utils.TestWithWallet;
|
import com.google.bitcoin.testing.TestWithWallet;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -96,7 +96,7 @@ public class DefaultCoinSelectorTest extends TestWithWallet {
|
|||||||
// and t3=0.01.
|
// and t3=0.01.
|
||||||
Transaction t1 = checkNotNull(sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN));
|
Transaction t1 = checkNotNull(sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN));
|
||||||
// Padding block.
|
// Padding block.
|
||||||
wallet.notifyNewBestBlock(TestUtils.createFakeBlock(blockStore).storedBlock);
|
wallet.notifyNewBestBlock(FakeTxBuilder.createFakeBlock(blockStore).storedBlock);
|
||||||
final BigInteger TWO_COINS = Utils.COIN.multiply(BigInteger.valueOf(2));
|
final BigInteger TWO_COINS = Utils.COIN.multiply(BigInteger.valueOf(2));
|
||||||
Transaction t2 = checkNotNull(sendMoneyToWallet(TWO_COINS, AbstractBlockChain.NewBlockType.BEST_CHAIN));
|
Transaction t2 = checkNotNull(sendMoneyToWallet(TWO_COINS, AbstractBlockChain.NewBlockType.BEST_CHAIN));
|
||||||
Transaction t3 = checkNotNull(sendMoneyToWallet(Utils.CENT, AbstractBlockChain.NewBlockType.BEST_CHAIN));
|
Transaction t3 = checkNotNull(sendMoneyToWallet(Utils.CENT, AbstractBlockChain.NewBlockType.BEST_CHAIN));
|
||||||
|
Loading…
Reference in New Issue
Block a user