Skip to content

Commit

Permalink
Break appcrypto dep cycle (paritytech#4347)
Browse files Browse the repository at this point in the history
* move application-crypto tests into seperate crate

* Fix crate name, update script and add docs

* pressing 'save' helps

* remove useless lines

* adding header

* split into actual modules
  • Loading branch information
gnunicorn authored and bkchr committed Dec 10, 2019
1 parent 52373bf commit d7c3fa2
Show file tree
Hide file tree
Showing 27 changed files with 174 additions and 100 deletions.
3 changes: 2 additions & 1 deletion .maintain/rename-crates-for-2.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ TO_RENAME=(
# OLD-CRATE-NAME NEW-CRATE-NAME

# PRIMITIVES
"substrate-application-crypto sc-application-crypto"
"substrate-application-crypto sp-application-crypto"
"sc-application-crypto sp-application-crypto"
"substrate-authority-discovery-primitives sp-authority-discovery"
"substrate-block-builder-runtime-api sp-block-builder"
"substrate-consensus-aura-primitives sp-consensus-aura"
Expand Down
63 changes: 35 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ members = [
"frame/treasury",
"frame/utility",
"primitives/application-crypto",
"primitives/application-crypto/test",
"primitives/authority-discovery",
"primitives/authorship",
"primitives/block-builder/runtime-api",
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "Aura consensus algorithm for substrate"
edition = "2018"

[dependencies]
app-crypto = { package = "sc-application-crypto", path = "../../../primitives/application-crypto" }
app-crypto = { package = "sp-application-crypto", path = "../../../primitives/application-crypto" }
aura_primitives = { package = "sp-consensus-aura", path = "../../../primitives/consensus/aura" }
block-builder-api = { package = "sp-block-builder", path = "../../../primitives/block-builder/runtime-api" }
client = { package = "sc-client", path = "../../" }
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] }
babe_primitives = { package = "sp-consensus-babe", path = "../../../primitives/consensus/babe" }
primitives = { package = "sp-core", path = "../../../primitives/core" }
app-crypto = { package = "sc-application-crypto", path = "../../../primitives/application-crypto" }
app-crypto = { package = "sp-application-crypto", path = "../../../primitives/application-crypto" }
num-bigint = "0.2.3"
num-rational = "0.2.2"
num-traits = "0.2.8"
Expand Down
2 changes: 1 addition & 1 deletion client/keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
derive_more = "0.99.2"
primitives = { package = "sp-core", path = "../../primitives/core" }
app-crypto = { package = "sc-application-crypto", path = "../../primitives/application-crypto" }
app-crypto = { package = "sp-application-crypto", path = "../../primitives/application-crypto" }
hex = "0.4.0"
rand = "0.7.2"
serde_json = "1.0.41"
Expand Down
2 changes: 1 addition & 1 deletion client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sp-runtime = { path = "../../primitives/runtime" }
sp-blockchain = { path = "../../primitives/blockchain" }
primitives = { package = "sp-core", path = "../../primitives/core" }
session = { package = "sp-session", path = "../../primitives/session" }
app-crypto = { package = "sc-application-crypto", path = "../../primitives/application-crypto" }
app-crypto = { package = "sp-application-crypto", path = "../../primitives/application-crypto" }
consensus_common = { package = "sp-consensus", path = "../../primitives/consensus/common" }
network = { package = "sc-network", path = "../network" }
chain-spec = { package = "sc-chain-spec", path = "../chain-spec" }
Expand Down
5 changes: 5 additions & 0 deletions docs/Upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Upgrade path for you building on substrate

## master
- crate rename has been fixed `sp-application-crypto` (was `sc-application-crypto`); `.maintain/rename-crates-for-2.0.sh` has been updated accordingly, you can use it to upgrade to latest naming convention
- crates have been renamed, run `bash .maintain/rename-crates-for-2.0.sh`
2 changes: 1 addition & 1 deletion frame/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
app-crypto = { package = "sc-application-crypto", path = "../../primitives/application-crypto", default-features = false }
app-crypto = { package = "sp-application-crypto", path = "../../primitives/application-crypto", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
inherents = { package = "sp-inherents", path = "../../primitives/inherents", default-features = false }
primitives = { package = "sp-core", path = "../../primitives/core", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion frame/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
authority-discovery-primitives = { package = "sp-authority-discovery", path = "../../primitives/authority-discovery", default-features = false }
app-crypto = { package = "sc-application-crypto", path = "../../primitives/application-crypto", default-features = false }
app-crypto = { package = "sp-application-crypto", path = "../../primitives/application-crypto", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
primitives = { package = "sp-core", path = "../../primitives/core", default-features = false }
sp-std = { path = "../../primitives/std", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion frame/im-online/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
app-crypto = { package = "sc-application-crypto", path = "../../primitives/application-crypto", default-features = false }
app-crypto = { package = "sp-application-crypto", path = "../../primitives/application-crypto", default-features = false }
authorship = { package = "pallet-authorship", path = "../authorship", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
primitives = { package="sp-core", path = "../../primitives/core", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion frame/session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl-trait-for-tuples = "0.1.3"

[dev-dependencies]
primitives = { package = "sp-core", path = "../../primitives/core" }
app-crypto = { package = "sc-application-crypto", path = "../../primitives/application-crypto" }
app-crypto = { package = "sp-application-crypto", path = "../../primitives/application-crypto" }
lazy_static = "1.4.0"

[features]
Expand Down
6 changes: 1 addition & 5 deletions primitives/application-crypto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "sc-application-crypto"
name = "sp-application-crypto"
version = "2.0.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"
Expand All @@ -12,10 +12,6 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] }
sp-std = { path = "../std", default-features = false }
sp-io = { path = "../../primitives/io", default-features = false }

[dev-dependencies]
test-client = { package = "substrate-test-runtime-client", path = "../../test/utils/runtime/client" }
sp-runtime = { path = "../../primitives/runtime" }

[features]
default = [ "std" ]
std = [ "full_crypto", "primitives/std", "codec/std", "serde", "sp-std/std", "sp-io/std" ]
Expand Down
23 changes: 0 additions & 23 deletions primitives/application-crypto/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,3 @@ impl RuntimePublic for Public {
}
}

#[cfg(test)]
mod tests {
use sp_runtime::{generic::BlockId, traits::ProvideRuntimeApi};
use primitives::{testing::{KeyStore, ED25519}, crypto::Pair};
use test_client::{
TestClientBuilder, DefaultTestClientBuilderExt, TestClientBuilderExt,
runtime::{TestAPI, app_crypto::ed25519::{AppPair, AppPublic}},
};

#[test]
fn ed25519_works_in_runtime() {
let keystore = KeyStore::new();
let test_client = TestClientBuilder::new().set_keystore(keystore.clone()).build();
let (signature, public) = test_client.runtime_api()
.test_ed25519_crypto(&BlockId::Number(0))
.expect("Tests `ed25519` crypto.");

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())));
}
}
6 changes: 3 additions & 3 deletions primitives/application-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub use traits::*;
/// Application-specific types whose identifier is `$key_type`.
///
/// ```rust
///# use sc_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
///# use sp_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
/// // Declare a new set of crypto types using Ed25519 logic that identifies as `KeyTypeId`
/// // of value `b"fuba"`.
/// app_crypto!(ed25519, KeyTypeId(*b"_uba"));
Expand All @@ -66,7 +66,7 @@ macro_rules! app_crypto {
/// Application-specific types whose identifier is `$key_type`.
///
/// ```rust
///# use sc_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
///# use sp_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
/// // Declare a new set of crypto types using Ed25519 logic that identifies as `KeyTypeId`
/// // of value `b"fuba"`.
/// app_crypto!(ed25519, KeyTypeId(*b"_uba"));
Expand Down Expand Up @@ -390,7 +390,7 @@ macro_rules! app_crypto_signature_common {
/// Implement bidirectional `From` and on-way `AsRef`/`AsMut` for two types, `$inner` and `$outer`.
///
/// ```rust
/// sc_application_crypto::wrap! {
/// sp_application_crypto::wrap! {
/// pub struct Wrapper(u32);
/// }
/// ```
Expand Down
Loading

0 comments on commit d7c3fa2

Please sign in to comment.