diff --git a/src/com/google/bitcoin/core/Message.java b/src/com/google/bitcoin/core/Message.java index c2cb49d0..540e06a8 100644 --- a/src/com/google/bitcoin/core/Message.java +++ b/src/com/google/bitcoin/core/Message.java @@ -153,9 +153,10 @@ public abstract class Message implements Serializable { cursor += 1; return ""; } + cursor += varInt.getSizeInBytes(); byte[] characters = new byte[(int)varInt.value]; System.arraycopy(bytes, cursor, characters, 0, characters.length); - cursor += varInt.getSizeInBytes(); + cursor += characters.length; try { return new String(characters, "UTF-8"); } catch (UnsupportedEncodingException e) { diff --git a/src/com/google/bitcoin/core/PeerAddress.java b/src/com/google/bitcoin/core/PeerAddress.java index 491c4b75..cb71c425 100644 --- a/src/com/google/bitcoin/core/PeerAddress.java +++ b/src/com/google/bitcoin/core/PeerAddress.java @@ -115,4 +115,14 @@ public class PeerAddress extends Message { public String toString() { return "[" + addr.getHostAddress() + "]:" + port; } + + @Override + public boolean equals(Object o) { + if (!(o instanceof PeerAddress)) return false; + PeerAddress other = (PeerAddress) o; + return other.addr.equals(addr) && + other.port == port && + other.services.equals(services) && + other.time == time; + } } diff --git a/src/com/google/bitcoin/core/PeerGroup.java b/src/com/google/bitcoin/core/PeerGroup.java index f2e70c80..3eb0dc1c 100644 --- a/src/com/google/bitcoin/core/PeerGroup.java +++ b/src/com/google/bitcoin/core/PeerGroup.java @@ -325,9 +325,9 @@ public class PeerGroup { } /** - * Download the blockchain from peers. + * Download the blockchain from peers.
* - *
This method wait until the download is complete. "Complete" is defined as downloading + * This method waits until the download is complete. "Complete" is defined as downloading * from at least one peer all the blocks that are in that peer's inventory. */ public void downloadBlockChain() { diff --git a/src/com/google/bitcoin/core/VersionMessage.java b/src/com/google/bitcoin/core/VersionMessage.java index 373c56ad..09ee18e3 100644 --- a/src/com/google/bitcoin/core/VersionMessage.java +++ b/src/com/google/bitcoin/core/VersionMessage.java @@ -124,4 +124,17 @@ public class VersionMessage extends Message { public boolean hasBlockChain() { return (localServices & NODE_NETWORK) == NODE_NETWORK; } + + @Override + public boolean equals(Object o) { + if (!(o instanceof VersionMessage)) return false; + VersionMessage other = (VersionMessage) o; + return other.bestHeight == bestHeight && + other.clientVersion == clientVersion && + other.localServices == localServices && + other.time == time && + other.subVer.equals(subVer) && + other.myAddr.equals(myAddr) && + other.theirAddr.equals(theirAddr); + } } diff --git a/tests/com/google/bitcoin/core/BitcoinSerializerTest.java b/tests/com/google/bitcoin/core/BitcoinSerializerTest.java index 92accb0f..fcad5fd1 100644 --- a/tests/com/google/bitcoin/core/BitcoinSerializerTest.java +++ b/tests/com/google/bitcoin/core/BitcoinSerializerTest.java @@ -62,6 +62,12 @@ public class BitcoinSerializerTest { assertEquals(31900, vm.clientVersion); assertEquals(1292899814L, vm.time); assertEquals(98645L, vm.bestHeight); + + // Standard version messsages don't use strings. Create one and round-trip here to check that works OK. + vm.subVer = "test string"; + byte[] bits = vm.bitcoinSerialize(); + VersionMessage vm2 = new VersionMessage(NetworkParameters.prodNet(), bits); + assertEquals(vm, vm2); }