Address extends VersionedChecksummedBytes { public static Address fromBase58(@Nullable NetworkParameters params, String base58) throws AddressFormatException { return new Address(params, base58); } Address(NetworkParameters params, int version, byte[] hash160);  Address(NetworkParameters params, byte[] hash160); @Deprecated  Address(@Nullable NetworkParameters params, String address); static Address fromP2SHHash(NetworkParameters params, byte[] hash160); static Address fromP2SHScript(NetworkParameters params, Script scriptPubKey); static Address fromBase58(@Nullable NetworkParameters params, String base58); byte[] getHash160(); boolean isP2SHAddress(); NetworkParameters getParameters(); static NetworkParameters getParametersFromAddress(String address); @Override Address clone(); static final int LENGTH; }
@Test public void errorPaths() { try { Address.fromBase58(testParams, "this is not a valid address!"); fail(); } catch (WrongNetworkException e) { fail(); } catch (AddressFormatException e) { } try { Address.fromBase58(testParams, ""); fail(); } catch (WrongNetworkException e) { fail(); } catch (AddressFormatException e) { } try { Address.fromBase58(testParams, "Xtqn4ks8sJS7iG7S7r1Jf37eFFSJGwh8a8"); fail(); } catch (WrongNetworkException e) { assertEquals(e.verCode, MainNetParams.get().getAddressHeader()); assertTrue(Arrays.equals(e.acceptableVersions, TestNet3Params.get().getAcceptableAddressCodes())); } catch (AddressFormatException e) { fail(); } }
@Test public void roundtripBase58() throws Exception { String base58 = "Xtqn4ks8sJS7iG7S7r1Jf37eFFSJGwh8a8"; assertEquals(base58, Address.fromBase58(null, base58).toBase58()); }
@Test public void comparisonLessThan() throws Exception { Address a = Address.fromBase58(mainParams, "XoVhYqRxPWkCw8WjZfiHPYsoR7g4Ny3x7K"); Address b = Address.fromBase58(mainParams, "XpDe4AXdEf9NtW5ZBeGmuzy2VShg3qZMFQ"); int result = a.compareTo(b); assertTrue(result < 0); }
@Test public void comparisonGreaterThan() throws Exception { Address a = Address.fromBase58(mainParams, "XpDe4AXdEf9NtW5ZBeGmuzy2VShg3qZMFQ"); Address b = Address.fromBase58(mainParams, "XoVhYqRxPWkCw8WjZfiHPYsoR7g4Ny3x7K"); int result = a.compareTo(b); assertTrue(result > 0); }
@Test public void comparisonBytesVsString() throws Exception { Address a = Address.fromBase58(mainParams, "XoVhYqRxPWkCw8WjZfiHPYsoR7g4Ny3x7K"); Address b = Address.fromBase58(mainParams, "XpDe4AXdEf9NtW5ZBeGmuzy2VShg3qZMFQ"); int resultBytes = a.compareTo(b); int resultsString = a.toString().compareTo(b.toString()); assertTrue( resultBytes < 0 ); assertTrue( resultsString < 0 ); }
@Test public void errorPaths() { try { Address.fromBase58(testParams, "this is not a valid address!"); fail(); } catch (WrongNetworkException e) { fail(); } catch (AddressFormatException e) { } try { Address.fromBase58(testParams, ""); fail(); } catch (WrongNetworkException e) { fail(); } catch (AddressFormatException e) { } try { Address.fromBase58(testParams, "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL"); fail(); } catch (WrongNetworkException e) { assertEquals(e.verCode, MainNetParams.get().getAddressHeader()); assertTrue(Arrays.equals(e.acceptableVersions, TestNet3Params.get().getAcceptableAddressCodes())); } catch (AddressFormatException e) { fail(); } }
@Test public void roundtripBase58() throws Exception { String base58 = "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL"; assertEquals(base58, Address.fromBase58(null, base58).toBase58()); }
@Test public void comparisonLessThan() throws Exception { Address a = Address.fromBase58(mainParams, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX"); Address b = Address.fromBase58(mainParams, "1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P"); int result = a.compareTo(b); assertTrue(result < 0); }
@Test public void comparisonGreaterThan() throws Exception { Address a = Address.fromBase58(mainParams, "1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P"); Address b = Address.fromBase58(mainParams, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX"); int result = a.compareTo(b); assertTrue(result > 0); }
@Test public void comparisonBytesVsString() throws Exception { Address a = Address.fromBase58(mainParams, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX"); Address b = Address.fromBase58(mainParams, "1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P"); int resultBytes = a.compareTo(b); int resultsString = a.toString().compareTo(b.toString()); assertTrue( resultBytes < 0 ); assertTrue( resultsString < 0 ); }