diff --git a/substrate/core/application-crypto/src/ed25519.rs b/substrate/core/application-crypto/src/ed25519.rs index a1aef4a328..d5c4fd7bad 100644 --- a/substrate/core/application-crypto/src/ed25519.rs +++ b/substrate/core/application-crypto/src/ed25519.rs @@ -21,7 +21,7 @@ use crate::{RuntimePublic, KeyTypeId}; pub use primitives::ed25519::*; mod app { - use crate::key_types::ED25519; + use primitives::testing::ED25519; crate::app_crypto!(super, ED25519); } @@ -53,7 +53,14 @@ impl RuntimePublic for Public { #[cfg(test)] mod tests { use sr_primitives::{generic::BlockId, traits::ProvideRuntimeApi}; - use primitives::{testing::KeyStore, crypto::Pair, traits::BareCryptoStore as _}; + use primitives::{ + testing::{ + KeyStore, + ED25519, + }, + crypto::Pair, + traits::BareCryptoStore as _, + }; use test_client::{ TestClientBuilder, DefaultTestClientBuilderExt, TestClientBuilderExt, runtime::{TestAPI, app_crypto::ed25519::{AppPair, AppPublic}}, @@ -67,7 +74,7 @@ mod tests { .test_ed25519_crypto(&BlockId::Number(0)) .expect("Tests `ed25519` crypto."); - let key_pair = keystore.read().ed25519_key_pair(crate::key_types::ED25519, &public.as_ref()) + let key_pair = keystore.read().ed25519_key_pair(ED25519, &public.as_ref()) .expect("There should be at a `ed25519` key in the keystore for the given public key."); assert!(AppPair::verify(&signature, "ed25519", &AppPublic::from(key_pair.public()))); diff --git a/substrate/core/application-crypto/src/sr25519.rs b/substrate/core/application-crypto/src/sr25519.rs index c3cc9df267..93565a628f 100644 --- a/substrate/core/application-crypto/src/sr25519.rs +++ b/substrate/core/application-crypto/src/sr25519.rs @@ -21,7 +21,7 @@ use crate::{RuntimePublic, KeyTypeId}; pub use primitives::sr25519::*; mod app { - use crate::key_types::SR25519; + use primitives::testing::SR25519; crate::app_crypto!(super, SR25519); } @@ -53,7 +53,14 @@ impl RuntimePublic for Public { #[cfg(test)] mod tests { use sr_primitives::{generic::BlockId, traits::ProvideRuntimeApi}; - use primitives::{testing::KeyStore, crypto::Pair, traits::BareCryptoStore as _}; + use primitives::{ + testing::{ + KeyStore, + SR25519, + }, + crypto::Pair, + traits::BareCryptoStore as _, + }; use test_client::{ TestClientBuilder, DefaultTestClientBuilderExt, TestClientBuilderExt, runtime::{TestAPI, app_crypto::sr25519::{AppPair, AppPublic}}, @@ -67,7 +74,7 @@ mod tests { .test_sr25519_crypto(&BlockId::Number(0)) .expect("Tests `sr25519` crypto."); - let key_pair = keystore.read().sr25519_key_pair(crate::key_types::SR25519, public.as_ref()) + let key_pair = keystore.read().sr25519_key_pair(SR25519, public.as_ref()) .expect("There should be at a `sr25519` key in the keystore for the given public key."); assert!(AppPair::verify(&signature, "sr25519", &AppPublic::from(key_pair.public()))); diff --git a/substrate/core/keystore/src/lib.rs b/substrate/core/keystore/src/lib.rs index 9125ddbda6..c86e9f8b88 100644 --- a/substrate/core/keystore/src/lib.rs +++ b/substrate/core/keystore/src/lib.rs @@ -318,7 +318,7 @@ impl BareCryptoStore for Store { mod tests { use super::*; use tempdir::TempDir; - use primitives::crypto::{Ss58Codec, key_types}; + use primitives::{testing::{SR25519}, crypto::{Ss58Codec}}; #[test] fn basic_store() { @@ -410,14 +410,14 @@ mod tests { let key_pair = sr25519::AppPair::from_string(secret_uri, None).expect("Generates key pair"); store.write().insert_unknown( - key_types::SR25519, + SR25519, secret_uri, key_pair.public().as_ref(), ).expect("Inserts unknown key"); let store_key_pair = store.read().key_pair_by_type::( &key_pair.public(), - key_types::SR25519, + SR25519, ).expect("Gets key pair from keystore"); assert_eq!(key_pair.public(), store_key_pair.public()); diff --git a/substrate/core/primitives/src/crypto.rs b/substrate/core/primitives/src/crypto.rs index 5887866735..e2838315d1 100644 --- a/substrate/core/primitives/src/crypto.rs +++ b/substrate/core/primitives/src/crypto.rs @@ -780,10 +780,6 @@ impl<'a> TryFrom<&'a str> for KeyTypeId { pub mod key_types { use super::KeyTypeId; - /// Key type for generic S/R 25519 key. - pub const SR25519: KeyTypeId = KeyTypeId(*b"sr25"); - /// Key type for generic Ed25519 key. - pub const ED25519: KeyTypeId = KeyTypeId(*b"ed25"); /// Key type for Babe module, build-in. pub const BABE: KeyTypeId = KeyTypeId(*b"babe"); /// Key type for Grandpa module, build-in. diff --git a/substrate/core/primitives/src/testing.rs b/substrate/core/primitives/src/testing.rs index 932c8b9cb1..ccfc36af73 100644 --- a/substrate/core/primitives/src/testing.rs +++ b/substrate/core/primitives/src/testing.rs @@ -17,7 +17,14 @@ //! Types that should only be used for testing! #[cfg(feature = "std")] -use crate::{ed25519, sr25519, crypto::{Public, Pair, KeyTypeId}}; +use crate::{ed25519, sr25519, crypto::{Public, Pair}}; +use crate::crypto::KeyTypeId; // No idea why this import had to move from + // the previous line, but now the compiler is happy + +/// Key type for generic Ed25519 key. +pub const ED25519: KeyTypeId = KeyTypeId(*b"ed25"); +/// Key type for generic Sr 25519 key. +pub const SR25519: KeyTypeId = KeyTypeId(*b"sr25"); /// A keystore implementation usable in tests. #[cfg(feature = "std")] @@ -126,18 +133,20 @@ impl crate::traits::BareCryptoStore for KeyStore { #[cfg(test)] mod tests { use super::*; - use crate::{sr25519, crypto::key_types, traits::BareCryptoStore}; + use crate::{sr25519, traits::BareCryptoStore}; + use crate::testing::{ED25519, SR25519}; + #[test] fn store_key_and_extract() { let store = KeyStore::new(); let public = store.write() - .ed25519_generate_new(key_types::ED25519, None) + .ed25519_generate_new(ED25519, None) .expect("Genrates key"); let store_key_pair = store.read() - .ed25519_key_pair(key_types::ED25519, &public) + .ed25519_key_pair(ED25519, &public) .expect("Key should exists in store"); assert_eq!(public, store_key_pair.public()); @@ -151,13 +160,13 @@ mod tests { let key_pair = sr25519::Pair::from_string(secret_uri, None).expect("Generates key pair"); store.write().insert_unknown( - key_types::SR25519, + SR25519, secret_uri, key_pair.public().as_ref(), ).expect("Inserts unknown key"); let store_key_pair = store.read().sr25519_key_pair( - key_types::SR25519, + SR25519, &key_pair.public(), ).expect("Gets key pair from keystore"); diff --git a/substrate/core/rpc/src/author/tests.rs b/substrate/core/rpc/src/author/tests.rs index 861b65bfe7..1f652aec64 100644 --- a/substrate/core/rpc/src/author/tests.rs +++ b/substrate/core/rpc/src/author/tests.rs @@ -25,8 +25,8 @@ use transaction_pool::{ }; use futures::Stream; use primitives::{ - H256, blake2_256, hexdisplay::HexDisplay, traits::BareCryptoStore, testing::KeyStore, - ed25519, crypto::{key_types, Pair}, + H256, blake2_256, hexdisplay::HexDisplay, traits::BareCryptoStore, + testing::{ED25519, SR25519, KeyStore}, ed25519, crypto::Pair }; use test_client::{ self, AccountKeyring, runtime::{Extrinsic, Transfer, SessionKeys}, DefaultTestClientBuilderExt, @@ -198,13 +198,13 @@ fn should_insert_key() { let suri = "//Alice"; let key_pair = ed25519::Pair::from_string(suri, None).expect("Generates keypair"); p.insert_key( - String::from_utf8(key_types::ED25519.0.to_vec()).expect("Keytype is a valid string"), + String::from_utf8(ED25519.0.to_vec()).expect("Keytype is a valid string"), suri.to_string(), key_pair.public().0.to_vec().into(), ).expect("Insert key"); let store_key_pair = keystore.read() - .ed25519_key_pair(key_types::ED25519, &key_pair.public()).expect("Key exists in store"); + .ed25519_key_pair(ED25519, &key_pair.public()).expect("Key exists in store"); assert_eq!(key_pair.public(), store_key_pair.public()); } @@ -227,12 +227,12 @@ fn should_rotate_keys() { .expect("SessionKeys decode successfully"); let ed25519_key_pair = keystore.read().ed25519_key_pair( - key_types::ED25519, + ED25519, &session_keys.ed25519.clone().into(), ).expect("ed25519 key exists in store"); let sr25519_key_pair = keystore.read().sr25519_key_pair( - key_types::SR25519, + SR25519, &session_keys.sr25519.clone().into(), ).expect("sr25519 key exists in store"); diff --git a/substrate/core/sr-primitives/src/traits.rs b/substrate/core/sr-primitives/src/traits.rs index a2bc5bc6dc..de200bdf55 100644 --- a/substrate/core/sr-primitives/src/traits.rs +++ b/substrate/core/sr-primitives/src/traits.rs @@ -1180,13 +1180,14 @@ macro_rules! count { /// just the bytes of the key. /// /// ```rust -/// use sr_primitives::{impl_opaque_keys, key_types, KeyTypeId, app_crypto::{sr25519, ed25519}}; +/// use sr_primitives::{impl_opaque_keys, KeyTypeId, app_crypto::{sr25519, ed25519}}; +/// use primitives::testing::{SR25519, ED25519}; /// /// impl_opaque_keys! { /// pub struct Keys { -/// #[id(key_types::ED25519)] +/// #[id(ED25519)] /// pub ed25519: ed25519::AppPublic, -/// #[id(key_types::SR25519)] +/// #[id(SR25519)] /// pub sr25519: sr25519::AppPublic, /// } /// } diff --git a/substrate/core/test-runtime/src/lib.rs b/substrate/core/test-runtime/src/lib.rs index c3b05b53d4..815f43c3db 100644 --- a/substrate/core/test-runtime/src/lib.rs +++ b/substrate/core/test-runtime/src/lib.rs @@ -25,7 +25,14 @@ pub mod system; use rstd::{prelude::*, marker::PhantomData}; use codec::{Encode, Decode, Input, Error}; -use primitives::{Blake2Hasher, OpaqueMetadata}; +use primitives::{ + Blake2Hasher, + OpaqueMetadata, + testing::{ + ED25519, + SR25519, + } +}; use app_crypto::{ed25519, sr25519, RuntimeAppPublic}; pub use app_crypto; use trie_db::{TrieMut, Trie}; @@ -47,7 +54,7 @@ use sr_primitives::{ }, }; use runtime_version::RuntimeVersion; -pub use primitives::{hash::H256, crypto::key_types}; +pub use primitives::{hash::H256}; #[cfg(any(feature = "std", test))] use runtime_version::NativeVersion; use runtime_support::{impl_outer_origin, parameter_types}; @@ -446,9 +453,9 @@ fn code_using_trie() -> u64 { impl_opaque_keys! { pub struct SessionKeys { - #[id(key_types::ED25519)] + #[id(ED25519)] pub ed25519: ed25519::AppPublic, - #[id(key_types::SR25519)] + #[id(SR25519)] pub sr25519: sr25519::AppPublic, } } diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index bee5e7fc22..70bc1a00af 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -85,7 +85,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. spec_version: 160, - impl_version: 160, + impl_version: 161, apis: RUNTIME_API_VERSIONS, };