mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 17:51:10 +00:00
Uniformize tests (#220)
* Initial commit Forked at:56753b7717Parent branch: origin/master * Copy runtime module from rococo Forked at:56753b7717Parent branch: origin/master * Also copy dependencies pallets and primitives Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * test-service * Move integration test * CLEANUP Forked at:56753b7717Parent branch: origin/master * Not sure what went wrong... * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * CLEANUP Forked at:56753b7717Parent branch: origin/master * fmt * CLEANUP Forked at:56753b7717Parent branch: origin/master * CLEANUP Forked at:56753b7717Parent branch: origin/master * Remove pallet contracts (not used) * Remove pallet parachain-info and token-dealer (not used) * Sort dependencies alphabetically * CLEANUP Forked at:56753b7717Parent branch: origin/master * CumulusTestNode for testing * Speed up block generation * Fix improper shutdown * rustfmt * runtime: replace const by storage * Fix for previous commit * Remove some generics * Move generate_genesis_state to cumulus-primitives * fmt * Remove message_example * fixup! Remove message_example * WIP Forked at:56753b7717Parent branch: origin/master * Half the solution to previous commit :( * Revert "Fix for previous commit" This reverts commit 60010bab6797487093ac8c790b3a536f7ca0895b. * Revert "runtime: replace const by storage" This reverts commit c64b3a46f0325a98922015e0cbf3570e2e431774. Not working for some reason... * Use helper Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * Remove test-primitives * Revert "Half the solution to previous commit :(" This reverts commit 9a8f89f9f06252198e6405057043c6b313f1aea4. * Revert "Revert "Half the solution to previous commit :("" This reverts commit 6a93f0f09d74ccdc3738dd78a777c483427c03ce. * Test with some extra extrinsics * WIP Forked at:56753b7717Parent branch: origin/master * CLEANUP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * WIP Forked at:56753b7717Parent branch: origin/master * CLEANUP Forked at:56753b7717Parent branch: origin/master * Remove message broker
This commit is contained in:
Generated
+486
-400
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,7 @@ members = [
|
|||||||
"service",
|
"service",
|
||||||
"test/runtime",
|
"test/runtime",
|
||||||
"test/client",
|
"test/client",
|
||||||
|
"test/service",
|
||||||
"upward-message",
|
"upward-message",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ decl_module! {
|
|||||||
/// Set the current validation function parameters
|
/// Set the current validation function parameters
|
||||||
///
|
///
|
||||||
/// This should be invoked exactly once per block. It will panic at the finalization
|
/// This should be invoked exactly once per block. It will panic at the finalization
|
||||||
/// phease if the call was not invoked.
|
/// phase if the call was not invoked.
|
||||||
///
|
///
|
||||||
/// The dispatch origin for this call must be `Inherent`
|
/// The dispatch origin for this call must be `Inherent`
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Substrate dependencies
|
# Substrate dependencies
|
||||||
|
sc-service = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", optional = true }
|
||||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", default-features = false }
|
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", default-features = false }
|
||||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", default-features = false }
|
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", default-features = false }
|
||||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", default-features = false }
|
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", default-features = false }
|
||||||
@@ -24,6 +25,7 @@ polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", bra
|
|||||||
[features]
|
[features]
|
||||||
default = [ "std" ]
|
default = [ "std" ]
|
||||||
std = [
|
std = [
|
||||||
|
"sc-service",
|
||||||
"sp-std/std",
|
"sp-std/std",
|
||||||
"codec/std",
|
"codec/std",
|
||||||
"polkadot-primitives/std",
|
"polkadot-primitives/std",
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Cumulus 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.
|
||||||
|
|
||||||
|
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use codec::Encode;
|
||||||
|
use sc_service::ChainSpec;
|
||||||
|
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero};
|
||||||
|
|
||||||
|
/// Generate the genesis state for a given ChainSpec.
|
||||||
|
pub fn generate_genesis_block<Block: BlockT>(
|
||||||
|
chain_spec: &Box<dyn ChainSpec>,
|
||||||
|
) -> Result<Block, String> {
|
||||||
|
let storage = chain_spec.build_storage()?;
|
||||||
|
|
||||||
|
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||||
|
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||||
|
child_content.data.clone().into_iter().collect(),
|
||||||
|
);
|
||||||
|
(sk.clone(), state_root.encode())
|
||||||
|
});
|
||||||
|
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||||
|
storage.top.clone().into_iter().chain(child_roots).collect(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let extrinsics_root =
|
||||||
|
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(Vec::new());
|
||||||
|
|
||||||
|
Ok(Block::new(
|
||||||
|
<<Block as BlockT>::Header as HeaderT>::new(
|
||||||
|
Zero::zero(),
|
||||||
|
extrinsics_root,
|
||||||
|
state_root,
|
||||||
|
Default::default(),
|
||||||
|
Default::default(),
|
||||||
|
),
|
||||||
|
Default::default(),
|
||||||
|
))
|
||||||
|
}
|
||||||
@@ -29,6 +29,8 @@ pub use polkadot_parachain::primitives::{
|
|||||||
Id as ParaId, ParachainDispatchOrigin as UpwardMessageOrigin,
|
Id as ParaId, ParachainDispatchOrigin as UpwardMessageOrigin,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub mod genesis;
|
||||||
pub mod validation_function_params;
|
pub mod validation_function_params;
|
||||||
pub mod xcmp;
|
pub mod xcmp;
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ sc-executor = { git = "https://github.com/paritytech/substrate", branch = "rococ
|
|||||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sc-service = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
sc-network = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
|
||||||
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", version = "0.8.0-rc5" }
|
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", version = "0.8.0-rc5" }
|
||||||
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
@@ -70,7 +69,6 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch =
|
|||||||
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||||
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||||
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||||
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
|
||||||
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
@@ -79,17 +77,3 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/substrate"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_cmd = "0.12"
|
assert_cmd = "0.12"
|
||||||
nix = "0.17"
|
nix = "0.17"
|
||||||
rand = "0.7.3"
|
|
||||||
tokio = { version = "0.2.21", features = ["macros"] }
|
|
||||||
|
|
||||||
# Polkadot dependencies
|
|
||||||
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
|
||||||
polkadot-test-runtime = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
|
||||||
polkadot-test-runtime-client = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
|
||||||
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
|
||||||
|
|
||||||
# Substrate dependencies
|
|
||||||
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
|
||||||
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
|
||||||
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
|
||||||
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use crate::{
|
|||||||
cli::{Cli, RelayChainCli, Subcommand},
|
cli::{Cli, RelayChainCli, Subcommand},
|
||||||
};
|
};
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use cumulus_primitives::ParaId;
|
use cumulus_primitives::{genesis::generate_genesis_block, ParaId};
|
||||||
use log::info;
|
use log::info;
|
||||||
use parachain_runtime::Block;
|
use parachain_runtime::Block;
|
||||||
use polkadot_parachain::primitives::AccountIdConversion;
|
use polkadot_parachain::primitives::AccountIdConversion;
|
||||||
@@ -29,7 +29,7 @@ use sc_cli::{
|
|||||||
};
|
};
|
||||||
use sc_service::config::{BasePath, PrometheusConfig};
|
use sc_service::config::{BasePath, PrometheusConfig};
|
||||||
use sp_core::hexdisplay::HexDisplay;
|
use sp_core::hexdisplay::HexDisplay;
|
||||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero};
|
use sp_runtime::traits::Block as BlockT;
|
||||||
use std::{io::Write, net::SocketAddr, sync::Arc};
|
use std::{io::Write, net::SocketAddr, sync::Arc};
|
||||||
|
|
||||||
fn load_spec(
|
fn load_spec(
|
||||||
@@ -134,34 +134,6 @@ impl SubstrateCli for RelayChainCli {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_genesis_state(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Block> {
|
|
||||||
let storage = chain_spec.build_storage()?;
|
|
||||||
|
|
||||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
|
||||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
|
||||||
child_content.data.clone().into_iter().collect(),
|
|
||||||
);
|
|
||||||
(sk.clone(), state_root.encode())
|
|
||||||
});
|
|
||||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
|
||||||
storage.top.clone().into_iter().chain(child_roots).collect(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let extrinsics_root =
|
|
||||||
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(Vec::new());
|
|
||||||
|
|
||||||
Ok(Block::new(
|
|
||||||
<<Block as BlockT>::Header as HeaderT>::new(
|
|
||||||
Zero::zero(),
|
|
||||||
extrinsics_root,
|
|
||||||
state_root,
|
|
||||||
Default::default(),
|
|
||||||
Default::default(),
|
|
||||||
),
|
|
||||||
Default::default(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {
|
fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {
|
||||||
let mut storage = chain_spec.build_storage()?;
|
let mut storage = chain_spec.build_storage()?;
|
||||||
|
|
||||||
@@ -216,7 +188,7 @@ pub fn run() -> Result<()> {
|
|||||||
Some(Subcommand::ExportGenesisState(params)) => {
|
Some(Subcommand::ExportGenesisState(params)) => {
|
||||||
sc_cli::init_logger("");
|
sc_cli::init_logger("");
|
||||||
|
|
||||||
let block = generate_genesis_state(&load_spec(
|
let block: Block = generate_genesis_block(&load_spec(
|
||||||
¶ms.chain.clone().unwrap_or_default(),
|
¶ms.chain.clone().unwrap_or_default(),
|
||||||
params.parachain_id.into(),
|
params.parachain_id.into(),
|
||||||
)?)?;
|
)?)?;
|
||||||
@@ -268,8 +240,8 @@ pub fn run() -> Result<()> {
|
|||||||
let parachain_account =
|
let parachain_account =
|
||||||
AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);
|
AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);
|
||||||
|
|
||||||
let block =
|
let block: Block =
|
||||||
generate_genesis_state(&config.chain_spec).map_err(|e| format!("{:?}", e))?;
|
generate_genesis_block(&config.chain_spec).map_err(|e| format!("{:?}", e))?;
|
||||||
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||||
|
|
||||||
let task_executor = config.task_executor.clone();
|
let task_executor = config.task_executor.clone();
|
||||||
@@ -293,7 +265,6 @@ pub fn run() -> Result<()> {
|
|||||||
polkadot_config,
|
polkadot_config,
|
||||||
id,
|
id,
|
||||||
collator,
|
collator,
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
crate::service::start_node(
|
crate::service::start_node(
|
||||||
@@ -302,7 +273,6 @@ pub fn run() -> Result<()> {
|
|||||||
polkadot_config,
|
polkadot_config,
|
||||||
id,
|
id,
|
||||||
collator,
|
collator,
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
.map(|r| r.0)
|
.map(|r| r.0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,215 +0,0 @@
|
|||||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
|
||||||
// This file is part of Substrate.
|
|
||||||
|
|
||||||
// Substrate 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.
|
|
||||||
|
|
||||||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
use codec::Encode;
|
|
||||||
use futures::future;
|
|
||||||
use polkadot_primitives::v0::{Id as ParaId, Info, Scheduling};
|
|
||||||
use polkadot_runtime_common::registrar;
|
|
||||||
use polkadot_test_runtime_client::Sr25519Keyring;
|
|
||||||
use sc_chain_spec::ChainSpec;
|
|
||||||
use sc_client_api::execution_extensions::ExecutionStrategies;
|
|
||||||
use sc_informant::OutputFormat;
|
|
||||||
use sc_network::{config::TransportConfig, multiaddr};
|
|
||||||
use sc_service::{
|
|
||||||
config::{
|
|
||||||
DatabaseConfig, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration,
|
|
||||||
OffchainWorkerConfig, PruningMode, WasmExecutionMethod,
|
|
||||||
},
|
|
||||||
BasePath, Configuration, Error as ServiceError, Role, TaskExecutor,
|
|
||||||
};
|
|
||||||
use sp_api::BlockT;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use substrate_test_client::BlockchainEventsExt;
|
|
||||||
use substrate_test_runtime_client::AccountKeyring::*;
|
|
||||||
|
|
||||||
#[substrate_test_utils::test]
|
|
||||||
#[ignore]
|
|
||||||
async fn integration_test(task_executor: TaskExecutor) {
|
|
||||||
let para_id = ParaId::from(100);
|
|
||||||
|
|
||||||
// generate parachain spec
|
|
||||||
let spec = Box::new(crate::chain_spec::get_chain_spec(para_id));
|
|
||||||
|
|
||||||
// start alice
|
|
||||||
let alice = polkadot_test_service::run_test_node(task_executor.clone(), Alice, || {}, vec![]);
|
|
||||||
|
|
||||||
// start bob
|
|
||||||
let bob = polkadot_test_service::run_test_node(
|
|
||||||
task_executor.clone(),
|
|
||||||
Bob,
|
|
||||||
|| {},
|
|
||||||
vec![alice.addr.clone()],
|
|
||||||
);
|
|
||||||
|
|
||||||
// ensure alice and bob can produce blocks
|
|
||||||
future::join(alice.wait_for_blocks(2), bob.wait_for_blocks(2)).await;
|
|
||||||
|
|
||||||
// export genesis state
|
|
||||||
let block = crate::command::generate_genesis_state(&(spec.clone() as Box<_>)).unwrap();
|
|
||||||
let genesis_state = block.header().encode();
|
|
||||||
|
|
||||||
// create and sign transaction to register parachain
|
|
||||||
let function = polkadot_test_runtime::Call::Sudo(pallet_sudo::Call::sudo(Box::new(
|
|
||||||
polkadot_test_runtime::Call::Registrar(registrar::Call::register_para(
|
|
||||||
para_id,
|
|
||||||
Info {
|
|
||||||
scheduling: Scheduling::Always,
|
|
||||||
},
|
|
||||||
parachain_runtime::WASM_BINARY
|
|
||||||
.expect("You need to build the WASM binary to run this test!")
|
|
||||||
.to_vec()
|
|
||||||
.into(),
|
|
||||||
genesis_state.into(),
|
|
||||||
)),
|
|
||||||
)));
|
|
||||||
|
|
||||||
// register parachain
|
|
||||||
let _ = alice.call_function(function, Alice).await.unwrap();
|
|
||||||
|
|
||||||
// run cumulus charlie (a validator)
|
|
||||||
let key = Arc::new(sp_core::Pair::generate().0);
|
|
||||||
let polkadot_config = polkadot_test_service::node_config(
|
|
||||||
|| {},
|
|
||||||
task_executor.clone(),
|
|
||||||
Charlie,
|
|
||||||
vec![alice.addr.clone(), bob.addr.clone()],
|
|
||||||
);
|
|
||||||
let charlie_config =
|
|
||||||
parachain_config(task_executor.clone(), Charlie, vec![], spec.clone()).unwrap();
|
|
||||||
let multiaddr = charlie_config.network.listen_addresses[0].clone();
|
|
||||||
let (charlie_task_manager, charlie_client, charlie_network) =
|
|
||||||
crate::service::start_node(charlie_config, key, polkadot_config, para_id, true, true)
|
|
||||||
.unwrap();
|
|
||||||
charlie_client.wait_for_blocks(4).await;
|
|
||||||
let peer_id = charlie_network.local_peer_id().clone();
|
|
||||||
let charlie_addr = MultiaddrWithPeerId { multiaddr, peer_id };
|
|
||||||
|
|
||||||
// run cumulus dave (not a validator)
|
|
||||||
//
|
|
||||||
// a collator running in non-validator mode should be able to sync blocks from the tip of the
|
|
||||||
// parachain
|
|
||||||
let key = Arc::new(sp_core::Pair::generate().0);
|
|
||||||
let polkadot_config = polkadot_test_service::node_config(
|
|
||||||
|| {},
|
|
||||||
task_executor.clone(),
|
|
||||||
Dave,
|
|
||||||
vec![alice.addr.clone(), bob.addr.clone()],
|
|
||||||
);
|
|
||||||
let dave_config = parachain_config(
|
|
||||||
task_executor.clone(),
|
|
||||||
Dave,
|
|
||||||
vec![charlie_addr],
|
|
||||||
spec.clone(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let (dave_task_manager, dave_client, _dave_network) =
|
|
||||||
crate::service::start_node(dave_config, key, polkadot_config, para_id, false, true)
|
|
||||||
.unwrap();
|
|
||||||
dave_client.wait_for_blocks(4).await;
|
|
||||||
|
|
||||||
alice.task_manager.clean_shutdown();
|
|
||||||
bob.task_manager.clean_shutdown();
|
|
||||||
charlie_task_manager.clean_shutdown();
|
|
||||||
dave_task_manager.clean_shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parachain_config(
|
|
||||||
task_executor: TaskExecutor,
|
|
||||||
key: Sr25519Keyring,
|
|
||||||
boot_nodes: Vec<MultiaddrWithPeerId>,
|
|
||||||
spec: Box<dyn ChainSpec>,
|
|
||||||
) -> Result<Configuration, ServiceError> {
|
|
||||||
let base_path = BasePath::new_temp_dir()?;
|
|
||||||
let root = base_path.path().to_path_buf();
|
|
||||||
let role = Role::Authority {
|
|
||||||
sentry_nodes: Vec::new(),
|
|
||||||
};
|
|
||||||
let key_seed = key.to_seed();
|
|
||||||
|
|
||||||
let mut network_config = NetworkConfiguration::new(
|
|
||||||
format!("Cumulus Test Node for: {}", key_seed),
|
|
||||||
"network/test/0.1",
|
|
||||||
Default::default(),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
let informant_output_format = OutputFormat {
|
|
||||||
enable_color: false,
|
|
||||||
prefix: format!("[{}] ", key_seed),
|
|
||||||
};
|
|
||||||
|
|
||||||
network_config.boot_nodes = boot_nodes;
|
|
||||||
|
|
||||||
network_config.allow_non_globals_in_dht = false;
|
|
||||||
|
|
||||||
network_config
|
|
||||||
.listen_addresses
|
|
||||||
.push(multiaddr::Protocol::Memory(rand::random()).into());
|
|
||||||
|
|
||||||
network_config.transport = TransportConfig::MemoryOnly;
|
|
||||||
|
|
||||||
Ok(Configuration {
|
|
||||||
impl_name: "cumulus-test-node".to_string(),
|
|
||||||
impl_version: "0.1".to_string(),
|
|
||||||
role,
|
|
||||||
task_executor,
|
|
||||||
transaction_pool: Default::default(),
|
|
||||||
network: network_config,
|
|
||||||
keystore: KeystoreConfig::Path {
|
|
||||||
path: root.join("key"),
|
|
||||||
password: None,
|
|
||||||
},
|
|
||||||
database: DatabaseConfig::RocksDb {
|
|
||||||
path: root.join("db"),
|
|
||||||
cache_size: 128,
|
|
||||||
},
|
|
||||||
state_cache_size: 67108864,
|
|
||||||
state_cache_child_ratio: None,
|
|
||||||
pruning: PruningMode::ArchiveAll,
|
|
||||||
chain_spec: spec,
|
|
||||||
wasm_method: WasmExecutionMethod::Interpreted,
|
|
||||||
// NOTE: we enforce the use of the native runtime to make the errors more debuggable
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
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: OffchainWorkerConfig {
|
|
||||||
enabled: true,
|
|
||||||
indexing_enabled: false,
|
|
||||||
},
|
|
||||||
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),
|
|
||||||
informant_output_format,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -24,8 +24,6 @@ mod chain_spec;
|
|||||||
mod service;
|
mod service;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod command;
|
mod command;
|
||||||
#[cfg(test)]
|
|
||||||
mod integration_test;
|
|
||||||
|
|
||||||
fn main() -> sc_cli::Result<()> {
|
fn main() -> sc_cli::Result<()> {
|
||||||
command::run()
|
command::run()
|
||||||
|
|||||||
@@ -15,24 +15,18 @@
|
|||||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use ansi_term::Color;
|
use ansi_term::Color;
|
||||||
use cumulus_collator::CollatorBuilder;
|
|
||||||
use cumulus_network::DelayedBlockAnnounceValidator;
|
use cumulus_network::DelayedBlockAnnounceValidator;
|
||||||
use cumulus_service::{
|
use cumulus_service::{
|
||||||
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
|
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
|
||||||
};
|
};
|
||||||
use polkadot_primitives::v0::CollatorPair;
|
use polkadot_primitives::v0::CollatorPair;
|
||||||
use rococo_parachain_primitives::Block;
|
use rococo_parachain_primitives::Block;
|
||||||
use sc_client_api::{Backend as BackendT, BlockBackend, Finalizer, UsageProvider};
|
|
||||||
use sc_executor::native_executor_instance;
|
use sc_executor::native_executor_instance;
|
||||||
pub use sc_executor::NativeExecutor;
|
pub use sc_executor::NativeExecutor;
|
||||||
use sc_informant::OutputFormat;
|
use sc_informant::OutputFormat;
|
||||||
use sc_network::NetworkService;
|
|
||||||
use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager};
|
use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager};
|
||||||
use sp_api::ConstructRuntimeApi;
|
use sp_api::ConstructRuntimeApi;
|
||||||
use sp_blockchain::HeaderBackend;
|
use sp_runtime::traits::BlakeTwo256;
|
||||||
use sp_consensus::{BlockImport, Environment, Error as ConsensusError, Proposer};
|
|
||||||
use sp_core::{crypto::Pair, H256};
|
|
||||||
use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
|
|
||||||
use sp_trie::PrefixedMemoryDB;
|
use sp_trie::PrefixedMemoryDB;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -122,91 +116,6 @@ where
|
|||||||
Ok(params)
|
Ok(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start a test collator node for a parachain.
|
|
||||||
///
|
|
||||||
/// A collator is similar to a validator in a normal blockchain.
|
|
||||||
/// It is responsible for producing blocks and sending the blocks to a
|
|
||||||
/// parachain validator for validation and inclusion into the relay chain.
|
|
||||||
pub fn start_test_collator<'a, Block, PF, BI, BS, Client, Backend>(
|
|
||||||
StartCollatorParams {
|
|
||||||
para_id,
|
|
||||||
proposer_factory,
|
|
||||||
inherent_data_providers,
|
|
||||||
block_import,
|
|
||||||
block_status,
|
|
||||||
announce_block,
|
|
||||||
client,
|
|
||||||
block_announce_validator,
|
|
||||||
task_manager,
|
|
||||||
polkadot_config,
|
|
||||||
collator_key,
|
|
||||||
}: StartCollatorParams<'a, Block, PF, BI, BS, Client>,
|
|
||||||
) -> sc_service::error::Result<()>
|
|
||||||
where
|
|
||||||
Block: BlockT,
|
|
||||||
PF: Environment<Block> + Send + 'static,
|
|
||||||
BI: BlockImport<
|
|
||||||
Block,
|
|
||||||
Error = ConsensusError,
|
|
||||||
Transaction = <PF::Proposer as Proposer<Block>>::Transaction,
|
|
||||||
> + Send
|
|
||||||
+ Sync
|
|
||||||
+ 'static,
|
|
||||||
BS: BlockBackend<Block> + Send + Sync + 'static,
|
|
||||||
Client: Finalizer<Block, Backend>
|
|
||||||
+ UsageProvider<Block>
|
|
||||||
+ HeaderBackend<Block>
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ BlockBackend<Block>
|
|
||||||
+ 'static,
|
|
||||||
for<'b> &'b Client: BlockImport<Block>,
|
|
||||||
Backend: BackendT<Block> + 'static,
|
|
||||||
{
|
|
||||||
let builder = CollatorBuilder::new(
|
|
||||||
proposer_factory,
|
|
||||||
inherent_data_providers,
|
|
||||||
block_import,
|
|
||||||
block_status,
|
|
||||||
para_id,
|
|
||||||
client,
|
|
||||||
announce_block,
|
|
||||||
block_announce_validator,
|
|
||||||
);
|
|
||||||
|
|
||||||
let (polkadot_future, polkadot_task_manager) = {
|
|
||||||
let (task_manager, client, handles, _network, _rpc_handlers) =
|
|
||||||
polkadot_test_service::polkadot_test_new_full(
|
|
||||||
polkadot_config,
|
|
||||||
Some((collator_key.public(), para_id)),
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
6000,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let test_client = polkadot_test_service::TestClient(client);
|
|
||||||
|
|
||||||
let future = polkadot_collator::build_collator_service(
|
|
||||||
task_manager.spawn_handle(),
|
|
||||||
handles,
|
|
||||||
test_client,
|
|
||||||
para_id,
|
|
||||||
collator_key,
|
|
||||||
builder,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
(future, task_manager)
|
|
||||||
};
|
|
||||||
|
|
||||||
task_manager
|
|
||||||
.spawn_essential_handle()
|
|
||||||
.spawn("polkadot", polkadot_future);
|
|
||||||
|
|
||||||
task_manager.add_child(polkadot_task_manager);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.
|
/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.
|
||||||
///
|
///
|
||||||
/// This is the actual implementation that is abstract over the executor and the runtime api.
|
/// This is the actual implementation that is abstract over the executor and the runtime api.
|
||||||
@@ -217,12 +126,7 @@ fn start_node_impl<RuntimeApi, Executor, RB>(
|
|||||||
id: polkadot_primitives::v0::Id,
|
id: polkadot_primitives::v0::Id,
|
||||||
validator: bool,
|
validator: bool,
|
||||||
rpc_ext_builder: RB,
|
rpc_ext_builder: RB,
|
||||||
test: bool,
|
) -> sc_service::error::Result<(TaskManager, Arc<TFullClient<Block, RuntimeApi, Executor>>)>
|
||||||
) -> sc_service::error::Result<(
|
|
||||||
TaskManager,
|
|
||||||
Arc<TFullClient<Block, RuntimeApi, Executor>>,
|
|
||||||
Arc<NetworkService<Block, H256>>,
|
|
||||||
)>
|
|
||||||
where
|
where
|
||||||
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, Executor>>
|
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, Executor>>
|
||||||
+ Send
|
+ Send
|
||||||
@@ -339,11 +243,7 @@ where
|
|||||||
collator_key,
|
collator_key,
|
||||||
};
|
};
|
||||||
|
|
||||||
if test {
|
start_collator(params)?;
|
||||||
start_test_collator(params)?;
|
|
||||||
} else {
|
|
||||||
start_collator(params)?;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let params = StartFullNodeParams {
|
let params = StartFullNodeParams {
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
@@ -360,7 +260,7 @@ where
|
|||||||
|
|
||||||
start_network.start_network();
|
start_network.start_network();
|
||||||
|
|
||||||
Ok((task_manager, client, network))
|
Ok((task_manager, client))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start a normal parachain node.
|
/// Start a normal parachain node.
|
||||||
@@ -370,11 +270,9 @@ pub fn start_node(
|
|||||||
polkadot_config: polkadot_collator::Configuration,
|
polkadot_config: polkadot_collator::Configuration,
|
||||||
id: polkadot_primitives::v0::Id,
|
id: polkadot_primitives::v0::Id,
|
||||||
validator: bool,
|
validator: bool,
|
||||||
test: bool,
|
|
||||||
) -> sc_service::error::Result<(
|
) -> sc_service::error::Result<(
|
||||||
TaskManager,
|
TaskManager,
|
||||||
Arc<TFullClient<Block, parachain_runtime::RuntimeApi, RuntimeExecutor>>,
|
Arc<TFullClient<Block, parachain_runtime::RuntimeApi, RuntimeExecutor>>,
|
||||||
Arc<NetworkService<Block, H256>>,
|
|
||||||
)> {
|
)> {
|
||||||
start_node_impl::<parachain_runtime::RuntimeApi, RuntimeExecutor, _>(
|
start_node_impl::<parachain_runtime::RuntimeApi, RuntimeExecutor, _>(
|
||||||
parachain_config,
|
parachain_config,
|
||||||
@@ -383,7 +281,6 @@ pub fn start_node(
|
|||||||
id,
|
id,
|
||||||
validator,
|
validator,
|
||||||
|_| Default::default(),
|
|_| Default::default(),
|
||||||
test,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,7 +291,6 @@ pub fn start_contracts_node(
|
|||||||
polkadot_config: polkadot_collator::Configuration,
|
polkadot_config: polkadot_collator::Configuration,
|
||||||
id: polkadot_primitives::v0::Id,
|
id: polkadot_primitives::v0::Id,
|
||||||
validator: bool,
|
validator: bool,
|
||||||
test: bool,
|
|
||||||
) -> sc_service::error::Result<TaskManager> {
|
) -> sc_service::error::Result<TaskManager> {
|
||||||
start_node_impl::<parachain_contracts_runtime::RuntimeApi, ContractsRuntimeExecutor, _>(
|
start_node_impl::<parachain_contracts_runtime::RuntimeApi, ContractsRuntimeExecutor, _>(
|
||||||
parachain_config,
|
parachain_config,
|
||||||
@@ -409,7 +305,6 @@ pub fn start_contracts_node(
|
|||||||
io.extend_with(ContractsApi::to_delegate(Contracts::new(client)));
|
io.extend_with(ContractsApi::to_delegate(Contracts::new(client)));
|
||||||
io
|
io
|
||||||
},
|
},
|
||||||
test,
|
|
||||||
)
|
)
|
||||||
.map(|r| r.0)
|
.map(|r| r.0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,30 +7,35 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
# Other dependencies
|
# Other dependencies
|
||||||
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = [ "derive" ] }
|
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = [ "derive" ] }
|
||||||
memory-db = { version = "0.24.0", default-features = false }
|
|
||||||
hash-db = { version = "0.15.2", default-features = false }
|
hash-db = { version = "0.15.2", default-features = false }
|
||||||
|
memory-db = { version = "0.24.0", default-features = false }
|
||||||
trie-db = { version = "0.22.0", default-features = false }
|
trie-db = { version = "0.22.0", default-features = false }
|
||||||
|
|
||||||
# Cumulus dependencies
|
# Cumulus dependencies
|
||||||
cumulus-primitives = { path = "../primitives", default-features = false }
|
cumulus-primitives = { path = "../primitives", default-features = false }
|
||||||
|
|
||||||
# Substrate dependencies
|
# Substrate dependencies
|
||||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
|
||||||
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
|
||||||
# Polkadot dependencies
|
# Polkadot dependencies
|
||||||
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", branch = "rococo-branch", default-features = false, features = [ "wasm-api" ] }
|
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", branch = "rococo-branch", default-features = false, features = [ "wasm-api" ] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
# Substrate dependencies
|
||||||
sc-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
sc-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
|
||||||
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
|
||||||
|
# Cumulus dependencies
|
||||||
test-client = { package = "cumulus-test-client", path = "../test/client" }
|
test-client = { package = "cumulus-test-client", path = "../test/client" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -25,14 +25,16 @@ use sp_blockchain::HeaderBackend;
|
|||||||
use sp_consensus::SelectChain;
|
use sp_consensus::SelectChain;
|
||||||
use sp_core::traits::CallInWasm;
|
use sp_core::traits::CallInWasm;
|
||||||
use sp_io::TestExternalities;
|
use sp_io::TestExternalities;
|
||||||
use sp_keyring::AccountKeyring;
|
use sp_keyring::AccountKeyring::*;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
generic::BlockId,
|
generic::BlockId,
|
||||||
traits::{Block as BlockT, Header as HeaderT},
|
traits::{Block as BlockT, Header as HeaderT},
|
||||||
};
|
};
|
||||||
use test_client::{
|
use test_client::{
|
||||||
runtime::{Block, Hash, Header, Transfer, WASM_BINARY},
|
generate_block_inherents,
|
||||||
Client, DefaultTestClientBuilderExt, LongestChain, TestClientBuilder, TestClientBuilderExt,
|
runtime::{Block, Hash, Header, UncheckedExtrinsic, WASM_BINARY},
|
||||||
|
transfer, Client, DefaultTestClientBuilderExt, LongestChain, TestClientBuilder,
|
||||||
|
TestClientBuilderExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
@@ -74,53 +76,27 @@ fn call_validate_block(
|
|||||||
.map_err(|err| err.into())
|
.map_err(|err| err.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_extrinsics() -> Vec<<Block as BlockT>::Extrinsic> {
|
|
||||||
vec![
|
|
||||||
Transfer {
|
|
||||||
from: AccountKeyring::Alice.into(),
|
|
||||||
to: AccountKeyring::Bob.into(),
|
|
||||||
amount: 69,
|
|
||||||
nonce: 0,
|
|
||||||
}
|
|
||||||
.into_signed_tx(),
|
|
||||||
Transfer {
|
|
||||||
from: AccountKeyring::Alice.into(),
|
|
||||||
to: AccountKeyring::Charlie.into(),
|
|
||||||
amount: 100,
|
|
||||||
nonce: 1,
|
|
||||||
}
|
|
||||||
.into_signed_tx(),
|
|
||||||
Transfer {
|
|
||||||
from: AccountKeyring::Bob.into(),
|
|
||||||
to: AccountKeyring::Charlie.into(),
|
|
||||||
amount: 100,
|
|
||||||
nonce: 0,
|
|
||||||
}
|
|
||||||
.into_signed_tx(),
|
|
||||||
Transfer {
|
|
||||||
from: AccountKeyring::Charlie.into(),
|
|
||||||
to: AccountKeyring::Alice.into(),
|
|
||||||
amount: 500,
|
|
||||||
nonce: 0,
|
|
||||||
}
|
|
||||||
.into_signed_tx(),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_test_client() -> (Client, LongestChain) {
|
fn create_test_client() -> (Client, LongestChain) {
|
||||||
TestClientBuilder::new().build_with_longest_chain()
|
TestClientBuilder::new()
|
||||||
|
// NOTE: this allows easier debugging
|
||||||
|
.set_execution_strategy(sc_client_api::ExecutionStrategy::NativeWhenPossible)
|
||||||
|
.build_with_longest_chain()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_block_with_proof(
|
fn build_block_with_proof(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
|
extra_extrinsics: Vec<UncheckedExtrinsic>,
|
||||||
) -> (Block, sp_trie::StorageProof) {
|
) -> (Block, sp_trie::StorageProof) {
|
||||||
let block_id = BlockId::Hash(client.info().best_hash);
|
let block_id = BlockId::Hash(client.info().best_hash);
|
||||||
let mut builder = client
|
let mut builder = client
|
||||||
.new_block_at(&block_id, Default::default(), true)
|
.new_block_at(&block_id, Default::default(), true)
|
||||||
.expect("Initializes new block");
|
.expect("Initializes new block");
|
||||||
|
|
||||||
extrinsics
|
generate_block_inherents(client)
|
||||||
|
.into_iter()
|
||||||
|
.for_each(|e| builder.push(e).expect("Pushes an inherent"));
|
||||||
|
|
||||||
|
extra_extrinsics
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|e| builder.push(e).expect("Pushes an extrinsic"));
|
.for_each(|e| builder.push(e).expect("Pushes an extrinsic"));
|
||||||
|
|
||||||
@@ -135,10 +111,10 @@ fn build_block_with_proof(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn validate_block_with_no_extrinsics() {
|
fn validate_block_no_extra_extrinsics() {
|
||||||
let (client, longest_chain) = create_test_client();
|
let (client, longest_chain) = create_test_client();
|
||||||
let parent_head = longest_chain.best_chain().expect("Best block exists");
|
let parent_head = longest_chain.best_chain().expect("Best block exists");
|
||||||
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
|
let (block, witness_data) = build_block_with_proof(&client, vec![]);
|
||||||
let (header, extrinsics) = block.deconstruct();
|
let (header, extrinsics) = block.deconstruct();
|
||||||
|
|
||||||
let block_data = ParachainBlockData::new(header.clone(), extrinsics, witness_data);
|
let block_data = ParachainBlockData::new(header.clone(), extrinsics, witness_data);
|
||||||
@@ -148,10 +124,16 @@ fn validate_block_with_no_extrinsics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn validate_block_with_extrinsics() {
|
fn validate_block_with_extra_extrinsics() {
|
||||||
let (client, longest_chain) = create_test_client();
|
let (client, longest_chain) = create_test_client();
|
||||||
let parent_head = longest_chain.best_chain().expect("Best block exists");
|
let parent_head = longest_chain.best_chain().expect("Best block exists");
|
||||||
let (block, witness_data) = build_block_with_proof(&client, create_extrinsics());
|
let extra_extrinsics = vec![
|
||||||
|
transfer(&client, Alice, Bob, 69),
|
||||||
|
transfer(&client, Bob, Charlie, 100),
|
||||||
|
transfer(&client, Charlie, Alice, 500),
|
||||||
|
];
|
||||||
|
|
||||||
|
let (block, witness_data) = build_block_with_proof(&client, extra_extrinsics);
|
||||||
let (header, extrinsics) = block.deconstruct();
|
let (header, extrinsics) = block.deconstruct();
|
||||||
|
|
||||||
let block_data = ParachainBlockData::new(header.clone(), extrinsics, witness_data);
|
let block_data = ParachainBlockData::new(header.clone(), extrinsics, witness_data);
|
||||||
@@ -161,11 +143,11 @@ fn validate_block_with_extrinsics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic(expected = "Calls `validate_block`: Other(\"Trap: Trap { kind: Unreachable }\")")]
|
||||||
fn validate_block_invalid_parent_hash() {
|
fn validate_block_invalid_parent_hash() {
|
||||||
let (client, longest_chain) = create_test_client();
|
let (client, longest_chain) = create_test_client();
|
||||||
let parent_head = longest_chain.best_chain().expect("Best block exists");
|
let parent_head = longest_chain.best_chain().expect("Best block exists");
|
||||||
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
|
let (block, witness_data) = build_block_with_proof(&client, vec![]);
|
||||||
let (mut header, extrinsics) = block.deconstruct();
|
let (mut header, extrinsics) = block.deconstruct();
|
||||||
header.set_parent_hash(Hash::from_low_u64_be(1));
|
header.set_parent_hash(Hash::from_low_u64_be(1));
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,22 @@ edition = "2018"
|
|||||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sc-service = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
test-client = { package = "substrate-test-client", git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
test-client = { package = "substrate-test-client", git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
runtime = { package = "cumulus-test-runtime", path = "../runtime" }
|
|
||||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
|
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
|
||||||
sp-test-primitives = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
sp-test-primitives = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
|
||||||
|
# Cumulus dependencies
|
||||||
|
cumulus-test-service = { path = "../service" }
|
||||||
|
cumulus-primitives = { path = "../../primitives" }
|
||||||
|
runtime = { package = "cumulus-test-runtime", path = "../runtime" }
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Cumulus 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.
|
||||||
|
|
||||||
|
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use crate::Client;
|
||||||
|
use cumulus_primitives::{
|
||||||
|
inherents::VALIDATION_FUNCTION_PARAMS_IDENTIFIER,
|
||||||
|
validation_function_params::ValidationFunctionParams,
|
||||||
|
};
|
||||||
|
use runtime::GetLastTimestamp;
|
||||||
|
use sc_block_builder::BlockBuilderApi;
|
||||||
|
use sp_api::ProvideRuntimeApi;
|
||||||
|
use sp_blockchain::HeaderBackend;
|
||||||
|
use sp_core::ExecutionContext;
|
||||||
|
use sp_runtime::generic::BlockId;
|
||||||
|
|
||||||
|
/// Generate the inherents to a block so you don't have to.
|
||||||
|
pub fn generate_block_inherents(client: &Client) -> Vec<runtime::UncheckedExtrinsic> {
|
||||||
|
let mut inherent_data = sp_consensus::InherentData::new();
|
||||||
|
let block_id = BlockId::Hash(client.info().best_hash);
|
||||||
|
let last_timestamp = client
|
||||||
|
.runtime_api()
|
||||||
|
.get_last_timestamp(&block_id)
|
||||||
|
.expect("Get last timestamp");
|
||||||
|
let timestamp = last_timestamp + runtime::MinimumPeriod::get();
|
||||||
|
|
||||||
|
inherent_data
|
||||||
|
.put_data(sp_timestamp::INHERENT_IDENTIFIER, ×tamp)
|
||||||
|
.expect("Put timestamp failed");
|
||||||
|
inherent_data
|
||||||
|
.put_data(
|
||||||
|
VALIDATION_FUNCTION_PARAMS_IDENTIFIER,
|
||||||
|
&ValidationFunctionParams::default(),
|
||||||
|
)
|
||||||
|
.expect("Put validation function params failed");
|
||||||
|
|
||||||
|
client
|
||||||
|
.runtime_api()
|
||||||
|
.inherent_extrinsics_with_context(
|
||||||
|
&BlockId::number(0),
|
||||||
|
ExecutionContext::BlockConstruction,
|
||||||
|
inherent_data,
|
||||||
|
)
|
||||||
|
.expect("Get inherents failed")
|
||||||
|
}
|
||||||
@@ -16,15 +16,25 @@
|
|||||||
|
|
||||||
//! A Cumulus test client.
|
//! A Cumulus test client.
|
||||||
|
|
||||||
|
mod block_builder;
|
||||||
|
|
||||||
|
pub use block_builder::*;
|
||||||
|
|
||||||
|
use codec::Encode;
|
||||||
pub use runtime;
|
pub use runtime;
|
||||||
use runtime::{
|
use runtime::{
|
||||||
genesismap::{additional_storage_with_genesis, GenesisConfig},
|
Balance, Block, BlockHashCount, Call, GenesisConfig, Runtime, Signature, SignedExtra,
|
||||||
Block,
|
SignedPayload, UncheckedExtrinsic, VERSION,
|
||||||
};
|
};
|
||||||
use sc_service::client;
|
use sc_service::client;
|
||||||
use sp_core::{sr25519, storage::Storage, ChangesTrieConfiguration};
|
use sp_blockchain::HeaderBackend;
|
||||||
use sp_keyring::{AccountKeyring, Sr25519Keyring};
|
use sp_core::{map, storage::Storage, twox_128, ChangesTrieConfiguration};
|
||||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
|
use sp_runtime::{
|
||||||
|
generic::Era,
|
||||||
|
traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
|
||||||
|
BuildStorage, SaturatedConversion,
|
||||||
|
};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
pub use test_client::*;
|
pub use test_client::*;
|
||||||
|
|
||||||
mod local_executor {
|
mod local_executor {
|
||||||
@@ -63,14 +73,12 @@ pub struct GenesisParameters {
|
|||||||
|
|
||||||
impl test_client::GenesisInit for GenesisParameters {
|
impl test_client::GenesisInit for GenesisParameters {
|
||||||
fn genesis_storage(&self) -> Storage {
|
fn genesis_storage(&self) -> Storage {
|
||||||
use codec::Encode;
|
|
||||||
|
|
||||||
let changes_trie_config: Option<ChangesTrieConfiguration> = if self.support_changes_trie {
|
let changes_trie_config: Option<ChangesTrieConfiguration> = if self.support_changes_trie {
|
||||||
Some(sp_test_primitives::changes_trie_config())
|
Some(sp_test_primitives::changes_trie_config())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let mut storage = genesis_config(changes_trie_config).genesis_map();
|
let mut storage = genesis_config(changes_trie_config).build_storage().unwrap();
|
||||||
|
|
||||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||||
let state_root =
|
let state_root =
|
||||||
@@ -128,20 +136,68 @@ impl DefaultTestClientBuilderExt for TestClientBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn genesis_config(changes_trie_config: Option<ChangesTrieConfiguration>) -> GenesisConfig {
|
fn genesis_config(changes_trie_config: Option<ChangesTrieConfiguration>) -> GenesisConfig {
|
||||||
GenesisConfig::new(
|
cumulus_test_service::local_testnet_genesis(changes_trie_config)
|
||||||
changes_trie_config,
|
}
|
||||||
vec![
|
|
||||||
sr25519::Public::from(Sr25519Keyring::Alice).into(),
|
fn additional_storage_with_genesis(genesis_block: &Block) -> BTreeMap<Vec<u8>, Vec<u8>> {
|
||||||
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
map![
|
||||||
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
|
twox_128(&b"latest"[..]).to_vec() => genesis_block.hash().as_fixed_bytes().to_vec()
|
||||||
],
|
]
|
||||||
vec![
|
}
|
||||||
AccountKeyring::Alice.into(),
|
|
||||||
AccountKeyring::Bob.into(),
|
/// Generate an extrinsic from the provided function call, origin and [`Client`].
|
||||||
AccountKeyring::Charlie.into(),
|
pub fn generate_extrinsic(
|
||||||
],
|
client: &Client,
|
||||||
1000,
|
origin: sp_keyring::AccountKeyring,
|
||||||
Default::default(),
|
function: Call,
|
||||||
Default::default(),
|
) -> UncheckedExtrinsic {
|
||||||
|
let current_block_hash = client.info().best_hash;
|
||||||
|
let current_block = client.info().best_number.saturated_into();
|
||||||
|
let genesis_block = client.hash(0).unwrap().unwrap();
|
||||||
|
let nonce = 0;
|
||||||
|
let period = BlockHashCount::get()
|
||||||
|
.checked_next_power_of_two()
|
||||||
|
.map(|c| c / 2)
|
||||||
|
.unwrap_or(2) as u64;
|
||||||
|
let tip = 0;
|
||||||
|
let extra: SignedExtra = (
|
||||||
|
frame_system::CheckSpecVersion::<Runtime>::new(),
|
||||||
|
frame_system::CheckGenesis::<Runtime>::new(),
|
||||||
|
frame_system::CheckEra::<Runtime>::from(Era::mortal(period, current_block)),
|
||||||
|
frame_system::CheckNonce::<Runtime>::from(nonce),
|
||||||
|
frame_system::CheckWeight::<Runtime>::new(),
|
||||||
|
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
|
||||||
|
);
|
||||||
|
let raw_payload = SignedPayload::from_raw(
|
||||||
|
function.clone(),
|
||||||
|
extra.clone(),
|
||||||
|
(
|
||||||
|
VERSION.spec_version,
|
||||||
|
genesis_block,
|
||||||
|
current_block_hash,
|
||||||
|
(),
|
||||||
|
(),
|
||||||
|
(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
let signature = raw_payload.using_encoded(|e| origin.sign(e));
|
||||||
|
|
||||||
|
UncheckedExtrinsic::new_signed(
|
||||||
|
function.clone(),
|
||||||
|
origin.public().into(),
|
||||||
|
Signature::Sr25519(signature.clone()),
|
||||||
|
extra.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Transfer some token from one account to another using a provided test [`Client`].
|
||||||
|
pub fn transfer(
|
||||||
|
client: &Client,
|
||||||
|
origin: sp_keyring::AccountKeyring,
|
||||||
|
dest: sp_keyring::AccountKeyring,
|
||||||
|
value: Balance,
|
||||||
|
) -> UncheckedExtrinsic {
|
||||||
|
let function = Call::Balances(pallet_balances::Call::transfer(dest.public().into(), value));
|
||||||
|
|
||||||
|
generate_extrinsic(client, origin, function)
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,18 +3,74 @@ name = "cumulus-test-runtime"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
runtime = { package = "cumulus-runtime", path = "../../runtime", default-features = false }
|
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
|
||||||
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch", version = "2.0.0-rc5" }
|
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||||
|
|
||||||
|
# Substrate dependencies
|
||||||
|
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
|
||||||
|
# Cumulus dependencies
|
||||||
|
cumulus-parachain-upgrade = { path = "../../parachain-upgrade", default-features = false }
|
||||||
|
cumulus-primitives = { path = "../../primitives", default-features = false }
|
||||||
|
cumulus-runtime = { path = "../../runtime", default-features = false }
|
||||||
|
cumulus-upward-message = { path = "../../upward-message", default-features = false }
|
||||||
|
|
||||||
|
# Polkadot dependencies
|
||||||
|
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch", default-features = false }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = " 1.0.6" }
|
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.6" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = [ "std" ]
|
||||||
std = [
|
std = [
|
||||||
"runtime/std",
|
"codec/std",
|
||||||
"substrate-test-runtime/std",
|
"cumulus-parachain-upgrade/std",
|
||||||
|
"cumulus-primitives/std",
|
||||||
|
"cumulus-runtime/std",
|
||||||
|
"cumulus-upward-message/std",
|
||||||
|
"frame-executive/std",
|
||||||
|
"frame-support/std",
|
||||||
|
"frame-system/std",
|
||||||
|
"pallet-balances/std",
|
||||||
|
"pallet-randomness-collective-flip/std",
|
||||||
|
"pallet-sudo/std",
|
||||||
|
"pallet-timestamp/std",
|
||||||
|
"pallet-transaction-payment/std",
|
||||||
|
"serde",
|
||||||
|
"sp-api/std",
|
||||||
|
"sp-block-builder/std",
|
||||||
|
"sp-core/std",
|
||||||
|
"sp-inherents/std",
|
||||||
|
"sp-io/std",
|
||||||
|
"sp-offchain/std",
|
||||||
|
"sp-runtime/std",
|
||||||
|
"sp-session/std",
|
||||||
|
"sp-std/std",
|
||||||
|
"sp-transaction-pool/std",
|
||||||
|
"sp-version/std",
|
||||||
|
]
|
||||||
|
# Will be enabled by the `wasm-builder` when building the runtime for WASM.
|
||||||
|
runtime-wasm = [
|
||||||
|
"cumulus-upward-message/runtime-wasm",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||||
// This file is part of Substrate.
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
// Substrate is free software: you can redistribute it and/or modify
|
// Substrate is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use wasm_builder_runner::WasmBuilder;
|
use wasm_builder_runner::WasmBuilder;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||||
// This file is part of Substrate.
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
// Substrate is free software: you can redistribute it and/or modify
|
// Cumulus is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
|
|
||||||
// Substrate is distributed in the hope that it will be useful,
|
// Cumulus is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
||||||
@@ -14,14 +14,338 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! A Cumulus test runtime.
|
|
||||||
|
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
|
||||||
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
// Make the WASM binary available.
|
// Make the WASM binary available.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||||
|
|
||||||
pub use substrate_test_runtime::*;
|
use sp_api::{decl_runtime_apis, impl_runtime_apis};
|
||||||
|
use sp_core::OpaqueMetadata;
|
||||||
|
use sp_runtime::{
|
||||||
|
create_runtime_str, generic, impl_opaque_keys,
|
||||||
|
traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, Saturating, Verify},
|
||||||
|
transaction_validity::{TransactionSource, TransactionValidity},
|
||||||
|
ApplyExtrinsicResult, MultiSignature,
|
||||||
|
};
|
||||||
|
use sp_std::prelude::*;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
use sp_version::NativeVersion;
|
||||||
|
use sp_version::RuntimeVersion;
|
||||||
|
|
||||||
runtime::register_validate_block!(Block, system::BlockExecutor);
|
// A few exports that help ease life for downstream crates.
|
||||||
|
pub use frame_support::{
|
||||||
|
construct_runtime, parameter_types,
|
||||||
|
traits::Randomness,
|
||||||
|
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight},
|
||||||
|
StorageValue,
|
||||||
|
};
|
||||||
|
pub use pallet_balances::Call as BalancesCall;
|
||||||
|
pub use pallet_timestamp::Call as TimestampCall;
|
||||||
|
#[cfg(any(feature = "std", test))]
|
||||||
|
pub use sp_runtime::BuildStorage;
|
||||||
|
pub use sp_runtime::{Perbill, Permill};
|
||||||
|
|
||||||
|
pub type SessionHandlers = ();
|
||||||
|
|
||||||
|
impl_opaque_keys! {
|
||||||
|
pub struct SessionKeys {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This runtime version.
|
||||||
|
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||||
|
spec_name: create_runtime_str!("cumulus-test-parachain"),
|
||||||
|
impl_name: create_runtime_str!("cumulus-test-parachain"),
|
||||||
|
authoring_version: 1,
|
||||||
|
spec_version: 3,
|
||||||
|
impl_version: 1,
|
||||||
|
apis: RUNTIME_API_VERSIONS,
|
||||||
|
transaction_version: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const MILLISECS_PER_BLOCK: u64 = 1000;
|
||||||
|
|
||||||
|
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
|
||||||
|
|
||||||
|
pub const EPOCH_DURATION_IN_BLOCKS: u32 = 10 * MINUTES;
|
||||||
|
|
||||||
|
// These time units are defined in number of blocks.
|
||||||
|
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
|
||||||
|
pub const HOURS: BlockNumber = MINUTES * 60;
|
||||||
|
pub const DAYS: BlockNumber = HOURS * 24;
|
||||||
|
|
||||||
|
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
|
||||||
|
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
|
||||||
|
|
||||||
|
/// The version information used to identify this runtime when compiled natively.
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub fn native_version() -> NativeVersion {
|
||||||
|
NativeVersion {
|
||||||
|
runtime_version: VERSION,
|
||||||
|
can_author_with: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter_types! {
|
||||||
|
pub const BlockHashCount: BlockNumber = 250;
|
||||||
|
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
|
||||||
|
/// Assume 10% of weight for average on_initialize calls.
|
||||||
|
pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
|
||||||
|
.saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
|
||||||
|
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
|
||||||
|
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
|
||||||
|
pub const Version: RuntimeVersion = VERSION;
|
||||||
|
pub const ExtrinsicBaseWeight: Weight = 10_000_000;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl frame_system::Trait for Runtime {
|
||||||
|
/// The identifier used to distinguish between accounts.
|
||||||
|
type AccountId = AccountId;
|
||||||
|
/// The aggregated dispatch type that is available for extrinsics.
|
||||||
|
type Call = Call;
|
||||||
|
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
|
||||||
|
type Lookup = IdentityLookup<AccountId>;
|
||||||
|
/// The index type for storing how many extrinsics an account has signed.
|
||||||
|
type Index = Index;
|
||||||
|
/// The index type for blocks.
|
||||||
|
type BlockNumber = BlockNumber;
|
||||||
|
/// The type for hashing blocks and tries.
|
||||||
|
type Hash = Hash;
|
||||||
|
/// The hashing algorithm used.
|
||||||
|
type Hashing = BlakeTwo256;
|
||||||
|
/// The header type.
|
||||||
|
type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||||
|
/// The ubiquitous event type.
|
||||||
|
type Event = Event;
|
||||||
|
/// The ubiquitous origin type.
|
||||||
|
type Origin = Origin;
|
||||||
|
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
|
||||||
|
type BlockHashCount = BlockHashCount;
|
||||||
|
/// Maximum weight of each block. With a default weight system of 1byte == 1weight, 4mb is ok.
|
||||||
|
type MaximumBlockWeight = MaximumBlockWeight;
|
||||||
|
/// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
|
||||||
|
type MaximumBlockLength = MaximumBlockLength;
|
||||||
|
/// Portion of the block weight that is available to all normal transactions.
|
||||||
|
type AvailableBlockRatio = AvailableBlockRatio;
|
||||||
|
/// Runtime version.
|
||||||
|
type Version = Version;
|
||||||
|
/// Converts a module to an index of this module in the runtime.
|
||||||
|
type ModuleToIndex = ModuleToIndex;
|
||||||
|
type AccountData = pallet_balances::AccountData<Balance>;
|
||||||
|
type OnNewAccount = ();
|
||||||
|
type OnKilledAccount = ();
|
||||||
|
type DbWeight = ();
|
||||||
|
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
|
||||||
|
type BlockExecutionWeight = ();
|
||||||
|
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
|
||||||
|
type BaseCallFilter = ();
|
||||||
|
type SystemWeightInfo = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter_types! {
|
||||||
|
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_timestamp::Trait for Runtime {
|
||||||
|
/// A timestamp: milliseconds since the unix epoch.
|
||||||
|
type Moment = u64;
|
||||||
|
type OnTimestampSet = ();
|
||||||
|
type MinimumPeriod = MinimumPeriod;
|
||||||
|
type WeightInfo = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter_types! {
|
||||||
|
pub const ExistentialDeposit: u128 = 500;
|
||||||
|
pub const TransferFee: u128 = 0;
|
||||||
|
pub const CreationFee: u128 = 0;
|
||||||
|
pub const TransactionByteFee: u128 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_balances::Trait for Runtime {
|
||||||
|
/// The type for recording an account's balance.
|
||||||
|
type Balance = Balance;
|
||||||
|
/// The ubiquitous event type.
|
||||||
|
type Event = Event;
|
||||||
|
type DustRemoval = ();
|
||||||
|
type ExistentialDeposit = ExistentialDeposit;
|
||||||
|
type AccountStore = System;
|
||||||
|
type WeightInfo = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_transaction_payment::Trait for Runtime {
|
||||||
|
type Currency = Balances;
|
||||||
|
type OnTransactionPayment = ();
|
||||||
|
type TransactionByteFee = TransactionByteFee;
|
||||||
|
type WeightToFee = IdentityFee<Balance>;
|
||||||
|
type FeeMultiplierUpdate = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_sudo::Trait for Runtime {
|
||||||
|
type Call = Call;
|
||||||
|
type Event = Event;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl cumulus_parachain_upgrade::Trait for Runtime {
|
||||||
|
type Event = Event;
|
||||||
|
type OnValidationFunctionParams = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter_types! {
|
||||||
|
pub storage ParachainId: cumulus_primitives::ParaId = 100.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
construct_runtime! {
|
||||||
|
pub enum Runtime where
|
||||||
|
Block = Block,
|
||||||
|
NodeBlock = NodeBlock,
|
||||||
|
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||||
|
{
|
||||||
|
System: frame_system::{Module, Call, Storage, Config, Event<T>},
|
||||||
|
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
|
||||||
|
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
|
||||||
|
Sudo: pallet_sudo::{Module, Call, Storage, Config<T>, Event<T>},
|
||||||
|
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
|
||||||
|
ParachainUpgrade: cumulus_parachain_upgrade::{Module, Call, Storage, Inherent, Event},
|
||||||
|
TransactionPayment: pallet_transaction_payment::{Module, Storage},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Index of a transaction in the chain.
|
||||||
|
pub type Index = u32;
|
||||||
|
/// A hash of some data used by the chain.
|
||||||
|
pub type Hash = sp_core::H256;
|
||||||
|
/// Balance of an account.
|
||||||
|
pub type Balance = u128;
|
||||||
|
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
|
||||||
|
pub type Signature = MultiSignature;
|
||||||
|
/// An index to a block.
|
||||||
|
pub type BlockNumber = u32;
|
||||||
|
/// Some way of identifying an account on the chain. We intentionally make it equivalent
|
||||||
|
/// to the public key of our transaction signing scheme.
|
||||||
|
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
|
||||||
|
/// Opaque block type.
|
||||||
|
pub type NodeBlock = generic::Block<Header, sp_runtime::OpaqueExtrinsic>;
|
||||||
|
|
||||||
|
/// The address format for describing accounts.
|
||||||
|
pub type Address = AccountId;
|
||||||
|
/// Block header type as expected by this runtime.
|
||||||
|
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||||
|
/// Block type as expected by this runtime.
|
||||||
|
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||||
|
/// A Block signed with a Justification
|
||||||
|
pub type SignedBlock = generic::SignedBlock<Block>;
|
||||||
|
/// BlockId type as expected by this runtime.
|
||||||
|
pub type BlockId = generic::BlockId<Block>;
|
||||||
|
/// The SignedExtension to the basic transaction logic.
|
||||||
|
pub type SignedExtra = (
|
||||||
|
frame_system::CheckSpecVersion<Runtime>,
|
||||||
|
frame_system::CheckGenesis<Runtime>,
|
||||||
|
frame_system::CheckEra<Runtime>,
|
||||||
|
frame_system::CheckNonce<Runtime>,
|
||||||
|
frame_system::CheckWeight<Runtime>,
|
||||||
|
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
|
||||||
|
);
|
||||||
|
/// Unchecked extrinsic type as expected by this runtime.
|
||||||
|
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
|
||||||
|
/// Extrinsic type that has already been checked.
|
||||||
|
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;
|
||||||
|
/// Executive: handles dispatch to the various modules.
|
||||||
|
pub type Executive = frame_executive::Executive<
|
||||||
|
Runtime,
|
||||||
|
Block,
|
||||||
|
frame_system::ChainContext<Runtime>,
|
||||||
|
Runtime,
|
||||||
|
AllModules,
|
||||||
|
>;
|
||||||
|
/// The payload being signed in transactions.
|
||||||
|
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
|
||||||
|
|
||||||
|
decl_runtime_apis! {
|
||||||
|
pub trait GetLastTimestamp {
|
||||||
|
/// Returns the last timestamp of a runtime.
|
||||||
|
fn get_last_timestamp() -> u64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_runtime_apis! {
|
||||||
|
impl sp_api::Core<Block> for Runtime {
|
||||||
|
fn version() -> RuntimeVersion {
|
||||||
|
VERSION
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute_block(block: Block) {
|
||||||
|
Executive::execute_block(block)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn initialize_block(header: &<Block as BlockT>::Header) {
|
||||||
|
Executive::initialize_block(header)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sp_api::Metadata<Block> for Runtime {
|
||||||
|
fn metadata() -> OpaqueMetadata {
|
||||||
|
Runtime::metadata().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sp_block_builder::BlockBuilder<Block> for Runtime {
|
||||||
|
fn apply_extrinsic(
|
||||||
|
extrinsic: <Block as BlockT>::Extrinsic,
|
||||||
|
) -> ApplyExtrinsicResult {
|
||||||
|
Executive::apply_extrinsic(extrinsic)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn finalize_block() -> <Block as BlockT>::Header {
|
||||||
|
Executive::finalize_block()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
|
||||||
|
data.create_extrinsics()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_inherents(block: Block, data: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult {
|
||||||
|
data.check_extrinsics(&block)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn random_seed() -> <Block as BlockT>::Hash {
|
||||||
|
RandomnessCollectiveFlip::random_seed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
|
||||||
|
fn validate_transaction(
|
||||||
|
source: TransactionSource,
|
||||||
|
tx: <Block as BlockT>::Extrinsic,
|
||||||
|
) -> TransactionValidity {
|
||||||
|
Executive::validate_transaction(source, tx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
|
||||||
|
fn offchain_worker(header: &<Block as BlockT>::Header) {
|
||||||
|
Executive::offchain_worker(header)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sp_session::SessionKeys<Block> for Runtime {
|
||||||
|
fn decode_session_keys(
|
||||||
|
encoded: Vec<u8>,
|
||||||
|
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
|
||||||
|
SessionKeys::decode_into_raw_public_keys(&encoded)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
|
||||||
|
SessionKeys::generate(seed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl crate::GetLastTimestamp<Block> for Runtime {
|
||||||
|
fn get_last_timestamp() -> u64 {
|
||||||
|
<pallet_timestamp::Module<Self>>::now()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cumulus_runtime::register_validate_block!(Block, Executive);
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
[package]
|
||||||
|
name = 'cumulus-test-service'
|
||||||
|
version = '0.1.0'
|
||||||
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
|
edition = '2018'
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
ansi_term = "0.12.1"
|
||||||
|
codec = { package = 'parity-scale-codec', version = '1.0.0' }
|
||||||
|
rand = "0.7.3"
|
||||||
|
serde = { version = "1.0.101", features = ["derive"] }
|
||||||
|
|
||||||
|
# Substrate
|
||||||
|
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", version = "0.8.0-rc5" }
|
||||||
|
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-informant = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-network = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-service = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||||
|
sp-session = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
|
||||||
|
# Polkadot
|
||||||
|
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||||
|
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||||
|
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||||
|
|
||||||
|
# Cumulus
|
||||||
|
cumulus-collator = { path = "../../collator" }
|
||||||
|
cumulus-consensus = { path = "../../consensus" }
|
||||||
|
cumulus-network = { path = "../../network" }
|
||||||
|
cumulus-primitives = { path = "../../primitives" }
|
||||||
|
cumulus-service = { path = "../../service" }
|
||||||
|
cumulus-test-runtime = { path = "../runtime" }
|
||||||
|
|
||||||
|
# RPC related dependencies
|
||||||
|
jsonrpc-core = "14.2.0"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
futures = { version = "0.3.5" }
|
||||||
|
tokio = { version = "0.2.21", features = ["macros"] }
|
||||||
|
|
||||||
|
# Polkadot dependencies
|
||||||
|
polkadot-test-runtime = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||||
|
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||||
|
|
||||||
|
# Substrate dependencies
|
||||||
|
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
|
substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Cumulus 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.
|
||||||
|
|
||||||
|
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
|
use cumulus_primitives::ParaId;
|
||||||
|
use cumulus_test_runtime::{AccountId, Signature};
|
||||||
|
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
|
||||||
|
use sc_service::ChainType;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use sp_core::{sr25519, ChangesTrieConfiguration, Pair, Public};
|
||||||
|
use sp_runtime::traits::{IdentifyAccount, Verify};
|
||||||
|
|
||||||
|
/// Specialized `ChainSpec` for the normal parachain runtime.
|
||||||
|
pub type ChainSpec = sc_service::GenericChainSpec<cumulus_test_runtime::GenesisConfig, Extensions>;
|
||||||
|
|
||||||
|
/// Helper function to generate a crypto pair from seed
|
||||||
|
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
|
||||||
|
TPublic::Pair::from_string(&format!("//{}", seed), None)
|
||||||
|
.expect("static values are valid; qed")
|
||||||
|
.public()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The extensions for the [`ChainSpec`].
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
pub struct Extensions {
|
||||||
|
/// The relay chain of the Parachain.
|
||||||
|
pub relay_chain: String,
|
||||||
|
/// The id of the Parachain.
|
||||||
|
pub para_id: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Extensions {
|
||||||
|
/// Try to get the extension from the given `ChainSpec`.
|
||||||
|
pub fn try_get(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Option<&Self> {
|
||||||
|
sc_chain_spec::get_extension(chain_spec.extensions())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type AccountPublic = <Signature as Verify>::Signer;
|
||||||
|
|
||||||
|
/// Helper function to generate an account ID from seed.
|
||||||
|
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
|
||||||
|
where
|
||||||
|
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
|
||||||
|
{
|
||||||
|
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the chain spec for a specific parachain ID.
|
||||||
|
pub fn get_chain_spec(id: ParaId) -> ChainSpec {
|
||||||
|
ChainSpec::from_genesis(
|
||||||
|
"Local Testnet",
|
||||||
|
"local_testnet",
|
||||||
|
ChainType::Local,
|
||||||
|
move || local_testnet_genesis(None),
|
||||||
|
vec![],
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Extensions {
|
||||||
|
relay_chain: "westend-dev".into(),
|
||||||
|
para_id: id.into(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Local testnet genesis for testing.
|
||||||
|
pub fn local_testnet_genesis(
|
||||||
|
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||||
|
) -> cumulus_test_runtime::GenesisConfig {
|
||||||
|
testnet_genesis(
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||||
|
vec![
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Charlie"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Dave"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Eve"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
|
||||||
|
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||||
|
],
|
||||||
|
changes_trie_config,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn testnet_genesis(
|
||||||
|
root_key: AccountId,
|
||||||
|
endowed_accounts: Vec<AccountId>,
|
||||||
|
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||||
|
) -> cumulus_test_runtime::GenesisConfig {
|
||||||
|
cumulus_test_runtime::GenesisConfig {
|
||||||
|
frame_system: Some(cumulus_test_runtime::SystemConfig {
|
||||||
|
code: cumulus_test_runtime::WASM_BINARY
|
||||||
|
.expect("WASM binary was not build, please build it!")
|
||||||
|
.to_vec(),
|
||||||
|
changes_trie_config,
|
||||||
|
}),
|
||||||
|
pallet_balances: Some(cumulus_test_runtime::BalancesConfig {
|
||||||
|
balances: endowed_accounts
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.map(|k| (k, 1 << 60))
|
||||||
|
.collect(),
|
||||||
|
}),
|
||||||
|
pallet_sudo: Some(cumulus_test_runtime::SudoConfig { key: root_key }),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Cumulus 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.
|
||||||
|
|
||||||
|
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use codec::Encode;
|
||||||
|
use cumulus_primitives::{genesis::generate_genesis_block, ParaId};
|
||||||
|
use cumulus_test_runtime::Block;
|
||||||
|
use polkadot_primitives::v0::HeadData;
|
||||||
|
use sp_runtime::traits::Block as BlockT;
|
||||||
|
|
||||||
|
/// Returns the initial head data for a parachain ID.
|
||||||
|
pub fn initial_head_data(para_id: ParaId) -> HeadData {
|
||||||
|
let spec = Box::new(crate::chain_spec::get_chain_spec(para_id));
|
||||||
|
let block: Block = generate_genesis_block(&(spec as Box<_>)).unwrap();
|
||||||
|
let genesis_state = block.header().encode();
|
||||||
|
genesis_state.into()
|
||||||
|
}
|
||||||
@@ -0,0 +1,509 @@
|
|||||||
|
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Cumulus.
|
||||||
|
|
||||||
|
// Cumulus 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.
|
||||||
|
|
||||||
|
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Crate used for testing with Cumulus.
|
||||||
|
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
mod chain_spec;
|
||||||
|
mod genesis;
|
||||||
|
|
||||||
|
pub use chain_spec::*;
|
||||||
|
pub use genesis::*;
|
||||||
|
|
||||||
|
use ansi_term::Color;
|
||||||
|
use core::future::Future;
|
||||||
|
use cumulus_collator::CollatorBuilder;
|
||||||
|
use cumulus_network::DelayedBlockAnnounceValidator;
|
||||||
|
use cumulus_primitives::ParaId;
|
||||||
|
use cumulus_service::{
|
||||||
|
prepare_node_config, start_full_node, StartCollatorParams, StartFullNodeParams,
|
||||||
|
};
|
||||||
|
use cumulus_test_runtime::{NodeBlock as Block, RuntimeApi};
|
||||||
|
use polkadot_primitives::v0::CollatorPair;
|
||||||
|
use sc_client_api::execution_extensions::ExecutionStrategies;
|
||||||
|
use sc_client_api::BlockBackend;
|
||||||
|
use sc_executor::native_executor_instance;
|
||||||
|
pub use sc_executor::NativeExecutor;
|
||||||
|
use sc_informant::OutputFormat;
|
||||||
|
use sc_network::{config::TransportConfig, multiaddr, NetworkService};
|
||||||
|
use sc_service::{
|
||||||
|
config::{
|
||||||
|
DatabaseConfig, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration,
|
||||||
|
OffchainWorkerConfig, PruningMode, WasmExecutionMethod,
|
||||||
|
},
|
||||||
|
BasePath, ChainSpec, Configuration, Error as ServiceError, PartialComponents, Role,
|
||||||
|
RpcHandlers, TFullBackend, TFullClient, TaskExecutor, TaskManager,
|
||||||
|
};
|
||||||
|
use sp_consensus::{BlockImport, Environment, Error as ConsensusError, Proposer};
|
||||||
|
use sp_core::{crypto::Pair, H256};
|
||||||
|
use sp_keyring::Sr25519Keyring;
|
||||||
|
use sp_runtime::traits::BlakeTwo256;
|
||||||
|
use sp_state_machine::BasicExternalities;
|
||||||
|
use sp_trie::PrefixedMemoryDB;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use substrate_test_client::BlockchainEventsExt;
|
||||||
|
|
||||||
|
// Native executor instance.
|
||||||
|
native_executor_instance!(
|
||||||
|
pub RuntimeExecutor,
|
||||||
|
cumulus_test_runtime::api::dispatch,
|
||||||
|
cumulus_test_runtime::native_version,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Starts a `ServiceBuilder` for a full service.
|
||||||
|
///
|
||||||
|
/// Use this macro if you don't actually need the full service, but just the builder in order to
|
||||||
|
/// be able to perform chain operations.
|
||||||
|
pub fn new_partial(
|
||||||
|
config: &mut Configuration,
|
||||||
|
) -> Result<
|
||||||
|
PartialComponents<
|
||||||
|
TFullClient<Block, RuntimeApi, RuntimeExecutor>,
|
||||||
|
TFullBackend<Block>,
|
||||||
|
(),
|
||||||
|
sp_consensus::import_queue::BasicQueue<Block, PrefixedMemoryDB<BlakeTwo256>>,
|
||||||
|
sc_transaction_pool::FullPool<Block, TFullClient<Block, RuntimeApi, RuntimeExecutor>>,
|
||||||
|
(),
|
||||||
|
>,
|
||||||
|
sc_service::Error,
|
||||||
|
> {
|
||||||
|
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
|
||||||
|
|
||||||
|
let (client, backend, keystore, task_manager) =
|
||||||
|
sc_service::new_full_parts::<Block, RuntimeApi, RuntimeExecutor>(&config)?;
|
||||||
|
let client = Arc::new(client);
|
||||||
|
|
||||||
|
let registry = config.prometheus_registry();
|
||||||
|
|
||||||
|
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
|
||||||
|
config.transaction_pool.clone(),
|
||||||
|
config.prometheus_registry(),
|
||||||
|
task_manager.spawn_handle(),
|
||||||
|
client.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let import_queue = cumulus_consensus::import_queue::import_queue(
|
||||||
|
client.clone(),
|
||||||
|
client.clone(),
|
||||||
|
inherent_data_providers.clone(),
|
||||||
|
&task_manager.spawn_handle(),
|
||||||
|
registry.clone(),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let params = PartialComponents {
|
||||||
|
backend,
|
||||||
|
client,
|
||||||
|
import_queue,
|
||||||
|
keystore,
|
||||||
|
task_manager,
|
||||||
|
transaction_pool,
|
||||||
|
inherent_data_providers,
|
||||||
|
select_chain: (),
|
||||||
|
other: (),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start a test collator node for a parachain.
|
||||||
|
///
|
||||||
|
/// A collator is similar to a validator in a normal blockchain.
|
||||||
|
/// It is responsible for producing blocks and sending the blocks to a
|
||||||
|
/// parachain validator for validation and inclusion into the relay chain.
|
||||||
|
pub fn start_test_collator<'a, PF, BI, BS>(
|
||||||
|
StartCollatorParams {
|
||||||
|
para_id,
|
||||||
|
proposer_factory,
|
||||||
|
inherent_data_providers,
|
||||||
|
block_import,
|
||||||
|
block_status,
|
||||||
|
announce_block,
|
||||||
|
client,
|
||||||
|
block_announce_validator,
|
||||||
|
task_manager,
|
||||||
|
polkadot_config,
|
||||||
|
collator_key,
|
||||||
|
}: StartCollatorParams<'a, Block, PF, BI, BS, TFullClient<Block, RuntimeApi, RuntimeExecutor>>,
|
||||||
|
) -> sc_service::error::Result<()>
|
||||||
|
where
|
||||||
|
PF: Environment<Block> + Send + 'static,
|
||||||
|
BI: BlockImport<
|
||||||
|
Block,
|
||||||
|
Error = ConsensusError,
|
||||||
|
Transaction = <PF::Proposer as Proposer<Block>>::Transaction,
|
||||||
|
> + Send
|
||||||
|
+ Sync
|
||||||
|
+ 'static,
|
||||||
|
BS: BlockBackend<Block> + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
let builder = CollatorBuilder::new(
|
||||||
|
proposer_factory,
|
||||||
|
inherent_data_providers,
|
||||||
|
block_import,
|
||||||
|
block_status,
|
||||||
|
para_id,
|
||||||
|
client,
|
||||||
|
announce_block,
|
||||||
|
block_announce_validator,
|
||||||
|
);
|
||||||
|
|
||||||
|
let (polkadot_future, polkadot_task_manager) = {
|
||||||
|
let (task_manager, client, handles, _network, _rpc_handlers) =
|
||||||
|
polkadot_test_service::polkadot_test_new_full(
|
||||||
|
polkadot_config,
|
||||||
|
Some((collator_key.public(), para_id)),
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
6000,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let test_client = polkadot_test_service::TestClient(client);
|
||||||
|
|
||||||
|
let future = polkadot_collator::build_collator_service(
|
||||||
|
task_manager.spawn_handle(),
|
||||||
|
handles,
|
||||||
|
test_client,
|
||||||
|
para_id,
|
||||||
|
collator_key,
|
||||||
|
builder,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
(future, task_manager)
|
||||||
|
};
|
||||||
|
|
||||||
|
task_manager
|
||||||
|
.spawn_essential_handle()
|
||||||
|
.spawn("polkadot", polkadot_future);
|
||||||
|
|
||||||
|
task_manager.add_child(polkadot_task_manager);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.
|
||||||
|
///
|
||||||
|
/// This is the actual implementation that is abstract over the executor and the runtime api.
|
||||||
|
fn start_node_impl<RB>(
|
||||||
|
parachain_config: Configuration,
|
||||||
|
collator_key: Arc<CollatorPair>,
|
||||||
|
mut polkadot_config: polkadot_collator::Configuration,
|
||||||
|
para_id: ParaId,
|
||||||
|
validator: bool,
|
||||||
|
rpc_ext_builder: RB,
|
||||||
|
) -> sc_service::error::Result<(
|
||||||
|
TaskManager,
|
||||||
|
Arc<TFullClient<Block, RuntimeApi, RuntimeExecutor>>,
|
||||||
|
Arc<NetworkService<Block, H256>>,
|
||||||
|
Arc<RpcHandlers>,
|
||||||
|
)>
|
||||||
|
where
|
||||||
|
RB: Fn(
|
||||||
|
Arc<TFullClient<Block, RuntimeApi, RuntimeExecutor>>,
|
||||||
|
) -> jsonrpc_core::IoHandler<sc_rpc::Metadata>
|
||||||
|
+ Send
|
||||||
|
+ 'static,
|
||||||
|
{
|
||||||
|
if matches!(parachain_config.role, Role::Light) {
|
||||||
|
return Err("Light client not supported!".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut parachain_config = prepare_node_config(parachain_config);
|
||||||
|
|
||||||
|
parachain_config.informant_output_format = OutputFormat {
|
||||||
|
enable_color: true,
|
||||||
|
prefix: format!("[{}] ", Color::Yellow.bold().paint("Parachain")),
|
||||||
|
};
|
||||||
|
polkadot_config.informant_output_format = OutputFormat {
|
||||||
|
enable_color: true,
|
||||||
|
prefix: format!("[{}] ", Color::Blue.bold().paint("Relaychain")),
|
||||||
|
};
|
||||||
|
|
||||||
|
let params = new_partial(&mut parachain_config)?;
|
||||||
|
params
|
||||||
|
.inherent_data_providers
|
||||||
|
.register_provider(sp_timestamp::InherentDataProvider)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let client = params.client.clone();
|
||||||
|
let backend = params.backend.clone();
|
||||||
|
let block_announce_validator = DelayedBlockAnnounceValidator::new();
|
||||||
|
let block_announce_validator_builder = {
|
||||||
|
let block_announce_validator = block_announce_validator.clone();
|
||||||
|
move |_| Box::new(block_announce_validator) as Box<_>
|
||||||
|
};
|
||||||
|
|
||||||
|
let prometheus_registry = parachain_config.prometheus_registry().cloned();
|
||||||
|
let transaction_pool = params.transaction_pool.clone();
|
||||||
|
let mut task_manager = params.task_manager;
|
||||||
|
let import_queue = params.import_queue;
|
||||||
|
let (network, network_status_sinks, system_rpc_tx, start_network) =
|
||||||
|
sc_service::build_network(sc_service::BuildNetworkParams {
|
||||||
|
config: ¶chain_config,
|
||||||
|
client: client.clone(),
|
||||||
|
transaction_pool: transaction_pool.clone(),
|
||||||
|
spawn_handle: task_manager.spawn_handle(),
|
||||||
|
import_queue,
|
||||||
|
on_demand: None,
|
||||||
|
block_announce_validator_builder: Some(Box::new(block_announce_validator_builder)),
|
||||||
|
finality_proof_request_builder: None,
|
||||||
|
finality_proof_provider: None,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let rpc_extensions_builder = {
|
||||||
|
let client = client.clone();
|
||||||
|
|
||||||
|
Box::new(move |_deny_unsafe| rpc_ext_builder(client.clone()))
|
||||||
|
};
|
||||||
|
|
||||||
|
let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
||||||
|
on_demand: None,
|
||||||
|
remote_blockchain: None,
|
||||||
|
rpc_extensions_builder,
|
||||||
|
client: client.clone(),
|
||||||
|
transaction_pool: transaction_pool.clone(),
|
||||||
|
task_manager: &mut task_manager,
|
||||||
|
telemetry_connection_sinks: Default::default(),
|
||||||
|
config: parachain_config,
|
||||||
|
keystore: params.keystore,
|
||||||
|
backend,
|
||||||
|
network: network.clone(),
|
||||||
|
network_status_sinks,
|
||||||
|
system_rpc_tx,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let announce_block = {
|
||||||
|
let network = network.clone();
|
||||||
|
Arc::new(move |hash, data| network.announce_block(hash, data))
|
||||||
|
};
|
||||||
|
|
||||||
|
if validator {
|
||||||
|
let proposer_factory = sc_basic_authorship::ProposerFactory::new(
|
||||||
|
client.clone(),
|
||||||
|
transaction_pool,
|
||||||
|
prometheus_registry.as_ref(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let params = StartCollatorParams {
|
||||||
|
para_id,
|
||||||
|
block_import: client.clone(),
|
||||||
|
proposer_factory,
|
||||||
|
inherent_data_providers: params.inherent_data_providers,
|
||||||
|
block_status: client.clone(),
|
||||||
|
announce_block,
|
||||||
|
client: client.clone(),
|
||||||
|
block_announce_validator,
|
||||||
|
task_manager: &mut task_manager,
|
||||||
|
polkadot_config,
|
||||||
|
collator_key,
|
||||||
|
};
|
||||||
|
|
||||||
|
start_test_collator(params)?;
|
||||||
|
} else {
|
||||||
|
let params = StartFullNodeParams {
|
||||||
|
client: client.clone(),
|
||||||
|
announce_block,
|
||||||
|
polkadot_config,
|
||||||
|
collator_key,
|
||||||
|
block_announce_validator,
|
||||||
|
task_manager: &mut task_manager,
|
||||||
|
para_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
start_full_node(params)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
start_network.start_network();
|
||||||
|
|
||||||
|
Ok((task_manager, client, network, rpc_handlers))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A Cumulus test node instance used for testing.
|
||||||
|
pub struct CumulusTestNode {
|
||||||
|
/// TaskManager's instance.
|
||||||
|
pub task_manager: TaskManager,
|
||||||
|
/// Client's instance.
|
||||||
|
pub client: Arc<TFullClient<Block, RuntimeApi, RuntimeExecutor>>,
|
||||||
|
/// Node's network.
|
||||||
|
pub network: Arc<NetworkService<Block, H256>>,
|
||||||
|
/// The `MultiaddrWithPeerId` to this node. This is useful if you want to pass it as "boot node"
|
||||||
|
/// to other nodes.
|
||||||
|
pub addr: MultiaddrWithPeerId,
|
||||||
|
/// RPCHandlers to make RPC queries.
|
||||||
|
pub rpc_handlers: Arc<RpcHandlers>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run a Cumulus test node using the Cumulus test runtime. The node will be using an in-memory
|
||||||
|
/// socket, therefore you need to provide boot nodes if you want it to be connected to other nodes.
|
||||||
|
/// The `storage_update_func` can be used to make adjustements to the runtime before the node
|
||||||
|
/// starts.
|
||||||
|
pub fn run_test_node(
|
||||||
|
task_executor: TaskExecutor,
|
||||||
|
key: Sr25519Keyring,
|
||||||
|
parachain_storage_update_func: impl Fn(),
|
||||||
|
polkadot_storage_update_func: impl Fn(),
|
||||||
|
parachain_boot_nodes: Vec<MultiaddrWithPeerId>,
|
||||||
|
polkadot_boot_nodes: Vec<MultiaddrWithPeerId>,
|
||||||
|
para_id: ParaId,
|
||||||
|
validator: bool,
|
||||||
|
) -> CumulusTestNode {
|
||||||
|
let collator_key = Arc::new(sp_core::Pair::generate().0);
|
||||||
|
let parachain_config = node_config(
|
||||||
|
parachain_storage_update_func,
|
||||||
|
task_executor.clone(),
|
||||||
|
key,
|
||||||
|
parachain_boot_nodes,
|
||||||
|
para_id,
|
||||||
|
)
|
||||||
|
.expect("could not generate Configuration");
|
||||||
|
let polkadot_config = polkadot_test_service::node_config(
|
||||||
|
polkadot_storage_update_func,
|
||||||
|
task_executor.clone(),
|
||||||
|
key,
|
||||||
|
polkadot_boot_nodes,
|
||||||
|
);
|
||||||
|
let multiaddr = parachain_config.network.listen_addresses[0].clone();
|
||||||
|
let (task_manager, client, network, rpc_handlers) = start_node_impl::<_>(
|
||||||
|
parachain_config,
|
||||||
|
collator_key,
|
||||||
|
polkadot_config,
|
||||||
|
para_id,
|
||||||
|
validator,
|
||||||
|
|_| Default::default(),
|
||||||
|
)
|
||||||
|
.expect("could not create Cumulus test service");
|
||||||
|
|
||||||
|
let peer_id = network.local_peer_id().clone();
|
||||||
|
let addr = MultiaddrWithPeerId { multiaddr, peer_id };
|
||||||
|
|
||||||
|
CumulusTestNode {
|
||||||
|
task_manager,
|
||||||
|
client,
|
||||||
|
network,
|
||||||
|
addr,
|
||||||
|
rpc_handlers,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a Cumulus `Configuration`. By default an in-memory socket will be used, therefore you
|
||||||
|
/// need to provide boot nodes if you want the future node to be connected to other nodes. The
|
||||||
|
/// `storage_update_func` can be used to make adjustments to the runtime before the node starts.
|
||||||
|
pub fn node_config(
|
||||||
|
storage_update_func: impl Fn(),
|
||||||
|
task_executor: TaskExecutor,
|
||||||
|
key: Sr25519Keyring,
|
||||||
|
boot_nodes: Vec<MultiaddrWithPeerId>,
|
||||||
|
para_id: ParaId,
|
||||||
|
) -> Result<Configuration, ServiceError> {
|
||||||
|
let base_path = BasePath::new_temp_dir()?;
|
||||||
|
let root = base_path.path().to_path_buf();
|
||||||
|
let role = Role::Authority {
|
||||||
|
sentry_nodes: Vec::new(),
|
||||||
|
};
|
||||||
|
let key_seed = key.to_seed();
|
||||||
|
let mut spec = Box::new(chain_spec::get_chain_spec(para_id));
|
||||||
|
|
||||||
|
let mut storage = spec
|
||||||
|
.as_storage_builder()
|
||||||
|
.build_storage()
|
||||||
|
.expect("could not build storage");
|
||||||
|
|
||||||
|
BasicExternalities::execute_with_storage(&mut storage, storage_update_func);
|
||||||
|
spec.set_storage(storage);
|
||||||
|
|
||||||
|
let mut network_config = NetworkConfiguration::new(
|
||||||
|
format!("Cumulus Test Node for: {}", key_seed),
|
||||||
|
"network/test/0.1",
|
||||||
|
Default::default(),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
let informant_output_format = OutputFormat {
|
||||||
|
enable_color: false,
|
||||||
|
prefix: format!("[{}] ", key_seed),
|
||||||
|
};
|
||||||
|
|
||||||
|
network_config.boot_nodes = boot_nodes;
|
||||||
|
|
||||||
|
network_config.allow_non_globals_in_dht = false;
|
||||||
|
|
||||||
|
network_config
|
||||||
|
.listen_addresses
|
||||||
|
.push(multiaddr::Protocol::Memory(rand::random()).into());
|
||||||
|
|
||||||
|
network_config.transport = TransportConfig::MemoryOnly;
|
||||||
|
|
||||||
|
Ok(Configuration {
|
||||||
|
impl_name: "cumulus-test-node".to_string(),
|
||||||
|
impl_version: "0.1".to_string(),
|
||||||
|
role,
|
||||||
|
task_executor,
|
||||||
|
transaction_pool: Default::default(),
|
||||||
|
network: network_config,
|
||||||
|
keystore: KeystoreConfig::Path {
|
||||||
|
path: root.join("key"),
|
||||||
|
password: None,
|
||||||
|
},
|
||||||
|
database: DatabaseConfig::RocksDb {
|
||||||
|
path: root.join("db"),
|
||||||
|
cache_size: 128,
|
||||||
|
},
|
||||||
|
state_cache_size: 67108864,
|
||||||
|
state_cache_child_ratio: None,
|
||||||
|
pruning: PruningMode::ArchiveAll,
|
||||||
|
chain_spec: spec,
|
||||||
|
wasm_method: WasmExecutionMethod::Interpreted,
|
||||||
|
// NOTE: we enforce the use of the native runtime to make the errors more debuggable
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
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: OffchainWorkerConfig {
|
||||||
|
enabled: true,
|
||||||
|
indexing_enabled: false,
|
||||||
|
},
|
||||||
|
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),
|
||||||
|
informant_output_format,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CumulusTestNode {
|
||||||
|
/// Wait for `count` blocks to be imported in the node and then exit. This function will not
|
||||||
|
/// return if no blocks are ever created, thus you should restrict the maximum amount of time of
|
||||||
|
/// the test execution.
|
||||||
|
pub fn wait_for_blocks(&self, count: usize) -> impl Future<Output = ()> {
|
||||||
|
self.client.wait_for_blocks(count)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
|
// Substrate 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.
|
||||||
|
|
||||||
|
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use cumulus_primitives::ParaId;
|
||||||
|
use cumulus_test_service::initial_head_data;
|
||||||
|
use futures::join;
|
||||||
|
use sc_service::TaskExecutor;
|
||||||
|
use substrate_test_runtime_client::AccountKeyring::*;
|
||||||
|
|
||||||
|
#[substrate_test_utils::test]
|
||||||
|
#[ignore]
|
||||||
|
async fn test_collating_and_non_collator_mode_catching_up(task_executor: TaskExecutor) {
|
||||||
|
let para_id = ParaId::from(100);
|
||||||
|
|
||||||
|
// start alice
|
||||||
|
let alice = polkadot_test_service::run_test_node(task_executor.clone(), Alice, || {}, vec![]);
|
||||||
|
|
||||||
|
// start bob
|
||||||
|
let bob = polkadot_test_service::run_test_node(
|
||||||
|
task_executor.clone(),
|
||||||
|
Bob,
|
||||||
|
|| {},
|
||||||
|
vec![alice.addr.clone()],
|
||||||
|
);
|
||||||
|
|
||||||
|
// ensure alice and bob can produce blocks
|
||||||
|
join!(alice.wait_for_blocks(2), bob.wait_for_blocks(2));
|
||||||
|
|
||||||
|
// register parachain
|
||||||
|
alice
|
||||||
|
.register_para(
|
||||||
|
para_id,
|
||||||
|
cumulus_test_runtime::WASM_BINARY
|
||||||
|
.expect("You need to build the WASM binary to run this test!")
|
||||||
|
.to_vec()
|
||||||
|
.into(),
|
||||||
|
initial_head_data(para_id),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// run cumulus charlie (a validator)
|
||||||
|
let charlie = cumulus_test_service::run_test_node(
|
||||||
|
task_executor.clone(),
|
||||||
|
Charlie,
|
||||||
|
|| {},
|
||||||
|
|| {},
|
||||||
|
vec![],
|
||||||
|
vec![alice.addr.clone(), bob.addr.clone()],
|
||||||
|
para_id,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
charlie.wait_for_blocks(2).await;
|
||||||
|
|
||||||
|
// run cumulus dave (not a validator)
|
||||||
|
//
|
||||||
|
// a collator running in non-validator mode should be able to sync blocks from the tip of the
|
||||||
|
// parachain
|
||||||
|
let dave = cumulus_test_service::run_test_node(
|
||||||
|
task_executor.clone(),
|
||||||
|
Dave,
|
||||||
|
|| {},
|
||||||
|
|| {},
|
||||||
|
vec![charlie.addr.clone()],
|
||||||
|
vec![alice.addr.clone(), bob.addr.clone()],
|
||||||
|
para_id,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
dave.wait_for_blocks(4).await;
|
||||||
|
|
||||||
|
join!(
|
||||||
|
alice.task_manager.clean_shutdown(),
|
||||||
|
bob.task_manager.clean_shutdown(),
|
||||||
|
charlie.task_manager.clean_shutdown(),
|
||||||
|
dave.task_manager.clean_shutdown(),
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user