Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Substrate Companion #9737 #3830

Merged
merged 3 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 157 additions & 155 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
9 changes: 3 additions & 6 deletions node/test/polkadot-simnet/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>;
Expand Down Expand Up @@ -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
Expand All @@ -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))?;
Expand All @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions node/test/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
16 changes: 7 additions & 9 deletions node/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 10 additions & 6 deletions node/test/service/tests/build-blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
Expand Down
6 changes: 3 additions & 3 deletions node/test/service/tests/call-function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions parachain/test-parachains/adder/collator/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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![],
Expand All @@ -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()],
Expand All @@ -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()],
Expand Down