mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 12:48:00 +00:00
Update test-runner api (#9302)
* better apis * .... * ... * Genensis -> UnimportedGenesis * adds rpc for runtime upgrades * simplify test-runner * clean up test-runner api * remove unused imports * fix doc-test * fix line width * correct Node::clean * correct Node::clean * add deny rules * remove unused extern crates * remove mutex from node * Update test-utils/test-runner/Cargo.toml Co-authored-by: Andronik Ordian <write@reusable.software> * adds docs, removes Node::clean Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: Seun Lanlege <seun@parity.io>
This commit is contained in:
@@ -16,17 +16,20 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use futures::{Sink, SinkExt};
|
||||
use std::fmt;
|
||||
use std::io::Write;
|
||||
use log::LevelFilter;
|
||||
use sc_service::{BasePath, ChainSpec, Configuration, TaskExecutor, DatabaseConfig, KeepBlocks, TransactionStorageMode};
|
||||
use sc_service::{
|
||||
BasePath, ChainSpec, Configuration, TaskExecutor,
|
||||
DatabaseConfig, KeepBlocks, TransactionStorageMode, TaskType,
|
||||
};
|
||||
use sp_keyring::sr25519::Keyring::Alice;
|
||||
use sc_network::{multiaddr, config::{NetworkConfiguration, TransportConfig, Role}};
|
||||
use sc_informant::OutputFormat;
|
||||
use sc_service::config::KeystoreConfig;
|
||||
use sc_executor::WasmExecutionMethod;
|
||||
use sc_client_api::execution_extensions::ExecutionStrategies;
|
||||
use tokio::runtime::Handle;
|
||||
use futures::FutureExt;
|
||||
|
||||
pub use sc_cli::build_runtime;
|
||||
|
||||
/// Base db path gotten from env
|
||||
pub fn base_path() -> BasePath {
|
||||
@@ -37,35 +40,6 @@ pub fn base_path() -> BasePath {
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the global logger.
|
||||
pub fn logger<S>(
|
||||
log_targets: Vec<(&'static str, LevelFilter)>,
|
||||
executor: tokio::runtime::Handle,
|
||||
log_sink: S,
|
||||
)
|
||||
where
|
||||
S: Sink<String> + Clone + Unpin + Send + Sync + 'static,
|
||||
S::Error: Send + Sync + fmt::Debug,
|
||||
{
|
||||
let mut builder = env_logger::builder();
|
||||
builder.format(move |buf: &mut env_logger::fmt::Formatter, record: &log::Record| {
|
||||
let entry = format!("{} {} {}", record.level(), record.target(), record.args());
|
||||
let res = writeln!(buf, "{}", entry);
|
||||
|
||||
let mut log_sink_clone = log_sink.clone();
|
||||
let _ = executor.spawn(async move {
|
||||
log_sink_clone.send(entry).await.expect("log_stream is dropped");
|
||||
});
|
||||
res
|
||||
});
|
||||
builder.write_style(env_logger::WriteStyle::Always);
|
||||
|
||||
for (module, level) in log_targets {
|
||||
builder.filter_module(module, level);
|
||||
}
|
||||
let _ = builder.is_test(true).try_init();
|
||||
}
|
||||
|
||||
/// Produces a default configuration object, suitable for use with most set ups.
|
||||
pub fn default_config(task_executor: TaskExecutor, mut chain_spec: Box<dyn ChainSpec>) -> Configuration {
|
||||
let base_path = base_path();
|
||||
@@ -150,3 +124,13 @@ pub fn default_config(task_executor: TaskExecutor, mut chain_spec: Box<dyn Chain
|
||||
transaction_storage: TransactionStorageMode::BlockBody,
|
||||
}
|
||||
}
|
||||
|
||||
/// Produce a task executor given a handle to a tokio runtime
|
||||
pub fn task_executor(handle: Handle) -> TaskExecutor {
|
||||
let task_executor = move |fut, task_type| match task_type {
|
||||
TaskType::Async => handle.spawn(fut).map(drop),
|
||||
TaskType::Blocking => handle.spawn_blocking(move || futures::executor::block_on(fut)).map(drop),
|
||||
};
|
||||
|
||||
task_executor.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user