mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +00:00
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:
@@ -16,9 +16,9 @@
|
||||
|
||||
use sp_runtime::{BuildStorage, traits::{Block as BlockT, Header as HeaderT, NumberFor}};
|
||||
use sc_client::StateMachine;
|
||||
use sc_cli::{ExecutionStrategy, WasmExecutionMethod};
|
||||
use sc_cli::{ExecutionStrategy, WasmExecutionMethod, VersionInfo};
|
||||
use sc_client_db::BenchmarkingState;
|
||||
use sc_service::{RuntimeGenesis, ChainSpecExtension};
|
||||
use sc_service::{RuntimeGenesis, ChainSpecExtension, Configuration, ChainSpec};
|
||||
use sc_executor::{NativeExecutor, NativeExecutionDispatch};
|
||||
use std::fmt::Debug;
|
||||
use codec::{Encode, Decode};
|
||||
@@ -68,26 +68,16 @@ pub struct BenchmarkCmd {
|
||||
}
|
||||
|
||||
impl BenchmarkCmd {
|
||||
/// Parse CLI arguments and initialize given config.
|
||||
pub fn init<G, E>(
|
||||
&self,
|
||||
config: &mut sc_service::config::Configuration<G, E>,
|
||||
spec_factory: impl FnOnce(&str) -> Result<Option<sc_service::ChainSpec<G, E>>, String>,
|
||||
version: &sc_cli::VersionInfo,
|
||||
) -> sc_cli::error::Result<()> where
|
||||
G: sc_service::RuntimeGenesis,
|
||||
E: sc_service::ChainSpecExtension,
|
||||
{
|
||||
sc_cli::init_config(config, &self.shared_params, version, spec_factory)?;
|
||||
// make sure to configure keystore
|
||||
sc_cli::fill_config_keystore_in_memory(config).map_err(Into::into)
|
||||
/// Initialize
|
||||
pub fn init(&self, version: &sc_cli::VersionInfo) -> sc_cli::Result<()> {
|
||||
self.shared_params.init(version)
|
||||
}
|
||||
|
||||
/// Runs the command and benchmarks the chain.
|
||||
pub fn run<G, E, BB, ExecDispatch>(
|
||||
self,
|
||||
config: sc_service::Configuration<G, E>,
|
||||
) -> sc_cli::error::Result<()>
|
||||
config: Configuration<G, E>,
|
||||
) -> sc_cli::Result<()>
|
||||
where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
@@ -149,4 +139,22 @@ impl BenchmarkCmd {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update and prepare a `Configuration` with command line parameters
|
||||
pub fn update_config<G, E>(
|
||||
&self,
|
||||
mut config: &mut Configuration<G, E>,
|
||||
spec_factory: impl FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
|
||||
version: &VersionInfo,
|
||||
) -> sc_cli::Result<()> where
|
||||
G: RuntimeGenesis,
|
||||
E: ChainSpecExtension,
|
||||
{
|
||||
self.shared_params.update_config(&mut config, spec_factory, version)?;
|
||||
|
||||
// make sure to configure keystore
|
||||
config.use_in_memory_keystore()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user