mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-30 23:02:15 +00:00
Fix Message.readStr(). Implement a unit test and some equals() methods. Resolves issue 79.
This commit is contained in:
parent
99385e7aee
commit
9009b83af5
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -325,9 +325,9 @@ public class PeerGroup {
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the blockchain from peers.
|
||||
* Download the blockchain from peers.<p>
|
||||
*
|
||||
* <p>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() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user