### Question:
ECKey implements Serializable { public boolean isPubKeyCanonical() { return isPubKeyCanonical(pub.getEncoded(false)); } ECKey();  ECKey(SecureRandom secureRandom);  ECKey(@Nullable BigInteger priv, ECPoint pub); static ECPoint compressPoint(ECPoint uncompressed); static ECPoint decompressPoint(ECPoint compressed); static ECKey fromPrivate(BigInteger privKey); static ECKey fromPrivate(byte[] privKeyBytes); static ECKey fromPrivateAndPrecalculatedPublic(BigInteger priv, ECPoint pub); static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub); static ECKey fromPublicOnly(ECPoint pub); static ECKey fromPublicOnly(byte[] pub); ECKey decompress(); boolean isPubKeyOnly(); boolean hasPrivKey(); static byte[] publicKeyFromPrivate(BigInteger privKey, boolean compressed); byte[] getAddress(); byte[] getNodeId(); byte[] getPubKey(); byte[] getPubKey(boolean compressed); ECPoint getPubKeyPoint(); BigInteger getPrivKey(); String toString(); String toStringWithPrivate(); ECDSASignature doSign(byte[] input); ECDSASignature sign(byte[] messageHash); static ECKey signatureToKey(byte[] messageHash, String signatureBase64); byte[] decryptAES(byte[] cipher); static boolean verify(byte[] data, ECDSASignature signature, byte[] pub); boolean verify(byte[] sigHash, ECDSASignature signature); boolean isPubKeyCanonical(); static boolean isPubKeyCanonical(byte[] pubkey); @Nullable static ECKey recoverFromSignature(int recId, ECDSASignature sig, byte[] messageHash, boolean compressed); @Nullable byte[] getPrivKeyBytes(); @Override boolean equals(Object o); @Override int hashCode(); static final ECDomainParameters CURVE; static final BigInteger HALF_CURVE_ORDER; }### Answer:
@Test public void testIsPubKeyCanonicalCorect() { byte[] canonicalPubkey1 = new byte[65]; canonicalPubkey1[0] = 0x04; assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey1)); byte[] canonicalPubkey2 = new byte[33]; canonicalPubkey2[0] = 0x02; assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey2)); byte[] canonicalPubkey3 = new byte[33]; canonicalPubkey3[0] = 0x03; assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey3)); }
@Test public void testIsPubKeyCanonicalWrongLength() { byte[] nonCanonicalPubkey1 = new byte[64]; nonCanonicalPubkey1[0] = 0x04; assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey1)); byte[] nonCanonicalPubkey2 = new byte[32]; nonCanonicalPubkey2[0] = 0x02; assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey2)); byte[] nonCanonicalPubkey3 = new byte[32]; nonCanonicalPubkey3[0] = 0x03; assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey3)); }
@Test public void testIsPubKeyCanonicalWrongPrefix() { byte[] nonCanonicalPubkey4 = new byte[65]; assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey4)); byte[] nonCanonicalPubkey5 = new byte[33]; assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey5)); byte[] nonCanonicalPubkey6 = new byte[33]; assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey6)); }