Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parachain_info in cumulus-test-runtime #4672

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make self_para_id non optional. I think it will put there null, which should fail at decoding. However, as we first patch this json into the default config, it may works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self_para_id is only optional to this method, not in the patch here. Some lines above we use cumulus_test_runtime::PARACHAIN_ID as default.

},
"aura": cumulus_test_runtime::AuraConfig { authorities: invulnerables }
})
}
Loading