Skip to content

Commit

Permalink
Add tests for parsing Casper public keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
koxu1996 committed Feb 29, 2024
1 parent 455872d commit 3775a71
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions kairos-cli/src/crypto/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,32 @@ impl CasperPublicKey {
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_casper_ed25519_public_key() {
// This public key has a 01 prefix indicating Ed25519.
let bytes = hex::decode("01c377281132044bd3278b039925eeb3efdb9d99dd5f46d9ec6a764add34581af7").unwrap();
let result = CasperPublicKey::from_bytes(&bytes);
assert!(result.is_ok(), "Ed25519 public key should be parsed correctly");
}

#[test]
fn test_casper_secp256k1_public_key() {
// This public key has a 02 prefix indicating Secp256k1.
let bytes = hex::decode("0202e99759649fa63a72c685b72e696b30c90f1deabb02d0d9b1de45eb371a73e5bb").unwrap();
let result = CasperPublicKey::from_bytes(&bytes);
assert!(result.is_ok(), "Secp256k1 public key should be parsed correctly");
}

#[test]
fn test_casper_unrecognized_prefix() {
// Using a 99 prefix which is not recognized.
let bytes = hex::decode("99c377281132044bd3278b039925eeb3efdb9d99dd5f46d9ec6a764add34581af7").unwrap();
let result = CasperPublicKey::from_bytes(&bytes);
assert!(result.is_err(), "Unrecognized prefix should result in an error");
}
}

0 comments on commit 3775a71

Please sign in to comment.