Skip to content

Commit

Permalink
fix(identity): use test fixture for ed25519
Browse files Browse the repository at this point in the history
Use test fixture from libp2p/specs#537 for ed25519 roundtrip test.

Pull-Request: #4228.
  • Loading branch information
mxinden authored and thomaseizinger committed Aug 20, 2023
1 parent 162238e commit 33fa190
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions identity/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,16 +766,18 @@ mod tests {
#[test]
#[cfg(feature = "ed25519")]
#[cfg(feature = "peerid")]
fn keypair_protobuf_roundtrip() {
let expected_keypair = Keypair::generate_ed25519();
let expected_peer_id = expected_keypair.public().to_peer_id();

let encoded = expected_keypair.to_protobuf_encoding().unwrap();
fn keypair_protobuf_roundtrip_ed25519() {
let priv_key = Keypair::from_protobuf_encoding(&hex_literal::hex!(
"080112407e0830617c4a7de83925dfb2694556b12936c477a0e1feb2e148ec9da60fee7d1ed1e8fae2c4a144b8be8fd4b47bf3d3b34b871c3cacf6010f0e42d474fce27e"
))
.unwrap();

let keypair = Keypair::from_protobuf_encoding(&encoded).unwrap();
let peer_id = keypair.public().to_peer_id();
let pub_key = PublicKey::try_decode_protobuf(&hex_literal::hex!(
"080112201ed1e8fae2c4a144b8be8fd4b47bf3d3b34b871c3cacf6010f0e42d474fce27e"
))
.unwrap();

assert_eq!(expected_peer_id, peer_id);
roundtrip_protobuf_encoding(&priv_key, &pub_key, KeyType::Ed25519);
}

#[test]
Expand Down

0 comments on commit 33fa190

Please sign in to comment.