From 5fae845478f7c507085896aedef05e3be537de9f Mon Sep 17 00:00:00 2001 From: Sabine Proll Date: Fri, 10 Feb 2023 17:13:54 +0100 Subject: [PATCH 1/3] implement from for ExtrinsicSigner --- Cargo.lock | 1 + primitives/Cargo.toml | 1 + primitives/src/signer.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e0681ec54..c822b1631 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,6 +75,7 @@ dependencies = [ "frame-system", "hex", "impl-serde", + "kitchensink-runtime", "node-template-runtime", "pallet-assets", "pallet-balances", diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 8dcd93f5f..770bfd951 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -29,6 +29,7 @@ pallet-staking = { optional = true, git = "https://github.com/paritytech/substra [dev-dependencies] node-template-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" } +kitchensink-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" } [features] default = ["std"] diff --git a/primitives/src/signer.rs b/primitives/src/signer.rs index f1433aa10..62bd53401 100644 --- a/primitives/src/signer.rs +++ b/primitives/src/signer.rs @@ -90,3 +90,37 @@ where self.extrinsic_address.clone() } } + +impl From for ExtrinsicSigner +where + Signer: Pair, + Runtime: FrameSystemConfig, + Runtime::AccountId: From, +{ + fn from(value: Signer) -> Self { + ExtrinsicSigner::::new(value) + } +} + +#[cfg(test)] +mod tests { + use crate::ExtrinsicSigner; + use kitchensink_runtime::Runtime; + use sp_core::{sr25519, Pair}; + + #[test] + fn test_extrinsic_signer_from_sr25519_pair() { + let alice: sr25519::Pair = Pair::from_string( + "0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a", + None, + ) + .unwrap(); + + let es_from = + ExtrinsicSigner::::from(alice.clone()); + let es_new = + ExtrinsicSigner::::new(alice.clone()); + + assert_eq!(es_from.signer.public(), es_new.signer.public()); + } +} From d480246462c655fff89f55fa7444729422354c00 Mon Sep 17 00:00:00 2001 From: Sabine Proll Date: Mon, 13 Feb 2023 09:42:28 +0100 Subject: [PATCH 2/3] more realistic example in test (with .into() instead of from()) --- primitives/src/signer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/primitives/src/signer.rs b/primitives/src/signer.rs index 62bd53401..270ad0909 100644 --- a/primitives/src/signer.rs +++ b/primitives/src/signer.rs @@ -116,11 +116,11 @@ mod tests { ) .unwrap(); - let es_from = - ExtrinsicSigner::::from(alice.clone()); + let es_converted: ExtrinsicSigner = + alice.clone().into(); let es_new = ExtrinsicSigner::::new(alice.clone()); - assert_eq!(es_from.signer.public(), es_new.signer.public()); + assert_eq!(es_converted.signer.public(), es_new.signer.public()); } } From 13d154802d4550d8ce56eafc80ce00d97c7807a0 Mon Sep 17 00:00:00 2001 From: Sabine Proll Date: Mon, 13 Feb 2023 15:49:29 +0100 Subject: [PATCH 3/3] removed dependency on kitchen-sink + simplification in test --- Cargo.lock | 1 - primitives/Cargo.toml | 1 - primitives/src/signer.rs | 5 ++--- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c822b1631..e0681ec54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,7 +75,6 @@ dependencies = [ "frame-system", "hex", "impl-serde", - "kitchensink-runtime", "node-template-runtime", "pallet-assets", "pallet-balances", diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 770bfd951..8dcd93f5f 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -29,7 +29,6 @@ pallet-staking = { optional = true, git = "https://github.com/paritytech/substra [dev-dependencies] node-template-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" } -kitchensink-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" } [features] default = ["std"] diff --git a/primitives/src/signer.rs b/primitives/src/signer.rs index 270ad0909..877a37062 100644 --- a/primitives/src/signer.rs +++ b/primitives/src/signer.rs @@ -105,7 +105,7 @@ where #[cfg(test)] mod tests { use crate::ExtrinsicSigner; - use kitchensink_runtime::Runtime; + use node_template_runtime::Runtime; use sp_core::{sr25519, Pair}; #[test] @@ -116,8 +116,7 @@ mod tests { ) .unwrap(); - let es_converted: ExtrinsicSigner = - alice.clone().into(); + let es_converted: ExtrinsicSigner<_, _, Runtime> = alice.clone().into(); let es_new = ExtrinsicSigner::::new(alice.clone());