Unverified Commit ecde2802 authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Substrate Companion #9737 (#3830)



Co-authored-by: parity-processbot <>
Co-authored-by: default avatarkianenigma <kian@parity.io>
parent 7229ab87
Pipeline #156728 failed with stages
in 45 minutes and 24 seconds
This diff is collapsed.
......@@ -410,9 +410,8 @@ pub fn run() -> Result<()> {
use sc_service::TaskManager;
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager =
TaskManager::new(runner.config().task_executor.clone(), *registry)
.map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;
let task_manager = TaskManager::new(runner.config().tokio_handle.clone(), *registry)
.map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;
ensure_dev(chain_spec).map_err(Error::Other)?;
......
......@@ -33,8 +33,7 @@ use sp_runtime::{app_crypto::sp_core::H256, generic::Era, AccountId32};
use std::{error::Error, future::Future, str::FromStr};
use support::{weights::Weight, StorageValue};
use test_runner::{
build_runtime, client_parts, task_executor, ChainInfo, ConfigOrChainSpec, Node,
SignatureVerificationOverride,
build_runtime, client_parts, ChainInfo, ConfigOrChainSpec, Node, SignatureVerificationOverride,
};
type BlockImport<B, BE, C, SC> = BabeBlockImport<B, C, GrandpaBlockImport<BE, B, C, SC>>;
......@@ -360,7 +359,6 @@ where
use structopt::StructOpt;
let tokio_runtime = build_runtime()?;
let task_executor = task_executor(tokio_runtime.handle().clone());
// parse cli args
let cmd = <polkadot_cli::Cli as StructOpt>::from_args();
// set up logging
......@@ -369,7 +367,7 @@ where
logger.init()?;
// set up the test-runner
let config = cmd.create_configuration(&cmd.run.base, task_executor)?;
let config = cmd.create_configuration(&cmd.run.base, tokio_runtime.handle().clone())?;
sc_cli::print_node_infos::<polkadot_cli::Cli>(&config);
let (rpc, task_manager, client, pool, command_sink, backend) =
client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::Config(config))?;
......@@ -392,11 +390,10 @@ mod tests {
#[test]
fn test_runner() {
let runtime = build_runtime().unwrap();
let task_executor = task_executor(runtime.handle().clone());
let (rpc, task_manager, client, pool, command_sink, backend) =
client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::ChainSpec(
Box::new(polkadot_development_config().unwrap()),
task_executor,
runtime.handle().clone(),
))
.unwrap();
let node =
......
......@@ -11,6 +11,7 @@ hex = "0.4.3"
tracing = "0.1.26"
rand = "0.8.3"
tempfile = "3.2.0"
tokio = "1.10.0"
# Polkadot dependencies
polkadot-overseer = { path = "../../overseer" }
......
......@@ -41,8 +41,7 @@ use sc_network::{
};
use service::{
config::{DatabaseSource, KeystoreConfig, MultiaddrWithPeerId, WasmExecutionMethod},
BasePath, Configuration, KeepBlocks, Role, RpcHandlers, TaskExecutor, TaskManager,
TransactionStorageMode,
BasePath, Configuration, KeepBlocks, Role, RpcHandlers, TaskManager, TransactionStorageMode,
};
use sp_arithmetic::traits::SaturatedConversion;
use sp_blockchain::HeaderBackend;
......@@ -112,7 +111,7 @@ impl ClientHandle for TestClient {
/// and can be used to make adjustments to the runtime genesis storage.
pub fn node_config(
storage_update_func: impl Fn(),
task_executor: TaskExecutor,
tokio_handle: tokio::runtime::Handle,
key: Sr25519Keyring,
boot_nodes: Vec<MultiaddrWithPeerId>,
is_validator: bool,
......@@ -149,7 +148,7 @@ pub fn node_config(
impl_name: "polkadot-test-node".to_string(),
impl_version: "0.1".to_string(),
role,
task_executor,
tokio_handle,
transaction_pool: Default::default(),
network: network_config,
keystore: KeystoreConfig::InMemory,
......@@ -171,7 +170,6 @@ pub fn node_config(
offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible,
other: sc_client_api::ExecutionStrategy::NativeWhenPossible,
},
rpc_http_threads: None,
rpc_http: None,
rpc_ws: None,
rpc_ipc: None,
......@@ -204,13 +202,13 @@ pub fn node_config(
/// The `storage_update_func` function will be executed in an externalities provided environment
/// and can be used to make adjustments to the runtime genesis storage.
pub fn run_validator_node(
task_executor: TaskExecutor,
tokio_handle: tokio::runtime::Handle,
key: Sr25519Keyring,
storage_update_func: impl Fn(),
boot_nodes: Vec<MultiaddrWithPeerId>,
worker_program_path: Option<PathBuf>,
) -> PolkadotTestNode {
let config = node_config(storage_update_func, task_executor, key, boot_nodes, true);
let config = node_config(storage_update_func, tokio_handle, key, boot_nodes, true);
let multiaddr = config.network.listen_addresses[0].clone();
let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } =
new_full(config, IsCollator::No, worker_program_path)
......@@ -236,13 +234,13 @@ pub fn run_validator_node(
/// The collator functionality still needs to be registered at the node! This can be done using
/// [`PolkadotTestNode::register_collator`].
pub fn run_collator_node(
task_executor: TaskExecutor,
tokio_handle: tokio::runtime::Handle,
key: Sr25519Keyring,
storage_update_func: impl Fn(),
boot_nodes: Vec<MultiaddrWithPeerId>,
collator_pair: CollatorPair,
) -> PolkadotTestNode {
let config = node_config(storage_update_func, task_executor, key, boot_nodes, false);
let config = node_config(storage_update_func, tokio_handle, key, boot_nodes, false);
let multiaddr = config.network.listen_addresses[0].clone();
let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } =
new_full(config, IsCollator::Yes(collator_pair), None)
......
......@@ -14,21 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use futures::{future, pin_mut, select};
use futures::{future, pin_mut, select, FutureExt};
use polkadot_test_service::*;
use service::TaskExecutor;
use sp_keyring::Sr25519Keyring;
#[substrate_test_utils::test]
async fn ensure_test_service_build_blocks(task_executor: TaskExecutor) {
async fn ensure_test_service_build_blocks() {
let mut builder = sc_cli::LoggerBuilder::new("");
builder.with_colors(false);
builder.init().expect("Sets up logger");
let mut alice =
run_validator_node(task_executor.clone(), Sr25519Keyring::Alice, || {}, Vec::new(), None);
let mut alice = run_validator_node(
tokio::runtime::Handle::current(),
Sr25519Keyring::Alice,
|| {},
Vec::new(),
None,
);
let mut bob = run_validator_node(
task_executor.clone(),
tokio::runtime::Handle::current(),
Sr25519Keyring::Bob,
|| {},
vec![alice.addr.clone()],
......
......@@ -15,12 +15,12 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use polkadot_test_service::*;
use service::TaskExecutor;
use sp_keyring::Sr25519Keyring::{Alice, Bob};
#[substrate_test_utils::test]
async fn call_function_actually_work(task_executor: TaskExecutor) {
let alice = run_validator_node(task_executor, Alice, || {}, Vec::new(), None);
async fn call_function_actually_work() {
let alice =
run_validator_node(tokio::runtime::Handle::current(), Alice, || {}, Vec::new(), None);
let function = polkadot_test_runtime::Call::Balances(pallet_balances::Call::transfer(
Default::default(),
......
......@@ -21,7 +21,7 @@ const PUPPET_EXE: &str = env!("CARGO_BIN_EXE_adder_collator_puppet_worker");
// If this test is failing, make sure to run all tests with the `real-overseer` feature being enabled.
#[substrate_test_utils::test]
async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor) {
async fn collating_using_adder_collator() {
use futures::join;
use polkadot_primitives::v1::Id as ParaId;
use sp_keyring::AccountKeyring::*;
......@@ -34,7 +34,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
// start alice
let alice = polkadot_test_service::run_validator_node(
task_executor.clone(),
tokio::runtime::Handle::current(),
Alice,
|| {},
vec![],
......@@ -43,7 +43,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
// start bob
let bob = polkadot_test_service::run_validator_node(
task_executor.clone(),
tokio::runtime::Handle::current(),
Bob,
|| {},
vec![alice.addr.clone()],
......@@ -60,7 +60,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
// run the collator node
let mut charlie = polkadot_test_service::run_collator_node(
task_executor.clone(),
tokio::runtime::Handle::current(),
Charlie,
|| {},
vec![alice.addr.clone(), bob.addr.clone()],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment