Skip to content

Commit edafb88

Browse files
committed
Move key unit tests to key module
There are currently two unit tests in the `schnorr` module that are testing keys from the `key` module. This is possible because the tests are only testing the public interface, none the less they are better placed in the `key` module.
1 parent e3d21a3 commit edafb88

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

src/key.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,4 +1476,38 @@ mod test {
14761476
assert_tokens(&pk.readable(), &[Token::String(PK_STR)]);
14771477

14781478
}
1479+
1480+
#[test]
1481+
fn test_tweak_add_assign_then_tweak_add_check() {
1482+
let s = Secp256k1::new();
1483+
1484+
for _ in 0..10 {
1485+
let mut tweak = [0u8; 32];
1486+
thread_rng().fill_bytes(&mut tweak);
1487+
let (mut kp, mut pk) = s.generate_schnorrsig_keypair(&mut thread_rng());
1488+
let orig_pk = pk;
1489+
kp.tweak_add_assign(&s, &tweak).expect("Tweak error");
1490+
let parity = pk.tweak_add_assign(&s, &tweak).expect("Tweak error");
1491+
assert_eq!(XOnlyPublicKey::from_keypair(&kp), pk);
1492+
assert!(orig_pk.tweak_add_check(&s, &pk, parity, tweak));
1493+
}
1494+
}
1495+
1496+
#[test]
1497+
fn test_from_key_pubkey() {
1498+
let kpk1 = PublicKey::from_str(
1499+
"02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443",
1500+
)
1501+
.unwrap();
1502+
let kpk2 = PublicKey::from_str(
1503+
"0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07",
1504+
)
1505+
.unwrap();
1506+
1507+
let pk1 = XOnlyPublicKey::from(kpk1);
1508+
let pk2 = XOnlyPublicKey::from(kpk2);
1509+
1510+
assert_eq!(pk1.serialize()[..], kpk1.serialize()[1..]);
1511+
assert_eq!(pk2.serialize()[..], kpk2.serialize()[1..]);
1512+
}
14791513
}

src/schnorr.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -565,37 +565,4 @@ mod tests {
565565
assert_tokens(&pk.readable(), &[Token::Str(PK_STR)]);
566566
assert_tokens(&pk.readable(), &[Token::String(PK_STR)]);
567567
}
568-
#[test]
569-
fn test_addition() {
570-
let s = Secp256k1::new();
571-
572-
for _ in 0..10 {
573-
let mut tweak = [0u8; 32];
574-
thread_rng().fill_bytes(&mut tweak);
575-
let (mut kp, mut pk) = s.generate_schnorrsig_keypair(&mut thread_rng());
576-
let orig_pk = pk;
577-
kp.tweak_add_assign(&s, &tweak).expect("Tweak error");
578-
let parity = pk.tweak_add_assign(&s, &tweak).expect("Tweak error");
579-
assert_eq!(XOnlyPublicKey::from_keypair(&kp), pk);
580-
assert!(orig_pk.tweak_add_check(&s, &pk, parity, tweak));
581-
}
582-
}
583-
584-
#[test]
585-
fn test_from_key_pubkey() {
586-
let kpk1 = ::key::PublicKey::from_str(
587-
"02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443",
588-
)
589-
.unwrap();
590-
let kpk2 = ::key::PublicKey::from_str(
591-
"0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07",
592-
)
593-
.unwrap();
594-
595-
let pk1 = XOnlyPublicKey::from(kpk1);
596-
let pk2 = XOnlyPublicKey::from(kpk2);
597-
598-
assert_eq!(pk1.serialize()[..], kpk1.serialize()[1..]);
599-
assert_eq!(pk2.serialize()[..], kpk2.serialize()[1..]);
600-
}
601568
}

0 commit comments

Comments
 (0)