Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
397bcb6
better apis
Jun 16, 2021
4004d1b
....
Jun 17, 2021
3fdf552
...
Jun 18, 2021
043000f
Merge branch 'master' of github.com:paritytech/substrate into test-ru…
Jun 18, 2021
7d1b8e1
Genensis -> UnimportedGenesis
Jun 18, 2021
7faacb6
adds rpc for runtime upgrades
Jun 23, 2021
5fc2ca2
Merge branch 'master' of github.com:paritytech/substrate into test-ru…
Jun 23, 2021
38e2734
Merge branch 'master' of github.com:paritytech/substrate into test-ru…
Jun 23, 2021
1e5c8a4
Merge branch 'master' of github.com:paritytech/substrate into test-ru…
Jun 24, 2021
4fb0c0a
simplify test-runner
Jul 7, 2021
4be3477
Merge branch 'master' of github.com:paritytech/substrate into test-ru…
Jul 7, 2021
b8087d3
clean up test-runner api
Jul 7, 2021
61c0f2a
remove unused imports
Jul 7, 2021
c3f2821
fix doc-test
Jul 8, 2021
7ecbc28
fix line width
Jul 8, 2021
dd6229d
correct Node::clean
Jul 8, 2021
35d73fe
correct Node::clean
Jul 8, 2021
80e813e
Merge branch 'master' of github.com:paritytech/substrate into test-ru…
Jul 8, 2021
f6233f8
add deny rules
Jul 8, 2021
f3af0e2
remove unused extern crates
Jul 8, 2021
56d7dc2
remove mutex from node
Jul 8, 2021
124f08b
Update test-utils/test-runner/Cargo.toml
Jul 8, 2021
a677d45
adds docs, removes Node::clean
Jul 8, 2021
84c5e54
remove parking_lot
Jul 8, 2021
4aa1dd4
Merge branch 'master' of github.com:paritytech/substrate into test-ru…
Jul 9, 2021
103b7ff
Merge branch 'master' of github.com:paritytech/substrate into test-ru…
Jul 12, 2021
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
9 changes: 6 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 27 additions & 26 deletions bin/node/test-runner-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,36 @@ edition = "2018"
publish = false

[dependencies]
test-runner = { path = "../../../test-utils/test-runner", version = "0.9.0" }
test-runner = { path = "../../../test-utils/test-runner" }

frame-system = { version = "4.0.0-dev", path = "../../../frame/system" }
frame-support = { path = "../../../frame/support", version = "4.0.0-dev"}
frame-benchmarking = { path = "../../../frame/benchmarking", version = "4.0.0-dev"}
pallet-balances = { path = "../../../frame/balances", version = "4.0.0-dev"}
pallet-sudo = { path = "../../../frame/sudo", version = "4.0.0-dev"}
pallet-transaction-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment" }
frame-system = { path = "../../../frame/system" }
frame-support = { path = "../../../frame/support" }
frame-benchmarking = { path = "../../../frame/benchmarking" }
pallet-balances = { path = "../../../frame/balances" }
pallet-sudo = { path = "../../../frame/sudo" }
pallet-transaction-payment = { path = "../../../frame/transaction-payment" }

node-runtime = { path = "../runtime", version = "3.0.0-dev"}
node-primitives = { version = "2.0.0", path = "../primitives" }
node-cli = { path = "../cli", version = "3.0.0-dev"}
node-runtime = { path = "../runtime" }
node-primitives = { path = "../primitives" }
node-cli = { path = "../cli" }

grandpa = { version = "0.10.0-dev", package = "sc-finality-grandpa", path = "../../../client/finality-grandpa" }
sp-consensus-babe = { version = "0.10.0-dev", path = "../../../primitives/consensus/babe" }
sc-consensus-babe = { version = "0.10.0-dev", path = "../../../client/consensus/babe" }
sc-consensus-manual-seal = { version = "0.10.0-dev", path = "../../../client/consensus/manual-seal" }
sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../client/service" }
sc-executor = { version = "0.10.0-dev", path = "../../../client/executor" }
sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" }
sc-network = { version = "0.10.0-dev", path = "../../../client/network" }
sc-informant = { version = "0.10.0-dev", path = "../../../client/informant" }
sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" }
grandpa = { package = "sc-finality-grandpa", path = "../../../client/finality-grandpa" }
sp-consensus-babe = { path = "../../../primitives/consensus/babe" }
sc-consensus-babe = { path = "../../../client/consensus/babe" }
sc-consensus-manual-seal = { path = "../../../client/consensus/manual-seal" }
sc-service = { default-features = false, path = "../../../client/service" }
sc-executor = { path = "../../../client/executor" }
sc-client-api = { path = "../../../client/api" }
sc-network = { path = "../../../client/network" }
sc-informant = { path = "../../../client/informant" }
sc-consensus = { path = "../../../client/consensus/common" }

sp-runtime = { path = "../../../primitives/runtime", version = "4.0.0-dev"}
sp-keyring = { version = "4.0.0-dev", path = "../../../primitives/keyring" }
sp-timestamp = { version = "4.0.0-dev", path = "../../../primitives/timestamp" }
sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" }
sp-inherents = { version = "4.0.0-dev", path = "../../../primitives/inherents" }
sp-keystore = { version = "0.10.0-dev", path = "../../../primitives/keystore" }
sp-runtime = { path = "../../../primitives/runtime" }
sp-consensus = { path = "../../../primitives/consensus/common" }
sp-keyring = { path = "../../../primitives/keyring" }
sp-timestamp = { path = "../../../primitives/timestamp" }
sp-api = { path = "../../../primitives/api" }
sp-inherents = { path = "../../../primitives/inherents" }
sp-keystore = { path = "../../../primitives/keystore" }

log = "0.4.14"
167 changes: 31 additions & 136 deletions bin/node/test-runner-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,16 @@

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#![deny(unused_extern_crates, missing_docs)]

//! Basic example of end to end runtime tests.

use test_runner::{Node, ChainInfo, SignatureVerificationOverride, default_config};
use test_runner::{ChainInfo, SignatureVerificationOverride};
use grandpa::GrandpaBlockImport;
use sc_service::{TFullBackend, TFullClient, Configuration, TaskManager, new_full_parts, TaskExecutor};
use std::sync::Arc;
use sp_inherents::CreateInherentDataProviders;
use sc_service::{TFullBackend, TFullClient};
use sc_consensus_babe::BabeBlockImport;
use sp_keystore::SyncCryptoStorePtr;
use sp_keyring::sr25519::Keyring::Alice;
use sp_consensus_babe::AuthorityId;
use sc_consensus_manual_seal::{
ConsensusDataProvider, consensus::babe::{BabeConsensusDataProvider, SlotTimestampProvider},
};
use sp_runtime::{traits::IdentifyAccount, MultiSigner, generic::Era};
use node_cli::chain_spec::development_config;
use sc_consensus_manual_seal::consensus::babe::SlotTimestampProvider;
use sp_runtime::generic::Era;

type BlockImport<B, BE, C, SC> = BabeBlockImport<B, C, GrandpaBlockImport<BE, B, C, SC>>;

Expand Down Expand Up @@ -74,137 +67,39 @@ impl ChainInfo for NodeTemplateChainInfo {
pallet_transaction_payment::ChargeTransactionPayment::<Self::Runtime>::from(0),
)
}

fn config(task_executor: TaskExecutor) -> Configuration {
default_config(task_executor, Box::new(development_config()))
}

fn create_client_parts(
config: &Configuration,
) -> Result<
(
Arc<TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>>,
Arc<TFullBackend<Self::Block>>,
SyncCryptoStorePtr,
TaskManager,
Box<dyn CreateInherentDataProviders<
Self::Block,
(),
InherentDataProviders = Self::InherentDataProviders
>>,
Option<
Box<
dyn ConsensusDataProvider<
Self::Block,
Transaction = sp_api::TransactionFor<
TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>,
Self::Block,
>,
>,
>,
>,
Self::SelectChain,
Self::BlockImport,
),
sc_service::Error,
> {
let (client, backend, keystore, task_manager) =
new_full_parts::<Self::Block, Self::RuntimeApi, Self::Executor>(config, None)?;
let client = Arc::new(client);

let select_chain = sc_consensus::LongestChain::new(backend.clone());

let (grandpa_block_import, ..) =
grandpa::block_import(
client.clone(),
&(client.clone() as Arc<_>),
select_chain.clone(),
None
)?;

let slot_duration = sc_consensus_babe::Config::get_or_compute(&*client)?;
let (block_import, babe_link) = sc_consensus_babe::block_import(
slot_duration.clone(),
grandpa_block_import,
client.clone(),
)?;

let consensus_data_provider = BabeConsensusDataProvider::new(
client.clone(),
keystore.sync_keystore(),
babe_link.epoch_changes().clone(),
vec![(AuthorityId::from(Alice.public()), 1000)],
)
.expect("failed to create ConsensusDataProvider");

Ok((
client.clone(),
backend,
keystore.sync_keystore(),
task_manager,
Box::new(move |_, _| {
let client = client.clone();
async move {
let timestamp = SlotTimestampProvider::new(client.clone()).map_err(|err| format!("{:?}", err))?;
let babe = sp_consensus_babe::inherents::InherentDataProvider::new(timestamp.slot().into());
Ok((timestamp, babe))
}
}),
Some(Box::new(consensus_data_provider)),
select_chain,
block_import,
))
}

fn dispatch_with_root(call: <Self::Runtime as frame_system::Config>::Call, node: &mut Node<Self>) {
let alice = MultiSigner::from(Alice.public()).into_account();
let call = pallet_sudo::Call::sudo(Box::new(call));
node.submit_extrinsic(call, alice);
node.seal_blocks(1);
}
}

#[cfg(test)]
mod tests {
use super::*;
use test_runner::NodeConfig;
use log::LevelFilter;
use test_runner::{Node, client_parts, ConfigOrChainSpec, build_runtime, task_executor};
use sp_keyring::sr25519::Keyring::Alice;
use node_cli::chain_spec::development_config;
use sp_runtime::{traits::IdentifyAccount, MultiSigner};

#[test]
fn test_runner() {
let config = NodeConfig {
log_targets: vec![
("yamux", LevelFilter::Off),
("multistream_select", LevelFilter::Off),
("libp2p", LevelFilter::Off),
("jsonrpc_client_transports", LevelFilter::Off),
("sc_network", LevelFilter::Off),
("tokio_reactor", LevelFilter::Off),
("parity-db", LevelFilter::Off),
("sub-libp2p", LevelFilter::Off),
("sync", LevelFilter::Off),
("peerset", LevelFilter::Off),
("ws", LevelFilter::Off),
("sc_network", LevelFilter::Off),
("sc_service", LevelFilter::Off),
("sc_basic_authorship", LevelFilter::Off),
("telemetry-logger", LevelFilter::Off),
("sc_peerset", LevelFilter::Off),
("rpc", LevelFilter::Off),
("runtime", LevelFilter::Trace),
("babe", LevelFilter::Debug)
],
};
let mut node = Node::<NodeTemplateChainInfo>::new(config).unwrap();
// seals blocks
node.seal_blocks(1);
// submit extrinsics
let alice = MultiSigner::from(Alice.public()).into_account();
node.submit_extrinsic(frame_system::Call::remark((b"hello world").to_vec()), alice);

// look ma, I can read state.
let _events = node.with_state(|| frame_system::Pallet::<node_runtime::Runtime>::events());
// get access to the underlying client.
let _client = node.client();
let mut tokio_runtime = build_runtime().unwrap();
let task_executor = task_executor(tokio_runtime.handle().clone());
let (rpc, task_manager, client, pool, command_sink, backend) =
client_parts::<NodeTemplateChainInfo>(
ConfigOrChainSpec::ChainSpec(Box::new(development_config()), task_executor)
).unwrap();
let node = Node::<NodeTemplateChainInfo>::new(rpc, task_manager, client, pool, command_sink, backend);

tokio_runtime.block_on(async {
// seals blocks
node.seal_blocks(1).await;
// submit extrinsics
let alice = MultiSigner::from(Alice.public()).into_account();
let _hash = node.submit_extrinsic(frame_system::Call::remark((b"hello world").to_vec()), alice)
.await
.unwrap();

// look ma, I can read state.
let _events = node.with_state(|| frame_system::Pallet::<node_runtime::Runtime>::events());
// get access to the underlying client.
let _client = node.client();
})
}
}
38 changes: 22 additions & 16 deletions client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,7 @@ impl<C: SubstrateCli> Runner<C> {
/// 2020-06-03 16:14:21 ⛓ Native runtime: node-251 (substrate-node-1.tx1.au10)
/// ```
fn print_node_infos(&self) {
info!("{}", C::impl_name());
info!("✌️ version {}", C::impl_version());
info!(
"❤️ by {}, {}-{}",
C::author(),
C::copyright_start_year(),
Local::today().year(),
);
info!("📋 Chain specification: {}", self.config.chain_spec.name());
info!("🏷 Node name: {}", self.config.network.node_name);
info!("👤 Role: {}", self.config.display_role());
info!("💾 Database: {} at {}",
self.config.database,
self.config.database.path().map_or_else(|| "<unknown>".to_owned(), |p| p.display().to_string())
);
info!("⛓ Native runtime: {}", C::native_runtime_version(&self.config.chain_spec));
print_node_infos::<C>(self.config())
}

/// A helper function that runs a node with tokio and stops if the process receives the signal
Expand Down Expand Up @@ -229,3 +214,24 @@ impl<C: SubstrateCli> Runner<C> {
&mut self.config
}
}

/// Log information about the node itself.
pub fn print_node_infos<C: SubstrateCli>(config: &Configuration) {
info!("{}", C::impl_name());
info!("✌️ version {}", C::impl_version());
info!(
"❤️ by {}, {}-{}",
C::author(),
C::copyright_start_year(),
Local::today().year(),
);
info!("📋 Chain specification: {}", config.chain_spec.name());
info!("🏷 Node name: {}", config.network.node_name);
info!("👤 Role: {}", config.display_role());
info!("💾 Database: {} at {}",
config.database,
config.database.path().map_or_else(|| "<unknown>".to_owned(), |p| p.display().to_string())
);
info!("⛓ Native runtime: {}", C::native_runtime_version(&config.chain_spec));
}

Loading