From 33c8a670303fdc6360ab190eec090ae89d2c035a Mon Sep 17 00:00:00 2001 From: ashWhiteHat Date: Fri, 28 Jul 2023 11:17:50 +0900 Subject: [PATCH 1/3] runtime: all signature test --- primitives/runtime/src/traits.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/primitives/runtime/src/traits.rs b/primitives/runtime/src/traits.rs index 51d91958ab533..1919e331c1055 100644 --- a/primitives/runtime/src/traits.rs +++ b/primitives/runtime/src/traits.rs @@ -2301,9 +2301,23 @@ mod tests { use crate::codec::{Decode, Encode, Input}; use sp_core::{ crypto::{Pair, UncheckedFrom}, - ecdsa, + ecdsa, ed25519, sr25519, }; + macro_rules! signature_verify_test { + ($algorithm:ident) => { + let msg = &b"test-message"[..]; + let wrong_msg = &b"test-msg"[..]; + let (pair, _) = $algorithm::Pair::generate(); + + let signature = pair.sign(&msg); + assert!($algorithm::Pair::verify(&signature, msg, &pair.public())); + + assert!(signature.verify(msg, &pair.public())); + assert!(!signature.verify(wrong_msg, &pair.public())); + }; + } + mod t { use sp_application_crypto::{app_crypto, sr25519}; use sp_core::crypto::KeyTypeId; @@ -2414,14 +2428,9 @@ mod tests { } #[test] - fn ecdsa_verify_works() { - let msg = &b"test-message"[..]; - let (pair, _) = ecdsa::Pair::generate(); - - let signature = pair.sign(&msg); - assert!(ecdsa::Pair::verify(&signature, msg, &pair.public())); - - assert!(signature.verify(msg, &pair.public())); - assert!(signature.verify(msg, &pair.public())); + fn signature_verify_works() { + signature_verify_test!(ed25519); + signature_verify_test!(sr25519); + signature_verify_test!(ecdsa); } } From 71e87645a31dfccc4c602bbe80f33dc4c548340d Mon Sep 17 00:00:00 2001 From: ashWhiteHat Date: Fri, 28 Jul 2023 12:05:09 +0900 Subject: [PATCH 2/3] test-utils: remove std duplication --- test-utils/runtime/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 35c26a62be2d6..c9be74786e83a 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -76,7 +76,6 @@ std = [ "log/std", "sp-offchain/std", "sp-core/std", - "sp-core/std", "sp-std/std", "sp-io/std", "frame-support/std", From f8056910d0d8273c4e27915192d9a41a6aabf6df Mon Sep 17 00:00:00 2001 From: ashWhiteHat Date: Sat, 29 Jul 2023 09:31:31 +0900 Subject: [PATCH 3/3] runtime: add bls verify test --- primitives/runtime/src/traits.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/primitives/runtime/src/traits.rs b/primitives/runtime/src/traits.rs index 1919e331c1055..903a795cc1209 100644 --- a/primitives/runtime/src/traits.rs +++ b/primitives/runtime/src/traits.rs @@ -2299,6 +2299,8 @@ pub trait BlockNumberProvider { mod tests { use super::*; use crate::codec::{Decode, Encode, Input}; + #[cfg(feature = "bls-experimental")] + use sp_core::{bls377, bls381}; use sp_core::{ crypto::{Pair, UncheckedFrom}, ecdsa, ed25519, sr25519, @@ -2428,9 +2430,27 @@ mod tests { } #[test] - fn signature_verify_works() { + fn ed25519_verify_works() { signature_verify_test!(ed25519); + } + + #[test] + fn sr25519_verify_works() { signature_verify_test!(sr25519); + } + + #[test] + fn ecdsa_verify_works() { signature_verify_test!(ecdsa); } + + #[cfg(feature = "bls-experimental")] + fn bls377_verify_works() { + signature_verify_test!(bls377) + } + + #[cfg(feature = "bls-experimental")] + fn bls381_verify_works() { + signature_verify_test!(bls381) + } }