Utils { public static byte[] addressStringToBytes(String hex) { final byte[] addr; try { addr = Hex.decode(hex); } catch (DecoderException addressIsNotValid) { return null; } if (isValidAddress(addr)) return addr; return null; }  static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static double JAVA_VERSION; }
@Test public void testAddressStringToBytes() { String HexStr = "6c386a4b26f73c802f34673f7248bb118f97424a"; byte[] expected = Hex.decode(HexStr); byte[] result = Utils.addressStringToBytes(HexStr); assertEquals(Arrays.areEqual(expected, result), true); HexStr = "6c386a4b26f73c802f34673f7248bb118f97424"; expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); HexStr = new String(Hex.encode("I am longer than 20 bytes, i promise".getBytes())); expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); HexStr = new String(Hex.encode("I am short".getBytes())); expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); }