mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 15:41:02 +00:00
cumulus test runtime: remove GenesisExt (#2147)
This PR removes the `GenesisExt` wrapper over the `GenesisRuntimeConfig` in `cumulus-test-service`. Initialization of values that were performed by `GenesisExt::BuildStorage` was moved into `test_pallet` genesis. --------- Co-authored-by: command-bot <> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
committed by
GitHub
parent
21fbc00d04
commit
1c0b437330
@@ -90,6 +90,7 @@ impl substrate_test_client::GenesisInit for GenesisParameters {
|
|||||||
cumulus_test_service::testnet_genesis(
|
cumulus_test_service::testnet_genesis(
|
||||||
cumulus_test_service::get_account_id_from_seed::<sr25519::Public>("Alice"),
|
cumulus_test_service::get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||||
self.endowed_accounts.clone(),
|
self.endowed_accounts.clone(),
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.build_storage()
|
.build_storage()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -127,7 +128,7 @@ impl DefaultTestClientBuilderExt for TestClientBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn genesis_config() -> RuntimeGenesisConfig {
|
fn genesis_config() -> RuntimeGenesisConfig {
|
||||||
cumulus_test_service::testnet_genesis_with_default_endowed(Default::default())
|
cumulus_test_service::testnet_genesis_with_default_endowed(Default::default(), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an unsigned extrinsic from a runtime call.
|
/// Create an unsigned extrinsic from a runtime call.
|
||||||
|
|||||||
@@ -76,10 +76,6 @@ impl_opaque_keys! {
|
|||||||
pub struct SessionKeys {}
|
pub struct SessionKeys {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Some key that we set in genesis and only read in [`TestOnRuntimeUpgrade`] to ensure that
|
|
||||||
/// [`OnRuntimeUpgrade`] works as expected.
|
|
||||||
pub const TEST_RUNTIME_UPGRADE_KEY: &[u8] = b"+test_runtime_upgrade_key+";
|
|
||||||
|
|
||||||
/// The para-id used in this runtime.
|
/// The para-id used in this runtime.
|
||||||
pub const PARACHAIN_ID: u32 = 100;
|
pub const PARACHAIN_ID: u32 = 100;
|
||||||
|
|
||||||
@@ -293,6 +289,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
|
// will be set by test_pallet during genesis init
|
||||||
pub storage ParachainId: cumulus_primitives_core::ParaId = PARACHAIN_ID.into();
|
pub storage ParachainId: cumulus_primitives_core::ParaId = PARACHAIN_ID.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +364,10 @@ pub struct TestOnRuntimeUpgrade;
|
|||||||
|
|
||||||
impl OnRuntimeUpgrade for TestOnRuntimeUpgrade {
|
impl OnRuntimeUpgrade for TestOnRuntimeUpgrade {
|
||||||
fn on_runtime_upgrade() -> frame_support::weights::Weight {
|
fn on_runtime_upgrade() -> frame_support::weights::Weight {
|
||||||
assert_eq!(sp_io::storage::get(TEST_RUNTIME_UPGRADE_KEY), Some(vec![1, 2, 3, 4].into()));
|
assert_eq!(
|
||||||
|
sp_io::storage::get(test_pallet::TEST_RUNTIME_UPGRADE_KEY),
|
||||||
|
Some(vec![1, 2, 3, 4].into())
|
||||||
|
);
|
||||||
Weight::from_parts(1, 0)
|
Weight::from_parts(1, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,13 @@
|
|||||||
/// A special pallet that exposes dispatchables that are only useful for testing.
|
/// A special pallet that exposes dispatchables that are only useful for testing.
|
||||||
pub use pallet::*;
|
pub use pallet::*;
|
||||||
|
|
||||||
|
/// Some key that we set in genesis and only read in [`TestOnRuntimeUpgrade`] to ensure that
|
||||||
|
/// [`OnRuntimeUpgrade`] works as expected.
|
||||||
|
pub const TEST_RUNTIME_UPGRADE_KEY: &[u8] = b"+test_runtime_upgrade_key+";
|
||||||
|
|
||||||
#[frame_support::pallet(dev_mode)]
|
#[frame_support::pallet(dev_mode)]
|
||||||
pub mod pallet {
|
pub mod pallet {
|
||||||
|
use crate::test_pallet::TEST_RUNTIME_UPGRADE_KEY;
|
||||||
use frame_support::pallet_prelude::*;
|
use frame_support::pallet_prelude::*;
|
||||||
use frame_system::pallet_prelude::*;
|
use frame_system::pallet_prelude::*;
|
||||||
|
|
||||||
@@ -45,4 +50,22 @@ pub mod pallet {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(frame_support::DefaultNoBound)]
|
||||||
|
#[pallet::genesis_config]
|
||||||
|
pub struct GenesisConfig<T: Config> {
|
||||||
|
pub self_para_id: Option<cumulus_primitives_core::ParaId>,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub _config: sp_std::marker::PhantomData<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pallet::genesis_build]
|
||||||
|
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||||
|
fn build(&self) {
|
||||||
|
sp_io::storage::set(TEST_RUNTIME_UPGRADE_KEY, &[1, 2, 3, 4]);
|
||||||
|
self.self_para_id.map(|para_id| {
|
||||||
|
crate::ParachainId::set(¶_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
use cumulus_primitives_core::ParaId;
|
use cumulus_primitives_core::ParaId;
|
||||||
use cumulus_test_runtime::{AccountId, Signature};
|
use cumulus_test_runtime::{AccountId, RuntimeGenesisConfig, Signature};
|
||||||
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
|
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
|
||||||
use sc_service::ChainType;
|
use sc_service::ChainType;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -25,27 +25,7 @@ use sp_core::{sr25519, Pair, Public};
|
|||||||
use sp_runtime::traits::{IdentifyAccount, Verify};
|
use sp_runtime::traits::{IdentifyAccount, Verify};
|
||||||
|
|
||||||
/// Specialized `ChainSpec` for the normal parachain runtime.
|
/// Specialized `ChainSpec` for the normal parachain runtime.
|
||||||
pub type ChainSpec = sc_service::GenericChainSpec<GenesisExt, Extensions>;
|
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig, Extensions>;
|
||||||
|
|
||||||
/// Extension for the genesis config to add custom keys easily.
|
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
|
||||||
pub struct GenesisExt {
|
|
||||||
/// The runtime genesis config.
|
|
||||||
runtime_genesis_config: cumulus_test_runtime::RuntimeGenesisConfig,
|
|
||||||
/// The parachain id.
|
|
||||||
para_id: ParaId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl sp_runtime::BuildStorage for GenesisExt {
|
|
||||||
fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> {
|
|
||||||
sp_state_machine::BasicExternalities::execute_with_storage(storage, || {
|
|
||||||
sp_io::storage::set(cumulus_test_runtime::TEST_RUNTIME_UPGRADE_KEY, &[1, 2, 3, 4]);
|
|
||||||
cumulus_test_runtime::ParachainId::set(&self.para_id);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.runtime_genesis_config.assimilate_storage(storage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper function to generate a crypto pair from seed
|
/// Helper function to generate a crypto pair from seed
|
||||||
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
|
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
|
||||||
@@ -90,12 +70,7 @@ pub fn get_chain_spec_with_extra_endowed(
|
|||||||
"Local Testnet",
|
"Local Testnet",
|
||||||
"local_testnet",
|
"local_testnet",
|
||||||
ChainType::Local,
|
ChainType::Local,
|
||||||
move || GenesisExt {
|
move || testnet_genesis_with_default_endowed(extra_endowed_accounts.clone(), Some(id)),
|
||||||
runtime_genesis_config: testnet_genesis_with_default_endowed(
|
|
||||||
extra_endowed_accounts.clone(),
|
|
||||||
),
|
|
||||||
para_id: id,
|
|
||||||
},
|
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@@ -113,6 +88,7 @@ pub fn get_chain_spec(id: ParaId) -> ChainSpec {
|
|||||||
/// Local testnet genesis for testing.
|
/// Local testnet genesis for testing.
|
||||||
pub fn testnet_genesis_with_default_endowed(
|
pub fn testnet_genesis_with_default_endowed(
|
||||||
mut extra_endowed_accounts: Vec<AccountId>,
|
mut extra_endowed_accounts: Vec<AccountId>,
|
||||||
|
self_para_id: Option<ParaId>,
|
||||||
) -> cumulus_test_runtime::RuntimeGenesisConfig {
|
) -> cumulus_test_runtime::RuntimeGenesisConfig {
|
||||||
let mut endowed = vec![
|
let mut endowed = vec![
|
||||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||||
@@ -130,13 +106,14 @@ pub fn testnet_genesis_with_default_endowed(
|
|||||||
];
|
];
|
||||||
endowed.append(&mut extra_endowed_accounts);
|
endowed.append(&mut extra_endowed_accounts);
|
||||||
|
|
||||||
testnet_genesis(get_account_id_from_seed::<sr25519::Public>("Alice"), endowed)
|
testnet_genesis(get_account_id_from_seed::<sr25519::Public>("Alice"), endowed, self_para_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a local testnet genesis with endowed accounts.
|
/// Creates a local testnet genesis with endowed accounts.
|
||||||
pub fn testnet_genesis(
|
pub fn testnet_genesis(
|
||||||
root_key: AccountId,
|
root_key: AccountId,
|
||||||
endowed_accounts: Vec<AccountId>,
|
endowed_accounts: Vec<AccountId>,
|
||||||
|
self_para_id: Option<ParaId>,
|
||||||
) -> cumulus_test_runtime::RuntimeGenesisConfig {
|
) -> cumulus_test_runtime::RuntimeGenesisConfig {
|
||||||
cumulus_test_runtime::RuntimeGenesisConfig {
|
cumulus_test_runtime::RuntimeGenesisConfig {
|
||||||
system: cumulus_test_runtime::SystemConfig {
|
system: cumulus_test_runtime::SystemConfig {
|
||||||
@@ -152,5 +129,6 @@ pub fn testnet_genesis(
|
|||||||
},
|
},
|
||||||
sudo: cumulus_test_runtime::SudoConfig { key: Some(root_key) },
|
sudo: cumulus_test_runtime::SudoConfig { key: Some(root_key) },
|
||||||
transaction_payment: Default::default(),
|
transaction_payment: Default::default(),
|
||||||
|
test_pallet: cumulus_test_runtime::TestPalletConfig { self_para_id, ..Default::default() },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ default_command = "polkadot"
|
|||||||
|
|
||||||
chain = "rococo-local"
|
chain = "rococo-local"
|
||||||
|
|
||||||
[relaychain.genesis.runtime.runtime_genesis_config.configuration.config]
|
[relaychain.genesis.runtime.configuration.config]
|
||||||
# set parameters such that collators only connect to 1 validator as a backing group
|
# set parameters such that collators only connect to 1 validator as a backing group
|
||||||
max_validators_per_core = 1
|
max_validators_per_core = 1
|
||||||
group_rotation_frequency = 100 # 10 mins
|
group_rotation_frequency = 100 # 10 mins
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ cumulus_based = true
|
|||||||
add_to_genesis = false
|
add_to_genesis = false
|
||||||
register_para = false
|
register_para = false
|
||||||
# Set some random value in the genesis state to create a different genesis hash.
|
# Set some random value in the genesis state to create a different genesis hash.
|
||||||
[parachains.genesis.runtime.runtime_genesis_config.sudo]
|
[parachains.genesis.runtime.sudo]
|
||||||
key = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
|
key = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
|
||||||
|
|
||||||
# run the parachain that will be used to return the header of the solo chain.
|
# run the parachain that will be used to return the header of the solo chain.
|
||||||
|
|||||||
Reference in New Issue
Block a user