Add tests for XOnlyPublicKey functions
What changed, and why it matters
This commit only adds two new unit tests for existing XOnlyPublicKey functions. It does not change any production code, fix bugs, or alter behavior. There is no security issue here.
No action needed. This is a routine test-only commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds test coverage for XOnlyPublicKey::from_byte_array and XOnlyPublicKey::into_inner in bitcoin/src/crypto/key.rs. Both tests use a fixed 32-byte x-only public key hex string and assert round-trip equality. No implementation code was modified.
Changed components
bitcoin/src/crypto/key.rs (tests only)Inspect captured patch +23 / −0
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 1a8a2d32..16fdfbf6 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -1852,4 +1852,27 @@ mod tests {
assert!(PrivateKey::from_slice(&[1u8; 31], Network::Regtest).is_err());
assert!(PrivateKey::from_slice(&[1u8; 33], Network::Regtest).is_err());
}
+
+ #[test]
+ fn xonly_pubkey_from_bytes() {
+ let key_bytes = &<[u8; 32]>::from_hex(
+ "5b1e57ec453cd33fdc7cfc901450a3931fd315422558f2fb7fefb064e6e7d60d",
+ ).expect("Failed to convert hex string to byte array");
+ let xonly_pub_key = XOnlyPublicKey::from_byte_array(key_bytes)
+ .expect("Failed to create an XOnlyPublicKey from a byte array");
+ // Confirm that the public key from bytes serializes back to the same bytes
+ assert_eq!(&xonly_pub_key.serialize(), key_bytes);
+ }
+
+ #[test]
+ fn xonly_pubkey_into_inner() {
+ let key_bytes = &<[u8; 32]>::from_hex(
+ "5b1e57ec453cd33fdc7cfc901450a3931fd315422558f2fb7fefb064e6e7d60d",
+ ).expect("Failed to convert hex string to byte array");
+ let inner_key = secp256k1::XOnlyPublicKey::from_byte_array(key_bytes)
+ .expect("Failed to create a secp256k1 x-only public key from a byte array");
+ let btc_pubkey = XOnlyPublicKey::new(inner_key);
+ // Confirm that the into_inner() returns the same data that was initially wrapped
+ assert_eq!(inner_key, btc_pubkey.into_inner());
+ }
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.