mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 07:01:03 +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:
@@ -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 }),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user