Skip to content

Commit

Permalink
Use parachain_info in cumulus-test-runtime (#4672)
Browse files Browse the repository at this point in the history
This allows to use custom para_ids with cumulus-test-runtime. 

Zombienet is patching the genesis entries for `ParachainInfo`. This did
not work with `test-parachain` because it was using the `test_pallet`
for historic reasons I guess.
  • Loading branch information
skunert authored Jun 4, 2024
1 parent 624a1d5 commit 9b76492
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cumulus/test/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sp-version = { path = "../../../substrate/primitives/version", default-features

# Cumulus
cumulus-pallet-parachain-system = { path = "../../pallets/parachain-system", default-features = false }
parachain-info = { package = "staging-parachain-info", path = "../../parachains/pallets/parachain-info", default-features = false }
cumulus-primitives-aura = { path = "../../primitives/aura", default-features = false }
pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false }
cumulus-pallet-aura-ext = { path = "../../pallets/aura-ext", default-features = false }
Expand Down Expand Up @@ -74,6 +75,7 @@ std = [
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment/std",
"parachain-info/std",
"scale-info/std",
"sp-api/std",
"sp-block-builder/std",
Expand Down
10 changes: 4 additions & 6 deletions cumulus/test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
>;
impl cumulus_pallet_parachain_system::Config for Runtime {
type WeightInfo = ();
type SelfParaId = ParachainId;
type SelfParaId = parachain_info::Pallet<Runtime>;
type RuntimeEvent = RuntimeEvent;
type OnSystemEvent = ();
type OutboundXcmpMessageSource = ();
Expand All @@ -294,6 +294,8 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ConsensusHook = ConsensusHook;
}

impl parachain_info::Config for Runtime {}

impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
Expand All @@ -302,11 +304,6 @@ impl pallet_aura::Config for Runtime {
type SlotDuration = ConstU64<SLOT_DURATION>;
}

parameter_types! {
// will be set by test_pallet during genesis init
pub storage ParachainId: cumulus_primitives_core::ParaId = PARACHAIN_ID.into();
}

impl test_pallet::Config for Runtime {}

construct_runtime! {
Expand All @@ -315,6 +312,7 @@ construct_runtime! {
System: frame_system,
ParachainSystem: cumulus_pallet_parachain_system,
Timestamp: pallet_timestamp,
ParachainInfo: parachain_info,
Balances: pallet_balances,
Sudo: pallet_sudo,
TransactionPayment: pallet_transaction_payment,
Expand Down
4 changes: 0 additions & 4 deletions cumulus/test/runtime/src/test_pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub mod pallet {
#[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>,
}
Expand All @@ -87,9 +86,6 @@ pub mod pallet {
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(&para_id);
});
}
}
}
4 changes: 3 additions & 1 deletion cumulus/test/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ pub fn testnet_genesis(
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
"sudo": cumulus_test_runtime::SudoConfig { key: Some(root_key) },
"testPallet": cumulus_test_runtime::TestPalletConfig { self_para_id: Some(self_para_id), ..Default::default() },
"parachainInfo": {
"parachainId": self_para_id,
},
"aura": cumulus_test_runtime::AuraConfig { authorities: invulnerables }
})
}

0 comments on commit 9b76492

Please sign in to comment.