Adds AuraConsensusDataProvider (#10503)

* adds support for parachains to test-runner

* adds file header

* Apply suggestions from code review

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* proper docs, remove unused _client

* fixes

* Update client/consensus/manual-seal/src/consensus/timestamp.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update client/consensus/manual-seal/src/consensus/timestamp.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* pr fixes

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Seun Lanlege
2022-01-10 15:39:04 +01:00
committed by GitHub
parent 2178cb1939
commit a4057bb9e2
17 changed files with 278 additions and 1368 deletions
@@ -1,29 +0,0 @@
[package]
name = "test-runner-example"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
publish = false
[dependencies]
test-runner = { path = "../../../test-utils/test-runner" }
frame-system = { path = "../../../frame/system" }
frame-benchmarking = { path = "../../../frame/benchmarking" }
pallet-transaction-payment = { path = "../../../frame/transaction-payment" }
pallet-asset-tx-payment = { path = "../../../frame/transaction-payment/asset-tx-payment/" }
node-runtime = { path = "../runtime" }
node-primitives = { path = "../primitives" }
node-cli = { path = "../cli" }
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-consensus = { path = "../../../client/consensus/common" }
sp-runtime = { path = "../../../primitives/runtime" }
sp-keyring = { path = "../../../primitives/keyring" }
@@ -1,132 +0,0 @@
// This file is part of Substrate.
// Copyright (C) 2021-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 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 grandpa::GrandpaBlockImport;
use sc_consensus_babe::BabeBlockImport;
use sc_consensus_manual_seal::consensus::babe::SlotTimestampProvider;
use sc_executor::NativeElseWasmExecutor;
use sc_service::{TFullBackend, TFullClient};
use sp_runtime::generic::Era;
use test_runner::{ChainInfo, SignatureVerificationOverride};
type BlockImport<B, BE, C, SC> = BabeBlockImport<B, C, GrandpaBlockImport<BE, B, C, SC>>;
/// A unit struct which implements `NativeExecutionDispatch` feeding in the
/// hard-coded runtime.
pub struct ExecutorDispatch;
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
type ExtendHostFunctions =
(frame_benchmarking::benchmarking::HostFunctions, SignatureVerificationOverride);
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
node_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
node_runtime::native_version()
}
}
/// ChainInfo implementation.
struct NodeTemplateChainInfo;
impl ChainInfo for NodeTemplateChainInfo {
type Block = node_primitives::Block;
type ExecutorDispatch = ExecutorDispatch;
type Runtime = node_runtime::Runtime;
type RuntimeApi = node_runtime::RuntimeApi;
type SelectChain = sc_consensus::LongestChain<TFullBackend<Self::Block>, Self::Block>;
type BlockImport = BlockImport<
Self::Block,
TFullBackend<Self::Block>,
TFullClient<Self::Block, Self::RuntimeApi, NativeElseWasmExecutor<Self::ExecutorDispatch>>,
Self::SelectChain,
>;
type SignedExtras = node_runtime::SignedExtra;
type InherentDataProviders =
(SlotTimestampProvider, sp_consensus_babe::inherents::InherentDataProvider);
fn signed_extras(
from: <Self::Runtime as frame_system::Config>::AccountId,
) -> Self::SignedExtras {
(
frame_system::CheckNonZeroSender::<Self::Runtime>::new(),
frame_system::CheckSpecVersion::<Self::Runtime>::new(),
frame_system::CheckTxVersion::<Self::Runtime>::new(),
frame_system::CheckGenesis::<Self::Runtime>::new(),
frame_system::CheckMortality::<Self::Runtime>::from(Era::Immortal),
frame_system::CheckNonce::<Self::Runtime>::from(
frame_system::Pallet::<Self::Runtime>::account_nonce(from),
),
frame_system::CheckWeight::<Self::Runtime>::new(),
pallet_asset_tx_payment::ChargeAssetTxPayment::<Self::Runtime>::from(0, None),
)
}
}
#[cfg(test)]
mod tests {
use super::*;
use node_cli::chain_spec::development_config;
use sp_keyring::sr25519::Keyring::Alice;
use sp_runtime::{traits::IdentifyAccount, MultiSigner};
use test_runner::{build_runtime, client_parts, ConfigOrChainSpec, Node};
#[test]
fn test_runner() {
let tokio_runtime = build_runtime().unwrap();
let (rpc, task_manager, client, pool, command_sink, backend) =
client_parts::<NodeTemplateChainInfo>(ConfigOrChainSpec::ChainSpec(
Box::new(development_config()),
tokio_runtime.handle().clone(),
))
.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 { remark: (b"hello world").to_vec() },
Some(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();
})
}
}