Add tests & Service's Configuration has optional fields that shouldn't be optional (#4842)

Related to #4776 
Related to https://github.com/paritytech/polkadot/pull/832

To summarize the changes:
1. I did not manage to validate with types the service's Configuration. But I did reduce the possibility of errors by moving all the "fill" functions to their respective structopts
2. I split params.rs to multiple modules: one module params for just CLI parameters and one module commands for CLI subcommands (and RunCmd). Every command and params are in their own file so things are grouped better together and easier to remove
3. I removed the run and run_subcommand helpers as they are not helping much anymore. Running a command is always a set of 3 commands: 1. init 2. update config 3. run. This still allow the user to change the config before arguments get parsed or right after.
4. I added tests for all subcommands.
5. [deleted]

Overall the aim is to improve the situation with the Configuration and the optional parameters, add tests, make the API more consistent and simpler.
This commit is contained in:
Cecile Tonglet
2020-02-21 13:53:01 +01:00
committed by GitHub
parent 1e3e6a75f9
commit e8000e7429
43 changed files with 3040 additions and 2400 deletions
+23 -1
View File
@@ -207,7 +207,7 @@ impl<G, E> Default for Configuration<G, E> {
impl<G, E> Configuration<G, E> {
/// Create a default config using `VersionInfo`
pub fn new(version: &VersionInfo) -> Self {
pub fn from_version(version: &VersionInfo) -> Self {
let mut config = Configuration::default();
config.impl_name = version.name;
config.impl_version = version.version;
@@ -254,6 +254,28 @@ impl<G, E> Configuration<G, E> {
pub fn expect_database(&self) -> &DatabaseConfig {
self.database.as_ref().expect("database must be specified")
}
/// Returns a string displaying the node role, special casing the sentry mode
/// (returning `SENTRY`), since the node technically has an `AUTHORITY` role but
/// doesn't participate.
pub fn display_role(&self) -> String {
if self.sentry_mode {
"SENTRY".to_string()
} else {
self.roles.to_string()
}
}
/// Use in memory keystore config when it is not required at all.
///
/// This function returns an error if the keystore is already set to something different than
/// `KeystoreConfig::None`.
pub fn use_in_memory_keystore(&mut self) -> Result<(), String> {
match &mut self.keystore {
cfg @ KeystoreConfig::None => { *cfg = KeystoreConfig::InMemory; Ok(()) },
_ => Err("Keystore config specified when it should not be!".into()),
}
}
}
/// Returns platform info