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 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
69732ef
substrate-test-runner
seunlanlege Dec 2, 2020
46cae57
PR grumbles
seunlanlege Jan 13, 2021
25bebb4
minor fixes
seunlanlege Jan 13, 2021
fd4fbef
bye test-runner
seunlanlege Jan 13, 2021
f5871d8
u128->u64
seunlanlege Jan 14, 2021
a1d8209
u64->u8
seunlanlege Jan 14, 2021
1c70a7f
patch manual seal
seunlanlege Jan 15, 2021
9a6c65a
patch manual seal
seunlanlege Jan 18, 2021
374df70
patch manual seal
seunlanlege Jan 18, 2021
6b965b9
make tests take args, make root calls dispatch generic
seunlanlege Jan 21, 2021
c566a90
runtime upgrade
seunlanlege Jan 21, 2021
f0f1bee
Update bin/node/e2e-tests/src/lib.rs
seunlanlege Jan 21, 2021
74421dc
Merge branch 'master' of github.com:paritytech/substrate into substra…
seunlanlege Feb 8, 2021
9bc449f
...
seunlanlege Feb 8, 2021
3af7142
Merge branch 'master' of github.com:paritytech/substrate into substra…
Mar 3, 2021
4364ddc
hi test-runner
Mar 3, 2021
c2c6519
Merge branch 'master' of github.com:paritytech/substrate into substra…
Mar 3, 2021
3f19754
Apply suggestions from code review
Mar 3, 2021
465632c
Update frame/executive/src/lib.rs
Mar 3, 2021
2c340d5
doc tests in test-runner crate
Mar 4, 2021
0a05661
Merge branch 'substrate-test-runner' of github.com:paritytech/substra…
Mar 4, 2021
0b22b08
fix import
Mar 4, 2021
b422a05
Merge branch 'master' of github.com:paritytech/substrate into substra…
Mar 8, 2021
ace0295
rename to test-runner-example
Mar 8, 2021
487bf82
remove unneeded test
Mar 8, 2021
edbafae
Apply suggestions from code review
Mar 10, 2021
f7c2358
Update test-utils/test-runner/src/lib.rs
Mar 10, 2021
5d7043f
introduce NodeConfig
Mar 11, 2021
3a8ca65
remove tokio-compat
Mar 11, 2021
9b5ed29
Merge branch 'master' of github.com:paritytech/substrate into substra…
Mar 11, 2021
a821a5a
Merge branch 'master' of github.com:paritytech/substrate into substra…
Mar 16, 2021
b394936
ignore test runner test
Mar 19, 2021
216e1b7
fix doc test
Mar 19, 2021
6101c74
fix test_runner test
shawntabrizi Mar 21, 2021
744a0f8
Merge branch 'master' into substrate-test-runner
shawntabrizi Mar 21, 2021
a17dfb4
fix test
Mar 21, 2021
bf51eb4
Merge branch 'substrate-test-runner' of github.com:paritytech/substra…
Mar 21, 2021
e741136
use Pallet instead
Mar 22, 2021
a9d5900
use no_run
Mar 22, 2021
a417c85
use ignore?
Mar 22, 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
Prev Previous commit
Next Next commit
introduce NodeConfig
  • Loading branch information
Seun Lanlege committed Mar 11, 2021
commit 5d7043f79bbf0e9afc106c5ebeef794ee23d83ea
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/node/test-runner-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ sp-inherents = { version = "3.0.0", path = "../../../primitives/inherents" }
sp-keystore = { version = "0.9.0", path = "../../../primitives/keystore" }

rand = "0.8.3"
log = "0.4.14"
139 changes: 38 additions & 101 deletions bin/node/test-runner-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

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

use test_runner::{Node, ChainInfo, SignatureVerificationOverride, base_path};
use test_runner::{Node, ChainInfo, SignatureVerificationOverride};
use grandpa::GrandpaBlockImport;
use sc_service::{
TFullBackend, TFullClient, Configuration, TaskManager, new_full_parts, BasePath,
DatabaseConfig, KeepBlocks, TransactionStorageMode, TaskExecutor, ChainSpec, Role,
config::{NetworkConfiguration, KeystoreConfig},
};
use sc_service::{TFullBackend, TFullClient, Configuration, TaskManager, new_full_parts};
use std::sync::Arc;
use sp_inherents::InherentDataProviders;
use sc_consensus_babe::BabeBlockImport;
Expand All @@ -34,10 +30,7 @@ use node_cli::chain_spec::development_config;
use sp_consensus_babe::AuthorityId;
use sc_consensus_manual_seal::{ConsensusDataProvider, consensus::babe::BabeConsensusDataProvider};
use sp_runtime::{traits::IdentifyAccount, MultiSigner, generic::Era};
use sc_executor::WasmExecutionMethod;
use sc_network::{multiaddr, config::TransportConfig};
use sc_client_api::execution_extensions::ExecutionStrategies;
use sc_informant::OutputFormat;

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

Expand Down Expand Up @@ -65,96 +58,6 @@ impl ChainInfo for NodeTemplateChainInfo {
>;
type SignedExtras = node_runtime::SignedExtra;

fn configuration(task_executor: TaskExecutor) -> Configuration {
let mut chain_spec = development_config();
let base_path = if let Some(base) = base_path() {
BasePath::new(base)
} else {
BasePath::new_temp_dir().expect("couldn't create a temp dir")
};
let root_path = base_path.path().to_path_buf().join("chains").join(chain_spec.id());

let key_seed = Alice.to_seed();
let storage = chain_spec
.as_storage_builder()
.build_storage()
.expect("could not build storage");

chain_spec.set_storage(storage);

let mut network_config = NetworkConfiguration::new(
format!("Test Node for: {}", key_seed),
"network/test/0.1",
Default::default(),
None,
);
let informant_output_format = OutputFormat { enable_color: false };

network_config.allow_non_globals_in_dht = true;

network_config
.listen_addresses
.push(multiaddr::Protocol::Memory(rand::random()).into());

network_config.transport = TransportConfig::MemoryOnly;

Configuration {
impl_name: "test-node".to_string(),
impl_version: "0.1".to_string(),
role: Role::Authority,
task_executor,
transaction_pool: Default::default(),
network: network_config,
keystore: KeystoreConfig::Path {
path: root_path.join("key"),
password: None,
},
database: DatabaseConfig::RocksDb {
path: root_path.join("db"),
cache_size: 128,
},
state_cache_size: 16777216,
state_cache_child_ratio: None,
chain_spec: Box::new(chain_spec),
wasm_method: WasmExecutionMethod::Interpreted,
// NOTE: we enforce the use of the wasm runtime to make use of the signature overrides
execution_strategies: ExecutionStrategies {
syncing: sc_client_api::ExecutionStrategy::AlwaysWasm,
importing: sc_client_api::ExecutionStrategy::AlwaysWasm,
block_construction: sc_client_api::ExecutionStrategy::AlwaysWasm,
offchain_worker: sc_client_api::ExecutionStrategy::AlwaysWasm,
other: sc_client_api::ExecutionStrategy::AlwaysWasm,
},
rpc_http: None,
rpc_ws: None,
rpc_ipc: None,
rpc_ws_max_connections: None,
rpc_cors: None,
rpc_methods: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
telemetry_external_transport: None,
default_heap_pages: None,
offchain_worker: Default::default(),
force_authoring: false,
disable_grandpa: false,
dev_key_seed: Some(key_seed),
tracing_targets: None,
tracing_receiver: Default::default(),
max_runtime_instances: 8,
announce_block: true,
base_path: Some(base_path),
wasm_runtime_overrides: None,
informant_output_format,
disable_log_reloading: false,
keystore_remote: None,
keep_blocks: KeepBlocks::All,
state_pruning: Default::default(),
transaction_storage: TransactionStorageMode::BlockBody,
telemetry_handle: Default::default(),
}
}

fn signed_extras(from: <Self::Runtime as frame_system::Config>::AccountId) -> Self::SignedExtras {
(
frame_system::CheckSpecVersion::<Self::Runtime>::new(),
Expand Down Expand Up @@ -240,10 +143,44 @@ impl ChainInfo for NodeTemplateChainInfo {
#[cfg(test)]
mod tests {
use super::*;
use test_runner::NodeConfig;
use log::LevelFilter;

#[test]
fn test_runner() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good showcase 👍

let mut node = Node::<NodeTemplateChainInfo>::new().unwrap();
let config = NodeConfig {
execution_strategies: ExecutionStrategies {
syncing: sc_client_api::ExecutionStrategy::AlwaysWasm,
importing: sc_client_api::ExecutionStrategy::AlwaysWasm,
block_construction: sc_client_api::ExecutionStrategy::AlwaysWasm,
offchain_worker: sc_client_api::ExecutionStrategy::AlwaysWasm,
other: sc_client_api::ExecutionStrategy::AlwaysWasm,
},
chain_spec: Box::new(development_config()),
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
Expand Down
1 change: 1 addition & 0 deletions test-utils/test-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ futures01 = { package = "futures", version = "0.1.29" }
futures = { package = "futures", version = "0.3", features = ["compat"] }
rand = "0.7"
tokio = { version = "0.2", features = ["full"] }
libp2p = "0.35.1"

# Calling RPC
jsonrpc-core-client = { version = "15.1", features = ["ws"] }
Expand Down
135 changes: 21 additions & 114 deletions test-utils/test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,7 @@
//! - Runtime Upgrades
//! - Pallets and general runtime functionality.
//!
//! This works by running a full node with a ManualSeal-BABE™ hybrid consensus for block authoring.
//!
//! The test runner provides two apis of note
//!
//! - `seal_blocks(count: u32)`
//! <br/>
//!
//! This tells manual seal authorship task running on the node to author `count` number of blocks, including any transactions in the transaction pool in those blocks.
//!
//! - `submit_extrinsic<T: frame_system::Config>(call: Impl Into<T::Call>, from: T::AccountId)`
//! <br/>
//!
//! Providing a `Call` and an `AccountId`, creates an `UncheckedExtrinsic` with an empty signature and sends to the node to be included in future block.
//! This works by running a full node with a Manual Seal-BABE™ hybrid consensus for block authoring.
//!
//! <h2>Note</h2>
//! The running node has no signature verification, which allows us author extrinsics for any account on chain.
Expand All @@ -49,11 +37,11 @@
//!
//!
//! ```rust
//! use test_runner::{Node, ChainInfo, SignatureVerificationOverride, base_path};
//! use test_runner::{Node, ChainInfo, SignatureVerificationOverride, base_path, NodeConfig};
//! use sc_finality_grandpa::GrandpaBlockImport;
//! use sc_service::{
//! TFullBackend, TFullClient, Configuration, TaskManager, new_full_parts, BasePath,
//! DatabaseConfig, KeepBlocks, TransactionStorageMode, TaskExecutor, ChainSpec, Role,
//! DatabaseConfig, KeepBlocks, TransactionStorageMode, ChainSpec, Role,
//! config::{NetworkConfiguration, KeystoreConfig},
//! };
//! use std::sync::Arc;
Expand Down Expand Up @@ -88,9 +76,9 @@
//! /// Provide an Executor type for the runtime
//! type Executor = Executor;
//! /// Provide the runtime itself
//! type Runtime = node_runeimt::Runtime;
//! type Runtime = node_runtime::Runtime;
//! /// A touch of runtime api
//! type RuntimeApi = node_runeimt::RuntimeApi;
//! type RuntimeApi = node_runtime::RuntimeApi;
//! /// A pinch of SelectChain implementation
//! type SelectChain = sc_consensus::LongestChain<TFullBackend<Self::Block>, Self::Block>;
//! /// A slice of concrete BlockImport type
Expand All @@ -103,97 +91,6 @@
//! /// and a dash of SignedExtensions
//! type SignedExtras = node_runtime::SignedExtra;
//!
//! /// Load the chain spec for your runtime here.
//! fn configuration(task_executor: TaskExecutor) -> Configuration {
//! let mut chain_spec = development_config();
//! let base_path = if let Some(base) = base_path() {
//! BasePath::new(base)
//! } else {
//! BasePath::new_temp_dir().expect("couldn't create a temp dir")
//! };
//! let root_path = base_path.path().to_path_buf().join("chains").join(chain_spec.id());
//!
//! let key_seed = Alice.to_seed();
//! let storage = chain_spec
//! .as_storage_builder()
//! .build_storage()
//! .expect("could not build storage");
//!
//! chain_spec.set_storage(storage);
//!
//! let mut network_config = NetworkConfiguration::new(
//! format!("Test Node for: {}", key_seed),
//! "network/test/0.1",
//! Default::default(),
//! None,
//! );
//! let informant_output_format = OutputFormat { enable_color: false };
//!
//! network_config.allow_non_globals_in_dht = true;
//!
//! network_config
//! .listen_addresses
//! .push(multiaddr::Protocol::Memory(rand::random()).into());
//!
//! network_config.transport = TransportConfig::MemoryOnly;
//!
//! Configuration {
//! impl_name: "test-node".to_string(),
//! impl_version: "0.1".to_string(),
//! role: Role::Authority,
//! task_executor,
//! transaction_pool: Default::default(),
//! network: network_config,
//! keystore: KeystoreConfig::Path {
//! path: root_path.join("key"),
//! password: None,
//! },
//! database: DatabaseConfig::RocksDb {
//! path: root_path.join("db"),
//! cache_size: 128,
//! },
//! state_cache_size: 16777216,
//! state_cache_child_ratio: None,
//! chain_spec: Box::new(chain_spec),
//! wasm_method: WasmExecutionMethod::Interpreted,
//! // NOTE: we enforce the use of the wasm runtime to make use of the signature overrides
//! execution_strategies: ExecutionStrategies {
//! syncing: sc_client_api::ExecutionStrategy::AlwaysWasm,
//! importing: sc_client_api::ExecutionStrategy::AlwaysWasm,
//! block_construction: sc_client_api::ExecutionStrategy::AlwaysWasm,
//! offchain_worker: sc_client_api::ExecutionStrategy::AlwaysWasm,
//! other: sc_client_api::ExecutionStrategy::AlwaysWasm,
//! },
//! rpc_http: None,
//! rpc_ws: None,
//! rpc_ipc: None,
//! rpc_ws_max_connections: None,
//! rpc_cors: None,
//! rpc_methods: Default::default(),
//! prometheus_config: None,
//! telemetry_endpoints: None,
//! telemetry_external_transport: None,
//! default_heap_pages: None,
//! offchain_worker: Default::default(),
//! force_authoring: false,
//! disable_grandpa: false,
//! dev_key_seed: Some(key_seed),
//! tracing_targets: None,
//! tracing_receiver: Default::default(),
//! max_runtime_instances: 8,
//! announce_block: true,
//! base_path: Some(base_path),
//! wasm_runtime_overrides: None,
//! informant_output_format,
//! disable_log_reloading: false,
//! keystore_remote: None,
//! keep_blocks: KeepBlocks::All,
//! state_pruning: Default::default(),
//! transaction_storage: TransactionStorageMode::BlockBody,
//! telemetry_handle: Default::default(),
//! }
//! }
//!
//! /// Create your signed extras here.
//! fn signed_extras(
//! from: <Self::Runtime as frame_system::Config>::AccountId,
Expand Down Expand Up @@ -280,7 +177,8 @@
//!
//! 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)); // :D
//! // for chains that support sudo, otherwise, you'd have to use pallet-democracy here.
//! let call = pallet_sudo::Call::sudo(Box::new(call));
//! node.submit_extrinsic(call, alice);
//! node.seal_blocks(1);
//! }
Expand All @@ -291,7 +189,18 @@
//! #[test]
//! fn simple_balances_test() {
//! // given
//! let mut node = Node::<Requirements>::new().unwrap();
//! let config = NodeConfig {
//! execution_strategies: ExecutionStrategies {
//! syncing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! importing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! block_construction: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! other: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! },
//! chain_spec: development_config(),
//! log_targets: vec![],
//! };
//! let mut node = Node::<Requirements>::new(config).unwrap();
//!
//! type Balances = pallet_balances::Module<node_runtime::Runtime>;
//!
Expand Down Expand Up @@ -323,7 +232,7 @@

use manual_seal::consensus::ConsensusDataProvider;
use sc_executor::NativeExecutionDispatch;
use sc_service::{Configuration, TFullBackend, TFullClient, TaskManager, TaskExecutor};
use sc_service::{Configuration, TFullBackend, TFullClient, TaskManager};
use sp_api::{ConstructRuntimeApi, TransactionFor};
use sp_consensus::{BlockImport, SelectChain};
use sp_inherents::InherentDataProviders;
Expand Down Expand Up @@ -368,11 +277,9 @@ pub trait ChainInfo: Sized {
Transaction = TransactionFor<TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>, Self::Block>,
> + 'static;

/// The signed extras required by the runtime
type SignedExtras: SignedExtension;

/// construct the node configuration.
fn configuration(task_executor: TaskExecutor) -> Configuration;

/// Signed extras, this function is caled in an externalities provided environment.
fn signed_extras(from: <Self::Runtime as frame_system::Config>::AccountId) -> Self::SignedExtras;

Expand Down
Loading