Skip to content

Commit

Permalink
PeerAddressTest: Tidy up parse and bitcoinSerialize tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Schildbach committed Apr 7, 2018
1 parent 321ac5d commit 144818e
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions core/src/test/java/org/bitcoinj/core/PeerAddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,23 @@

public class PeerAddressTest {
private static final NetworkParameters MAINNET = MainNetParams.get();

@Test
public void parse_ancientProtocolVersion() throws Exception {
// copied from https://en.bitcoin.it/wiki/Protocol_documentation#Network_address
String hex = "010000000000000000000000000000000000ffff0a000001208d";
PeerAddress pa = new PeerAddress(MAINNET, HEX.decode(hex), 0, 0);
assertEquals(26, pa.length);
assertEquals(VersionMessage.NODE_NETWORK, pa.getServices().longValue());
assertEquals("10.0.0.1", pa.getAddr().getHostAddress());
assertEquals(8333, pa.getPort());
}

@Test
public void testPeerAddressRoundtrip() throws Exception {
// copied verbatim from https://en.bitcoin.it/wiki/Protocol_specification#Network_address
String fromSpec = "010000000000000000000000000000000000ffff0a000001208d";
PeerAddress pa = new PeerAddress(MAINNET, HEX.decode(fromSpec), 0, 0);
String reserialized = Utils.HEX.encode(pa.unsafeBitcoinSerialize());
assertEquals(reserialized, fromSpec);
public void bitcoinSerialize_ancientProtocolVersion() throws Exception {
PeerAddress pa = new PeerAddress(MAINNET, InetAddress.getByName(null), 8333, 0, BigInteger.ZERO);
assertEquals(26, pa.length);
assertEquals("000000000000000000000000000000000000ffff7f000001208d", Utils.HEX.encode(pa.bitcoinSerialize()));
}

@Test
Expand Down Expand Up @@ -89,10 +98,4 @@ public void roundtrip_ipv6_ancientProtocolVersion() throws Exception {
assertEquals(BigInteger.ZERO, pa2.getServices());
assertEquals(-1, pa2.getTime());
}

@Test
public void testBitcoinSerialize() throws Exception {
PeerAddress pa = new PeerAddress(MAINNET, InetAddress.getByName(null), 8333, 0, BigInteger.ZERO);
assertEquals("000000000000000000000000000000000000ffff7f000001208d", Utils.HEX.encode(pa.bitcoinSerialize()));
}
}

0 comments on commit 144818e

Please sign in to comment.