mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +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:
@@ -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"
|
||||
|
||||
@@ -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>>;
|
||||
|
||||
@@ -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);
|
||||
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);
|
||||
|
||||
// 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();
|
||||
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();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user