Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Runtime: avoid duplication and test all signature #14663

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions primitives/runtime/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
ashWhiteHat marked this conversation as resolved.
Show resolved Hide resolved
}
}
1 change: 0 additions & 1 deletion test-utils/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ std = [
"log/std",
"sp-offchain/std",
"sp-core/std",
"sp-core/std",
liamaharon marked this conversation as resolved.
Show resolved Hide resolved
"sp-std/std",
"sp-io/std",
"frame-support/std",
Expand Down