Add test for cli keystore path generation (#4571)

* Add test for cli keystore path generation

* Fix test
This commit is contained in:
Bastian Köcher
2020-01-11 18:47:26 +01:00
committed by GitHub
parent 070148e9fd
commit e8dd1205ee
7 changed files with 218 additions and 149 deletions
+6 -4
View File
@@ -165,10 +165,11 @@ fn new_full_parts<TBl, TRtApi, TExecDisp, TCfg, TGen, TCSExt>(
{
let keystore = match &config.keystore {
KeystoreConfig::Path { path, password } => Keystore::open(
path.clone().ok_or("No basepath configured")?,
path.clone(),
password.clone()
)?,
KeystoreConfig::InMemory => Keystore::new_in_memory()
KeystoreConfig::InMemory => Keystore::new_in_memory(),
KeystoreConfig::None => return Err("No keystore config provided!".into()),
};
let executor = NativeExecutor::<TExecDisp>::new(
@@ -289,10 +290,11 @@ where TGen: RuntimeGenesis, TCSExt: Extension {
>, Error> {
let keystore = match &config.keystore {
KeystoreConfig::Path { path, password } => Keystore::open(
path.clone().ok_or("No basepath configured")?,
path.clone(),
password.clone()
)?,
KeystoreConfig::InMemory => Keystore::new_in_memory()
KeystoreConfig::InMemory => Keystore::new_in_memory(),
KeystoreConfig::None => return Err("No keystore config provided!".into()),
};
let executor = NativeExecutor::<TExecDisp>::new(
+16 -7
View File
@@ -21,7 +21,7 @@ pub use sc_client_db::{kvdb::KeyValueDB, PruningMode};
pub use sc_network::config::{ExtTransport, NetworkConfiguration, Roles};
pub use sc_executor::WasmExecutionMethod;
use std::{path::PathBuf, net::SocketAddr, sync::Arc};
use std::{path::{PathBuf, Path}, net::SocketAddr, sync::Arc};
pub use sc_transaction_pool::txpool::Options as TransactionPoolOptions;
use sc_chain_spec::{ChainSpec, RuntimeGenesis, Extension, NoExtension};
use sp_core::crypto::Protected;
@@ -107,10 +107,12 @@ pub struct Configuration<C, G, E = NoExtension> {
/// Configuration of the client keystore.
#[derive(Clone)]
pub enum KeystoreConfig {
/// No config supplied.
None,
/// Keystore at a path on-disk. Recommended for native nodes.
Path {
/// The path of the keystore. Will panic if no path is specified.
path: Option<PathBuf>,
/// The path of the keystore.
path: PathBuf,
/// Node keystore's password.
password: Option<Protected<String>>
},
@@ -118,6 +120,16 @@ pub enum KeystoreConfig {
InMemory
}
impl KeystoreConfig {
/// Returns the path for the keystore.
pub fn path(&self) -> Option<&Path> {
match self {
Self::Path { path, .. } => Some(&path),
Self::None | Self::InMemory => None,
}
}
}
/// Configuration of the database of the client.
#[derive(Clone)]
pub enum DatabaseConfig {
@@ -150,10 +162,7 @@ impl<C, G, E> Configuration<C, G, E> where
roles: Roles::FULL,
transaction_pool: Default::default(),
network: Default::default(),
keystore: KeystoreConfig::Path {
path: config_dir.map(|c| c.join("keystore")),
password: None
},
keystore: KeystoreConfig::None,
database: DatabaseConfig::Path {
path: Default::default(),
cache_size: Default::default(),