From 5a673ebe7e7ede093527c5857780fcae0b2165a9 Mon Sep 17 00:00:00 2001
From: Mike Hearn
Date: Mon, 14 Oct 2013 12:33:04 +0200
Subject: [PATCH] Untabify
---
.../java/com/google/bitcoin/core/Block.java | 2 +-
.../java/com/google/bitcoin/core/Message.java | 8 +-
.../com/google/bitcoin/core/PeerGroup.java | 6 +-
.../com/google/bitcoin/kits/WalletAppKit.java | 66 +-
.../PaymentChannelClientConnection.java | 14 +-
.../channels/PaymentChannelClientState.java | 2 +-
.../PaymentChannelServerListener.java | 8 +-
.../channels/PaymentChannelServerState.java | 6 +-
.../protocols/niowrapper/ProtobufParser.java | 4 +-
.../bitcoin/store/H2FullPrunedBlockStore.java | 4 +-
.../utils/MockTransactionBroadcaster.java | 42 +-
.../bitcoin/core/BitcoinSerializerTest.java | 40 +-
.../bitcoin/core/BitcoindComparisonTool.java | 4 +-
.../bitcoin/core/LazyParseByteCacheTest.java | 726 +++++++++---------
.../com/google/bitcoin/core/WalletTest.java | 12 +-
.../bitcoin/discovery/SeedPeersTest.java | 42 +-
.../channels/ChannelConnectionTest.java | 56 +-
.../channels/PaymentChannelStateTest.java | 12 +-
18 files changed, 527 insertions(+), 527 deletions(-)
diff --git a/core/src/main/java/com/google/bitcoin/core/Block.java b/core/src/main/java/com/google/bitcoin/core/Block.java
index ca4101a6..371ed7d1 100644
--- a/core/src/main/java/com/google/bitcoin/core/Block.java
+++ b/core/src/main/java/com/google/bitcoin/core/Block.java
@@ -976,7 +976,7 @@ public class Block extends Message {
/**
* Returns a solved block that builds on top of this one. This exists for unit tests.
*/
- @VisibleForTesting
+ @VisibleForTesting
public Block createNextBlock(Address to, long time) {
return createNextBlock(to, null, time, EMPTY_BYTES, Utils.toNanoCoins(50, 0));
}
diff --git a/core/src/main/java/com/google/bitcoin/core/Message.java b/core/src/main/java/com/google/bitcoin/core/Message.java
index 11680ba2..48b2ed8b 100644
--- a/core/src/main/java/com/google/bitcoin/core/Message.java
+++ b/core/src/main/java/com/google/bitcoin/core/Message.java
@@ -505,10 +505,10 @@ public abstract class Message implements Serializable {
return cursor < bytes.length;
}
- /** Network parameters this message was created with. */
- public NetworkParameters getParams() {
- return params;
- }
+ /** Network parameters this message was created with. */
+ public NetworkParameters getParams() {
+ return params;
+ }
public static class LazyParseException extends RuntimeException {
private static final long serialVersionUID = 6971943053112975594L;
diff --git a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java
index 15ab6a74..86c4741f 100644
--- a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java
+++ b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java
@@ -402,9 +402,9 @@ public class PeerGroup extends AbstractIdleService implements TransactionBroadca
// Note that the default here means that no tx invs will be received if no wallet is ever added
lock.lock();
try {
- boolean spvMode = chain != null && !chain.shouldVerifyTransactions();
- boolean willSendFilter = spvMode && peerFilterProviders.size() > 0;
- ver.relayTxesBeforeFilter = !willSendFilter;
+ boolean spvMode = chain != null && !chain.shouldVerifyTransactions();
+ boolean willSendFilter = spvMode && peerFilterProviders.size() > 0;
+ ver.relayTxesBeforeFilter = !willSendFilter;
} finally {
lock.unlock();
}
diff --git a/core/src/main/java/com/google/bitcoin/kits/WalletAppKit.java b/core/src/main/java/com/google/bitcoin/kits/WalletAppKit.java
index 8321ebc1..8a6f74b2 100644
--- a/core/src/main/java/com/google/bitcoin/kits/WalletAppKit.java
+++ b/core/src/main/java/com/google/bitcoin/kits/WalletAppKit.java
@@ -227,28 +227,28 @@ public class WalletAppKit extends AbstractIdleService {
vPeerGroup.addWallet(vWallet);
onSetupCompleted();
- if (blockingStartup) {
- vPeerGroup.startAndWait();
- // Make sure we shut down cleanly.
- installShutdownHook();
- // TODO: Be able to use the provided download listener when doing a blocking startup.
- final DownloadListener listener = new DownloadListener();
- vPeerGroup.startBlockChainDownload(listener);
- listener.await();
- } else {
- Futures.addCallback(vPeerGroup.start(), new FutureCallback() {
- @Override
- public void onSuccess(State result) {
- final PeerEventListener l = downloadListener == null ? new DownloadListener() : downloadListener;
- vPeerGroup.startBlockChainDownload(l);
- }
+ if (blockingStartup) {
+ vPeerGroup.startAndWait();
+ // Make sure we shut down cleanly.
+ installShutdownHook();
+ // TODO: Be able to use the provided download listener when doing a blocking startup.
+ final DownloadListener listener = new DownloadListener();
+ vPeerGroup.startBlockChainDownload(listener);
+ listener.await();
+ } else {
+ Futures.addCallback(vPeerGroup.start(), new FutureCallback() {
+ @Override
+ public void onSuccess(State result) {
+ final PeerEventListener l = downloadListener == null ? new DownloadListener() : downloadListener;
+ vPeerGroup.startBlockChainDownload(l);
+ }
- @Override
- public void onFailure(Throwable t) {
- throw new RuntimeException(t);
- }
- });
- }
+ @Override
+ public void onFailure(Throwable t) {
+ throw new RuntimeException(t);
+ }
+ });
+ }
} catch (BlockStoreException e) {
throw new IOException(e);
} finally {
@@ -256,19 +256,19 @@ public class WalletAppKit extends AbstractIdleService {
}
}
- private void installShutdownHook() {
- if (autoStop) Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override public void run() {
- try {
- WalletAppKit.this.stopAndWait();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- });
- }
+ private void installShutdownHook() {
+ if (autoStop) Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override public void run() {
+ try {
+ WalletAppKit.this.stopAndWait();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
- @Override
+ @Override
protected void shutDown() throws Exception {
// Runs in a separate thread.
try {
diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientConnection.java b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientConnection.java
index 227eecb9..89717260 100644
--- a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientConnection.java
+++ b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientConnection.java
@@ -88,13 +88,13 @@ public class PaymentChannelClientConnection {
wireParser = new ProtobufParser(new ProtobufParser.Listener() {
@Override
public void messageReceived(ProtobufParser handler, Protos.TwoWayChannelMessage msg) {
- try {
- channelClient.receiveMessage(msg);
- } catch (ValueOutOfRangeException e) {
- // We should only get this exception during INITIATE, so channelOpen wasn't called yet.
- channelOpenFuture.setException(e);
- }
- }
+ try {
+ channelClient.receiveMessage(msg);
+ } catch (ValueOutOfRangeException e) {
+ // We should only get this exception during INITIATE, so channelOpen wasn't called yet.
+ channelOpenFuture.setException(e);
+ }
+ }
@Override
public void connectionOpen(ProtobufParser handler) {
diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientState.java b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientState.java
index ace449bc..936a32db 100644
--- a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientState.java
+++ b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelClientState.java
@@ -451,7 +451,7 @@ public class PaymentChannelClientState {
@VisibleForTesting synchronized void doStoreChannelInWallet(Sha256Hash id) {
StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates)
wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID);
- checkNotNull(channels, "You have not added the StoredPaymentChannelClientStates extension to the wallet.");
+ checkNotNull(channels, "You have not added the StoredPaymentChannelClientStates extension to the wallet.");
checkState(channels.getChannel(id, multisigContract.getHash()) == null);
storedChannel = new StoredClientChannel(id, multisigContract, refundTx, myKey, valueToMe, refundFees, true);
channels.putChannel(storedChannel);
diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerListener.java b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerListener.java
index 038af1c8..377abf0d 100644
--- a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerListener.java
+++ b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerListener.java
@@ -65,13 +65,13 @@ public class PaymentChannelServerListener {
public ServerHandler(final SocketAddress address, final int timeoutSeconds) {
paymentChannelManager = new PaymentChannelServer(broadcaster, wallet, minAcceptedChannelSize, new PaymentChannelServer.ServerConnection() {
@Override public void sendToClient(Protos.TwoWayChannelMessage msg) {
- socketProtobufHandler.write(msg);
+ socketProtobufHandler.write(msg);
}
@Override public void destroyConnection(PaymentChannelCloseException.CloseReason reason) {
if (closeReason != null)
closeReason = reason;
- socketProtobufHandler.closeConnection();
+ socketProtobufHandler.closeConnection();
}
@Override public void channelOpen(Sha256Hash contractHash) {
@@ -125,11 +125,11 @@ public class PaymentChannelServerListener {
private final PaymentChannelServer paymentChannelManager;
// The connection handler which puts/gets protobufs from the TCP socket
- private final ProtobufParser socketProtobufHandler;
+ private final ProtobufParser socketProtobufHandler;
// The listener which connects to socketProtobufHandler
private final ProtobufParser.Listener protobufHandlerListener;
- }
+ }
/**
* Binds to the given port and starts accepting new client connections.
diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerState.java b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerState.java
index ee4b89b7..c908011b 100644
--- a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerState.java
+++ b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerState.java
@@ -379,15 +379,15 @@ public class PaymentChannelServerState {
}
if (state != State.READY) {
// TODO: What is this codepath for?
- log.warn("Failed attempt to close a channel in state " + state);
+ log.warn("Failed attempt to close a channel in state " + state);
return closedFuture;
- }
+ }
if (bestValueToMe.equals(BigInteger.ZERO)) {
// TODO: This is bogus. We shouldn't allow the client to get into this state (where they open and close
// a channel without sending us any money). We should either send an error at this point, or require
// the submission of an initial zero-valued payment during the open phase.
- log.warn("Closing channel that never received any payments.");
+ log.warn("Closing channel that never received any payments.");
state = State.CLOSED;
closedFuture.set(null);
return closedFuture;
diff --git a/core/src/main/java/com/google/bitcoin/protocols/niowrapper/ProtobufParser.java b/core/src/main/java/com/google/bitcoin/protocols/niowrapper/ProtobufParser.java
index fd500b59..a7a78277 100644
--- a/core/src/main/java/com/google/bitcoin/protocols/niowrapper/ProtobufParser.java
+++ b/core/src/main/java/com/google/bitcoin/protocols/niowrapper/ProtobufParser.java
@@ -37,7 +37,7 @@ import static com.google.common.base.Preconditions.checkState;
* serialized protobuf
*/
public class ProtobufParser extends AbstractTimeoutHandler implements StreamParser {
- private static final Logger log = LoggerFactory.getLogger(ProtobufParser.class);
+ private static final Logger log = LoggerFactory.getLogger(ProtobufParser.class);
/**
* An interface which can be implemented to handle callbacks as new messages are generated and socket events occur.
@@ -110,7 +110,7 @@ public class ProtobufParser extends AbstractTim
@Override
protected void timeoutOccurred() {
- log.warn("Timeout occurred for " + handler);
+ log.warn("Timeout occurred for " + handler);
closeConnection();
}
diff --git a/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java b/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java
index 76d9ace6..21fa6f89 100644
--- a/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java
+++ b/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java
@@ -635,7 +635,7 @@ public class H2FullPrunedBlockStore implements FullPrunedBlockStore {
try {
s = conn.get()
.prepareStatement("SELECT height, value, scriptBytes FROM openOutputs " +
- "WHERE hash = ? AND index = ?");
+ "WHERE hash = ? AND index = ?");
s.setBytes(1, hash.getBytes());
// index is actually an unsigned int
s.setInt(2, (int)index);
@@ -664,7 +664,7 @@ public class H2FullPrunedBlockStore implements FullPrunedBlockStore {
PreparedStatement s = null;
try {
s = conn.get().prepareStatement("INSERT INTO openOutputs (hash, index, height, value, scriptBytes) " +
- "VALUES (?, ?, ?, ?, ?)");
+ "VALUES (?, ?, ?, ?, ?)");
s.setBytes(1, out.getHash().getBytes());
// index is actually an unsigned int
s.setInt(2, (int)out.getIndex());
diff --git a/core/src/main/java/com/google/bitcoin/utils/MockTransactionBroadcaster.java b/core/src/main/java/com/google/bitcoin/utils/MockTransactionBroadcaster.java
index 42dd9e46..b0d856b3 100644
--- a/core/src/main/java/com/google/bitcoin/utils/MockTransactionBroadcaster.java
+++ b/core/src/main/java/com/google/bitcoin/utils/MockTransactionBroadcaster.java
@@ -32,15 +32,15 @@ import java.util.concurrent.locks.ReentrantLock;
public class MockTransactionBroadcaster implements TransactionBroadcaster {
private final ReentrantLock lock = Threading.lock("mock tx broadcaster");
- public static class TxFuturePair {
- public Transaction tx;
- public SettableFuture future;
+ public static class TxFuturePair {
+ public Transaction tx;
+ public SettableFuture future;
- public TxFuturePair(Transaction tx, SettableFuture future) {
- this.tx = tx;
- this.future = future;
- }
- }
+ public TxFuturePair(Transaction tx, SettableFuture future) {
+ this.tx = tx;
+ this.future = future;
+ }
+ }
private final LinkedBlockingQueue broadcasts = new LinkedBlockingQueue();
@@ -70,19 +70,19 @@ public class MockTransactionBroadcaster implements TransactionBroadcaster {
}
}
- public Transaction waitForTransaction() {
- return waitForTxFuture().tx;
- }
+ public Transaction waitForTransaction() {
+ return waitForTxFuture().tx;
+ }
- public TxFuturePair waitForTxFuture() {
- try {
- return broadcasts.take();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
+ public TxFuturePair waitForTxFuture() {
+ try {
+ return broadcasts.take();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
- public int size() {
- return broadcasts.size();
- }
+ public int size() {
+ return broadcasts.size();
+ }
}
diff --git a/core/src/test/java/com/google/bitcoin/core/BitcoinSerializerTest.java b/core/src/test/java/com/google/bitcoin/core/BitcoinSerializerTest.java
index 91895b77..201c355b 100644
--- a/core/src/test/java/com/google/bitcoin/core/BitcoinSerializerTest.java
+++ b/core/src/test/java/com/google/bitcoin/core/BitcoinSerializerTest.java
@@ -53,7 +53,7 @@ public class BitcoinSerializerTest {
@Test
public void testAddr() throws Exception {
- BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get());
+ BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get());
// the actual data from https://en.bitcoin.it/wiki/Protocol_specification#addr
ByteArrayInputStream bais = new ByteArrayInputStream(addrMessage);
AddressMessage a = (AddressMessage)bs.deserialize(bais);
@@ -70,10 +70,10 @@ public class BitcoinSerializerTest {
@Test
public void testLazyParsing() throws Exception {
- BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get(), true, false);
-
- ByteArrayInputStream bais = new ByteArrayInputStream(txMessage);
- Transaction tx = (Transaction)bs.deserialize(bais);
+ BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get(), true, false);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(txMessage);
+ Transaction tx = (Transaction)bs.deserialize(bais);
assertNotNull(tx);
assertEquals(false, tx.isParsed());
assertEquals(true, tx.isCached());
@@ -88,16 +88,16 @@ public class BitcoinSerializerTest {
@Test
public void testCachedParsing() throws Exception {
- testCachedParsing(true);
- testCachedParsing(false);
+ testCachedParsing(true);
+ testCachedParsing(false);
}
private void testCachedParsing(boolean lazy) throws Exception {
- BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get(), lazy, true);
-
- //first try writing to a fields to ensure uncaching and children are not affected
- ByteArrayInputStream bais = new ByteArrayInputStream(txMessage);
- Transaction tx = (Transaction)bs.deserialize(bais);
+ BitcoinSerializer bs = new BitcoinSerializer(MainNetParams.get(), lazy, true);
+
+ //first try writing to a fields to ensure uncaching and children are not affected
+ ByteArrayInputStream bais = new ByteArrayInputStream(txMessage);
+ Transaction tx = (Transaction)bs.deserialize(bais);
assertNotNull(tx);
assertEquals(!lazy, tx.isParsed());
assertEquals(true, tx.isCached());
@@ -111,11 +111,11 @@ public class BitcoinSerializerTest {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bs.serialize(tx, bos);
assertEquals(true, !Arrays.equals(txMessage, bos.toByteArray()));
-
+
//now try writing to a child to ensure uncaching is propagated up to parent but not to siblings
- bais = new ByteArrayInputStream(txMessage);
- tx = (Transaction)bs.deserialize(bais);
- assertNotNull(tx);
+ bais = new ByteArrayInputStream(txMessage);
+ tx = (Transaction)bs.deserialize(bais);
+ assertNotNull(tx);
assertEquals(!lazy, tx.isParsed());
assertEquals(true, tx.isCached());
@@ -131,8 +131,8 @@ public class BitcoinSerializerTest {
//deserialize/reserialize to check for equals.
bais = new ByteArrayInputStream(txMessage);
- tx = (Transaction)bs.deserialize(bais);
- assertNotNull(tx);
+ tx = (Transaction)bs.deserialize(bais);
+ assertNotNull(tx);
assertEquals(!lazy, tx.isParsed());
assertEquals(true, tx.isCached());
bos = new ByteArrayOutputStream();
@@ -141,8 +141,8 @@ public class BitcoinSerializerTest {
//deserialize/reserialize to check for equals. Set a field to it's existing value to trigger uncache
bais = new ByteArrayInputStream(txMessage);
- tx = (Transaction)bs.deserialize(bais);
- assertNotNull(tx);
+ tx = (Transaction)bs.deserialize(bais);
+ assertNotNull(tx);
assertEquals(!lazy, tx.isParsed());
assertEquals(true, tx.isCached());
diff --git a/core/src/test/java/com/google/bitcoin/core/BitcoindComparisonTool.java b/core/src/test/java/com/google/bitcoin/core/BitcoindComparisonTool.java
index 18ea4c6a..d4c109f5 100644
--- a/core/src/test/java/com/google/bitcoin/core/BitcoindComparisonTool.java
+++ b/core/src/test/java/com/google/bitcoin/core/BitcoindComparisonTool.java
@@ -237,8 +237,8 @@ public class BitcoindComparisonTool {
}
log.info("Done testing.\n" +
- "Blocks which were not handled the same between bitcoind/bitcoinj: " + differingBlocks + "\n" +
- "Blocks which should/should not have been accepted but weren't/were: " + invalidBlocks + "\n" +
+ "Blocks which were not handled the same between bitcoind/bitcoinj: " + differingBlocks + "\n" +
+ "Blocks which should/should not have been accepted but weren't/were: " + invalidBlocks + "\n" +
"Transactions which were/weren't in memory pool but shouldn't/should have been: " + mempoolRulesFailed + "\n" +
"Unexpected inv messages: " + unexpectedInvs.get());
System.exit(differingBlocks > 0 || invalidBlocks > 0 || mempoolRulesFailed > 0 || unexpectedInvs.get() > 0 ? 1 : 0);
diff --git a/core/src/test/java/com/google/bitcoin/core/LazyParseByteCacheTest.java b/core/src/test/java/com/google/bitcoin/core/LazyParseByteCacheTest.java
index f7aa1c09..d0c12278 100644
--- a/core/src/test/java/com/google/bitcoin/core/LazyParseByteCacheTest.java
+++ b/core/src/test/java/com/google/bitcoin/core/LazyParseByteCacheTest.java
@@ -86,8 +86,8 @@ public class LazyParseByteCacheTest {
resetBlockStore();
Transaction tx1 = createFakeTx(unitTestParams,
- Utils.toNanoCoins(2, 0),
- wallet.getKeys().get(0).toAddress(unitTestParams));
+ Utils.toNanoCoins(2, 0),
+ wallet.getKeys().get(0).toAddress(unitTestParams));
//add a second input so can test granularity of byte cache.
Transaction prevTx = new Transaction(unitTestParams);
@@ -121,407 +121,407 @@ public class LazyParseByteCacheTest {
@Test
public void validateSetup() {
- byte[] b1 = new byte[] {1, 1, 1, 2, 3, 4, 5, 6, 7};
- byte[] b2 = new byte[] {1, 2, 3};
- assertTrue(arrayContains(b1, b2));
- assertTrue(arrayContains(txMessage, txMessagePart));
- assertTrue(arrayContains(tx1BytesWithHeader, tx1Bytes));
- assertTrue(arrayContains(tx2BytesWithHeader, tx2Bytes));
- assertTrue(arrayContains(b1BytesWithHeader, b1Bytes));
- assertTrue(arrayContains(b1BytesWithHeader, tx1Bytes));
- assertTrue(arrayContains(b1BytesWithHeader, tx2Bytes));
- assertFalse(arrayContains(tx1BytesWithHeader, b1Bytes));
+ byte[] b1 = new byte[] {1, 1, 1, 2, 3, 4, 5, 6, 7};
+ byte[] b2 = new byte[] {1, 2, 3};
+ assertTrue(arrayContains(b1, b2));
+ assertTrue(arrayContains(txMessage, txMessagePart));
+ assertTrue(arrayContains(tx1BytesWithHeader, tx1Bytes));
+ assertTrue(arrayContains(tx2BytesWithHeader, tx2Bytes));
+ assertTrue(arrayContains(b1BytesWithHeader, b1Bytes));
+ assertTrue(arrayContains(b1BytesWithHeader, tx1Bytes));
+ assertTrue(arrayContains(b1BytesWithHeader, tx2Bytes));
+ assertFalse(arrayContains(tx1BytesWithHeader, b1Bytes));
}
@Test
public void testTransactionsLazyRetain() throws Exception {
- testTransaction(MainNetParams.get(), txMessage, false, true, true);
- testTransaction(unitTestParams, tx1BytesWithHeader, false, true, true);
- testTransaction(unitTestParams, tx2BytesWithHeader, false, true, true);
+ testTransaction(MainNetParams.get(), txMessage, false, true, true);
+ testTransaction(unitTestParams, tx1BytesWithHeader, false, true, true);
+ testTransaction(unitTestParams, tx2BytesWithHeader, false, true, true);
}
@Test
public void testTransactionsLazyNoRetain() throws Exception {
- testTransaction(MainNetParams.get(), txMessage, false, true, false);
- testTransaction(unitTestParams, tx1BytesWithHeader, false, true, false);
- testTransaction(unitTestParams, tx2BytesWithHeader, false, true, false);
+ testTransaction(MainNetParams.get(), txMessage, false, true, false);
+ testTransaction(unitTestParams, tx1BytesWithHeader, false, true, false);
+ testTransaction(unitTestParams, tx2BytesWithHeader, false, true, false);
}
@Test
public void testTransactionsNoLazyNoRetain() throws Exception {
- testTransaction(MainNetParams.get(), txMessage, false, false, false);
- testTransaction(unitTestParams, tx1BytesWithHeader, false, false, false);
- testTransaction(unitTestParams, tx2BytesWithHeader, false, false, false);
+ testTransaction(MainNetParams.get(), txMessage, false, false, false);
+ testTransaction(unitTestParams, tx1BytesWithHeader, false, false, false);
+ testTransaction(unitTestParams, tx2BytesWithHeader, false, false, false);
}
@Test
public void testTransactionsNoLazyRetain() throws Exception {
- testTransaction(MainNetParams.get(), txMessage, false, false, true);
- testTransaction(unitTestParams, tx1BytesWithHeader, false, false, true);
- testTransaction(unitTestParams, tx2BytesWithHeader, false, false, true);
+ testTransaction(MainNetParams.get(), txMessage, false, false, true);
+ testTransaction(unitTestParams, tx1BytesWithHeader, false, false, true);
+ testTransaction(unitTestParams, tx2BytesWithHeader, false, false, true);
}
@Test
public void testBlockAll() throws Exception {
- testBlock(b1BytesWithHeader, false, false, false);
- testBlock(b1BytesWithHeader, false, true, true);
- testBlock(b1BytesWithHeader, false, true, false);
- testBlock(b1BytesWithHeader, false, false, true);
+ testBlock(b1BytesWithHeader, false, false, false);
+ testBlock(b1BytesWithHeader, false, true, true);
+ testBlock(b1BytesWithHeader, false, true, false);
+ testBlock(b1BytesWithHeader, false, false, true);
}
public void testBlock(byte[] blockBytes, boolean isChild, boolean lazy, boolean retain) throws Exception {
- //reference serializer to produce comparison serialization output after changes to
- //message structure.
- BitcoinSerializer bsRef = new BitcoinSerializer(unitTestParams, false, false);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- BitcoinSerializer bs = new BitcoinSerializer(unitTestParams, lazy, retain);
- Block b1;
- Block bRef;
- b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
- bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
-
- //verify our reference BitcoinSerializer produces matching byte array.
- bos.reset();
- bsRef.serialize(bRef, bos);
- assertTrue(Arrays.equals(bos.toByteArray(), blockBytes));
-
- //check lazy and retain status survive both before and after a serialization
- assertEquals(!lazy, b1.isParsedTransactions());
- assertEquals(!lazy, b1.isParsedHeader());
- if (b1.isParsedHeader())
- assertEquals(retain, b1.isHeaderBytesValid());
- if (b1.isParsedTransactions())
- assertEquals(retain, b1.isTransactionBytesValid());
-
- serDeser(bs, b1, blockBytes, null, null);
-
- assertEquals(!lazy, b1.isParsedTransactions());
- assertEquals(!lazy, b1.isParsedHeader());
- if (b1.isParsedHeader())
- assertEquals(retain, b1.isHeaderBytesValid());
- if (b1.isParsedTransactions())
- assertEquals(retain, b1.isTransactionBytesValid());
-
- //compare to ref block
- bos.reset();
- bsRef.serialize(bRef, bos);
- serDeser(bs, b1, bos.toByteArray(), null, null);
-
- //retrieve a value from a child
- b1.getTransactions();
- assertTrue(b1.isParsedTransactions());
- if (b1.getTransactions().size() > 0) {
- assertTrue(b1.isParsedTransactions());
- Transaction tx1 = b1.getTransactions().get(0);
-
- //this will always be true for all children of a block once they are retrieved.
- //the tx child inputs/outputs may not be parsed however.
-
- //no longer forced to parse if length not provided.
- //assertEquals(true, tx1.isParsed());
- if (tx1.isParsed())
- assertEquals(retain, tx1.isCached());
- else
- assertTrue(tx1.isCached());
-
- //does it still match ref block?
- serDeser(bs, b1, bos.toByteArray(), null, null);
+ //reference serializer to produce comparison serialization output after changes to
+ //message structure.
+ BitcoinSerializer bsRef = new BitcoinSerializer(unitTestParams, false, false);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ BitcoinSerializer bs = new BitcoinSerializer(unitTestParams, lazy, retain);
+ Block b1;
+ Block bRef;
+ b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
+ bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
+
+ //verify our reference BitcoinSerializer produces matching byte array.
+ bos.reset();
+ bsRef.serialize(bRef, bos);
+ assertTrue(Arrays.equals(bos.toByteArray(), blockBytes));
+
+ //check lazy and retain status survive both before and after a serialization
+ assertEquals(!lazy, b1.isParsedTransactions());
+ assertEquals(!lazy, b1.isParsedHeader());
+ if (b1.isParsedHeader())
+ assertEquals(retain, b1.isHeaderBytesValid());
+ if (b1.isParsedTransactions())
+ assertEquals(retain, b1.isTransactionBytesValid());
+
+ serDeser(bs, b1, blockBytes, null, null);
+
+ assertEquals(!lazy, b1.isParsedTransactions());
+ assertEquals(!lazy, b1.isParsedHeader());
+ if (b1.isParsedHeader())
+ assertEquals(retain, b1.isHeaderBytesValid());
+ if (b1.isParsedTransactions())
+ assertEquals(retain, b1.isTransactionBytesValid());
+
+ //compare to ref block
+ bos.reset();
+ bsRef.serialize(bRef, bos);
+ serDeser(bs, b1, bos.toByteArray(), null, null);
+
+ //retrieve a value from a child
+ b1.getTransactions();
+ assertTrue(b1.isParsedTransactions());
+ if (b1.getTransactions().size() > 0) {
+ assertTrue(b1.isParsedTransactions());
+ Transaction tx1 = b1.getTransactions().get(0);
+
+ //this will always be true for all children of a block once they are retrieved.
+ //the tx child inputs/outputs may not be parsed however.
+
+ //no longer forced to parse if length not provided.
+ //assertEquals(true, tx1.isParsed());
+ if (tx1.isParsed())
+ assertEquals(retain, tx1.isCached());
+ else
+ assertTrue(tx1.isCached());
+
+ //does it still match ref block?
+ serDeser(bs, b1, bos.toByteArray(), null, null);
}
-
- //refresh block
- b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
- bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
-
- //retrieve a value from header
- b1.getDifficultyTarget();
- assertTrue(b1.isParsedHeader());
- assertEquals(lazy, !b1.isParsedTransactions());
-
- //does it still match ref block?
- serDeser(bs, b1, bos.toByteArray(), null, null);
+
+ //refresh block
+ b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
+ bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
+
+ //retrieve a value from header
+ b1.getDifficultyTarget();
+ assertTrue(b1.isParsedHeader());
+ assertEquals(lazy, !b1.isParsedTransactions());
+
+ //does it still match ref block?
+ serDeser(bs, b1, bos.toByteArray(), null, null);
-
- //refresh block
- b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
- bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
-
- //retrieve a value from a child and header
- b1.getDifficultyTarget();
- assertTrue(b1.isParsedHeader());
- assertEquals(lazy, !b1.isParsedTransactions());
-
- b1.getTransactions();
- assertTrue(b1.isParsedTransactions());
- if (b1.getTransactions().size() > 0) {
- assertTrue(b1.isParsedTransactions());
- Transaction tx1 = b1.getTransactions().get(0);
-
- //no longer forced to parse if length not provided.
- //assertEquals(true, tx1.isParsed());
-
- if (tx1.isParsed())
- assertEquals(retain, tx1.isCached());
- else
- assertTrue(tx1.isCached());
+
+ //refresh block
+ b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
+ bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
+
+ //retrieve a value from a child and header
+ b1.getDifficultyTarget();
+ assertTrue(b1.isParsedHeader());
+ assertEquals(lazy, !b1.isParsedTransactions());
+
+ b1.getTransactions();
+ assertTrue(b1.isParsedTransactions());
+ if (b1.getTransactions().size() > 0) {
+ assertTrue(b1.isParsedTransactions());
+ Transaction tx1 = b1.getTransactions().get(0);
+
+ //no longer forced to parse if length not provided.
+ //assertEquals(true, tx1.isParsed());
+
+ if (tx1.isParsed())
+ assertEquals(retain, tx1.isCached());
+ else
+ assertTrue(tx1.isCached());
}
- //does it still match ref block?
- serDeser(bs, b1, bos.toByteArray(), null, null);
-
- //refresh block
- b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
- bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
-
- //change a value in header
- b1.setNonce(23);
- bRef.setNonce(23);
- assertTrue(b1.isParsedHeader());
- assertEquals(lazy, !b1.isParsedTransactions());
- assertFalse(b1.isHeaderBytesValid());
- if (b1.isParsedTransactions())
- assertEquals(retain , b1.isTransactionBytesValid());
- else
- assertEquals(true, b1.isTransactionBytesValid());
- //does it still match ref block?
- bos.reset();
- bsRef.serialize(bRef, bos);
- serDeser(bs, b1, bos.toByteArray(), null, null);
-
- //refresh block
- b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
- bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
-
- //retrieve a value from a child of a child
- b1.getTransactions();
- if (b1.getTransactions().size() > 0) {
- Transaction tx1 = b1.getTransactions().get(0);
-
- TransactionInput tin = tx1.getInputs().get(0);
-
- assertTrue(tx1.isParsed());
- assertTrue(b1.isParsedTransactions());
- assertEquals(!lazy, b1.isParsedHeader());
-
- assertEquals(!lazy, tin.isParsed());
- assertEquals(tin.isParsed() ? retain : true, tin.isCached());
-
- //does it still match ref tx?
- bos.reset();
- bsRef.serialize(bRef, bos);
- serDeser(bs, b1, bos.toByteArray(), null, null);
+ //does it still match ref block?
+ serDeser(bs, b1, bos.toByteArray(), null, null);
+
+ //refresh block
+ b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
+ bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
+
+ //change a value in header
+ b1.setNonce(23);
+ bRef.setNonce(23);
+ assertTrue(b1.isParsedHeader());
+ assertEquals(lazy, !b1.isParsedTransactions());
+ assertFalse(b1.isHeaderBytesValid());
+ if (b1.isParsedTransactions())
+ assertEquals(retain , b1.isTransactionBytesValid());
+ else
+ assertEquals(true, b1.isTransactionBytesValid());
+ //does it still match ref block?
+ bos.reset();
+ bsRef.serialize(bRef, bos);
+ serDeser(bs, b1, bos.toByteArray(), null, null);
+
+ //refresh block
+ b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
+ bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
+
+ //retrieve a value from a child of a child
+ b1.getTransactions();
+ if (b1.getTransactions().size() > 0) {
+ Transaction tx1 = b1.getTransactions().get(0);
+
+ TransactionInput tin = tx1.getInputs().get(0);
+
+ assertTrue(tx1.isParsed());
+ assertTrue(b1.isParsedTransactions());
+ assertEquals(!lazy, b1.isParsedHeader());
+
+ assertEquals(!lazy, tin.isParsed());
+ assertEquals(tin.isParsed() ? retain : true, tin.isCached());
+
+ //does it still match ref tx?
+ bos.reset();
+ bsRef.serialize(bRef, bos);
+ serDeser(bs, b1, bos.toByteArray(), null, null);
}
-
- //refresh block
- b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
- bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
-
- //add an input
- b1.getTransactions();
- if (b1.getTransactions().size() > 0) {
- Transaction tx1 = b1.getTransactions().get(0);
-
- if (tx1.getInputs().size() > 0) {
- tx1.addInput(tx1.getInputs().get(0));
- //replicate on reference tx
- bRef.getTransactions().get(0).addInput(bRef.getTransactions().get(0).getInputs().get(0));
-
- assertFalse(tx1.isCached());
- assertTrue(tx1.isParsed());
- assertFalse(b1.isTransactionBytesValid());
- assertTrue(b1.isParsedHeader());
-
- //confirm sibling cache status was unaffected
- if (tx1.getInputs().size() > 1) {
- boolean parsed = tx1.getInputs().get(1).isParsed();
- assertEquals(parsed ? retain : true, tx1.getInputs().get(1).isCached());
- assertEquals(!lazy, parsed);
- }
-
- //this has to be false. Altering a tx invalidates the merkle root.
- //when we have seperate merkle caching then the entire header won't need to be
- //invalidated.
- assertFalse(b1.isHeaderBytesValid());
-
- bos.reset();
- bsRef.serialize(bRef, bos);
- byte[] source = bos.toByteArray();
- //confirm we still match the reference tx.
- serDeser(bs, b1, source, null, null);
- }
-
- //does it still match ref tx?
- bos.reset();
- bsRef.serialize(bRef, bos);
- serDeser(bs, b1, bos.toByteArray(), null, null);
+
+ //refresh block
+ b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
+ bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
+
+ //add an input
+ b1.getTransactions();
+ if (b1.getTransactions().size() > 0) {
+ Transaction tx1 = b1.getTransactions().get(0);
+
+ if (tx1.getInputs().size() > 0) {
+ tx1.addInput(tx1.getInputs().get(0));
+ //replicate on reference tx
+ bRef.getTransactions().get(0).addInput(bRef.getTransactions().get(0).getInputs().get(0));
+
+ assertFalse(tx1.isCached());
+ assertTrue(tx1.isParsed());
+ assertFalse(b1.isTransactionBytesValid());
+ assertTrue(b1.isParsedHeader());
+
+ //confirm sibling cache status was unaffected
+ if (tx1.getInputs().size() > 1) {
+ boolean parsed = tx1.getInputs().get(1).isParsed();
+ assertEquals(parsed ? retain : true, tx1.getInputs().get(1).isCached());
+ assertEquals(!lazy, parsed);
+ }
+
+ //this has to be false. Altering a tx invalidates the merkle root.
+ //when we have seperate merkle caching then the entire header won't need to be
+ //invalidated.
+ assertFalse(b1.isHeaderBytesValid());
+
+ bos.reset();
+ bsRef.serialize(bRef, bos);
+ byte[] source = bos.toByteArray();
+ //confirm we still match the reference tx.
+ serDeser(bs, b1, source, null, null);
+ }
+
+ //does it still match ref tx?
+ bos.reset();
+ bsRef.serialize(bRef, bos);
+ serDeser(bs, b1, bos.toByteArray(), null, null);
}
-
- //refresh block
- b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
- Block b2 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
- bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
- Block bRef2 = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
-
- //reparent an input
- b1.getTransactions();
- if (b1.getTransactions().size() > 0) {
- Transaction tx1 = b1.getTransactions().get(0);
- Transaction tx2 = b2.getTransactions().get(0);
-
- if (tx1.getInputs().size() > 0) {
- TransactionInput fromTx1 = tx1.getInputs().get(0);
- tx2.addInput(fromTx1);
-
- //replicate on reference tx
- TransactionInput fromTxRef = bRef.getTransactions().get(0).getInputs().get(0);
- bRef2.getTransactions().get(0).addInput(fromTxRef);
-
- //b1 hasn't changed but it's no longer in the parent
- //chain of fromTx1 so has to have been uncached since it won't be
- //notified of changes throught the parent chain anymore.
- assertFalse(b1.isTransactionBytesValid());
-
- //b2 should have it's cache invalidated because it has changed.
- assertFalse(b2.isTransactionBytesValid());
-
- bos.reset();
- bsRef.serialize(bRef2, bos);
- byte[] source = bos.toByteArray();
- //confirm altered block matches altered ref block.
- serDeser(bs, b2, source, null, null);
- }
-
- //does unaltered block still match ref block?
- bos.reset();
- bsRef.serialize(bRef, bos);
- serDeser(bs, b1, bos.toByteArray(), null, null);
-
- //how about if we refresh it?
- bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
- bos.reset();
- bsRef.serialize(bRef, bos);
- serDeser(bs, b1, bos.toByteArray(), null, null);
+
+ //refresh block
+ b1 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
+ Block b2 = (Block) bs.deserialize(new ByteArrayInputStream(blockBytes));
+ bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
+ Block bRef2 = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
+
+ //reparent an input
+ b1.getTransactions();
+ if (b1.getTransactions().size() > 0) {
+ Transaction tx1 = b1.getTransactions().get(0);
+ Transaction tx2 = b2.getTransactions().get(0);
+
+ if (tx1.getInputs().size() > 0) {
+ TransactionInput fromTx1 = tx1.getInputs().get(0);
+ tx2.addInput(fromTx1);
+
+ //replicate on reference tx
+ TransactionInput fromTxRef = bRef.getTransactions().get(0).getInputs().get(0);
+ bRef2.getTransactions().get(0).addInput(fromTxRef);
+
+ //b1 hasn't changed but it's no longer in the parent
+ //chain of fromTx1 so has to have been uncached since it won't be
+ //notified of changes throught the parent chain anymore.
+ assertFalse(b1.isTransactionBytesValid());
+
+ //b2 should have it's cache invalidated because it has changed.
+ assertFalse(b2.isTransactionBytesValid());
+
+ bos.reset();
+ bsRef.serialize(bRef2, bos);
+ byte[] source = bos.toByteArray();
+ //confirm altered block matches altered ref block.
+ serDeser(bs, b2, source, null, null);
+ }
+
+ //does unaltered block still match ref block?
+ bos.reset();
+ bsRef.serialize(bRef, bos);
+ serDeser(bs, b1, bos.toByteArray(), null, null);
+
+ //how about if we refresh it?
+ bRef = (Block) bsRef.deserialize(new ByteArrayInputStream(blockBytes));
+ bos.reset();
+ bsRef.serialize(bRef, bos);
+ serDeser(bs, b1, bos.toByteArray(), null, null);
}
-
+
}
public void testTransaction(NetworkParameters params, byte[] txBytes, boolean isChild, boolean lazy, boolean retain) throws Exception {
-
- //reference serializer to produce comparison serialization output after changes to
- //message structure.
- BitcoinSerializer bsRef = new BitcoinSerializer(params, false, false);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- BitcoinSerializer bs = new BitcoinSerializer(params, lazy, retain);
- Transaction t1;
- Transaction tRef;
- t1 = (Transaction) bs.deserialize(new ByteArrayInputStream(txBytes));
- tRef = (Transaction) bsRef.deserialize(new ByteArrayInputStream(txBytes));
-
- //verify our reference BitcoinSerializer produces matching byte array.
- bos.reset();
- bsRef.serialize(tRef, bos);
- assertTrue(Arrays.equals(bos.toByteArray(), txBytes));
-
- //check lazy and retain status survive both before and after a serialization
- assertEquals(!lazy, t1.isParsed());
- if (t1.isParsed())
- assertEquals(retain, t1.isCached());
-
- serDeser(bs, t1, txBytes, null, null);
-
- assertEquals(lazy, !t1.isParsed());
- if (t1.isParsed())
- assertEquals(retain, t1.isCached());
-
- //compare to ref tx
- bos.reset();
- bsRef.serialize(tRef, bos);
- serDeser(bs, t1, bos.toByteArray(), null, null);
-
- //retrieve a value from a child
- t1.getInputs();
- assertTrue(t1.isParsed());
- if (t1.getInputs().size() > 0) {
- assertTrue(t1.isParsed());
- TransactionInput tin = t1.getInputs().get(0);
- assertEquals(!lazy, tin.isParsed());
- if (tin.isParsed())
- assertEquals(retain, tin.isCached());
-
- //does it still match ref tx?
- serDeser(bs, t1, bos.toByteArray(), null, null);
- }
-
- //refresh tx
- t1 = (Transaction) bs.deserialize(new ByteArrayInputStream(txBytes));
- tRef = (Transaction) bsRef.deserialize(new ByteArrayInputStream(txBytes));
-
- //add an input
- if (t1.getInputs().size() > 0) {
-
- t1.addInput(t1.getInputs().get(0));
-
- //replicate on reference tx
- tRef.addInput(tRef.getInputs().get(0));
-
- assertFalse(t1.isCached());
- assertTrue(t1.isParsed());
-
- bos.reset();
- bsRef.serialize(tRef, bos);
- byte[] source = bos.toByteArray();
- //confirm we still match the reference tx.
- serDeser(bs, t1, source, null, null);
- }
-
+
+ //reference serializer to produce comparison serialization output after changes to
+ //message structure.
+ BitcoinSerializer bsRef = new BitcoinSerializer(params, false, false);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ BitcoinSerializer bs = new BitcoinSerializer(params, lazy, retain);
+ Transaction t1;
+ Transaction tRef;
+ t1 = (Transaction) bs.deserialize(new ByteArrayInputStream(txBytes));
+ tRef = (Transaction) bsRef.deserialize(new ByteArrayInputStream(txBytes));
+
+ //verify our reference BitcoinSerializer produces matching byte array.
+ bos.reset();
+ bsRef.serialize(tRef, bos);
+ assertTrue(Arrays.equals(bos.toByteArray(), txBytes));
+
+ //check lazy and retain status survive both before and after a serialization
+ assertEquals(!lazy, t1.isParsed());
+ if (t1.isParsed())
+ assertEquals(retain, t1.isCached());
+
+ serDeser(bs, t1, txBytes, null, null);
+
+ assertEquals(lazy, !t1.isParsed());
+ if (t1.isParsed())
+ assertEquals(retain, t1.isCached());
+
+ //compare to ref tx
+ bos.reset();
+ bsRef.serialize(tRef, bos);
+ serDeser(bs, t1, bos.toByteArray(), null, null);
+
+ //retrieve a value from a child
+ t1.getInputs();
+ assertTrue(t1.isParsed());
+ if (t1.getInputs().size() > 0) {
+ assertTrue(t1.isParsed());
+ TransactionInput tin = t1.getInputs().get(0);
+ assertEquals(!lazy, tin.isParsed());
+ if (tin.isParsed())
+ assertEquals(retain, tin.isCached());
+
+ //does it still match ref tx?
+ serDeser(bs, t1, bos.toByteArray(), null, null);
+ }
+
+ //refresh tx
+ t1 = (Transaction) bs.deserialize(new ByteArrayInputStream(txBytes));
+ tRef = (Transaction) bsRef.deserialize(new ByteArrayInputStream(txBytes));
+
+ //add an input
+ if (t1.getInputs().size() > 0) {
+
+ t1.addInput(t1.getInputs().get(0));
+
+ //replicate on reference tx
+ tRef.addInput(tRef.getInputs().get(0));
+
+ assertFalse(t1.isCached());
+ assertTrue(t1.isParsed());
+
+ bos.reset();
+ bsRef.serialize(tRef, bos);
+ byte[] source = bos.toByteArray();
+ //confirm we still match the reference tx.
+ serDeser(bs, t1, source, null, null);
+ }
+
}
private void serDeser(BitcoinSerializer bs, Message message, byte[] sourceBytes, byte[] containedBytes, byte[] containingBytes) throws Exception {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- bs.serialize(message, bos);
- byte[] b1 = bos.toByteArray();
-
- Message m2 = bs.deserialize(new ByteArrayInputStream(b1));
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ bs.serialize(message, bos);
+ byte[] b1 = bos.toByteArray();
+
+ Message m2 = bs.deserialize(new ByteArrayInputStream(b1));
- assertEquals(message, m2);
+ assertEquals(message, m2);
- bos.reset();
- bs.serialize(m2, bos);
- byte[] b2 = bos.toByteArray();
- assertTrue(Arrays.equals(b1, b2));
-
- if (sourceBytes != null) {
- assertTrue(arrayContains(sourceBytes, b1));
-
- assertTrue(arrayContains(sourceBytes, b2));
- }
-
- if (containedBytes != null) {
- assertTrue(arrayContains(b1, containedBytes));
- }
- if (containingBytes != null) {
- assertTrue(arrayContains(containingBytes, b1));
- }
+ bos.reset();
+ bs.serialize(m2, bos);
+ byte[] b2 = bos.toByteArray();
+ assertTrue(Arrays.equals(b1, b2));
+
+ if (sourceBytes != null) {
+ assertTrue(arrayContains(sourceBytes, b1));
+
+ assertTrue(arrayContains(sourceBytes, b2));
+ }
+
+ if (containedBytes != null) {
+ assertTrue(arrayContains(b1, containedBytes));
+ }
+ if (containingBytes != null) {
+ assertTrue(arrayContains(containingBytes, b1));
+ }
}
public static boolean arrayContains(byte[] sup, byte[] sub) {
- if (sup.length < sub.length)
- return false;
-
- String superstring = Utils.bytesToHexString(sup);
- String substring = Utils.bytesToHexString(sub);
-
- int ind = superstring.indexOf(substring);
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < superstring.indexOf(substring); i++)
- sb.append(" ");
-
- //System.out.println(superstring);
- //System.out.println(sb.append(substring).toString());
- //System.out.println();
- return ind > -1;
-
+ if (sup.length < sub.length)
+ return false;
+
+ String superstring = Utils.bytesToHexString(sup);
+ String substring = Utils.bytesToHexString(sub);
+
+ int ind = superstring.indexOf(substring);
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < superstring.indexOf(substring); i++)
+ sb.append(" ");
+
+ //System.out.println(superstring);
+ //System.out.println(sb.append(substring).toString());
+ //System.out.println();
+ return ind > -1;
+
}
}
diff --git a/core/src/test/java/com/google/bitcoin/core/WalletTest.java b/core/src/test/java/com/google/bitcoin/core/WalletTest.java
index beb1b5f1..fe45bcdf 100644
--- a/core/src/test/java/com/google/bitcoin/core/WalletTest.java
+++ b/core/src/test/java/com/google/bitcoin/core/WalletTest.java
@@ -97,13 +97,13 @@ public class WalletTest extends TestWithWallet {
myEncryptedAddress2 = myEncryptedKey2.toAddress(params);
}
- @After
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
- @Test
+ @Test
public void basicSpending() throws Exception {
basicSpendingCommon(wallet, myAddress, false);
}
diff --git a/core/src/test/java/com/google/bitcoin/discovery/SeedPeersTest.java b/core/src/test/java/com/google/bitcoin/discovery/SeedPeersTest.java
index 11715aa6..b929f6f3 100644
--- a/core/src/test/java/com/google/bitcoin/discovery/SeedPeersTest.java
+++ b/core/src/test/java/com/google/bitcoin/discovery/SeedPeersTest.java
@@ -26,25 +26,25 @@ import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
public class SeedPeersTest {
- @Test
- public void getPeer_one() throws Exception{
- SeedPeers seedPeers = new SeedPeers(MainNetParams.get());
- assertThat(seedPeers.getPeer(), notNullValue());
- }
-
- @Test
- public void getPeer_all() throws Exception{
- SeedPeers seedPeers = new SeedPeers(MainNetParams.get());
- for(int i = 0; i < SeedPeers.seedAddrs.length; ++i){
- assertThat("Failed on index: "+i, seedPeers.getPeer(), notNullValue());
- }
- assertThat(seedPeers.getPeer(), equalTo(null));
- }
-
- @Test
- public void getPeers_length() throws Exception{
- SeedPeers seedPeers = new SeedPeers(MainNetParams.get());
- InetSocketAddress[] addresses = seedPeers.getPeers(0, TimeUnit.SECONDS);
- assertThat(addresses.length, equalTo(SeedPeers.seedAddrs.length));
- }
+ @Test
+ public void getPeer_one() throws Exception{
+ SeedPeers seedPeers = new SeedPeers(MainNetParams.get());
+ assertThat(seedPeers.getPeer(), notNullValue());
+ }
+
+ @Test
+ public void getPeer_all() throws Exception{
+ SeedPeers seedPeers = new SeedPeers(MainNetParams.get());
+ for(int i = 0; i < SeedPeers.seedAddrs.length; ++i){
+ assertThat("Failed on index: "+i, seedPeers.getPeer(), notNullValue());
+ }
+ assertThat(seedPeers.getPeer(), equalTo(null));
+ }
+
+ @Test
+ public void getPeers_length() throws Exception{
+ SeedPeers seedPeers = new SeedPeers(MainNetParams.get());
+ InetSocketAddress[] addresses = seedPeers.getPeers(0, TimeUnit.SECONDS);
+ assertThat(addresses.length, equalTo(SeedPeers.seedAddrs.length));
+ }
}
diff --git a/core/src/test/java/com/google/bitcoin/protocols/channels/ChannelConnectionTest.java b/core/src/test/java/com/google/bitcoin/protocols/channels/ChannelConnectionTest.java
index 588b84c8..e941b96d 100644
--- a/core/src/test/java/com/google/bitcoin/protocols/channels/ChannelConnectionTest.java
+++ b/core/src/test/java/com/google/bitcoin/protocols/channels/ChannelConnectionTest.java
@@ -95,13 +95,13 @@ public class ChannelConnectionTest extends TestWithWallet {
Threading.warnOnLockCycles();
}
- @After
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
- @After
+ @After
public void checkFail() {
assertFalse(fail.get());
Threading.throwOnLockCycles();
@@ -523,28 +523,28 @@ public class ChannelConnectionTest extends TestWithWallet {
assertEquals(myValue, refund.getOutput(0).getValue());
}
- @Test
- public void testEmptyWallet() throws Exception {
- Wallet emptyWallet = new Wallet(params);
- emptyWallet.addKey(new ECKey());
- ChannelTestUtils.RecordingPair pair = ChannelTestUtils.makeRecorders(serverWallet, mockBroadcaster);
- PaymentChannelServer server = pair.server;
- PaymentChannelClient client = new PaymentChannelClient(emptyWallet, myKey, Utils.COIN, Sha256Hash.ZERO_HASH, pair.clientRecorder);
- client.connectionOpen();
- server.connectionOpen();
- server.receiveMessage(pair.clientRecorder.checkNextMsg(MessageType.CLIENT_VERSION));
- client.receiveMessage(pair.serverRecorder.checkNextMsg(MessageType.SERVER_VERSION));
- try {
- client.receiveMessage(Protos.TwoWayChannelMessage.newBuilder()
- .setInitiate(Protos.Initiate.newBuilder().setExpireTimeSecs(Utils.now().getTime() / 1000)
- .setMinAcceptedChannelSize(Utils.CENT.longValue())
- .setMultisigKey(ByteString.copyFrom(new ECKey().getPubKey())))
- .setType(MessageType.INITIATE).build());
- fail();
- } catch (ValueOutOfRangeException expected) {
- // This should be thrown.
- }
- }
+ @Test
+ public void testEmptyWallet() throws Exception {
+ Wallet emptyWallet = new Wallet(params);
+ emptyWallet.addKey(new ECKey());
+ ChannelTestUtils.RecordingPair pair = ChannelTestUtils.makeRecorders(serverWallet, mockBroadcaster);
+ PaymentChannelServer server = pair.server;
+ PaymentChannelClient client = new PaymentChannelClient(emptyWallet, myKey, Utils.COIN, Sha256Hash.ZERO_HASH, pair.clientRecorder);
+ client.connectionOpen();
+ server.connectionOpen();
+ server.receiveMessage(pair.clientRecorder.checkNextMsg(MessageType.CLIENT_VERSION));
+ client.receiveMessage(pair.serverRecorder.checkNextMsg(MessageType.SERVER_VERSION));
+ try {
+ client.receiveMessage(Protos.TwoWayChannelMessage.newBuilder()
+ .setInitiate(Protos.Initiate.newBuilder().setExpireTimeSecs(Utils.now().getTime() / 1000)
+ .setMinAcceptedChannelSize(Utils.CENT.longValue())
+ .setMultisigKey(ByteString.copyFrom(new ECKey().getPubKey())))
+ .setType(MessageType.INITIATE).build());
+ fail();
+ } catch (ValueOutOfRangeException expected) {
+ // This should be thrown.
+ }
+ }
@Test
public void testClientResumeNothing() throws Exception {
diff --git a/core/src/test/java/com/google/bitcoin/protocols/channels/PaymentChannelStateTest.java b/core/src/test/java/com/google/bitcoin/protocols/channels/PaymentChannelStateTest.java
index bab5f790..e97b9451 100644
--- a/core/src/test/java/com/google/bitcoin/protocols/channels/PaymentChannelStateTest.java
+++ b/core/src/test/java/com/google/bitcoin/protocols/channels/PaymentChannelStateTest.java
@@ -86,13 +86,13 @@ public class PaymentChannelStateTest extends TestWithWallet {
};
}
- @After
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
- @Test
+ @Test
public void stateErrors() throws Exception {
PaymentChannelClientState channelState = new PaymentChannelClientState(wallet, myKey, serverKey,
Utils.COIN.multiply(BigInteger.TEN), 20);