From 735c299769728e7f61355c69ff27a9bce3114493 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 17 Mar 2025 15:59:57 +0100 Subject: [PATCH 01/53] Integration emulated governance tests (with `authorize_upgrade`) init --- Cargo.lock | 20 +++ Cargo.toml | 1 + .../chains/relays/polkadot/src/lib.rs | 1 + .../tests/governance/polkadot/Cargo.toml | 32 +++++ .../tests/governance/polkadot/src/lib.rs | 63 +++++++++ .../polkadot/src/open_gov_on_asset_hub.rs | 26 ++++ .../polkadot/src/open_gov_on_relay.rs | 125 ++++++++++++++++++ 7 files changed, 268 insertions(+) create mode 100644 integration-tests/emulated/tests/governance/polkadot/Cargo.toml create mode 100644 integration-tests/emulated/tests/governance/polkadot/src/lib.rs create mode 100644 integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs create mode 100644 integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs diff --git a/Cargo.lock b/Cargo.lock index ae03feb786..f0e0359d03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4941,6 +4941,26 @@ dependencies = [ "system-parachains-constants", ] +[[package]] +name = "governance-polkadot-integration-tests" +version = "1.0.0" +dependencies = [ + "collectives-polkadot-runtime", + "emulated-integration-tests-common", + "frame-support", + "frame-system", + "integration-tests-helpers", + "pallet-utility", + "pallet-whitelist", + "pallet-xcm", + "parity-scale-codec", + "polkadot-runtime", + "polkadot-system-emulated-network", + "sp-core 34.0.0", + "sp-runtime 39.0.5", + "staging-xcm", +] + [[package]] name = "group" version = "0.13.0" diff --git a/Cargo.toml b/Cargo.toml index 9a6dd0b10e..68143b7b64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -291,6 +291,7 @@ members = [ "integration-tests/emulated/tests/collectives/collectives-polkadot", "integration-tests/emulated/tests/coretime/coretime-kusama", "integration-tests/emulated/tests/coretime/coretime-polkadot", + "integration-tests/emulated/tests/governance/polkadot", "integration-tests/emulated/tests/people/people-kusama", "integration-tests/emulated/tests/people/people-polkadot", "integration-tests/zombienet", diff --git a/integration-tests/emulated/chains/relays/polkadot/src/lib.rs b/integration-tests/emulated/chains/relays/polkadot/src/lib.rs index 3093c3f3bb..504170b40b 100644 --- a/integration-tests/emulated/chains/relays/polkadot/src/lib.rs +++ b/integration-tests/emulated/chains/relays/polkadot/src/lib.rs @@ -37,6 +37,7 @@ decl_test_relay_chains! { Balances: polkadot_runtime::Balances, Treasury: polkadot_runtime::Treasury, AssetRate: polkadot_runtime::AssetRate, + Preimage: polkadot_runtime::Preimage, Hrmp: polkadot_runtime::Hrmp, } }, diff --git a/integration-tests/emulated/tests/governance/polkadot/Cargo.toml b/integration-tests/emulated/tests/governance/polkadot/Cargo.toml new file mode 100644 index 0000000000..9385aa996e --- /dev/null +++ b/integration-tests/emulated/tests/governance/polkadot/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "governance-polkadot-integration-tests" +version.workspace = true +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +description = "Polkadot governance integration tests with xcm-emulator" +publish = false + +[dependencies] +codec = { workspace = true, default-features = true } + +# Substrate +sp-core = { workspace = true, default-features = true } +sp-runtime = { workspace = true, default-features = true } +frame-support = { workspace = true, default-features = true } +frame-system = { workspace = true, default-features = true } +pallet-whitelist = { workspace = true, default-features = true } +pallet-utility = { workspace = true, default-features = true } + +# Polkadot +pallet-xcm = { workspace = true, default-features = true } +xcm = { workspace = true, default-features = true } + +# Cumulus +emulated-integration-tests-common = { workspace = true } + +# Local +polkadot-runtime = { workspace = true } +integration-tests-helpers = { workspace = true } +collectives-polkadot-runtime = { workspace = true } +polkadot-system-emulated-network = { workspace = true } diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs new file mode 100644 index 0000000000..fd91c25be6 --- /dev/null +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -0,0 +1,63 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use emulated_integration_tests_common::impls::{assert_expected_events, bx, TestExt}; +use frame_support::assert_ok; +use integration_tests_helpers::Chain; +use polkadot_system_emulated_network::CollectivesPolkadotPara as CollectivesPolkadot; +use sp_runtime::traits::Dispatchable; +use xcm::latest::prelude::*; +use xcm::{VersionedLocation, VersionedXcm}; + +#[cfg(test)] +mod open_gov_on_asset_hub; +#[cfg(test)] +mod open_gov_on_relay; + +/// CollectivesPolkadot dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded whitelist call. +pub fn collectives_send_whitelist( + dest: Location, + encoded_whitelist_call: impl FnOnce() -> Vec, +) { + CollectivesPolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type RuntimeCall = ::RuntimeCall; + type RuntimeOrigin = ::RuntimeOrigin; + type Runtime = ::Runtime; + + let whitelist_call = RuntimeCall::PolkadotXcm(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(dest)), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::Xcm, + require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), + call: encoded_whitelist_call().into(), + } + ]))), + }); + + use collectives_polkadot_runtime::fellowship::pallet_fellowship_origins::Origin::Fellows as FellowsOrigin; + let fellows_origin: RuntimeOrigin = FellowsOrigin.into(); + assert_ok!(whitelist_call.dispatch(fellows_origin)); + assert_expected_events!( + CollectivesPolkadot, + vec![ + RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); +} diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs new file mode 100644 index 0000000000..aff71e60fd --- /dev/null +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs @@ -0,0 +1,26 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[test] +fn can_authorize_upgrade_for_relaychain() { + // TODO: upgrage relaychain +} + +#[test] +fn can_authorize_upgrade_for_system_chains() { + // TODO: upgrage AssetHub (self) + // TODO: upgrage Collectives + // TODO: upgrage BridgeHub +} diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs new file mode 100644 index 0000000000..fb483ac339 --- /dev/null +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -0,0 +1,125 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::collectives_send_whitelist; +use codec::Encode; +use emulated_integration_tests_common::xcm_emulator::{Chain, TestExt}; +use frame_support::dispatch::DispatchResultWithPostInfo; +use frame_support::{assert_err, assert_ok}; +use polkadot_runtime::governance::pallet_custom_origins::Origin; +use polkadot_system_emulated_network::{ + polkadot_emulated_chain::PolkadotRelayPallet as PolkadotPallet, PolkadotRelay as Polkadot, +}; +use sp_core::H256; +use sp_runtime::traits::Dispatchable; +use sp_runtime::traits::Hash; +use sp_runtime::DispatchError; +use xcm::latest::Location; + +fn store_preimage(call: polkadot_runtime::RuntimeCall) -> H256 { + Polkadot::execute_with(|| { + type Runtime = ::Runtime; + type Preimage = ::Preimage; + + // get hash and store preimage + let call_hash = ::Hashing::hash(call.encode().as_ref()); + // Root is not important here, we could have an account with enough balance also. + assert_ok!(Preimage::note_preimage(polkadot_runtime::RuntimeOrigin::root(), call.encode())); + + call_hash + }) +} + +fn dispatch_whitelisted_call_with_preimage( + call: polkadot_runtime::RuntimeCall, + origin: polkadot_runtime::RuntimeOrigin, +) -> DispatchResultWithPostInfo { + Polkadot::execute_with(|| { + type Runtime = ::Runtime; + + // wrap with whitelist call + let whitelist_call = polkadot_runtime::RuntimeCall::Whitelist( + pallet_whitelist::Call::::dispatch_whitelisted_call_with_preimage { + call: Box::new(call), + }, + ); + + whitelist_call.dispatch(origin) + }) +} + +#[test] +fn can_authorize_upgrade_for_relaychain() { + let code_hash = [1u8; 32].into(); + type Runtime = ::Runtime; + + let authorize_upgrade = + polkadot_runtime::RuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![ + // upgrade the relaychain + polkadot_runtime::RuntimeCall::System(frame_system::Call::authorize_upgrade { + code_hash, + }), + ], + }); + + // bad origin + let invalid_origin: polkadot_runtime::RuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: polkadot_runtime::RuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = store_preimage(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage(authorize_upgrade.clone(), ok_origin.clone()), + DispatchError::Module(sp_runtime::ModuleError { + index: 23, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + collectives_send_whitelist(Location::parent(), || { + polkadot_runtime::RuntimeCall::Whitelist( + pallet_whitelist::Call::::whitelist_call { call_hash }, + ) + .encode() + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage(authorize_upgrade.clone(), invalid_origin), + DispatchError::BadOrigin + ); + + // check before + Polkadot::execute_with(|| assert!(polkadot_runtime::System::authorized_upgrade().is_none())); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage(authorize_upgrade, ok_origin)); + + // check after - authorized + Polkadot::execute_with(|| assert!(polkadot_runtime::System::authorized_upgrade().is_some())); +} + +#[test] +fn can_authorize_upgrade_for_system_chains() { + // TODO: upgrage AssetHub + // TODO: upgrage Collectives + // TODO: upgrage BridgeHub +} From 9e33edad2ce0dec6a13d39b5d0fb6efb8dd6f9ce Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 17 Mar 2025 16:07:52 +0100 Subject: [PATCH 02/53] Updated TODOs to check later --- relay/kusama/src/lib.rs | 2 ++ relay/kusama/src/xcm_config.rs | 1 + relay/polkadot/src/lib.rs | 1 + relay/polkadot/src/xcm_config.rs | 1 + system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs | 2 ++ .../asset-hubs/asset-hub-polkadot/src/governance/mod.rs | 2 +- .../asset-hubs/asset-hub-polkadot/src/xcm_config.rs | 1 + .../bridge-hubs/bridge-hub-kusama/src/xcm_config.rs | 2 ++ .../bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs | 1 + .../collectives/collectives-polkadot/src/xcm_config.rs | 1 + system-parachains/coretime/coretime-kusama/src/xcm_config.rs | 2 ++ system-parachains/coretime/coretime-polkadot/src/xcm_config.rs | 1 + system-parachains/people/people-kusama/src/xcm_config.rs | 2 ++ system-parachains/people/people-polkadot/src/xcm_config.rs | 1 + 14 files changed, 19 insertions(+), 1 deletion(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index a94a576212..4e570938dd 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -726,6 +726,7 @@ impl EnsureOriginWithArg for DynamicParamet match key { Inflation(_) => frame_system::ensure_root(origin.clone()), Treasury(_) => + // TODO: review - GeneralAdmin propagation from AssetHub? EitherOf::, GeneralAdmin>::ensure_origin(origin.clone()), } .map_err(|_| origin) @@ -1421,6 +1422,7 @@ parameter_types! { impl parachains_hrmp::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; + // TODO: review - GeneralAdmin propagation from AssetHub? type ChannelManager = EitherOf, GeneralAdmin>; type Currency = Balances; // Use the `HrmpChannelSizeAndCapacityWithSystemRatio` ratio from the actual active diff --git a/relay/kusama/src/xcm_config.rs b/relay/kusama/src/xcm_config.rs index 04d84533a2..8400486707 100644 --- a/relay/kusama/src/xcm_config.rs +++ b/relay/kusama/src/xcm_config.rs @@ -255,6 +255,7 @@ pub type FellowsToPlurality = OriginToPluralityVoice; +// TODO: review - after AHM and gov migration - not a local pallets anymore /// Type to convert a pallet `Origin` type value into a `Location` value which represents an /// interior location of this chain for a destination chain. pub type LocalPalletOrSignedOriginToLocation = ( diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 5ab22a6c35..489db03fee 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1226,6 +1226,7 @@ parameter_types! { impl parachains_hrmp::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; + // TODO: review - GeneralAdmin propagation from AssetHub? type ChannelManager = EitherOf, GeneralAdmin>; type Currency = Balances; // Use the `HrmpChannelSizeAndCapacityWithSystemRatio` ratio from the actual active diff --git a/relay/polkadot/src/xcm_config.rs b/relay/polkadot/src/xcm_config.rs index d55aa09f5a..53719e3a34 100644 --- a/relay/polkadot/src/xcm_config.rs +++ b/relay/polkadot/src/xcm_config.rs @@ -264,6 +264,7 @@ pub type FellowshipAdminToPlurality = /// Type to convert the `Treasurer` origin to a Plurality `Location` value. pub type TreasurerToPlurality = OriginToPluralityVoice; +// TODO: review - after AHM and gov migration - not a local pallets anymore /// Type to convert a pallet `Origin` type value into a `Location` value which represents an /// interior location of this chain for a destination chain. pub type LocalPalletOrSignedOriginToLocation = ( diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 868ca92c93..e81b576a71 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -74,7 +74,9 @@ parameter_types! { pub PoolAssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + // TODO: wrong - before/during/after migration setup? pub const GovernanceLocation: Location = Location::parent(); + // TODO: wrong - before/during/after migration setup? pub const FellowshipLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(kusama_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs index 8caba55727..316e9fd938 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs @@ -40,7 +40,7 @@ impl pallet_conviction_voting::Config for Runtime { type Currency = Balances; type VoteLockingPeriod = VoteLockingPeriod; type MaxVotes = ConstU32<512>; // TODO check with weight - // TODO: review + // TODO: review - after/before migration check? type MaxTurnout = frame_support::traits::tokens::currency::ActiveIssuanceOf; type Polls = Referenda; diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index 435b97111a..827f8c2640 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -71,6 +71,7 @@ parameter_types! { PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); + // TODO: wrong - before/during/after migration setup? pub const GovernanceLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index 911958288f..d7ef3c2755 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -57,7 +57,9 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; + // TODO: wrong - before/during/after migration setup? pub const GovernanceLocation: Location = Location::parent(); + // TODO: wrong - before/during/after migration setup? pub const FellowshipLocation: Location = Location::parent(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(kusama_runtime_constants::TREASURY_PALLET_ID)).into(); diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 6183d7bd79..5aba9d14d5 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -63,6 +63,7 @@ parameter_types! { pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); + // TODO: wrong - before/during/after migration setup? pub const GovernanceLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index b9e6f996a1..8a8d67f29f 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -57,6 +57,7 @@ parameter_types! { pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + // TODO: wrong - before/during/after migration setup? pub const GovernanceLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); diff --git a/system-parachains/coretime/coretime-kusama/src/xcm_config.rs b/system-parachains/coretime/coretime-kusama/src/xcm_config.rs index d0d58ce6ed..ccf7e49279 100644 --- a/system-parachains/coretime/coretime-kusama/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-kusama/src/xcm_config.rs @@ -57,7 +57,9 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; + // TODO: wrong - before/during/after migration setup? pub const GovernanceLocation: Location = Location::parent(); + // TODO: wrong - before/during/after migration setup? pub const FellowshipLocation: Location = Location::parent(); pub StakingPot: AccountId = CollatorSelection::account_id(); } diff --git a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs index d0e4f6f001..5d4fe22f6d 100644 --- a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs @@ -58,6 +58,7 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; + // TODO: wrong - before/during/after migration setup? pub const GovernanceLocation: Location = Location::parent(); pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); pub StakingPot: AccountId = CollatorSelection::account_id(); diff --git a/system-parachains/people/people-kusama/src/xcm_config.rs b/system-parachains/people/people-kusama/src/xcm_config.rs index 43174a863c..ca81e51ad2 100644 --- a/system-parachains/people/people-kusama/src/xcm_config.rs +++ b/system-parachains/people/people-kusama/src/xcm_config.rs @@ -55,7 +55,9 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; + // TODO: wrong - before/during/after migration setup? pub const GovernanceLocation: Location = Location::parent(); + // TODO: wrong - before/during/after migration setup? pub const FellowshipLocation: Location = Location::parent(); /// The asset ID for the asset that we use to pay for message delivery fees. Just KSM. pub FeeAssetId: AssetId = AssetId(RelayLocation::get()); diff --git a/system-parachains/people/people-polkadot/src/xcm_config.rs b/system-parachains/people/people-polkadot/src/xcm_config.rs index 409a87e9d8..28163ab207 100644 --- a/system-parachains/people/people-polkadot/src/xcm_config.rs +++ b/system-parachains/people/people-polkadot/src/xcm_config.rs @@ -56,6 +56,7 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; + // TODO: wrong - before/during/after migration setup? pub const GovernanceLocation: Location = Location::parent(); pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); /// The asset ID for the asset that we use to pay for message delivery fees. Just DOT. From 28411c3593bb15aec4b5d5f04f144651609e0cbd Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Fri, 21 Mar 2025 14:56:40 +0100 Subject: [PATCH 03/53] [Governance tests] can_authorize_upgrade_for_system_chains initial impl (#9) * [Governance tests] can_authorize_upgrade_for_system_chains initial impl * Update integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs * [Governance tests] Add more chains & extract common logic to utility funcs --------- Co-authored-by: Branislav Kontur --- Cargo.lock | 4 + .../tests/governance/polkadot/Cargo.toml | 8 +- .../tests/governance/polkadot/src/lib.rs | 6 +- .../polkadot/src/open_gov_on_relay.rs | 170 +++++++++++++++--- 4 files changed, 159 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f0e0359d03..799be5735c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4945,7 +4945,10 @@ dependencies = [ name = "governance-polkadot-integration-tests" version = "1.0.0" dependencies = [ + "asset-hub-polkadot-runtime", + "bridge-hub-polkadot-runtime", "collectives-polkadot-runtime", + "coretime-polkadot-runtime", "emulated-integration-tests-common", "frame-support", "frame-system", @@ -4954,6 +4957,7 @@ dependencies = [ "pallet-whitelist", "pallet-xcm", "parity-scale-codec", + "people-polkadot-runtime", "polkadot-runtime", "polkadot-system-emulated-network", "sp-core 34.0.0", diff --git a/integration-tests/emulated/tests/governance/polkadot/Cargo.toml b/integration-tests/emulated/tests/governance/polkadot/Cargo.toml index 9385aa996e..6701a2388b 100644 --- a/integration-tests/emulated/tests/governance/polkadot/Cargo.toml +++ b/integration-tests/emulated/tests/governance/polkadot/Cargo.toml @@ -26,7 +26,11 @@ xcm = { workspace = true, default-features = true } emulated-integration-tests-common = { workspace = true } # Local -polkadot-runtime = { workspace = true } -integration-tests-helpers = { workspace = true } +asset-hub-polkadot-runtime = { workspace = true } +bridge-hub-polkadot-runtime = { workspace = true } collectives-polkadot-runtime = { workspace = true } +coretime-polkadot-runtime = { workspace = true } +integration-tests-helpers = { workspace = true } +people-polkadot-runtime = { workspace = true } +polkadot-runtime = { workspace = true } polkadot-system-emulated-network = { workspace = true } diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs index fd91c25be6..fd38935139 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -19,15 +19,15 @@ use frame_support::assert_ok; use integration_tests_helpers::Chain; use polkadot_system_emulated_network::CollectivesPolkadotPara as CollectivesPolkadot; use sp_runtime::traits::Dispatchable; -use xcm::latest::prelude::*; -use xcm::{VersionedLocation, VersionedXcm}; +use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; #[cfg(test)] mod open_gov_on_asset_hub; #[cfg(test)] mod open_gov_on_relay; -/// CollectivesPolkadot dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded whitelist call. +/// CollectivesPolkadot dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded +/// whitelist call. pub fn collectives_send_whitelist( dest: Location, encoded_whitelist_call: impl FnOnce() -> Vec, diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs index fb483ac339..f427ebb76a 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -12,21 +12,25 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - -use crate::collectives_send_whitelist; +use crate::*; use codec::Encode; -use emulated_integration_tests_common::xcm_emulator::{Chain, TestExt}; -use frame_support::dispatch::DispatchResultWithPostInfo; -use frame_support::{assert_err, assert_ok}; +use emulated_integration_tests_common::{ + impls::RelayChain, + xcm_emulator::{Chain, Parachain, TestExt}, +}; +use frame_support::{assert_err, assert_ok, dispatch::DispatchResultWithPostInfo}; use polkadot_runtime::governance::pallet_custom_origins::Origin; use polkadot_system_emulated_network::{ - polkadot_emulated_chain::PolkadotRelayPallet as PolkadotPallet, PolkadotRelay as Polkadot, + polkadot_emulated_chain::PolkadotRelayPallet as PolkadotPallet, + AssetHubPolkadotPara as AssetHubPolkadot, BridgeHubPolkadotPara as BridgeHubPolkadot, + CoretimePolkadotPara as CoretimePolkadot, PeoplePolkadotPara as PeoplePolkadot, + PolkadotRelay as Polkadot, }; use sp_core::H256; -use sp_runtime::traits::Dispatchable; -use sp_runtime::traits::Hash; -use sp_runtime::DispatchError; -use xcm::latest::Location; +use sp_runtime::{ + traits::{Dispatchable, Hash}, + DispatchError, +}; fn store_preimage(call: polkadot_runtime::RuntimeCall) -> H256 { Polkadot::execute_with(|| { @@ -48,9 +52,10 @@ fn dispatch_whitelisted_call_with_preimage( ) -> DispatchResultWithPostInfo { Polkadot::execute_with(|| { type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; // wrap with whitelist call - let whitelist_call = polkadot_runtime::RuntimeCall::Whitelist( + let whitelist_call = RuntimeCall::Whitelist( pallet_whitelist::Call::::dispatch_whitelisted_call_with_preimage { call: Box::new(call), }, @@ -63,22 +68,22 @@ fn dispatch_whitelisted_call_with_preimage( #[test] fn can_authorize_upgrade_for_relaychain() { let code_hash = [1u8; 32].into(); - type Runtime = ::Runtime; + type PolkadotRuntime = ::Runtime; + type PolkadotRuntimeCall = ::RuntimeCall; + type PolkadotRuntimeOrigin = ::RuntimeOrigin; let authorize_upgrade = - polkadot_runtime::RuntimeCall::Utility(pallet_utility::Call::::force_batch { + PolkadotRuntimeCall::Utility(pallet_utility::Call::::force_batch { calls: vec![ // upgrade the relaychain - polkadot_runtime::RuntimeCall::System(frame_system::Call::authorize_upgrade { - code_hash, - }), + PolkadotRuntimeCall::System(frame_system::Call::authorize_upgrade { code_hash }), ], }); // bad origin - let invalid_origin: polkadot_runtime::RuntimeOrigin = Origin::StakingAdmin.into(); + let invalid_origin: PolkadotRuntimeOrigin = Origin::StakingAdmin.into(); // ok origin - let ok_origin: polkadot_runtime::RuntimeOrigin = Origin::WhitelistedCaller.into(); + let ok_origin: PolkadotRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage let call_hash = store_preimage(authorize_upgrade.clone()); @@ -95,9 +100,9 @@ fn can_authorize_upgrade_for_relaychain() { // whitelist collectives_send_whitelist(Location::parent(), || { - polkadot_runtime::RuntimeCall::Whitelist( - pallet_whitelist::Call::::whitelist_call { call_hash }, - ) + PolkadotRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { + call_hash, + }) .encode() }); @@ -117,9 +122,126 @@ fn can_authorize_upgrade_for_relaychain() { Polkadot::execute_with(|| assert!(polkadot_runtime::System::authorized_upgrade().is_some())); } +fn build_xcm_send_authorize_upgrade_call, P: Parachain>( +) -> ::RuntimeCall { + let code_hash = [1u8; 32].into(); + let location = Polkadot::child_location_of(P::para_id()); + // TODO: calculate real weight + let weight = Weight::from_parts(5_000_000_000, 500_000); + + let call: R::RuntimeCall = frame_system::Call::::authorize_upgrade { code_hash }.into(); + + ::RuntimeCall::XcmPallet(pallet_xcm::Call::send { + dest: bx!(VersionedLocation::from(location)), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::Superuser, + require_weight_at_most: weight, + call: call.encode().into(), + } + ]))), + }) +} + #[test] fn can_authorize_upgrade_for_system_chains() { - // TODO: upgrage AssetHub - // TODO: upgrage Collectives - // TODO: upgrage BridgeHub + type PolkadotRuntime = ::Runtime; + type PolkadotRuntimeCall = ::RuntimeCall; + type PolkadotRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + PolkadotRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![ + build_xcm_send_authorize_upgrade_call::< + ::Runtime, + AssetHubPolkadot, + >(), + build_xcm_send_authorize_upgrade_call::< + ::Runtime, + BridgeHubPolkadot, + >(), + build_xcm_send_authorize_upgrade_call::< + ::Runtime, + CollectivesPolkadot, + >(), + build_xcm_send_authorize_upgrade_call::< + ::Runtime, + CoretimePolkadot, + >(), + build_xcm_send_authorize_upgrade_call::< + ::Runtime, + PeoplePolkadot, + >(), + ], + }); + + // bad origin + let invalid_origin: PolkadotRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: PolkadotRuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = store_preimage(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage(authorize_upgrade.clone(), ok_origin.clone()), + DispatchError::Module(sp_runtime::ModuleError { + index: 23, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + collectives_send_whitelist(Location::parent(), || { + PolkadotRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { + call_hash, + }) + .encode() + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage(authorize_upgrade.clone(), invalid_origin), + DispatchError::BadOrigin + ); + + // check before + AssetHubPolkadot::execute_with(|| { + assert!(asset_hub_polkadot_runtime::System::authorized_upgrade().is_none()) + }); + BridgeHubPolkadot::execute_with(|| { + assert!(bridge_hub_polkadot_runtime::System::authorized_upgrade().is_none()) + }); + CollectivesPolkadot::execute_with(|| { + assert!(collectives_polkadot_runtime::System::authorized_upgrade().is_none()) + }); + CoretimePolkadot::execute_with(|| { + assert!(coretime_polkadot_runtime::System::authorized_upgrade().is_none()) + }); + PeoplePolkadot::execute_with(|| { + assert!(people_polkadot_runtime::System::authorized_upgrade().is_none()) + }); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage(authorize_upgrade, ok_origin)); + + // check after - authorized + AssetHubPolkadot::execute_with(|| { + assert!(asset_hub_polkadot_runtime::System::authorized_upgrade().is_some()) + }); + BridgeHubPolkadot::execute_with(|| { + assert!(bridge_hub_polkadot_runtime::System::authorized_upgrade().is_some()) + }); + CollectivesPolkadot::execute_with(|| { + assert!(collectives_polkadot_runtime::System::authorized_upgrade().is_some()) + }); + CoretimePolkadot::execute_with(|| { + assert!(coretime_polkadot_runtime::System::authorized_upgrade().is_some()) + }); + PeoplePolkadot::execute_with(|| { + assert!(people_polkadot_runtime::System::authorized_upgrade().is_some()) + }); } From 66d4cea5c10433d505efa9c5baef1ae10f41cc4f Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 27 Mar 2025 09:43:43 +0100 Subject: [PATCH 04/53] Governance tests - continuation (#10) * [Governance tests] can_authorize_upgrade_for_system_chains initial impl * Update integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs * [Governance tests] Add more chains & extract common logic to utility funcs * [Governance tests] Introduce Asset Hub authorize upgrade itself scenario * [Governance tests] assethub_can_authorize_upgrade_for_polkadot scenario * [Governance tests] Refactor + assethub_can_authorize_upgrade_for_system_chains * [Governance tests] Comments changes * Update integration-tests/emulated/tests/governance/polkadot/src/lib.rs Co-authored-by: Branislav Kontur * Apply suggestions from code review --------- Co-authored-by: Branislav Kontur --- Cargo.lock | 3 +- .../assets/asset-hub-polkadot/src/lib.rs | 1 + .../tests/governance/polkadot/Cargo.toml | 3 +- .../tests/governance/polkadot/src/lib.rs | 89 ++++++- .../polkadot/src/open_gov_on_asset_hub.rs | 250 +++++++++++++++++- .../polkadot/src/open_gov_on_relay.rs | 157 ++++------- 6 files changed, 384 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 799be5735c..32d80f6403 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4946,13 +4946,12 @@ name = "governance-polkadot-integration-tests" version = "1.0.0" dependencies = [ "asset-hub-polkadot-runtime", - "bridge-hub-polkadot-runtime", "collectives-polkadot-runtime", - "coretime-polkadot-runtime", "emulated-integration-tests-common", "frame-support", "frame-system", "integration-tests-helpers", + "pallet-preimage", "pallet-utility", "pallet-whitelist", "pallet-xcm", diff --git a/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/lib.rs b/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/lib.rs index ecefcf0148..1b84ba2f2c 100644 --- a/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/lib.rs +++ b/integration-tests/emulated/chains/parachains/assets/asset-hub-polkadot/src/lib.rs @@ -48,6 +48,7 @@ decl_test_parachains! { ForeignAssets: asset_hub_polkadot_runtime::ForeignAssets, PoolAssets: asset_hub_polkadot_runtime::PoolAssets, AssetConversion: asset_hub_polkadot_runtime::AssetConversion, + Preimage: asset_hub_polkadot_runtime::Preimage, } }, } diff --git a/integration-tests/emulated/tests/governance/polkadot/Cargo.toml b/integration-tests/emulated/tests/governance/polkadot/Cargo.toml index 6701a2388b..dee4ed7ce4 100644 --- a/integration-tests/emulated/tests/governance/polkadot/Cargo.toml +++ b/integration-tests/emulated/tests/governance/polkadot/Cargo.toml @@ -16,6 +16,7 @@ sp-runtime = { workspace = true, default-features = true } frame-support = { workspace = true, default-features = true } frame-system = { workspace = true, default-features = true } pallet-whitelist = { workspace = true, default-features = true } +pallet-preimage = { workspace = true, default-features = true } pallet-utility = { workspace = true, default-features = true } # Polkadot @@ -27,9 +28,7 @@ emulated-integration-tests-common = { workspace = true } # Local asset-hub-polkadot-runtime = { workspace = true } -bridge-hub-polkadot-runtime = { workspace = true } collectives-polkadot-runtime = { workspace = true } -coretime-polkadot-runtime = { workspace = true } integration-tests-helpers = { workspace = true } people-polkadot-runtime = { workspace = true } polkadot-runtime = { workspace = true } diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs index fd38935139..2de2df49c3 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -14,11 +14,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -use emulated_integration_tests_common::impls::{assert_expected_events, bx, TestExt}; -use frame_support::assert_ok; -use integration_tests_helpers::Chain; +use emulated_integration_tests_common::{ + impls::{assert_expected_events, bx, Encode, TestExt}, + xcm_emulator::Chain, +}; +use frame_support::{ + assert_ok, + dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}, +}; use polkadot_system_emulated_network::CollectivesPolkadotPara as CollectivesPolkadot; -use sp_runtime::traits::Dispatchable; +use sp_core::H256; +use sp_runtime::traits::{Dispatchable, Hash}; use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; #[cfg(test)] @@ -26,6 +32,81 @@ mod open_gov_on_asset_hub; #[cfg(test)] mod open_gov_on_relay; +/// Wraps a runtime call in a whitelist preimage call and dispatches it +pub fn dispatch_whitelisted_call_with_preimage( + call: T::RuntimeCall, + origin: T::RuntimeOrigin, +) -> DispatchResultWithPostInfo +where + T: Chain, + T::Runtime: pallet_whitelist::Config, + T::RuntimeCall: From> + + Into<::RuntimeCall> + + Dispatchable, +{ + T::execute_with(|| { + let whitelist_call: T::RuntimeCall = + pallet_whitelist::Call::::dispatch_whitelisted_call_with_preimage { + call: Box::new(call.into()), + } + .into(); + whitelist_call.dispatch(origin) + }) +} + +/// Encodes a runtime call, stores it as a preimage, and returns its H256 hash +pub fn dispatch_note_preimage_call(call: T::RuntimeCall) -> H256 +where + T: Chain, + T::Runtime: frame_system::Config + pallet_preimage::Config, + T::RuntimeCall: Encode + + From> + + Dispatchable, + T::RuntimeOrigin: From<::RuntimeOrigin>, +{ + T::execute_with(|| { + let call_bytes = call.encode(); + let call_hash = ::Hashing::hash(&call_bytes); + let preimage_call: T::RuntimeCall = + pallet_preimage::Call::::note_preimage { bytes: call_bytes.clone() }.into(); + + let root_origin = T::RuntimeOrigin::from(frame_system::RawOrigin::Root.into()); + assert_ok!(preimage_call.dispatch(root_origin)); + call_hash + }) +} + +/// Builds an XCM call to send an authorize upgrade message using the provided location +pub fn build_xcm_send_authorize_upgrade_call(location: Location) -> T::RuntimeCall +where + T: Chain, + T::Runtime: pallet_xcm::Config, + T::RuntimeCall: Encode + From>, + D: Chain, + D::Runtime: frame_system::Config, + D::RuntimeCall: Encode + From>, +{ + let code_hash = [1u8; 32].into(); + // TODO: calculate real weight + let weight = Weight::from_parts(5_000_000_000, 500_000); + + let transact_call: D::RuntimeCall = frame_system::Call::authorize_upgrade { code_hash }.into(); + + let call: T::RuntimeCall = pallet_xcm::Call::send { + dest: bx!(VersionedLocation::from(location)), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::Superuser, + require_weight_at_most: weight, + call: transact_call.encode().into(), + } + ]))), + } + .into(); + call +} + /// CollectivesPolkadot dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded /// whitelist call. pub fn collectives_send_whitelist( diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs index aff71e60fd..5458e979dc 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs @@ -12,15 +12,253 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +use crate::*; +use asset_hub_polkadot_runtime::governance::pallet_custom_origins::Origin; +use codec::Encode; +use emulated_integration_tests_common::xcm_emulator::{Chain, Parachain, TestExt}; +use frame_support::assert_err; +use polkadot_system_emulated_network::{ + AssetHubPolkadotPara as AssetHubPolkadot, BridgeHubPolkadotPara as BridgeHubPolkadot, + CoretimePolkadotPara as CoretimePolkadot, PeoplePolkadotPara as PeoplePolkadot, + PolkadotRelay as Polkadot, +}; +use sp_runtime::DispatchError; #[test] -fn can_authorize_upgrade_for_relaychain() { - // TODO: upgrage relaychain +fn assethub_can_authorize_upgrade_for_itself() { + let code_hash = [1u8; 32].into(); + type AssetHubRuntime = ::Runtime; + type AssetHubRuntimeCall = ::RuntimeCall; + type AssetHubRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![AssetHubRuntimeCall::System(frame_system::Call::authorize_upgrade { + code_hash, + })], + }); + + // bad origin + let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 64, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + collectives_send_whitelist( + CollectivesPolkadot::sibling_location_of(::para_id()), + || { + AssetHubRuntimeCall::Whitelist( + pallet_whitelist::Call::::whitelist_call { call_hash }, + ) + .encode() + }, + ); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + AssetHubPolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::( + authorize_upgrade, + ok_origin + )); + + // check after - authorized + AssetHubPolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); +} + +#[test] +fn assethub_can_authorize_upgrade_for_relay_chain() { + type AssetHubRuntime = ::Runtime; + type AssetHubRuntimeCall = ::RuntimeCall; + type AssetHubRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![build_xcm_send_authorize_upgrade_call::( + AssetHubPolkadot::parent_location(), + )], + }); + + // bad origin + let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 64, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + collectives_send_whitelist( + CollectivesPolkadot::sibling_location_of(::para_id()), + || { + AssetHubRuntimeCall::Whitelist( + pallet_whitelist::Call::::whitelist_call { call_hash }, + ) + .encode() + }, + ); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + Polkadot::execute_with(|| assert!(::System::authorized_upgrade().is_none())); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::( + authorize_upgrade, + ok_origin + )); + + // check after - authorized + Polkadot::execute_with(|| assert!(::System::authorized_upgrade().is_some())); } #[test] -fn can_authorize_upgrade_for_system_chains() { - // TODO: upgrage AssetHub (self) - // TODO: upgrage Collectives - // TODO: upgrage BridgeHub +fn assethub_can_authorize_upgrade_for_system_chains() { + type AssetHubRuntime = ::Runtime; + type AssetHubRuntimeCall = ::RuntimeCall; + type AssetHubRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![ + build_xcm_send_authorize_upgrade_call::( + AssetHubPolkadot::sibling_location_of(BridgeHubPolkadot::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + AssetHubPolkadot::sibling_location_of(CollectivesPolkadot::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + AssetHubPolkadot::sibling_location_of(CoretimePolkadot::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + AssetHubPolkadot::sibling_location_of(PeoplePolkadot::para_id()), + ), + ], + }); + + // bad origin + let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 64, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + collectives_send_whitelist( + CollectivesPolkadot::sibling_location_of(::para_id()), + || { + AssetHubRuntimeCall::Whitelist( + pallet_whitelist::Call::::whitelist_call { call_hash }, + ) + .encode() + }, + ); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + BridgeHubPolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + CollectivesPolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + CoretimePolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + PeoplePolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::( + authorize_upgrade, + ok_origin + )); + + // check after - authorized + BridgeHubPolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); + CollectivesPolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); + CoretimePolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); + PeoplePolkadot::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); } diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs index f427ebb76a..46f05f4125 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -18,55 +18,17 @@ use emulated_integration_tests_common::{ impls::RelayChain, xcm_emulator::{Chain, Parachain, TestExt}, }; -use frame_support::{assert_err, assert_ok, dispatch::DispatchResultWithPostInfo}; +use frame_support::assert_err; use polkadot_runtime::governance::pallet_custom_origins::Origin; use polkadot_system_emulated_network::{ - polkadot_emulated_chain::PolkadotRelayPallet as PolkadotPallet, AssetHubPolkadotPara as AssetHubPolkadot, BridgeHubPolkadotPara as BridgeHubPolkadot, CoretimePolkadotPara as CoretimePolkadot, PeoplePolkadotPara as PeoplePolkadot, PolkadotRelay as Polkadot, }; -use sp_core::H256; -use sp_runtime::{ - traits::{Dispatchable, Hash}, - DispatchError, -}; - -fn store_preimage(call: polkadot_runtime::RuntimeCall) -> H256 { - Polkadot::execute_with(|| { - type Runtime = ::Runtime; - type Preimage = ::Preimage; - - // get hash and store preimage - let call_hash = ::Hashing::hash(call.encode().as_ref()); - // Root is not important here, we could have an account with enough balance also. - assert_ok!(Preimage::note_preimage(polkadot_runtime::RuntimeOrigin::root(), call.encode())); - - call_hash - }) -} - -fn dispatch_whitelisted_call_with_preimage( - call: polkadot_runtime::RuntimeCall, - origin: polkadot_runtime::RuntimeOrigin, -) -> DispatchResultWithPostInfo { - Polkadot::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - - // wrap with whitelist call - let whitelist_call = RuntimeCall::Whitelist( - pallet_whitelist::Call::::dispatch_whitelisted_call_with_preimage { - call: Box::new(call), - }, - ); - - whitelist_call.dispatch(origin) - }) -} +use sp_runtime::DispatchError; #[test] -fn can_authorize_upgrade_for_relaychain() { +fn relaychain_can_authorize_upgrade_for_itself() { let code_hash = [1u8; 32].into(); type PolkadotRuntime = ::Runtime; type PolkadotRuntimeCall = ::RuntimeCall; @@ -86,11 +48,14 @@ fn can_authorize_upgrade_for_relaychain() { let ok_origin: PolkadotRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = store_preimage(authorize_upgrade.clone()); + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); // Err - when dispatch non-whitelisted assert_err!( - dispatch_whitelisted_call_with_preimage(authorize_upgrade.clone(), ok_origin.clone()), + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), DispatchError::Module(sp_runtime::ModuleError { index: 23, error: [3, 0, 0, 0], @@ -108,44 +73,25 @@ fn can_authorize_upgrade_for_relaychain() { // Err - when dispatch wrong origin assert_err!( - dispatch_whitelisted_call_with_preimage(authorize_upgrade.clone(), invalid_origin), + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), DispatchError::BadOrigin ); // check before - Polkadot::execute_with(|| assert!(polkadot_runtime::System::authorized_upgrade().is_none())); + Polkadot::execute_with(|| assert!(::System::authorized_upgrade().is_none())); // ok - authorized - assert_ok!(dispatch_whitelisted_call_with_preimage(authorize_upgrade, ok_origin)); + assert_ok!(dispatch_whitelisted_call_with_preimage::(authorize_upgrade, ok_origin)); // check after - authorized - Polkadot::execute_with(|| assert!(polkadot_runtime::System::authorized_upgrade().is_some())); -} - -fn build_xcm_send_authorize_upgrade_call, P: Parachain>( -) -> ::RuntimeCall { - let code_hash = [1u8; 32].into(); - let location = Polkadot::child_location_of(P::para_id()); - // TODO: calculate real weight - let weight = Weight::from_parts(5_000_000_000, 500_000); - - let call: R::RuntimeCall = frame_system::Call::::authorize_upgrade { code_hash }.into(); - - ::RuntimeCall::XcmPallet(pallet_xcm::Call::send { - dest: bx!(VersionedLocation::from(location)), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind: OriginKind::Superuser, - require_weight_at_most: weight, - call: call.encode().into(), - } - ]))), - }) + Polkadot::execute_with(|| assert!(::System::authorized_upgrade().is_some())); } #[test] -fn can_authorize_upgrade_for_system_chains() { +fn relaychain_can_authorize_upgrade_for_system_chains() { type PolkadotRuntime = ::Runtime; type PolkadotRuntimeCall = ::RuntimeCall; type PolkadotRuntimeOrigin = ::RuntimeOrigin; @@ -153,26 +99,21 @@ fn can_authorize_upgrade_for_system_chains() { let authorize_upgrade = PolkadotRuntimeCall::Utility(pallet_utility::Call::::force_batch { calls: vec![ - build_xcm_send_authorize_upgrade_call::< - ::Runtime, - AssetHubPolkadot, - >(), - build_xcm_send_authorize_upgrade_call::< - ::Runtime, - BridgeHubPolkadot, - >(), - build_xcm_send_authorize_upgrade_call::< - ::Runtime, - CollectivesPolkadot, - >(), - build_xcm_send_authorize_upgrade_call::< - ::Runtime, - CoretimePolkadot, - >(), - build_xcm_send_authorize_upgrade_call::< - ::Runtime, - PeoplePolkadot, - >(), + build_xcm_send_authorize_upgrade_call::( + Polkadot::child_location_of(AssetHubPolkadot::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + Polkadot::child_location_of(BridgeHubPolkadot::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + Polkadot::child_location_of(CollectivesPolkadot::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + Polkadot::child_location_of(CoretimePolkadot::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + Polkadot::child_location_of(PeoplePolkadot::para_id()), + ), ], }); @@ -182,11 +123,14 @@ fn can_authorize_upgrade_for_system_chains() { let ok_origin: PolkadotRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = store_preimage(authorize_upgrade.clone()); + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); // Err - when dispatch non-whitelisted assert_err!( - dispatch_whitelisted_call_with_preimage(authorize_upgrade.clone(), ok_origin.clone()), + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), DispatchError::Module(sp_runtime::ModuleError { index: 23, error: [3, 0, 0, 0], @@ -204,44 +148,47 @@ fn can_authorize_upgrade_for_system_chains() { // Err - when dispatch wrong origin assert_err!( - dispatch_whitelisted_call_with_preimage(authorize_upgrade.clone(), invalid_origin), + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), DispatchError::BadOrigin ); // check before AssetHubPolkadot::execute_with(|| { - assert!(asset_hub_polkadot_runtime::System::authorized_upgrade().is_none()) + assert!(::System::authorized_upgrade().is_none()) }); BridgeHubPolkadot::execute_with(|| { - assert!(bridge_hub_polkadot_runtime::System::authorized_upgrade().is_none()) + assert!(::System::authorized_upgrade().is_none()) }); CollectivesPolkadot::execute_with(|| { - assert!(collectives_polkadot_runtime::System::authorized_upgrade().is_none()) + assert!(::System::authorized_upgrade().is_none()) }); CoretimePolkadot::execute_with(|| { - assert!(coretime_polkadot_runtime::System::authorized_upgrade().is_none()) + assert!(::System::authorized_upgrade().is_none()) }); PeoplePolkadot::execute_with(|| { - assert!(people_polkadot_runtime::System::authorized_upgrade().is_none()) + assert!(::System::authorized_upgrade().is_none()) }); // ok - authorized - assert_ok!(dispatch_whitelisted_call_with_preimage(authorize_upgrade, ok_origin)); + assert_ok!(dispatch_whitelisted_call_with_preimage::(authorize_upgrade, ok_origin)); - // check after - authorized AssetHubPolkadot::execute_with(|| { - assert!(asset_hub_polkadot_runtime::System::authorized_upgrade().is_some()) + assert!(::System::authorized_upgrade().is_some()) }); + // check after - authorized BridgeHubPolkadot::execute_with(|| { - assert!(bridge_hub_polkadot_runtime::System::authorized_upgrade().is_some()) + assert!(::System::authorized_upgrade().is_some()) }); CollectivesPolkadot::execute_with(|| { - assert!(collectives_polkadot_runtime::System::authorized_upgrade().is_some()) + assert!(::System::authorized_upgrade().is_some()) }); CoretimePolkadot::execute_with(|| { - assert!(coretime_polkadot_runtime::System::authorized_upgrade().is_some()) + assert!(::System::authorized_upgrade().is_some()) }); PeoplePolkadot::execute_with(|| { - assert!(people_polkadot_runtime::System::authorized_upgrade().is_some()) + assert!(::System::authorized_upgrade().is_some()) }); } From 306c2ff3f343729da61180f9e441430ffe660551 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 10 Apr 2025 09:51:06 +0200 Subject: [PATCH 05/53] [AHM Gov] AssetHub as Superuser on Polkadot relay - utils & config (#12) * [AHM Gov] AssetHub as Superuser on Polkadot relay - utils & config * [Governance tests] LocationAsSuperuser - shared utils & chains configuration * [Governance tests] Formatting - cargo fmt * [AHM Gov] Replace custom ContainsAssetHub with Equals * Fix Cargo.toml(s) formatting with taplo * Use Equals instead of custom struct for tests * Update pallets/common/src/lib.rs * Rustdocs for LocationAsSuperuser * Update pallets/common/src/lib.rs --------- Co-authored-by: Branislav Kontur --- Cargo.lock | 18 +++ Cargo.toml | 2 + pallets/common/Cargo.toml | 29 ++++ pallets/common/src/lib.rs | 140 ++++++++++++++++++ relay/common/Cargo.toml | 1 - relay/kusama/src/lib.rs | 2 +- relay/polkadot/Cargo.toml | 2 + relay/polkadot/src/lib.rs | 15 +- relay/polkadot/src/xcm_config.rs | 4 + .../asset-hub-polkadot/src/governance/mod.rs | 2 +- .../bridge-hub-polkadot/Cargo.toml | 2 + .../bridge-hub-polkadot/src/xcm_config.rs | 5 + .../collectives-polkadot/Cargo.toml | 2 + .../collectives-polkadot/src/xcm_config.rs | 8 +- .../coretime/coretime-polkadot/Cargo.toml | 2 + .../coretime-polkadot/src/xcm_config.rs | 5 + .../people/people-polkadot/Cargo.toml | 2 + .../people/people-polkadot/src/xcm_config.rs | 5 + 18 files changed, 230 insertions(+), 16 deletions(-) create mode 100644 pallets/common/Cargo.toml create mode 100644 pallets/common/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 32d80f6403..91859f4f7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1982,6 +1982,7 @@ dependencies = [ "pallet-xcm", "pallet-xcm-benchmarks", "pallet-xcm-bridge-hub", + "pallets-common", "parachains-common", "parachains-runtimes-test-utils", "parity-scale-codec", @@ -2502,6 +2503,7 @@ dependencies = [ "pallet-utility", "pallet-xcm", "pallet-xcm-benchmarks", + "pallets-common", "parachains-common", "parachains-runtimes-test-utils", "parity-scale-codec", @@ -2856,6 +2858,7 @@ dependencies = [ "pallet-utility", "pallet-xcm", "pallet-xcm-benchmarks", + "pallets-common", "parachains-common", "parachains-runtimes-test-utils", "parity-scale-codec", @@ -9346,6 +9349,19 @@ dependencies = [ "staging-xcm-builder", ] +[[package]] +name = "pallets-common" +version = "1.0.0" +dependencies = [ + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "staging-xcm", + "staging-xcm-executor", +] + [[package]] name = "parachains-common" version = "18.0.0" @@ -9863,6 +9879,7 @@ dependencies = [ "pallet-utility", "pallet-xcm", "pallet-xcm-benchmarks", + "pallets-common", "parachains-common", "parachains-runtimes-test-utils", "parity-scale-codec", @@ -10215,6 +10232,7 @@ dependencies = [ "pallet-whitelist", "pallet-xcm", "pallet-xcm-benchmarks", + "pallets-common", "parity-scale-codec", "polkadot-parachain-primitives", "polkadot-primitives", diff --git a/Cargo.toml b/Cargo.toml index 68143b7b64..bb7f6a62c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -261,6 +261,7 @@ zombienet-sdk = { version = "0.2.4" } tuplex = { version = "0.1.0", default-features = false } relay-common = { path = "relay/common", default-features = false } ss58-registry = { version = "1.47.0" } +pallets-common = { path = "pallets/common", default-features = false } [workspace] resolver = "2" @@ -297,6 +298,7 @@ members = [ "integration-tests/zombienet", "pallets/ah-migrator", "pallets/ah-ops", + "pallets/common", "pallets/rc-migrator", "pallets/remote-proxy", "relay/common", diff --git a/pallets/common/Cargo.toml b/pallets/common/Cargo.toml new file mode 100644 index 0000000000..37879280b4 --- /dev/null +++ b/pallets/common/Cargo.toml @@ -0,0 +1,29 @@ +[package] +authors.workspace = true +description = "Shared utilities" +edition.workspace = true +license.workspace = true +name = "pallets-common" +repository.workspace = true +version.workspace = true + +[dependencies] +codec = { features = ["derive", "max-encoded-len"], workspace = true } +scale-info = { features = ["derive"], workspace = true } +xcm = { workspace = true } +xcm-executor = { workspace = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +log = { workspace = true } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "log/std", + "scale-info/std", + "xcm-executor/std", + "xcm/std", +] diff --git a/pallets/common/src/lib.rs b/pallets/common/src/lib.rs new file mode 100644 index 0000000000..8f1757c8c2 --- /dev/null +++ b/pallets/common/src/lib.rs @@ -0,0 +1,140 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Code shared between all runtimes +#![cfg_attr(not(feature = "std"), no_std)] + +use core::marker::PhantomData; +use frame_support::traits::{Contains, OriginTrait}; +use xcm::latest::{Location, OriginKind}; +use xcm_executor::traits::ConvertOrigin; + +/// TODO: `LocationAsSuperuser` is temporary placed here, the final solution will be imported from +/// `xcm_builder` (depends on backports) instead. +/// +/// A converter that allows a specific `Location` to act as a superuser (`RuntimeOrigin::root()`) +/// if it matches the predefined `SuperuserLocation` filter and `OriginKind::Superuser`. +pub struct LocationAsSuperuser( + PhantomData<(SuperuserLocation, RuntimeOrigin)>, +); +impl, RuntimeOrigin: OriginTrait> ConvertOrigin + for LocationAsSuperuser +{ + fn convert_origin( + origin: impl Into, + kind: OriginKind, + ) -> Result { + let origin = origin.into(); + log::trace!(target: "xcm::origin_conversion", "LocationAsSuperuser origin: {:?}, kind: {:?}", origin, kind); + match (kind, &origin) { + (OriginKind::Superuser, loc) if SuperuserLocation::contains(loc) => + Ok(RuntimeOrigin::root()), + _ => Err(origin), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use frame_support::{construct_runtime, derive_impl, parameter_types, traits::Equals}; + use xcm::latest::{Junction::*, Junctions::*, OriginKind}; + + type Block = frame_system::mocking::MockBlock; + + construct_runtime!( + pub enum Test + { + System: frame_system, + } + ); + + #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] + impl frame_system::Config for Test { + type Block = Block; + } + + parameter_types! { + pub SuperuserLocation: Location = Location::new(0, Parachain(1)); + } + + #[test] + fn superuser_location_works() { + let test_conversion = |loc, kind| { + LocationAsSuperuser::, RuntimeOrigin>::convert_origin( + loc, kind, + ) + }; + + // Location that was set as SuperUserLocation should result in success conversion to Root + assert!(matches!(test_conversion(SuperuserLocation::get(), OriginKind::Superuser), Ok(..))); + // Same Location as SuperUserLocation::get() + assert!(matches!( + test_conversion(Location::new(0, Parachain(1)), OriginKind::Superuser), + Ok(..) + )); + + // Same Location but different origin kind + assert!(matches!(test_conversion(SuperuserLocation::get(), OriginKind::Native), Err(..))); + assert!(matches!( + test_conversion(SuperuserLocation::get(), OriginKind::SovereignAccount), + Err(..) + )); + assert!(matches!(test_conversion(SuperuserLocation::get(), OriginKind::Xcm), Err(..))); + + // No other location should result in successful conversion to Root + // thus expecting Err in all cases below + // + // Non-matching parachain number + assert!(matches!( + test_conversion(Location::new(0, Parachain(2)), OriginKind::Superuser), + Err(..) + )); + // Non-matching parents count + assert!(matches!( + test_conversion(Location::new(1, Parachain(1)), OriginKind::Superuser), + Err(..) + )); + // Child location of SuperUserLocation + assert!(matches!( + test_conversion( + Location::new(1, [Parachain(1), GeneralIndex(0)]), + OriginKind::Superuser + ), + Err(..) + )); + // Here + assert!(matches!(test_conversion(Location::new(0, Here), OriginKind::Superuser), Err(..))); + // Parent + assert!(matches!(test_conversion(Location::new(1, Here), OriginKind::Superuser), Err(..))); + // Some random account + assert!(matches!( + test_conversion( + Location::new(0, AccountId32 { network: None, id: [0u8; 32] }), + OriginKind::Superuser + ), + Err(..) + )); + // Child location of SuperUserLocation + assert!(matches!( + test_conversion( + Location::new(0, [Parachain(1), AccountId32 { network: None, id: [1u8; 32] }]), + OriginKind::Superuser + ), + Err(..) + )); + } +} diff --git a/relay/common/Cargo.toml b/relay/common/Cargo.toml index 0b735c6645..038757b28c 100644 --- a/relay/common/Cargo.toml +++ b/relay/common/Cargo.toml @@ -16,7 +16,6 @@ sp-runtime = { workspace = true } polkadot-primitives = { workspace = true } pallet-staking-reward-fn = { workspace = true } - [features] default = ["std"] std = [ diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 4e570938dd..1f4c26de48 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -726,7 +726,7 @@ impl EnsureOriginWithArg for DynamicParamet match key { Inflation(_) => frame_system::ensure_root(origin.clone()), Treasury(_) => - // TODO: review - GeneralAdmin propagation from AssetHub? + // TODO: review - GeneralAdmin propagation from AssetHub? EitherOf::, GeneralAdmin>::ensure_origin(origin.clone()), } .map_err(|_| origin) diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index c3cf82fee2..1f316d9bf5 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -104,6 +104,7 @@ polkadot-runtime-common = { workspace = true } runtime-parachains = { workspace = true } polkadot-primitives = { workspace = true } relay-common = { workspace = true } +pallets-common = { workspace = true } xcm = { workspace = true } xcm-executor = { workspace = true } @@ -197,6 +198,7 @@ std = [ "pallet-whitelist/std", "pallet-xcm-benchmarks?/std", "pallet-xcm/std", + "pallets-common/std", "polkadot-parachain-primitives/std", "polkadot-primitives/std", "polkadot-runtime-common/std", diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 489db03fee..cc2ff192e4 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -68,9 +68,9 @@ use frame_support::{ traits::{ fungible::HoldConsideration, tokens::{imbalance::ResolveTo, UnityOrOuterConversion}, - ConstU32, ConstU8, Contains, EitherOf, EitherOfDiverse, FromContains, Get, InstanceFilter, - KeyOwnerProofSystem, LinearStoragePrice, OnRuntimeUpgrade, PrivilegeCmp, ProcessMessage, - ProcessMessageError, WithdrawReasons, + ConstU32, ConstU8, Contains, EitherOf, EitherOfDiverse, Equals, FromContains, Get, + InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, OnRuntimeUpgrade, PrivilegeCmp, + ProcessMessage, ProcessMessageError, WithdrawReasons, }, weights::{ constants::{WEIGHT_PROOF_SIZE_PER_KB, WEIGHT_REF_TIME_PER_MICROS}, @@ -1524,20 +1524,13 @@ parameter_types! { pub AhExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT / 100; } -pub struct ContainsAssetHub; -impl Contains for ContainsAssetHub { - fn contains(loc: &Location) -> bool { - *loc == AssetHubLocation::get() - } -} - impl pallet_rc_migrator::Config for Runtime { type RuntimeEvent = RuntimeEvent; type ManagerOrigin = EitherOfDiverse< EnsureRoot, EitherOfDiverse< EnsureXcm>, - EnsureXcm, + EnsureXcm, Location>, >, >; type Currency = Balances; diff --git a/relay/polkadot/src/xcm_config.rs b/relay/polkadot/src/xcm_config.rs index 53719e3a34..149e58ea89 100644 --- a/relay/polkadot/src/xcm_config.rs +++ b/relay/polkadot/src/xcm_config.rs @@ -46,6 +46,8 @@ use xcm_builder::{ WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, }; +use pallets_common::LocationAsSuperuser; + pub use pallet_rc_migrator::xcm_config::*; parameter_types! { @@ -113,6 +115,8 @@ type LocalOriginConverter = ( SignedAccountId32AsNative, // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. XcmPassthrough, + // AssetHub can execute as root + LocationAsSuperuser, RuntimeOrigin>, ); parameter_types! { diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs index 316e9fd938..25bb07f4d2 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs @@ -40,7 +40,7 @@ impl pallet_conviction_voting::Config for Runtime { type Currency = Balances; type VoteLockingPeriod = VoteLockingPeriod; type MaxVotes = ConstU32<512>; // TODO check with weight - // TODO: review - after/before migration check? + // TODO: review - after/before migration check? type MaxTurnout = frame_support::traits::tokens::currency::ActiveIssuanceOf; type Polls = Referenda; diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index babee6733f..773582d276 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -85,6 +85,7 @@ cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } +pallets-common = { workspace = true } system-parachains-constants = { workspace = true } # Bridges @@ -186,6 +187,7 @@ std = [ "pallet-xcm-benchmarks?/std", "pallet-xcm-bridge-hub/std", "pallet-xcm/std", + "pallets-common/std", "parachain-info/std", "parachains-common/std", "polkadot-core-primitives/std", diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 5aba9d14d5..a1d62b4e20 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -28,6 +28,7 @@ use frame_support::{ use frame_system::EnsureRoot; use pallet_collator_selection::StakingPotAccountId; use pallet_xcm::XcmPassthrough; +use pallets_common::LocationAsSuperuser; use parachains_common::xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -73,6 +74,7 @@ parameter_types! { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) .unwrap_or(TreasuryAccount::get()); pub StakingPot: AccountId = CollatorSelection::account_id(); + pub AssetHubLocation: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); } /// Type for specifying how a `Location` can be converted into an `AccountId`. @@ -127,6 +129,8 @@ pub type XcmOriginToTransactDispatchOrigin = ( SignedAccountId32AsNative, // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. XcmPassthrough, + // AssetHub can execute as root + LocationAsSuperuser, RuntimeOrigin>, ); pub struct ParentOrParentsPlurality; @@ -171,6 +175,7 @@ pub type Barrier = TrailingSetTopicAsId< ParentOrParentsPlurality, FellowsPlurality, Equals, + Equals, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index 9ecc69471e..70529c5d9c 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -84,6 +84,7 @@ cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } +pallets-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] @@ -213,6 +214,7 @@ std = [ "pallet-utility/std", "pallet-xcm-benchmarks?/std", "pallet-xcm/std", + "pallets-common/std", "parachain-info/std", "parachains-common/std", "polkadot-core-primitives/std", diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index 8a8d67f29f..5dcfc76ce4 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -25,6 +25,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; +use pallets_common::LocationAsSuperuser; use parachains_common::xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -68,9 +69,9 @@ parameter_types! { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) .unwrap_or(TreasuryAccount::get()); pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX); - pub AssetHub: Location = (Parent, Parachain(ASSET_HUB_ID)).into(); + pub AssetHubLocation: Location = (Parent, Parachain(ASSET_HUB_ID)).into(); pub AssetHubUsdt: LocatableAssetId = LocatableAssetId { - location: AssetHub::get(), + location: AssetHubLocation::get(), asset_id: (PalletInstance(50), GeneralIndex(1984)).into(), }; pub StakingPot: AccountId = CollatorSelection::account_id(); @@ -131,6 +132,8 @@ pub type XcmOriginToTransactDispatchOrigin = ( SignedAccountId32AsNative, // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. XcmPassthrough, + // AssetHub can execute as root + LocationAsSuperuser, RuntimeOrigin>, ); parameter_types! { @@ -173,6 +176,7 @@ pub type Barrier = TrailingSetTopicAsId< AllowExplicitUnpaidExecutionFrom<( ParentOrParentsPlurality, Equals, + Equals, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, diff --git a/system-parachains/coretime/coretime-polkadot/Cargo.toml b/system-parachains/coretime/coretime-polkadot/Cargo.toml index ed605b911e..4b40a9eb15 100644 --- a/system-parachains/coretime/coretime-polkadot/Cargo.toml +++ b/system-parachains/coretime/coretime-polkadot/Cargo.toml @@ -79,6 +79,7 @@ cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } +pallets-common = { workspace = true } [dev-dependencies] parachains-runtimes-test-utils = { workspace = true } @@ -122,6 +123,7 @@ std = [ "pallet-utility/std", "pallet-xcm-benchmarks?/std", "pallet-xcm/std", + "pallets-common/std", "parachain-info/std", "parachains-common/std", "polkadot-core-primitives/std", diff --git a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs index 5d4fe22f6d..34a613f2f2 100644 --- a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs @@ -26,6 +26,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; +use pallets_common::LocationAsSuperuser; use parachains_common::xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -62,6 +63,7 @@ parameter_types! { pub const GovernanceLocation: Location = Location::parent(); pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); pub StakingPot: AccountId = CollatorSelection::account_id(); + pub AssetHubLocation: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); } /// Type for specifying how a `Location` can be converted into an `AccountId`. @@ -136,6 +138,8 @@ pub type XcmOriginToTransactDispatchOrigin = ( SignedAccountId32AsNative, // XCM origins can be represented natively under the XCM pallet's `Xcm` origin. XcmPassthrough, + // AssetHub can execute as root + LocationAsSuperuser, RuntimeOrigin>, ); pub struct ParentOrParentsPlurality; @@ -180,6 +184,7 @@ pub type Barrier = TrailingSetTopicAsId< ParentOrParentsPlurality, FellowsPlurality, Equals, + Equals, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, diff --git a/system-parachains/people/people-polkadot/Cargo.toml b/system-parachains/people/people-polkadot/Cargo.toml index 362ce2a1e1..7c9112b4d9 100644 --- a/system-parachains/people/people-polkadot/Cargo.toml +++ b/system-parachains/people/people-polkadot/Cargo.toml @@ -75,6 +75,7 @@ cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } +pallets-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] @@ -120,6 +121,7 @@ std = [ "pallet-utility/std", "pallet-xcm-benchmarks?/std", "pallet-xcm/std", + "pallets-common/std", "parachain-info/std", "parachains-common/std", "polkadot-parachain-primitives/std", diff --git a/system-parachains/people/people-polkadot/src/xcm_config.rs b/system-parachains/people/people-polkadot/src/xcm_config.rs index 28163ab207..f58faadd33 100644 --- a/system-parachains/people/people-polkadot/src/xcm_config.rs +++ b/system-parachains/people/people-polkadot/src/xcm_config.rs @@ -24,6 +24,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; +use pallets_common::LocationAsSuperuser; use parachains_common::{ xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, @@ -70,6 +71,7 @@ parameter_types! { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) .unwrap_or(TreasuryAccount::get()); pub StakingPot: AccountId = CollatorSelection::account_id(); + pub AssetHubLocation: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); } pub type PriceForParentDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< @@ -140,6 +142,8 @@ pub type XcmOriginToTransactDispatchOrigin = ( SignedAccountId32AsNative, // XCM origins can be represented natively under the XCM pallet's `Xcm` origin. XcmPassthrough, + // AssetHub can execute as root + LocationAsSuperuser, RuntimeOrigin>, ); pub struct LocalPlurality; @@ -191,6 +195,7 @@ pub type Barrier = TrailingSetTopicAsId< ParentOrParentsPlurality, FellowsPlurality, Equals, + Equals, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, From d79e7cb010397f7feb15813fe256183dbe1a305f Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 10 Jun 2025 12:53:03 +0200 Subject: [PATCH 06/53] Governance integration tests for Kusama (#15) * [AHM Gov] AssetHub as Superuser on Polkadot relay - utils & config * [Governance tests] LocationAsSuperuser - shared utils & chains configuration * [Governance tests] Formatting - cargo fmt * [AHM Gov] Replace custom ContainsAssetHub with Equals * Fix Cargo.toml(s) formatting with taplo * Use Equals instead of custom struct for tests * Update pallets/common/src/lib.rs * Rustdocs for LocationAsSuperuser * Governance tests on Kusama --------- Co-authored-by: Branislav Kontur --- Cargo.lock | 28 +- Cargo.toml | 1 + integration-tests/emulated/helpers/Cargo.toml | 8 + integration-tests/emulated/helpers/src/lib.rs | 84 ++++++ .../tests/governance/kusama/Cargo.toml | 28 ++ .../tests/governance/kusama/src/lib.rs | 21 ++ .../kusama/src/open_gov_on_asset_hub.rs | 255 ++++++++++++++++++ .../kusama/src/open_gov_on_relay.rs | 192 +++++++++++++ .../tests/governance/polkadot/Cargo.toml | 3 - .../tests/governance/polkadot/src/lib.rs | 85 +----- .../polkadot/src/open_gov_on_asset_hub.rs | 4 + .../polkadot/src/open_gov_on_relay.rs | 4 + 12 files changed, 625 insertions(+), 88 deletions(-) create mode 100644 integration-tests/emulated/tests/governance/kusama/Cargo.toml create mode 100644 integration-tests/emulated/tests/governance/kusama/src/lib.rs create mode 100644 integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs create mode 100644 integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs diff --git a/Cargo.lock b/Cargo.lock index 62603542e2..90e35a846e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4956,6 +4956,24 @@ dependencies = [ "system-parachains-constants", ] +[[package]] +name = "governance-kusama-integration-tests" +version = "1.0.0" +dependencies = [ + "asset-hub-kusama-runtime", + "emulated-integration-tests-common", + "frame-support", + "frame-system", + "integration-tests-helpers", + "kusama-system-emulated-network", + "pallet-utility", + "pallet-whitelist", + "parity-scale-codec", + "people-kusama-runtime", + "sp-runtime 39.0.5", + "staging-kusama-runtime", +] + [[package]] name = "governance-polkadot-integration-tests" version = "1.0.0" @@ -4966,15 +4984,12 @@ dependencies = [ "frame-support", "frame-system", "integration-tests-helpers", - "pallet-preimage", "pallet-utility", "pallet-whitelist", "pallet-xcm", "parity-scale-codec", - "people-polkadot-runtime", "polkadot-runtime", "polkadot-system-emulated-network", - "sp-core 34.0.0", "sp-runtime 39.0.5", "staging-xcm", ] @@ -5629,10 +5644,17 @@ version = "1.0.0" dependencies = [ "asset-test-utils 20.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "cumulus-pallet-xcmp-queue", + "emulated-integration-tests-common", + "frame-support", + "frame-system", "pallet-balances", "pallet-message-queue", + "pallet-preimage", + "pallet-whitelist", "pallet-xcm", "paste", + "sp-core 34.0.0", + "sp-runtime 39.0.5", "staging-xcm", "xcm-emulator", ] diff --git a/Cargo.toml b/Cargo.toml index 7117f14ce5..5be4c283b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -293,6 +293,7 @@ members = [ "integration-tests/emulated/tests/collectives/collectives-polkadot", "integration-tests/emulated/tests/coretime/coretime-kusama", "integration-tests/emulated/tests/coretime/coretime-polkadot", + "integration-tests/emulated/tests/governance/kusama", "integration-tests/emulated/tests/governance/polkadot", "integration-tests/emulated/tests/people/people-kusama", "integration-tests/emulated/tests/people/people-polkadot", diff --git a/integration-tests/emulated/helpers/Cargo.toml b/integration-tests/emulated/helpers/Cargo.toml index b5c6401bf9..83e6f571eb 100644 --- a/integration-tests/emulated/helpers/Cargo.toml +++ b/integration-tests/emulated/helpers/Cargo.toml @@ -13,12 +13,20 @@ paste = { workspace = true } # Substrate pallet-balances = { workspace = true, default-features = true } pallet-message-queue = { workspace = true, default-features = true } +pallet-preimage = { workspace = true, default-features = true } +sp-runtime = { workspace = true, default-features = true } +sp-core = { workspace = true, default-features = true } +frame-support = { workspace = true, default-features = true } +frame-system = { workspace = true, default-features = true } +pallet-whitelist = { workspace = true, default-features = true } # Polkadot xcm = { workspace = true, default-features = true } pallet-xcm = { workspace = true, default-features = true } + # Cumulus xcm-emulator = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true, default-features = true } asset-test-utils = { workspace = true } +emulated-integration-tests-common = { workspace = true } diff --git a/integration-tests/emulated/helpers/src/lib.rs b/integration-tests/emulated/helpers/src/lib.rs index 08bf402e9d..edae31a458 100644 --- a/integration-tests/emulated/helpers/src/lib.rs +++ b/integration-tests/emulated/helpers/src/lib.rs @@ -28,6 +28,15 @@ pub use asset_test_utils; pub use cumulus_pallet_xcmp_queue; pub use xcm_emulator::Chain; +use emulated_integration_tests_common::impls::{bx, Encode}; +use frame_support::{ + assert_ok, + dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}, +}; +use sp_core::H256; +use sp_runtime::traits::{Dispatchable, Hash}; +use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; + /// TODO: when bumping to polkadot-sdk v1.8.0, /// remove this crate altogether and get the macros from `emulated-integration-tests-common`. /// TODO: backport this macros to polkadot-sdk @@ -404,3 +413,78 @@ macro_rules! test_chain_can_claim_assets { } }; } + +/// Wraps a runtime call in a whitelist preimage call and dispatches it +pub fn dispatch_whitelisted_call_with_preimage( + call: T::RuntimeCall, + origin: T::RuntimeOrigin, +) -> DispatchResultWithPostInfo +where + T: Chain, + T::Runtime: pallet_whitelist::Config, + T::RuntimeCall: From> + + Into<::RuntimeCall> + + Dispatchable, +{ + T::execute_with(|| { + let whitelist_call: T::RuntimeCall = + pallet_whitelist::Call::::dispatch_whitelisted_call_with_preimage { + call: Box::new(call.into()), + } + .into(); + whitelist_call.dispatch(origin) + }) +} + +/// Encodes a runtime call, stores it as a preimage, and returns its H256 hash +pub fn dispatch_note_preimage_call(call: T::RuntimeCall) -> H256 +where + T: Chain, + T::Runtime: frame_system::Config + pallet_preimage::Config, + T::RuntimeCall: Encode + + From> + + Dispatchable, + T::RuntimeOrigin: From<::RuntimeOrigin>, +{ + T::execute_with(|| { + let call_bytes = call.encode(); + let call_hash = ::Hashing::hash(&call_bytes); + let preimage_call: T::RuntimeCall = + pallet_preimage::Call::::note_preimage { bytes: call_bytes.clone() }.into(); + + let root_origin = T::RuntimeOrigin::from(frame_system::RawOrigin::Root.into()); + assert_ok!(preimage_call.dispatch(root_origin)); + call_hash + }) +} + +/// Builds an XCM call to send an authorize upgrade message using the provided location +pub fn build_xcm_send_authorize_upgrade_call(location: Location) -> T::RuntimeCall +where + T: Chain, + T::Runtime: pallet_xcm::Config, + T::RuntimeCall: Encode + From>, + D: Chain, + D::Runtime: frame_system::Config, + D::RuntimeCall: Encode + From>, +{ + let code_hash = [1u8; 32].into(); + // TODO: calculate real weight + let weight = Weight::from_parts(5_000_000_000, 500_000); + + let transact_call: D::RuntimeCall = frame_system::Call::authorize_upgrade { code_hash }.into(); + + let call: T::RuntimeCall = pallet_xcm::Call::send { + dest: bx!(VersionedLocation::from(location)), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::Superuser, + require_weight_at_most: weight, + call: transact_call.encode().into(), + } + ]))), + } + .into(); + call +} diff --git a/integration-tests/emulated/tests/governance/kusama/Cargo.toml b/integration-tests/emulated/tests/governance/kusama/Cargo.toml new file mode 100644 index 0000000000..664b31c4e8 --- /dev/null +++ b/integration-tests/emulated/tests/governance/kusama/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "governance-kusama-integration-tests" +version.workspace = true +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +description = "Kusama governance integration tests with xcm-emulator" +publish = false + +[dependencies] +codec = { workspace = true, default-features = true } + +# Substrate +sp-runtime = { workspace = true, default-features = true } +frame-support = { workspace = true, default-features = true } +frame-system = { workspace = true, default-features = true } +pallet-whitelist = { workspace = true, default-features = true } +pallet-utility = { workspace = true, default-features = true } + +# Cumulus +emulated-integration-tests-common = { workspace = true } + +# Local +asset-hub-kusama-runtime = { workspace = true } +integration-tests-helpers = { workspace = true } +people-kusama-runtime = { workspace = true } +kusama-runtime = { workspace = true } +kusama-system-emulated-network = { workspace = true } diff --git a/integration-tests/emulated/tests/governance/kusama/src/lib.rs b/integration-tests/emulated/tests/governance/kusama/src/lib.rs new file mode 100644 index 0000000000..f1cc4ee468 --- /dev/null +++ b/integration-tests/emulated/tests/governance/kusama/src/lib.rs @@ -0,0 +1,21 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[cfg(test)] +// TODO: currently it doesn't compile as there is no governance on KAH implemented yet +// mod open_gov_on_asset_hub; +#[cfg(test)] +mod open_gov_on_relay; diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs new file mode 100644 index 0000000000..3e04d4e26f --- /dev/null +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs @@ -0,0 +1,255 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +use asset_hub_kusama_runtime::governance::pallet_custom_origins::Origin; +use emulated_integration_tests_common::xcm_emulator::{Chain, Parachain, TestExt}; +use frame_support::{assert_ok, assert_err}; +use kusama_system_emulated_network::{ + AssetHubKusamaPara as AssetHubKusama, BridgeHubKusamaPara as BridgeHubKusama, + CoretimeKusamaPara as CoretimeKusama, PeopleKusamaPara as PeopleKusama, + KusamaRelay as Kusama, +}; +use sp_runtime::DispatchError; +use integration_tests_helpers::{dispatch_note_preimage_call, dispatch_whitelisted_call_with_preimage, build_xcm_send_authorize_upgrade_call}; + + +#[test] +fn assethub_can_authorize_upgrade_for_itself() { + let code_hash = [1u8; 32].into(); + type AssetHubRuntime = ::Runtime; + type AssetHubRuntimeCall = ::RuntimeCall; + type AssetHubRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![AssetHubRuntimeCall::System(frame_system::Call::authorize_upgrade { + code_hash, + })], + }); + + // bad origin + let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 64, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + AssetHubKusama::execute_with(|| { + let whitelist_call = + AssetHubRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { + call_hash, + }); + use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; + let fellows_origin: AssetHubRuntimeOrigin = FellowsOrigin.into(); + assert_ok!(whitelist_call.dispatch(fellows_origin)); + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + AssetHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::( + authorize_upgrade, + ok_origin + )); + + // check after - authorized + AssetHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); +} + +#[test] +fn assethub_can_authorize_upgrade_for_relay_chain() { + type AssetHubRuntime = ::Runtime; + type AssetHubRuntimeCall = ::RuntimeCall; + type AssetHubRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![build_xcm_send_authorize_upgrade_call::( + AssetHubKusama::parent_location(), + )], + }); + + // bad origin + let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 64, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + AssetHubKusama::execute_with(|| { + let whitelist_call = + AssetHubRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { + call_hash, + }); + use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; + let fellows_origin: AssetHubRuntimeOrigin = FellowsOrigin.into(); + assert_ok!(whitelist_call.dispatch(fellows_origin)); + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + Kusama::execute_with(|| assert!(::System::authorized_upgrade().is_none())); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::( + authorize_upgrade, + ok_origin + )); + + // check after - authorized + Kusama::execute_with(|| assert!(::System::authorized_upgrade().is_some())); +} + +#[test] +fn assethub_can_authorize_upgrade_for_system_chains() { + type AssetHubRuntime = ::Runtime; + type AssetHubRuntimeCall = ::RuntimeCall; + type AssetHubRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![ + build_xcm_send_authorize_upgrade_call::( + AssetHubKusama::sibling_location_of(BridgeHubKusama::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + AssetHubKusama::sibling_location_of(CoretimeKusama::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + AssetHubKusama::sibling_location_of(PeopleKusama::para_id()), + ), + ], + }); + + // bad origin + let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 64, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + Kusama::execute_with(|| { + let whitelist_call = + KusamaRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { + call_hash, + }); + use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; + let fellows_origin: KusamaRuntimeOrigin = FellowsOrigin.into(); + assert_ok!(whitelist_call.dispatch(fellows_origin)); + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + BridgeHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + CoretimeKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + PeopleKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::( + authorize_upgrade, + ok_origin + )); + + // check after - authorized + BridgeHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); + CoretimeKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); + PeopleKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); +} diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs new file mode 100644 index 0000000000..491828aae2 --- /dev/null +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs @@ -0,0 +1,192 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +use emulated_integration_tests_common::{ + impls::RelayChain, + xcm_emulator::{Chain, Parachain, TestExt}, +}; +use frame_support::{assert_err, assert_ok}; +use integration_tests_helpers::{ + build_xcm_send_authorize_upgrade_call, dispatch_note_preimage_call, + dispatch_whitelisted_call_with_preimage, +}; +use kusama_runtime::governance::pallet_custom_origins::Origin; +use kusama_system_emulated_network::{ + AssetHubKusamaPara as AssetHubKusama, BridgeHubKusamaPara as BridgeHubKusama, + CoretimeKusamaPara as CoretimeKusama, KusamaRelay as Kusama, PeopleKusamaPara as PeopleKusama, +}; +use sp_runtime::{traits::Dispatchable, DispatchError}; + +#[test] +fn relaychain_can_authorize_upgrade_for_itself() { + let code_hash = [1u8; 32].into(); + type KusamaRuntime = ::Runtime; + type KusamaRuntimeCall = ::RuntimeCall; + type KusamaRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + KusamaRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![ + // upgrade the relaychain + KusamaRuntimeCall::System(frame_system::Call::authorize_upgrade { code_hash }), + ], + }); + + // bad origin + let invalid_origin: KusamaRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: KusamaRuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 44, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + Kusama::execute_with(|| { + let whitelist_call = + KusamaRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { + call_hash, + }); + use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; + let fellows_origin: KusamaRuntimeOrigin = FellowsOrigin.into(); + assert_ok!(whitelist_call.dispatch(fellows_origin)); + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + Kusama::execute_with(|| assert!(::System::authorized_upgrade().is_none())); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::(authorize_upgrade, ok_origin)); + + // check after - authorized + Kusama::execute_with(|| assert!(::System::authorized_upgrade().is_some())); +} + +#[test] +fn relaychain_can_authorize_upgrade_for_system_chains() { + type KusamaRuntime = ::Runtime; + type KusamaRuntimeCall = ::RuntimeCall; + type KusamaRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + KusamaRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![ + build_xcm_send_authorize_upgrade_call::( + Kusama::child_location_of(AssetHubKusama::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + Kusama::child_location_of(BridgeHubKusama::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + Kusama::child_location_of(CoretimeKusama::para_id()), + ), + build_xcm_send_authorize_upgrade_call::( + Kusama::child_location_of(PeopleKusama::para_id()), + ), + ], + }); + + // bad origin + let invalid_origin: KusamaRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: KusamaRuntimeOrigin = Origin::WhitelistedCaller.into(); + + // store preimage + let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 44, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist + Kusama::execute_with(|| { + let whitelist_call = + KusamaRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { + call_hash, + }); + use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; + let fellows_origin: KusamaRuntimeOrigin = FellowsOrigin.into(); + assert_ok!(whitelist_call.dispatch(fellows_origin)); + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + AssetHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + BridgeHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + CoretimeKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + PeopleKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::(authorize_upgrade, ok_origin)); + + AssetHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); + // check after - authorized + BridgeHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); + CoretimeKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); + PeopleKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_some()) + }); +} diff --git a/integration-tests/emulated/tests/governance/polkadot/Cargo.toml b/integration-tests/emulated/tests/governance/polkadot/Cargo.toml index dee4ed7ce4..c7a7c92415 100644 --- a/integration-tests/emulated/tests/governance/polkadot/Cargo.toml +++ b/integration-tests/emulated/tests/governance/polkadot/Cargo.toml @@ -11,12 +11,10 @@ publish = false codec = { workspace = true, default-features = true } # Substrate -sp-core = { workspace = true, default-features = true } sp-runtime = { workspace = true, default-features = true } frame-support = { workspace = true, default-features = true } frame-system = { workspace = true, default-features = true } pallet-whitelist = { workspace = true, default-features = true } -pallet-preimage = { workspace = true, default-features = true } pallet-utility = { workspace = true, default-features = true } # Polkadot @@ -30,6 +28,5 @@ emulated-integration-tests-common = { workspace = true } asset-hub-polkadot-runtime = { workspace = true } collectives-polkadot-runtime = { workspace = true } integration-tests-helpers = { workspace = true } -people-polkadot-runtime = { workspace = true } polkadot-runtime = { workspace = true } polkadot-system-emulated-network = { workspace = true } diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs index 2de2df49c3..2569444b4c 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -15,16 +15,12 @@ // limitations under the License. use emulated_integration_tests_common::{ - impls::{assert_expected_events, bx, Encode, TestExt}, + impls::{assert_expected_events, bx, TestExt}, xcm_emulator::Chain, }; -use frame_support::{ - assert_ok, - dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}, -}; +use frame_support::assert_ok; use polkadot_system_emulated_network::CollectivesPolkadotPara as CollectivesPolkadot; -use sp_core::H256; -use sp_runtime::traits::{Dispatchable, Hash}; +use sp_runtime::traits::Dispatchable; use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; #[cfg(test)] @@ -32,81 +28,6 @@ mod open_gov_on_asset_hub; #[cfg(test)] mod open_gov_on_relay; -/// Wraps a runtime call in a whitelist preimage call and dispatches it -pub fn dispatch_whitelisted_call_with_preimage( - call: T::RuntimeCall, - origin: T::RuntimeOrigin, -) -> DispatchResultWithPostInfo -where - T: Chain, - T::Runtime: pallet_whitelist::Config, - T::RuntimeCall: From> - + Into<::RuntimeCall> - + Dispatchable, -{ - T::execute_with(|| { - let whitelist_call: T::RuntimeCall = - pallet_whitelist::Call::::dispatch_whitelisted_call_with_preimage { - call: Box::new(call.into()), - } - .into(); - whitelist_call.dispatch(origin) - }) -} - -/// Encodes a runtime call, stores it as a preimage, and returns its H256 hash -pub fn dispatch_note_preimage_call(call: T::RuntimeCall) -> H256 -where - T: Chain, - T::Runtime: frame_system::Config + pallet_preimage::Config, - T::RuntimeCall: Encode - + From> - + Dispatchable, - T::RuntimeOrigin: From<::RuntimeOrigin>, -{ - T::execute_with(|| { - let call_bytes = call.encode(); - let call_hash = ::Hashing::hash(&call_bytes); - let preimage_call: T::RuntimeCall = - pallet_preimage::Call::::note_preimage { bytes: call_bytes.clone() }.into(); - - let root_origin = T::RuntimeOrigin::from(frame_system::RawOrigin::Root.into()); - assert_ok!(preimage_call.dispatch(root_origin)); - call_hash - }) -} - -/// Builds an XCM call to send an authorize upgrade message using the provided location -pub fn build_xcm_send_authorize_upgrade_call(location: Location) -> T::RuntimeCall -where - T: Chain, - T::Runtime: pallet_xcm::Config, - T::RuntimeCall: Encode + From>, - D: Chain, - D::Runtime: frame_system::Config, - D::RuntimeCall: Encode + From>, -{ - let code_hash = [1u8; 32].into(); - // TODO: calculate real weight - let weight = Weight::from_parts(5_000_000_000, 500_000); - - let transact_call: D::RuntimeCall = frame_system::Call::authorize_upgrade { code_hash }.into(); - - let call: T::RuntimeCall = pallet_xcm::Call::send { - dest: bx!(VersionedLocation::from(location)), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind: OriginKind::Superuser, - require_weight_at_most: weight, - call: transact_call.encode().into(), - } - ]))), - } - .into(); - call -} - /// CollectivesPolkadot dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded /// whitelist call. pub fn collectives_send_whitelist( diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs index 5458e979dc..43ece39468 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs @@ -17,6 +17,10 @@ use asset_hub_polkadot_runtime::governance::pallet_custom_origins::Origin; use codec::Encode; use emulated_integration_tests_common::xcm_emulator::{Chain, Parachain, TestExt}; use frame_support::assert_err; +use integration_tests_helpers::{ + build_xcm_send_authorize_upgrade_call, dispatch_note_preimage_call, + dispatch_whitelisted_call_with_preimage, +}; use polkadot_system_emulated_network::{ AssetHubPolkadotPara as AssetHubPolkadot, BridgeHubPolkadotPara as BridgeHubPolkadot, CoretimePolkadotPara as CoretimePolkadot, PeoplePolkadotPara as PeoplePolkadot, diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs index 46f05f4125..55d119c604 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -19,6 +19,10 @@ use emulated_integration_tests_common::{ xcm_emulator::{Chain, Parachain, TestExt}, }; use frame_support::assert_err; +use integration_tests_helpers::{ + build_xcm_send_authorize_upgrade_call, dispatch_note_preimage_call, + dispatch_whitelisted_call_with_preimage, +}; use polkadot_runtime::governance::pallet_custom_origins::Origin; use polkadot_system_emulated_network::{ AssetHubPolkadotPara as AssetHubPolkadot, BridgeHubPolkadotPara as BridgeHubPolkadot, From a7942f2cfdb633f1e63c93fb85b55e98ba7d2265 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 10 Jun 2025 14:26:47 +0200 Subject: [PATCH 07/53] We dont need `note_preimage` with `dispatch_whitelisted_call_with_preimage` --- integration-tests/emulated/helpers/src/lib.rs | 14 +++----------- .../governance/kusama/src/open_gov_on_asset_hub.rs | 8 ++++---- .../governance/kusama/src/open_gov_on_relay.rs | 6 +++--- .../polkadot/src/open_gov_on_asset_hub.rs | 8 ++++---- .../governance/polkadot/src/open_gov_on_relay.rs | 6 +++--- relay/polkadot/src/xcm_config.rs | 2 +- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/integration-tests/emulated/helpers/src/lib.rs b/integration-tests/emulated/helpers/src/lib.rs index edae31a458..507694842a 100644 --- a/integration-tests/emulated/helpers/src/lib.rs +++ b/integration-tests/emulated/helpers/src/lib.rs @@ -437,23 +437,15 @@ where } /// Encodes a runtime call, stores it as a preimage, and returns its H256 hash -pub fn dispatch_note_preimage_call(call: T::RuntimeCall) -> H256 +pub fn call_hash_of(call: &T::RuntimeCall) -> H256 where T: Chain, - T::Runtime: frame_system::Config + pallet_preimage::Config, + T::Runtime: frame_system::Config, T::RuntimeCall: Encode - + From> - + Dispatchable, - T::RuntimeOrigin: From<::RuntimeOrigin>, { T::execute_with(|| { let call_bytes = call.encode(); - let call_hash = ::Hashing::hash(&call_bytes); - let preimage_call: T::RuntimeCall = - pallet_preimage::Call::::note_preimage { bytes: call_bytes.clone() }.into(); - - let root_origin = T::RuntimeOrigin::from(frame_system::RawOrigin::Root.into()); - assert_ok!(preimage_call.dispatch(root_origin)); + let call_hash = ::Hashing::hash_of(&call_bytes); call_hash }) } diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs index 3e04d4e26f..0927358af7 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs @@ -21,7 +21,7 @@ use kusama_system_emulated_network::{ KusamaRelay as Kusama, }; use sp_runtime::DispatchError; -use integration_tests_helpers::{dispatch_note_preimage_call, dispatch_whitelisted_call_with_preimage, build_xcm_send_authorize_upgrade_call}; +use integration_tests_helpers::{call_hash_of, dispatch_whitelisted_call_with_preimage, build_xcm_send_authorize_upgrade_call}; #[test] @@ -44,7 +44,7 @@ fn assethub_can_authorize_upgrade_for_itself() { let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( @@ -115,7 +115,7 @@ fn assethub_can_authorize_upgrade_for_relay_chain() { let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( @@ -190,7 +190,7 @@ fn assethub_can_authorize_upgrade_for_system_chains() { let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs index 491828aae2..9fda14db06 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs @@ -18,7 +18,7 @@ use emulated_integration_tests_common::{ }; use frame_support::{assert_err, assert_ok}; use integration_tests_helpers::{ - build_xcm_send_authorize_upgrade_call, dispatch_note_preimage_call, + build_xcm_send_authorize_upgrade_call, call_hash_of, dispatch_whitelisted_call_with_preimage, }; use kusama_runtime::governance::pallet_custom_origins::Origin; @@ -49,7 +49,7 @@ fn relaychain_can_authorize_upgrade_for_itself() { let ok_origin: KusamaRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( @@ -124,7 +124,7 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { let ok_origin: KusamaRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs index 43ece39468..63df7b1563 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs @@ -18,7 +18,7 @@ use codec::Encode; use emulated_integration_tests_common::xcm_emulator::{Chain, Parachain, TestExt}; use frame_support::assert_err; use integration_tests_helpers::{ - build_xcm_send_authorize_upgrade_call, dispatch_note_preimage_call, + build_xcm_send_authorize_upgrade_call, call_hash_of, dispatch_whitelisted_call_with_preimage, }; use polkadot_system_emulated_network::{ @@ -48,7 +48,7 @@ fn assethub_can_authorize_upgrade_for_itself() { let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( @@ -119,7 +119,7 @@ fn assethub_can_authorize_upgrade_for_relay_chain() { let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( @@ -197,7 +197,7 @@ fn assethub_can_authorize_upgrade_for_system_chains() { let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs index 55d119c604..214d4e9ab7 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -20,7 +20,7 @@ use emulated_integration_tests_common::{ }; use frame_support::assert_err; use integration_tests_helpers::{ - build_xcm_send_authorize_upgrade_call, dispatch_note_preimage_call, + build_xcm_send_authorize_upgrade_call, call_hash_of, dispatch_whitelisted_call_with_preimage, }; use polkadot_runtime::governance::pallet_custom_origins::Origin; @@ -52,7 +52,7 @@ fn relaychain_can_authorize_upgrade_for_itself() { let ok_origin: PolkadotRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( @@ -127,7 +127,7 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { let ok_origin: PolkadotRuntimeOrigin = Origin::WhitelistedCaller.into(); // store preimage - let call_hash = dispatch_note_preimage_call::(authorize_upgrade.clone()); + let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted assert_err!( diff --git a/relay/polkadot/src/xcm_config.rs b/relay/polkadot/src/xcm_config.rs index c803401763..bea7c456aa 100644 --- a/relay/polkadot/src/xcm_config.rs +++ b/relay/polkadot/src/xcm_config.rs @@ -23,7 +23,7 @@ use super::{ }; use frame_support::{ parameter_types, - traits::{Contains, Everything, Nothing}, + traits::{Contains, Everything, Equals, Nothing}, }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; From 0aa31bf705a2a06e17945fa2d6fd221e7dc9638d Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 10 Jun 2025 14:29:12 +0200 Subject: [PATCH 08/53] Add TODOs --- .../emulated/tests/governance/polkadot/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs index 2569444b4c..0683615937 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -44,6 +44,7 @@ pub fn collectives_send_whitelist( dest: bx!(VersionedLocation::from(dest)), message: bx!(VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + TODO: (Karol)(check the TODO: bellow first) - missing DecentOrigin for Fellows - to match `EnsureXcm>,` Transact { origin_kind: OriginKind::Xcm, require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), @@ -62,4 +63,6 @@ pub fn collectives_send_whitelist( ] ); }); + + TODO: (Karol)(start with this) - add here the relaychain assert for CallWhitelisted event } From 77e9014adf9b18d9071389e84e68d6a6cf738021 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 10 Jun 2025 15:26:40 +0200 Subject: [PATCH 09/53] Adding `CallIsNotWhitelisted` event check --- .../emulated/tests/governance/polkadot/src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs index 0683615937..f03302bb7b 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -19,7 +19,9 @@ use emulated_integration_tests_common::{ xcm_emulator::Chain, }; use frame_support::assert_ok; -use polkadot_system_emulated_network::CollectivesPolkadotPara as CollectivesPolkadot; +use polkadot_system_emulated_network::{ + CollectivesPolkadotPara as CollectivesPolkadot, PolkadotRelay as Polkadot, +}; use sp_runtime::traits::Dispatchable; use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; @@ -44,7 +46,6 @@ pub fn collectives_send_whitelist( dest: bx!(VersionedLocation::from(dest)), message: bx!(VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - TODO: (Karol)(check the TODO: bellow first) - missing DecentOrigin for Fellows - to match `EnsureXcm>,` Transact { origin_kind: OriginKind::Xcm, require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), @@ -64,5 +65,13 @@ pub fn collectives_send_whitelist( ); }); - TODO: (Karol)(start with this) - add here the relaychain assert for CallWhitelisted event + Polkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::Whitelist(pallet_whitelist::Event::CallWhitelisted { .. }) => {}, + ] + ); + }); } From a8796ec2dd2ed63be2b168ecdc4d9fddba89f810 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 10 Jun 2025 15:33:17 +0200 Subject: [PATCH 10/53] Mistery solved --- integration-tests/emulated/helpers/src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/integration-tests/emulated/helpers/src/lib.rs b/integration-tests/emulated/helpers/src/lib.rs index 507694842a..5bf6d3f3ad 100644 --- a/integration-tests/emulated/helpers/src/lib.rs +++ b/integration-tests/emulated/helpers/src/lib.rs @@ -29,10 +29,7 @@ pub use cumulus_pallet_xcmp_queue; pub use xcm_emulator::Chain; use emulated_integration_tests_common::impls::{bx, Encode}; -use frame_support::{ - assert_ok, - dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}, -}; +use frame_support::dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}; use sp_core::H256; use sp_runtime::traits::{Dispatchable, Hash}; use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; @@ -441,11 +438,10 @@ pub fn call_hash_of(call: &T::RuntimeCall) -> H256 where T: Chain, T::Runtime: frame_system::Config, - T::RuntimeCall: Encode + T::RuntimeCall: Encode, { T::execute_with(|| { - let call_bytes = call.encode(); - let call_hash = ::Hashing::hash_of(&call_bytes); + let call_hash = ::Hashing::hash_of(&call); call_hash }) } From 6298e0d01d8603c569efbbf3fc4711ac79e47768 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 10 Jun 2025 15:38:46 +0200 Subject: [PATCH 11/53] TODO --- .../tests/governance/polkadot/src/lib.rs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs index f03302bb7b..20b842496f 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -20,7 +20,8 @@ use emulated_integration_tests_common::{ }; use frame_support::assert_ok; use polkadot_system_emulated_network::{ - CollectivesPolkadotPara as CollectivesPolkadot, PolkadotRelay as Polkadot, + CollectivesPolkadotPara as CollectivesPolkadot, + /*PolkadotRelay as Polkadot,*/ }; use sp_runtime::traits::Dispatchable; use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; @@ -65,13 +66,14 @@ pub fn collectives_send_whitelist( ); }); - Polkadot::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - Polkadot, - vec![ - RuntimeEvent::Whitelist(pallet_whitelist::Event::CallWhitelisted { .. }) => {}, - ] - ); - }); + // TODO: find a way how to set Polkadot or AssetHubPolkadot chain + // Polkadot::execute_with(|| { + // type RuntimeEvent = ::RuntimeEvent; + // assert_expected_events!( + // Polkadot, + // vec![ + // RuntimeEvent::Whitelist(pallet_whitelist::Event::CallWhitelisted { .. }) => {}, + // ] + // ); + // }); } From 42c1e3da468262880c5d4081a4b20401e83d91cf Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 12 Jun 2025 13:09:27 +0200 Subject: [PATCH 12/53] Introduce assert_whitelisted impl and usage (#16) * Introduce assert_whitelisted impl and usage * Remove misleading comments --- integration-tests/emulated/helpers/src/lib.rs | 20 +++++++++++++++++-- .../kusama/src/open_gov_on_asset_hub.rs | 4 +--- .../kusama/src/open_gov_on_relay.rs | 5 ++--- .../tests/governance/polkadot/src/lib.rs | 16 +-------------- .../polkadot/src/open_gov_on_asset_hub.rs | 14 +++++++++---- .../polkadot/src/open_gov_on_relay.rs | 10 +++++++--- 6 files changed, 39 insertions(+), 30 deletions(-) diff --git a/integration-tests/emulated/helpers/src/lib.rs b/integration-tests/emulated/helpers/src/lib.rs index 5bf6d3f3ad..a8db3a21d6 100644 --- a/integration-tests/emulated/helpers/src/lib.rs +++ b/integration-tests/emulated/helpers/src/lib.rs @@ -20,13 +20,14 @@ pub use pallet_balances; pub use pallet_message_queue; // Polkadot +pub use pallet_whitelist; pub use pallet_xcm; pub use xcm::prelude::{AccountId32, VersionedAssets, Weight, WeightLimit}; // Cumulus pub use asset_test_utils; pub use cumulus_pallet_xcmp_queue; -pub use xcm_emulator::Chain; +pub use xcm_emulator::{assert_expected_events, Chain}; use emulated_integration_tests_common::impls::{bx, Encode}; use frame_support::dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}; @@ -433,7 +434,22 @@ where }) } -/// Encodes a runtime call, stores it as a preimage, and returns its H256 hash +#[macro_export] +macro_rules! assert_whitelisted { + ($chain:ident, $expected_call_hash:expr) => { + type RuntimeEvent = <$chain as $crate::Chain>::RuntimeEvent; + $crate::assert_expected_events!( + $chain, + vec![ + RuntimeEvent::Whitelist($crate::pallet_whitelist::Event::CallWhitelisted { call_hash }) => { + call_hash: *call_hash == $expected_call_hash, + }, + ] + ); + }; +} + +/// Encodes a runtime call and returns its H256 hash pub fn call_hash_of(call: &T::RuntimeCall) -> H256 where T: Chain, diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs index 0927358af7..63d874a001 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs @@ -43,7 +43,6 @@ fn assethub_can_authorize_upgrade_for_itself() { // ok origin let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted @@ -114,7 +113,6 @@ fn assethub_can_authorize_upgrade_for_relay_chain() { // ok origin let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted @@ -139,6 +137,7 @@ fn assethub_can_authorize_upgrade_for_relay_chain() { use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; let fellows_origin: AssetHubRuntimeOrigin = FellowsOrigin.into(); assert_ok!(whitelist_call.dispatch(fellows_origin)); + assert_whitelisted!(AssetHubKusama, call_hash); }); // Err - when dispatch wrong origin @@ -189,7 +188,6 @@ fn assethub_can_authorize_upgrade_for_system_chains() { // ok origin let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs index 9fda14db06..093302f799 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs @@ -18,7 +18,7 @@ use emulated_integration_tests_common::{ }; use frame_support::{assert_err, assert_ok}; use integration_tests_helpers::{ - build_xcm_send_authorize_upgrade_call, call_hash_of, + assert_whitelisted, build_xcm_send_authorize_upgrade_call, call_hash_of, dispatch_whitelisted_call_with_preimage, }; use kusama_runtime::governance::pallet_custom_origins::Origin; @@ -48,7 +48,6 @@ fn relaychain_can_authorize_upgrade_for_itself() { // ok origin let ok_origin: KusamaRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted @@ -73,6 +72,7 @@ fn relaychain_can_authorize_upgrade_for_itself() { use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; let fellows_origin: KusamaRuntimeOrigin = FellowsOrigin.into(); assert_ok!(whitelist_call.dispatch(fellows_origin)); + assert_whitelisted!(Kusama, call_hash); }); // Err - when dispatch wrong origin @@ -123,7 +123,6 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { // ok origin let ok_origin: KusamaRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs index 20b842496f..2569444b4c 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -19,10 +19,7 @@ use emulated_integration_tests_common::{ xcm_emulator::Chain, }; use frame_support::assert_ok; -use polkadot_system_emulated_network::{ - CollectivesPolkadotPara as CollectivesPolkadot, - /*PolkadotRelay as Polkadot,*/ -}; +use polkadot_system_emulated_network::CollectivesPolkadotPara as CollectivesPolkadot; use sp_runtime::traits::Dispatchable; use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; @@ -65,15 +62,4 @@ pub fn collectives_send_whitelist( ] ); }); - - // TODO: find a way how to set Polkadot or AssetHubPolkadot chain - // Polkadot::execute_with(|| { - // type RuntimeEvent = ::RuntimeEvent; - // assert_expected_events!( - // Polkadot, - // vec![ - // RuntimeEvent::Whitelist(pallet_whitelist::Event::CallWhitelisted { .. }) => {}, - // ] - // ); - // }); } diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs index 63df7b1563..3d74ffec3a 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs @@ -18,7 +18,7 @@ use codec::Encode; use emulated_integration_tests_common::xcm_emulator::{Chain, Parachain, TestExt}; use frame_support::assert_err; use integration_tests_helpers::{ - build_xcm_send_authorize_upgrade_call, call_hash_of, + assert_whitelisted, build_xcm_send_authorize_upgrade_call, call_hash_of, dispatch_whitelisted_call_with_preimage, }; use polkadot_system_emulated_network::{ @@ -47,7 +47,6 @@ fn assethub_can_authorize_upgrade_for_itself() { // ok origin let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted @@ -73,6 +72,9 @@ fn assethub_can_authorize_upgrade_for_itself() { .encode() }, ); + AssetHubPolkadot::execute_with(|| { + assert_whitelisted!(AssetHubPolkadot, call_hash); + }); // Err - when dispatch wrong origin assert_err!( @@ -118,7 +120,6 @@ fn assethub_can_authorize_upgrade_for_relay_chain() { // ok origin let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted @@ -144,6 +145,9 @@ fn assethub_can_authorize_upgrade_for_relay_chain() { .encode() }, ); + AssetHubPolkadot::execute_with(|| { + assert_whitelisted!(AssetHubPolkadot, call_hash); + }); // Err - when dispatch wrong origin assert_err!( @@ -196,7 +200,6 @@ fn assethub_can_authorize_upgrade_for_system_chains() { // ok origin let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted @@ -222,6 +225,9 @@ fn assethub_can_authorize_upgrade_for_system_chains() { .encode() }, ); + AssetHubPolkadot::execute_with(|| { + assert_whitelisted!(AssetHubPolkadot, call_hash); + }); // Err - when dispatch wrong origin assert_err!( diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs index 214d4e9ab7..5c5ad22a07 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -20,7 +20,7 @@ use emulated_integration_tests_common::{ }; use frame_support::assert_err; use integration_tests_helpers::{ - build_xcm_send_authorize_upgrade_call, call_hash_of, + assert_whitelisted, build_xcm_send_authorize_upgrade_call, call_hash_of, dispatch_whitelisted_call_with_preimage, }; use polkadot_runtime::governance::pallet_custom_origins::Origin; @@ -51,7 +51,6 @@ fn relaychain_can_authorize_upgrade_for_itself() { // ok origin let ok_origin: PolkadotRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted @@ -74,6 +73,9 @@ fn relaychain_can_authorize_upgrade_for_itself() { }) .encode() }); + Polkadot::execute_with(|| { + assert_whitelisted!(Polkadot, call_hash); + }); // Err - when dispatch wrong origin assert_err!( @@ -126,7 +128,6 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { // ok origin let ok_origin: PolkadotRuntimeOrigin = Origin::WhitelistedCaller.into(); - // store preimage let call_hash = call_hash_of::(&authorize_upgrade); // Err - when dispatch non-whitelisted @@ -149,6 +150,9 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { }) .encode() }); + Polkadot::execute_with(|| { + assert_whitelisted!(Polkadot, call_hash); + }); // Err - when dispatch wrong origin assert_err!( From 1e3bfc00c22b80dfa287e072ef0feaa9608666ad Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 4 Jul 2025 00:01:50 +0200 Subject: [PATCH 13/53] Fix/split `GovernanceLocation` for system paras (Polkadot). --- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 4 +- .../asset-hub-polkadot/src/xcm_config.rs | 3 +- .../bridge-hub-polkadot/src/lib.rs | 10 ++- .../bridge-hub-polkadot/src/xcm_config.rs | 8 ++- .../src/ambassador/mod.rs | 34 ++++++--- .../src/fellowship/mod.rs | 72 ++++++++++++++----- .../collectives-polkadot/src/lib.rs | 19 +++-- .../collectives-polkadot/src/xcm_config.rs | 8 ++- .../coretime/coretime-polkadot/src/lib.rs | 9 ++- .../coretime-polkadot/src/xcm_config.rs | 8 ++- .../people/people-polkadot/src/lib.rs | 13 ++-- .../people/people-polkadot/src/people.rs | 6 +- .../people/people-polkadot/src/xcm_config.rs | 8 ++- 13 files changed, 146 insertions(+), 56 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 3bbedd88fb..94ab901a72 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -141,7 +141,7 @@ use xcm::{ }; use xcm_config::{ DotLocation, FellowshipLocation, ForeignAssetsConvertedConcreteId, - ForeignCreatorsSovereignAccountOf, GovernanceLocation, PoolAssetsConvertedConcreteId, + ForeignCreatorsSovereignAccountOf, PoolAssetsConvertedConcreteId, RcGovernanceLocation, TrustBackedAssetsConvertedConcreteId, XcmOriginToTransactDispatchOrigin, }; @@ -837,7 +837,7 @@ parameter_types! { /// We allow root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EnsureXcm>, >; impl pallet_collator_selection::Config for Runtime { diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index 959768688b..794b6f8a88 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -69,8 +69,7 @@ parameter_types! { PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); - // TODO: wrong - before/during/after migration setup? - pub const GovernanceLocation: Location = Location::parent(); + pub const RcGovernanceLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub PoolAssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index e33e13a971..2865dcc94c 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -59,7 +59,7 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, Contains, + tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOf, EitherOfDiverse, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, @@ -73,7 +73,8 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{ - FellowshipLocation, GovernanceLocation, StakingPot, XcmOriginToTransactDispatchOrigin, + AhGovernanceLocation, FellowshipLocation, RcGovernanceLocation, StakingPot, + XcmOriginToTransactDispatchOrigin, }; #[cfg(any(feature = "std", test))] @@ -507,7 +508,10 @@ parameter_types! { /// We allow root, the StakingAdmin to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >; impl pallet_collator_selection::Config for Runtime { diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index a1d62b4e20..03df13ac16 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -64,8 +64,11 @@ parameter_types! { pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); - // TODO: wrong - before/during/after migration setup? - pub const GovernanceLocation: Location = Location::parent(); + + // The AHM migration does not send progress to other chains, so we need to keep and trust two constants for a while. + pub const RcGovernanceLocation: Location = Location::parent(); + pub AhGovernanceLocation: Location = AssetHubLocation::get(); + pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); // Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location @@ -74,6 +77,7 @@ parameter_types! { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) .unwrap_or(TreasuryAccount::get()); pub StakingPot: AccountId = CollatorSelection::account_id(); + // TODO: replace from system consts pub AssetHubLocation: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); } diff --git a/system-parachains/collectives/collectives-polkadot/src/ambassador/mod.rs b/system-parachains/collectives/collectives-polkadot/src/ambassador/mod.rs index 6096c2ef27..641fcd504d 100644 --- a/system-parachains/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -78,9 +78,15 @@ impl pallet_ambassador_origins::Config for Runtime {} pub type DemoteOrigin = EitherOf< EnsureRootWithSuccess>, EitherOf< - MapSuccess< - EnsureXcm>, - Replace>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + MapSuccess< + EnsureXcm>, + Replace>, + >, >, TryMapSuccess< EnsureAmbassadorsFrom>, @@ -101,7 +107,10 @@ pub type OpenGovOrHeadAmbassadors = EitherOfDiverse< EnsureRoot, EitherOfDiverse< HeadAmbassadors, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >, >; @@ -217,7 +226,10 @@ impl pallet_core_fellowship::Config for Runtime { type InductOrigin = EitherOfDiverse< EnsureRoot, EitherOfDiverse< - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, pallet_ranked_collective::EnsureMember< Runtime, AmbassadorCollectiveInstance, @@ -328,9 +340,15 @@ impl pallet_treasury::Config for Runtime { type SpendOrigin = EitherOf< EitherOf< EnsureRootWithSuccess, - MapSuccess< - EnsureXcm>, - Replace>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + MapSuccess< + EnsureXcm>, + Replace>, + >, >, >, EitherOf< diff --git a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs index b1354bd647..ad14e188af 100644 --- a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -23,9 +23,9 @@ use crate::{ impls::ToParentTreasury, weights, xcm_config::{AssetHubUsdt, LocationToAccountId, TreasurerBodyId}, - AccountId, AssetRateWithNative, Balance, Balances, FellowshipReferenda, GovernanceLocation, - PolkadotTreasuryAccount, Preimage, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - Scheduler, DAYS, FELLOWSHIP_TREASURY_PALLET_ID, + AccountId, AhGovernanceLocation, AssetRateWithNative, Balance, Balances, FellowshipReferenda, + PolkadotTreasuryAccount, Preimage, RcGovernanceLocation, Runtime, RuntimeCall, RuntimeEvent, + RuntimeOrigin, Scheduler, DAYS, FELLOWSHIP_TREASURY_PALLET_ID, }; use frame_support::{ parameter_types, @@ -133,9 +133,15 @@ impl pallet_ranked_collective::Config for Runtime // pass. type DemoteOrigin = EitherOf< EnsureRootWithSuccess>, - MapSuccess< - EnsureXcm>, - Replace>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + MapSuccess< + EnsureXcm>, + Replace>, + >, >, >; // Exchange is by any of: @@ -166,7 +172,10 @@ impl pallet_core_fellowship::Config for Runtime { // - the FellowshipAdmin origin (i.e. token holder referendum); // - a vote among all Fellows. type ParamsOrigin = EitherOfDiverse< - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, Fellows, >; // Induction (creating a candidate) is by any of: @@ -175,7 +184,10 @@ impl pallet_core_fellowship::Config for Runtime { // - a single Fellow; // - a vote among all Members. type InductOrigin = EitherOfDiverse< - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, EitherOfDiverse< pallet_ranked_collective::EnsureMember< Runtime, @@ -190,9 +202,15 @@ impl pallet_core_fellowship::Config for Runtime { // - the FellowshipAdmin origin (i.e. token holder referendum); // - a vote by the rank two above the current rank for all retention up to the Master rank. type ApproveOrigin = EitherOf< - MapSuccess< - EnsureXcm>, - Replace>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + MapSuccess< + EnsureXcm>, + Replace>, + >, >, EnsureCanRetainAt, >; @@ -201,9 +219,15 @@ impl pallet_core_fellowship::Config for Runtime { // - the FellowshipAdmin origin (i.e. token holder referendum); // - a vote by the rank two above the new rank for all promotions up to the Master rank. type PromoteOrigin = EitherOf< - MapSuccess< - EnsureXcm>, - Replace>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + MapSuccess< + EnsureXcm>, + Replace>, + >, >, EnsureCanPromoteTo, >; @@ -297,7 +321,13 @@ impl pallet_treasury::Config for Runtime { type Currency = Balances; type RejectOrigin = EitherOfDiverse< EnsureRoot, - EitherOfDiverse>, Fellows>, + EitherOfDiverse< + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, + Fellows, + >, >; type SpendPeriod = ConstU32<{ 7 * DAYS }>; type Burn = Burn; @@ -307,9 +337,15 @@ impl pallet_treasury::Config for Runtime { type SpendOrigin = EitherOf< EitherOf< EnsureRootWithSuccess, - MapSuccess< - EnsureXcm>, - Replace>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + MapSuccess< + EnsureXcm>, + Replace>, + >, >, >, EitherOf< diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index 9a2a760a96..194ac90df9 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -76,7 +76,7 @@ use frame_support::{ traits::{ fungible::HoldConsideration, tokens::{imbalance::ResolveTo, UnityOrOuterConversion}, - ConstBool, ConstU16, ConstU32, ConstU64, ConstU8, EitherOfDiverse, FromContains, + ConstBool, ConstU16, ConstU32, ConstU64, ConstU8, EitherOf, EitherOfDiverse, FromContains, InstanceFilter, LinearStoragePrice, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, @@ -96,8 +96,8 @@ use system_parachains_constants::{ SLOT_DURATION, }; use xcm_config::{ - GovernanceLocation, LocationToAccountId, SelfParaId, StakingPot, TreasurerBodyId, - XcmOriginToTransactDispatchOrigin, + AhGovernanceLocation, LocationToAccountId, RcGovernanceLocation, SelfParaId, StakingPot, + TreasurerBodyId, XcmOriginToTransactDispatchOrigin, }; #[cfg(any(feature = "std", test))] @@ -528,7 +528,10 @@ parameter_types! { /// We allow root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >; impl pallet_collator_selection::Config for Runtime { @@ -672,7 +675,13 @@ impl pallet_asset_rate::Config for Runtime { type RuntimeEvent = RuntimeEvent; type CreateOrigin = EitherOfDiverse< EnsureRoot, - EitherOfDiverse>, Fellows>, + EitherOfDiverse< + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, + Fellows, + >, >; type RemoveOrigin = Self::CreateOrigin; type UpdateOrigin = Self::CreateOrigin; diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index 5dcfc76ce4..18ebd5d62c 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -58,8 +58,11 @@ parameter_types! { pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); - // TODO: wrong - before/during/after migration setup? - pub const GovernanceLocation: Location = Location::parent(); + + // The AHM migration does not send progress to other chains, so we need to keep and trust two constants for a while. + pub const RcGovernanceLocation: Location = Location::parent(); + pub AhGovernanceLocation: Location = AssetHubLocation::get(); + pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); pub const TreasurerBodyId: BodyId = BodyId::Treasury; @@ -69,6 +72,7 @@ parameter_types! { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) .unwrap_or(TreasuryAccount::get()); pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX); + // TODO: replace from system consts pub AssetHubLocation: Location = (Parent, Parachain(ASSET_HUB_ID)).into(); pub AssetHubUsdt: LocatableAssetId = LocatableAssetId { location: AssetHubLocation::get(), diff --git a/system-parachains/coretime/coretime-polkadot/src/lib.rs b/system-parachains/coretime/coretime-polkadot/src/lib.rs index 6fd2dcf8c5..dd3b4ef8ce 100644 --- a/system-parachains/coretime/coretime-polkadot/src/lib.rs +++ b/system-parachains/coretime/coretime-polkadot/src/lib.rs @@ -40,7 +40,7 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, Contains, + tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOf, EitherOfDiverse, EverythingBut, InstanceFilter, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, @@ -77,7 +77,7 @@ use system_parachains_constants::{ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use xcm::prelude::*; use xcm_config::{ - DotRelayLocation, FellowshipLocation, GovernanceLocation, StakingPot, + AhGovernanceLocation, DotRelayLocation, FellowshipLocation, RcGovernanceLocation, StakingPot, XcmOriginToTransactDispatchOrigin, }; use xcm_runtime_apis::{ @@ -426,7 +426,10 @@ parameter_types! { /// We allow Root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >; impl pallet_collator_selection::Config for Runtime { diff --git a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs index 34a613f2f2..3ebabae6c6 100644 --- a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs @@ -59,10 +59,14 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - // TODO: wrong - before/during/after migration setup? - pub const GovernanceLocation: Location = Location::parent(); + + // The AHM migration does not send progress to other chains, so we need to keep and trust two constants for a while. + pub const RcGovernanceLocation: Location = Location::parent(); + pub AhGovernanceLocation: Location = AssetHubLocation::get(); + pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); pub StakingPot: AccountId = CollatorSelection::account_id(); + // TODO: replace from system consts pub AssetHubLocation: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); } diff --git a/system-parachains/people/people-polkadot/src/lib.rs b/system-parachains/people/people-polkadot/src/lib.rs index be10258301..38ac6028d4 100644 --- a/system-parachains/people/people-polkadot/src/lib.rs +++ b/system-parachains/people/people-polkadot/src/lib.rs @@ -35,8 +35,8 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, - Everything, InstanceFilter, TransformOrigin, + tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, EitherOf, + EitherOfDiverse, Everything, InstanceFilter, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, PalletId, @@ -75,8 +75,8 @@ use xcm::{ VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm, }; use xcm_config::{ - FellowshipLocation, GovernanceLocation, PriceForSiblingParachainDelivery, StakingPot, - XcmConfig, XcmOriginToTransactDispatchOrigin, + AhGovernanceLocation, FellowshipLocation, PriceForSiblingParachainDelivery, + RcGovernanceLocation, StakingPot, XcmConfig, XcmOriginToTransactDispatchOrigin, }; use xcm_runtime_apis::{ dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects}, @@ -378,7 +378,10 @@ parameter_types! { /// We allow Root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >; impl pallet_collator_selection::Config for Runtime { diff --git a/system-parachains/people/people-polkadot/src/people.rs b/system-parachains/people/people-polkadot/src/people.rs index 026ec0f881..e93c1a2546 100644 --- a/system-parachains/people/people-polkadot/src/people.rs +++ b/system-parachains/people/people-polkadot/src/people.rs @@ -29,7 +29,6 @@ use sp_runtime::{ }; use sp_std::prelude::*; use xcm::latest::prelude::BodyId; -use xcm_config::GovernanceLocation; parameter_types! { // 27 | Min encoded size of `Registration` @@ -46,7 +45,10 @@ parameter_types! { pub type IdentityAdminOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >; impl pallet_identity::Config for Runtime { diff --git a/system-parachains/people/people-polkadot/src/xcm_config.rs b/system-parachains/people/people-polkadot/src/xcm_config.rs index f58faadd33..77e7f4a4da 100644 --- a/system-parachains/people/people-polkadot/src/xcm_config.rs +++ b/system-parachains/people/people-polkadot/src/xcm_config.rs @@ -57,8 +57,11 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - // TODO: wrong - before/during/after migration setup? - pub const GovernanceLocation: Location = Location::parent(); + + // The AHM migration does not send progress to other chains, so we need to keep and trust two constants for a while. + pub const RcGovernanceLocation: Location = Location::parent(); + pub AhGovernanceLocation: Location = AssetHubLocation::get(); + pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); /// The asset ID for the asset that we use to pay for message delivery fees. Just DOT. pub FeeAssetId: AssetId = AssetId(RelayLocation::get()); @@ -71,6 +74,7 @@ parameter_types! { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) .unwrap_or(TreasuryAccount::get()); pub StakingPot: AccountId = CollatorSelection::account_id(); + // TODO: replace from system consts pub AssetHubLocation: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); } From a314683928a8ac8b5df08d6b8c557c65c2b2befb Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 4 Jul 2025 00:18:27 +0200 Subject: [PATCH 14/53] GeneralAdmin/StakingAdmin/Fellows/Treasurer origin for OpenGov on AH (Polkadot) --- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 4 +- .../asset-hub-polkadot/src/xcm_config.rs | 72 +++++++++++++++---- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 94ab901a72..e21e59c102 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -79,7 +79,9 @@ use assets_common::{ use core::cmp::Ordering; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; -use governance::{pallet_custom_origins, Treasurer, TreasurySpender}; +use governance::{ + pallet_custom_origins, FellowshipAdmin, GeneralAdmin, StakingAdmin, Treasurer, TreasurySpender, +}; use polkadot_core_primitives::AccountIndex; use polkadot_runtime_constants::time::{DAYS as RC_DAYS, HOURS as RC_HOURS, MINUTES as RC_MINUTES}; use sp_api::impl_runtime_apis; diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index 794b6f8a88..a354aae264 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -15,10 +15,10 @@ use super::{ AccountId, AllPalletsWithSystem, AssetConversion, Assets, Authorship, Balance, Balances, - CollatorSelection, ForeignAssets, ForeignAssetsInstance, NativeAndAssets, ParachainInfo, - ParachainSystem, PolkadotXcm, PoolAssets, PriceForParentDelivery, Runtime, RuntimeCall, - RuntimeEvent, RuntimeOrigin, ToKusamaXcmRouter, TrustBackedAssetsInstance, WeightToFee, - XcmpQueue, + CollatorSelection, FellowshipAdmin, ForeignAssets, ForeignAssetsInstance, GeneralAdmin, + NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, + PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin, + ToKusamaXcmRouter, Treasurer, TrustBackedAssetsInstance, WeightToFee, XcmpQueue, }; use assets_common::{ matching::{FromNetwork, IsForeignConcreteAsset, ParentLocation}, @@ -38,7 +38,11 @@ use parachains_common::xcm_config::{ AssetFeeAsExistentialDepositMultiplier, ParentRelayOrSiblingParachains, }; use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_constants::system_parachain; +use polkadot_runtime_constants::{ + system_parachain, + // TODO: check this? + xcm::body::FELLOWSHIP_ADMIN_INDEX, +}; use snowbridge_router_primitives::inbound::GlobalConsensusEthereumConvertsFor; use sp_runtime::traits::{AccountIdConversion, ConvertInto, TryConvertInto}; use xcm::latest::prelude::*; @@ -47,13 +51,14 @@ use xcm_builder::{ AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, GlobalConsensusParachainConvertsFor, HashedDescription, - IsConcrete, LocalMint, MatchedConvertedConcreteId, MintLocation, NoChecking, ParentAsSuperuser, - ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SingleAssetExchangeAdapter, SovereignPaidRemoteExporter, SovereignSignedViaLocation, - StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WeightInfoBounds, WithComputedOrigin, WithLatestLocationConverter, - WithUniqueTopic, XcmFeeManagerFromComponents, + IsConcrete, LocalMint, MatchedConvertedConcreteId, MintLocation, NoChecking, + OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SingleAssetExchangeAdapter, + SovereignPaidRemoteExporter, SovereignSignedViaLocation, StartsWith, + StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, + WeightInfoBounds, WithComputedOrigin, WithLatestLocationConverter, WithUniqueTopic, + XcmFeeManagerFromComponents, }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; @@ -400,10 +405,51 @@ impl xcm_executor::Config for XcmConfig { type HrmpChannelClosingHandler = (); } +parameter_types! { + // `GeneralAdmin` pluralistic body. + pub const GeneralAdminBodyId: BodyId = BodyId::Administration; + // StakingAdmin pluralistic body. + pub const StakingAdminBodyId: BodyId = BodyId::Defense; + // FellowshipAdmin pluralistic body. + pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX); + // `Treasurer` pluralistic body. + pub const TreasurerBodyId: BodyId = BodyId::Treasury; +} + +/// Type to convert the `GeneralAdmin` origin to a Plurality `Location` value. +pub type GeneralAdminToPlurality = + OriginToPluralityVoice; + +/// Type to convert the `StakingAdmin` origin to a Plurality `Location` value. +pub type StakingAdminToPlurality = + OriginToPluralityVoice; + +/// Type to convert the `FellowshipAdmin` origin to a Plurality `Location` value. +pub type FellowshipAdminToPlurality = + OriginToPluralityVoice; + +/// Type to convert the `Treasurer` origin to a Plurality `Location` value. +pub type TreasurerToPlurality = OriginToPluralityVoice; + /// Converts a local signed origin into an XCM `Location`. /// Forms the basis for local origins sending/executing XCMs. pub type LocalSignedOriginToLocation = SignedToAccountId32; +/// Type to convert a pallet `Origin` type value into a `Location` value which represents an +/// interior location of this chain for a destination chain. +pub type LocalPalletOrSignedOriginToLocation = ( + // GeneralAdmin origin to be used in XCM as a corresponding Plurality `Location` value. + GeneralAdminToPlurality, + // StakingAdmin origin to be used in XCM as a corresponding Plurality `Location` value. + StakingAdminToPlurality, + // FellowshipAdmin origin to be used in XCM as a corresponding Plurality `Location` value. + FellowshipAdminToPlurality, + // `Treasurer` origin to be used in XCM as a corresponding Plurality `Location` value. + TreasurerToPlurality, + // And a usual Signed origin to be used in XCM as a corresponding `AccountId32`. + SignedToAccountId32, +); + /// For routing XCM messages which do not cross local consensus boundary. type LocalXcmRouter = ( // Two routers - use UMP to communicate with the relay chain: @@ -433,7 +479,7 @@ pub type XcmRouter = WithUniqueTopic<( impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; // Any local signed origin can send XCM messages. - type SendXcmOrigin = EnsureXcmOrigin; + type SendXcmOrigin = EnsureXcmOrigin; type XcmRouter = XcmRouter; // Any local signed origin can execute XCM messages. type ExecuteXcmOrigin = EnsureXcmOrigin; From 3f5c537300bc8667f8617a246124d7959e3df234 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 7 Jul 2025 18:38:46 +0200 Subject: [PATCH 15/53] Clean-up after rebase --- integration-tests/emulated/helpers/src/lib.rs | 4 +- .../tests/governance/polkadot/src/lib.rs | 2 +- .../polkadot/src/open_gov_on_relay.rs | 10 +- pallets/common/Cargo.toml | 29 ---- pallets/common/src/lib.rs | 140 ------------------ relay/polkadot/Cargo.toml | 2 - relay/polkadot/src/xcm_config.rs | 13 +- .../bridge-hub-polkadot/Cargo.toml | 2 - .../bridge-hub-polkadot/src/lib.rs | 2 +- .../bridge-hub-polkadot/src/xcm_config.rs | 13 +- .../bridge-hub-polkadot/tests/snowbridge.rs | 11 +- .../bridge-hub-polkadot/tests/tests.rs | 18 ++- .../collectives-polkadot/Cargo.toml | 2 - .../collectives-polkadot/src/secretary/mod.rs | 12 +- .../collectives-polkadot/src/xcm_config.rs | 5 +- .../coretime/coretime-polkadot/Cargo.toml | 2 - .../coretime-polkadot/src/xcm_config.rs | 11 +- .../people/people-polkadot/Cargo.toml | 2 - .../people/people-polkadot/src/xcm_config.rs | 14 +- 19 files changed, 61 insertions(+), 233 deletions(-) delete mode 100644 pallets/common/Cargo.toml delete mode 100644 pallets/common/src/lib.rs diff --git a/integration-tests/emulated/helpers/src/lib.rs b/integration-tests/emulated/helpers/src/lib.rs index 3e0e4dbe3d..ac46ec0009 100644 --- a/integration-tests/emulated/helpers/src/lib.rs +++ b/integration-tests/emulated/helpers/src/lib.rs @@ -620,8 +620,6 @@ where D::RuntimeCall: Encode + From>, { let code_hash = [1u8; 32].into(); - // TODO: calculate real weight - let weight = Weight::from_parts(5_000_000_000, 500_000); let transact_call: D::RuntimeCall = frame_system::Call::authorize_upgrade { code_hash }.into(); @@ -631,7 +629,7 @@ where UnpaidExecution { weight_limit: Unlimited, check_origin: None }, Transact { origin_kind: OriginKind::Superuser, - require_weight_at_most: weight, + fallback_max_weight: None, call: transact_call.encode().into(), } ]))), diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs index 2569444b4c..657c3df2d9 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -46,7 +46,7 @@ pub fn collectives_send_whitelist( UnpaidExecution { weight_limit: Unlimited, check_origin: None }, Transact { origin_kind: OriginKind::Xcm, - require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), + fallback_max_weight: None, call: encoded_whitelist_call().into(), } ]))), diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs index 5c5ad22a07..2c0659f3c5 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -23,7 +23,7 @@ use integration_tests_helpers::{ assert_whitelisted, build_xcm_send_authorize_upgrade_call, call_hash_of, dispatch_whitelisted_call_with_preimage, }; -use polkadot_runtime::governance::pallet_custom_origins::Origin; +use polkadot_runtime::{governance::pallet_custom_origins::Origin, Dmp}; use polkadot_system_emulated_network::{ AssetHubPolkadotPara as AssetHubPolkadot, BridgeHubPolkadotPara as BridgeHubPolkadot, CoretimePolkadotPara as CoretimePolkadot, PeoplePolkadotPara as PeoplePolkadot, @@ -102,6 +102,14 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { type PolkadotRuntimeCall = ::RuntimeCall; type PolkadotRuntimeOrigin = ::RuntimeOrigin; + Polkadot::execute_with(|| { + Dmp::make_parachain_reachable(AssetHubPolkadot::para_id()); + Dmp::make_parachain_reachable(BridgeHubPolkadot::para_id()); + Dmp::make_parachain_reachable(CollectivesPolkadot::para_id()); + Dmp::make_parachain_reachable(CoretimePolkadot::para_id()); + Dmp::make_parachain_reachable(PeoplePolkadot::para_id()); + }); + let authorize_upgrade = PolkadotRuntimeCall::Utility(pallet_utility::Call::::force_batch { calls: vec![ diff --git a/pallets/common/Cargo.toml b/pallets/common/Cargo.toml deleted file mode 100644 index 37879280b4..0000000000 --- a/pallets/common/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -authors.workspace = true -description = "Shared utilities" -edition.workspace = true -license.workspace = true -name = "pallets-common" -repository.workspace = true -version.workspace = true - -[dependencies] -codec = { features = ["derive", "max-encoded-len"], workspace = true } -scale-info = { features = ["derive"], workspace = true } -xcm = { workspace = true } -xcm-executor = { workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -log = { workspace = true } - -[features] -default = ["std"] -std = [ - "codec/std", - "frame-support/std", - "frame-system/std", - "log/std", - "scale-info/std", - "xcm-executor/std", - "xcm/std", -] diff --git a/pallets/common/src/lib.rs b/pallets/common/src/lib.rs deleted file mode 100644 index 8f1757c8c2..0000000000 --- a/pallets/common/src/lib.rs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot 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. - -// Polkadot 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 Polkadot. If not, see . - -//! Code shared between all runtimes -#![cfg_attr(not(feature = "std"), no_std)] - -use core::marker::PhantomData; -use frame_support::traits::{Contains, OriginTrait}; -use xcm::latest::{Location, OriginKind}; -use xcm_executor::traits::ConvertOrigin; - -/// TODO: `LocationAsSuperuser` is temporary placed here, the final solution will be imported from -/// `xcm_builder` (depends on backports) instead. -/// -/// A converter that allows a specific `Location` to act as a superuser (`RuntimeOrigin::root()`) -/// if it matches the predefined `SuperuserLocation` filter and `OriginKind::Superuser`. -pub struct LocationAsSuperuser( - PhantomData<(SuperuserLocation, RuntimeOrigin)>, -); -impl, RuntimeOrigin: OriginTrait> ConvertOrigin - for LocationAsSuperuser -{ - fn convert_origin( - origin: impl Into, - kind: OriginKind, - ) -> Result { - let origin = origin.into(); - log::trace!(target: "xcm::origin_conversion", "LocationAsSuperuser origin: {:?}, kind: {:?}", origin, kind); - match (kind, &origin) { - (OriginKind::Superuser, loc) if SuperuserLocation::contains(loc) => - Ok(RuntimeOrigin::root()), - _ => Err(origin), - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use frame_support::{construct_runtime, derive_impl, parameter_types, traits::Equals}; - use xcm::latest::{Junction::*, Junctions::*, OriginKind}; - - type Block = frame_system::mocking::MockBlock; - - construct_runtime!( - pub enum Test - { - System: frame_system, - } - ); - - #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] - impl frame_system::Config for Test { - type Block = Block; - } - - parameter_types! { - pub SuperuserLocation: Location = Location::new(0, Parachain(1)); - } - - #[test] - fn superuser_location_works() { - let test_conversion = |loc, kind| { - LocationAsSuperuser::, RuntimeOrigin>::convert_origin( - loc, kind, - ) - }; - - // Location that was set as SuperUserLocation should result in success conversion to Root - assert!(matches!(test_conversion(SuperuserLocation::get(), OriginKind::Superuser), Ok(..))); - // Same Location as SuperUserLocation::get() - assert!(matches!( - test_conversion(Location::new(0, Parachain(1)), OriginKind::Superuser), - Ok(..) - )); - - // Same Location but different origin kind - assert!(matches!(test_conversion(SuperuserLocation::get(), OriginKind::Native), Err(..))); - assert!(matches!( - test_conversion(SuperuserLocation::get(), OriginKind::SovereignAccount), - Err(..) - )); - assert!(matches!(test_conversion(SuperuserLocation::get(), OriginKind::Xcm), Err(..))); - - // No other location should result in successful conversion to Root - // thus expecting Err in all cases below - // - // Non-matching parachain number - assert!(matches!( - test_conversion(Location::new(0, Parachain(2)), OriginKind::Superuser), - Err(..) - )); - // Non-matching parents count - assert!(matches!( - test_conversion(Location::new(1, Parachain(1)), OriginKind::Superuser), - Err(..) - )); - // Child location of SuperUserLocation - assert!(matches!( - test_conversion( - Location::new(1, [Parachain(1), GeneralIndex(0)]), - OriginKind::Superuser - ), - Err(..) - )); - // Here - assert!(matches!(test_conversion(Location::new(0, Here), OriginKind::Superuser), Err(..))); - // Parent - assert!(matches!(test_conversion(Location::new(1, Here), OriginKind::Superuser), Err(..))); - // Some random account - assert!(matches!( - test_conversion( - Location::new(0, AccountId32 { network: None, id: [0u8; 32] }), - OriginKind::Superuser - ), - Err(..) - )); - // Child location of SuperUserLocation - assert!(matches!( - test_conversion( - Location::new(0, [Parachain(1), AccountId32 { network: None, id: [1u8; 32] }]), - OriginKind::Superuser - ), - Err(..) - )); - } -} diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 9470c5c50e..7afa049f99 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -102,7 +102,6 @@ polkadot-runtime-common = { workspace = true } runtime-parachains = { workspace = true } polkadot-primitives = { workspace = true } relay-common = { workspace = true } -pallets-common = { workspace = true } xcm = { workspace = true } xcm-executor = { workspace = true } @@ -199,7 +198,6 @@ std = [ "pallet-whitelist/std", "pallet-xcm-benchmarks?/std", "pallet-xcm/std", - "pallets-common/std", "polkadot-parachain-primitives/std", "polkadot-primitives/std", "polkadot-runtime-common/std", diff --git a/relay/polkadot/src/xcm_config.rs b/relay/polkadot/src/xcm_config.rs index 85b946f052..74d8b69f7c 100644 --- a/relay/polkadot/src/xcm_config.rs +++ b/relay/polkadot/src/xcm_config.rs @@ -26,6 +26,7 @@ use frame_support::{ traits::{Contains, Disabled, Equals, Everything, FromContains, Nothing}, }; use frame_system::EnsureRoot; +pub use pallet_rc_migrator::xcm_config::{AssetHubLocation, CollectivesLocation}; use pallet_xcm::XcmPassthrough; use polkadot_runtime_common::{ xcm_sender::{ChildParachainRouter, ExponentialPrice}, @@ -40,15 +41,13 @@ use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily, FrameTransactionalProcessor, - FungibleAdapter, HashedDescription, IsChildSystemParachain, IsConcrete, MintLocation, - OriginToPluralityVoice, SendXcmFeeToAccount, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, + FungibleAdapter, HashedDescription, IsChildSystemParachain, IsConcrete, LocationAsSuperuser, + MintLocation, OriginToPluralityVoice, SendXcmFeeToAccount, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeeManagerFromComponents, }; -use pallets_common::LocationAsSuperuser; -pub use pallet_rc_migrator::xcm_config::{AssetHubLocation, CollectivesLocation}; - parameter_types! { /// The location of the DOT token, from the context of this chain. Since this token is native to this /// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index e1edbb0ee5..10af5f38fb 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -84,7 +84,6 @@ cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } -pallets-common = { workspace = true } system-parachains-constants = { workspace = true } # Bridges @@ -183,7 +182,6 @@ std = [ "pallet-xcm-benchmarks?/std", "pallet-xcm-bridge-hub/std", "pallet-xcm/std", - "pallets-common/std", "parachain-info/std", "parachains-common/std", "polkadot-core-primitives/std", diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 0110258617..6062ca0394 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -61,7 +61,7 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOf, + tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, EitherOf, EitherOfDiverse, Everything, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 556fec9846..3da2ab0023 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -30,7 +30,6 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use pallets_common::LocationAsSuperuser; use parachains_common::xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -39,17 +38,17 @@ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::system_parachain; use snowbridge_runtime_common::XcmExportFeeToSibling; use sp_runtime::traits::AccountIdConversion; -use system_parachains_constants::TREASURY_PALLET_ID; +use system_parachains_constants::{polkadot::locations::AssetHubLocation, TREASURY_PALLET_ID}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HandleFee, HashedDescription, - IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + IsConcrete, LocationAsSuperuser, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::{ traits::{ConvertLocation, FeeManager, FeeReason, FeeReason::Export}, @@ -79,8 +78,6 @@ parameter_types! { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) .unwrap_or(TreasuryAccount::get()); pub StakingPot: AccountId = CollatorSelection::account_id(); - // TODO: replace from system consts - pub AssetHubLocation: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); } /// Type for specifying how a `Location` can be converted into an `AccountId`. diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/snowbridge.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/snowbridge.rs index 0e05a36201..b7cab159e0 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/snowbridge.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/snowbridge.rs @@ -20,10 +20,10 @@ use bp_polkadot_core::Signature; use bridge_hub_polkadot_runtime::{ bridge_to_ethereum_config::{EthereumGatewayAddress, EthereumNetwork}, bridge_to_kusama_config::OnBridgeHubPolkadotRefundBridgeHubKusamaMessages, - xcm_config::{GovernanceLocation, XcmConfig, XcmFeeManagerFromComponentsBridgeHub}, + xcm_config::{XcmConfig, XcmFeeManagerFromComponentsBridgeHub}, AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive, - MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, TxExtension, - UncheckedExtrinsic, + MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, + TxExtension, UncheckedExtrinsic, }; use bridge_hub_test_utils::GovernanceOrigin; use codec::{Decode, Encode}; @@ -48,8 +48,11 @@ use sp_runtime::{ use xcm::latest::prelude::*; use xcm_builder::HandleFee; use xcm_executor::traits::{FeeManager, FeeReason}; + parameter_types! { pub const DefaultBridgeHubEthereumBaseFee: Balance = 3_833_568_200_000; + // Local OpenGov + pub Governance: GovernanceOrigin = GovernanceOrigin::Origin(RuntimeOrigin::root()); } type RuntimeHelper = parachains_runtimes_test_utils::RuntimeHelper; @@ -129,7 +132,7 @@ fn change_ethereum_gateway_by_governance_works() { change_storage_constant_by_governance_works::( collator_session_keys(), bp_bridge_hub_polkadot::BRIDGE_HUB_POLKADOT_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + Governance::get(), || (EthereumGatewayAddress::key().to_vec(), EthereumGatewayAddress::get()), |_| [1; 20].into(), ) diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 9b8c587a23..011ae26a72 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -26,8 +26,8 @@ use bridge_hub_polkadot_runtime::{ XcmOverBridgeHubKusamaInstance, }, xcm_config::{ - DotRelayLocation, GovernanceLocation, LocationToAccountId, RelayNetwork, - RelayTreasuryLocation, RelayTreasuryPalletAccount, XcmConfig, + DotRelayLocation, LocationToAccountId, RelayNetwork, RelayTreasuryLocation, + RelayTreasuryPalletAccount, XcmConfig, }, AllPalletsWithoutSystem, Block, BridgeRejectObsoleteHeadersAndMessages, Executive, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, @@ -76,6 +76,8 @@ type RuntimeTestsAdapter = from_parachain::WithRemoteParachainHelperAdapter< parameter_types! { pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + // Local OpenGov + pub Governance: GovernanceOrigin = GovernanceOrigin::Origin(RuntimeOrigin::root()); } fn construct_extrinsic( @@ -167,7 +169,7 @@ fn initialize_bridge_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_polkadot::BRIDGE_HUB_POLKADOT_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + Governance::get(), ) } @@ -180,7 +182,7 @@ fn change_bridge_grandpa_pallet_mode_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_polkadot::BRIDGE_HUB_POLKADOT_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + Governance::get(), ) } @@ -193,7 +195,7 @@ fn change_bridge_parachains_pallet_mode_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_polkadot::BRIDGE_HUB_POLKADOT_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + Governance::get(), ) } @@ -206,7 +208,7 @@ fn change_bridge_messages_pallet_mode_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_polkadot::BRIDGE_HUB_POLKADOT_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + Governance::get(), ) } @@ -219,7 +221,7 @@ fn change_delivery_reward_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_polkadot::BRIDGE_HUB_POLKADOT_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + Governance::get(), || (DeliveryRewardInBalance::key().to_vec(), DeliveryRewardInBalance::get()), |old_value| old_value.checked_mul(2).unwrap(), ) @@ -234,7 +236,7 @@ fn change_required_stake_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_polkadot::BRIDGE_HUB_POLKADOT_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + Governance::get(), || (RequiredStakeForStakeAndSlash::key().to_vec(), RequiredStakeForStakeAndSlash::get()), |old_value| old_value.checked_mul(2).unwrap(), ) diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index 18efe058b8..8f7f435c92 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -83,7 +83,6 @@ cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } -pallets-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] @@ -215,7 +214,6 @@ std = [ "pallet-utility/std", "pallet-xcm-benchmarks?/std", "pallet-xcm/std", - "pallets-common/std", "parachain-info/std", "parachains-common/std", "polkadot-core-primitives/std", diff --git a/system-parachains/collectives/collectives-polkadot/src/secretary/mod.rs b/system-parachains/collectives/collectives-polkadot/src/secretary/mod.rs index 52f144fe5c..d62407466b 100644 --- a/system-parachains/collectives/collectives-polkadot/src/secretary/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/secretary/mod.rs @@ -54,9 +54,15 @@ pub mod ranks { type ApproveOrigin = EitherOf< EnsureRootWithSuccess>, EitherOf< - MapSuccess< - EnsureXcm>, - Replace>, + EitherOf< + MapSuccess< + EnsureXcm>, + Replace>, + >, + MapSuccess< + EnsureXcm>, + Replace>, + >, >, MapSuccess>>, >, diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index 019535c714..52ebed1e36 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -27,7 +27,6 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use pallets_common::LocationAsSuperuser; use parachains_common::xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -43,8 +42,8 @@ use xcm_builder::{ AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribeTerminus, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, LocatableAssetId, - OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, + LocationAsSuperuser, OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, + RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, diff --git a/system-parachains/coretime/coretime-polkadot/Cargo.toml b/system-parachains/coretime/coretime-polkadot/Cargo.toml index 12d600debf..7bfcd9fb80 100644 --- a/system-parachains/coretime/coretime-polkadot/Cargo.toml +++ b/system-parachains/coretime/coretime-polkadot/Cargo.toml @@ -78,7 +78,6 @@ cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } -pallets-common = { workspace = true } [dev-dependencies] parachains-runtimes-test-utils = { workspace = true } @@ -122,7 +121,6 @@ std = [ "pallet-utility/std", "pallet-xcm-benchmarks?/std", "pallet-xcm/std", - "pallets-common/std", "parachain-info/std", "parachains-common/std", "polkadot-core-primitives/std", diff --git a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs index 4a0df55d14..8d5a98bf88 100644 --- a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs @@ -28,7 +28,6 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use pallets_common::LocationAsSuperuser; use parachains_common::xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains, @@ -44,10 +43,10 @@ use xcm_builder::{ AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribeTerminus, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, - NonFungibleAdapter, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + LocationAsSuperuser, NonFungibleAdapter, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; @@ -70,8 +69,6 @@ parameter_types! { pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); pub StakingPot: AccountId = CollatorSelection::account_id(); - // TODO: replace from system consts - pub AssetHubLocation: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); } /// Type for specifying how a `Location` can be converted into an `AccountId`. diff --git a/system-parachains/people/people-polkadot/Cargo.toml b/system-parachains/people/people-polkadot/Cargo.toml index 95a3513ad3..f592cf400d 100644 --- a/system-parachains/people/people-polkadot/Cargo.toml +++ b/system-parachains/people/people-polkadot/Cargo.toml @@ -75,7 +75,6 @@ cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } -pallets-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] @@ -122,7 +121,6 @@ std = [ "pallet-utility/std", "pallet-xcm-benchmarks?/std", "pallet-xcm/std", - "pallets-common/std", "parachain-info/std", "parachains-common/std", "polkadot-parachain-primitives/std", diff --git a/system-parachains/people/people-polkadot/src/xcm_config.rs b/system-parachains/people/people-polkadot/src/xcm_config.rs index eef1b6b2c2..eaa3270cc0 100644 --- a/system-parachains/people/people-polkadot/src/xcm_config.rs +++ b/system-parachains/people/people-polkadot/src/xcm_config.rs @@ -26,7 +26,6 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; -use pallets_common::LocationAsSuperuser; use parachains_common::{ xcm_config::{ AllSiblingSystemParachains, ConcreteAssetFromSystem, ParentRelayOrSiblingParachains, @@ -44,11 +43,12 @@ use xcm_builder::{ AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribeTerminus, EnsureXcmOrigin, - FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, ParentAsSuperuser, - ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, + FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, + LocationAsSuperuser, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeeManagerFromComponents, }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; @@ -78,8 +78,6 @@ parameter_types! { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) .unwrap_or(TreasuryAccount::get()); pub StakingPot: AccountId = CollatorSelection::account_id(); - // TODO: replace from system consts - pub AssetHubLocation: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); } pub type PriceForParentDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice< From 1aa8c6d55c092672a1bdaa86eaf6ff8c1f891df8 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 15:58:18 +0200 Subject: [PATCH 16/53] AssetHub Polkadot runtime governance tests --- .../asset-hub-polkadot/tests/tests.rs | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index 43f7d082b5..6106f34464 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -35,13 +35,13 @@ use asset_test_utils::{ }; use codec::{Decode, Encode}; use core::ops::Mul; -use frame_support::{assert_ok, traits::fungibles::InspectEnumerable}; +use frame_support::{assert_ok, assert_err, traits::fungibles::InspectEnumerable}; use parachains_common::{ AccountId, AssetHubPolkadotAuraId as AuraId, AssetIdForTrustBackedAssets, Balance, }; use sp_consensus_aura::SlotDuration; use sp_core::crypto::Ss58Codec; -use sp_runtime::traits::MaybeEquivalence; +use sp_runtime::{traits::MaybeEquivalence, Either}; use system_parachains_constants::{ kusama::consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, polkadot::fee::WeightToFee, }; @@ -1775,3 +1775,54 @@ pub mod remove_when_asset_test_utils_doesnt_use_latest_xcm_location { } ); } + +#[test] +fn governance_authorize_upgrade_works() { + use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::BadOrigin) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} \ No newline at end of file From 2c80abd797422719ba73b751a3ed8264b1d2a348 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 21:47:22 +0200 Subject: [PATCH 17/53] asset-hub-polkadot/tests/tests.rs formatting --- .../asset-hubs/asset-hub-polkadot/tests/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index 6106f34464..fae833a734 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -35,7 +35,7 @@ use asset_test_utils::{ }; use codec::{Decode, Encode}; use core::ops::Mul; -use frame_support::{assert_ok, assert_err, traits::fungibles::InspectEnumerable}; +use frame_support::{assert_err, assert_ok, traits::fungibles::InspectEnumerable}; use parachains_common::{ AccountId, AssetHubPolkadotAuraId as AuraId, AssetIdForTrustBackedAssets, Balance, }; @@ -1825,4 +1825,4 @@ fn governance_authorize_upgrade_works() { Runtime, RuntimeOrigin, >(GovernanceOrigin::Location(GovernanceLocation::get()))); -} \ No newline at end of file +} From 2cb063352d59e62cce36d9eeb5daf3fc05bda7dc Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 21:47:51 +0200 Subject: [PATCH 18/53] Kusama Asset Hub governance_authorize_upgrade_works tests --- .../asset-hub-kusama/tests/tests.rs | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 6bea2b322f..fad21902d6 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -39,11 +39,11 @@ use asset_test_utils::{ }; use codec::{Decode, Encode}; use core::ops::Mul; -use frame_support::{assert_ok, traits::fungibles::InspectEnumerable}; +use frame_support::{assert_err, assert_ok, traits::fungibles::InspectEnumerable}; use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance}; use sp_consensus_aura::SlotDuration; use sp_core::crypto::Ss58Codec; -use sp_runtime::traits::MaybeEquivalence; +use sp_runtime::{traits::MaybeEquivalence, Either}; use system_parachains_constants::kusama::{ consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, fee::WeightToFee, }; @@ -1754,3 +1754,35 @@ fn xcm_payment_api_works() { // Block, // >(); } + +#[test] +fn governance_authorize_upgrade_works() { + use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} From 12e461a8249630ec02e361f79d06e7b962543f61 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 22:07:20 +0200 Subject: [PATCH 19/53] Polkadot Collectives governance_authorize_upgrade_works tests --- Cargo.lock | 1 + .../collectives-polkadot/Cargo.toml | 1 + .../collectives-polkadot/tests/tests.rs | 56 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 system-parachains/collectives/collectives-polkadot/tests/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 39ac5381ed..53f50f7dfd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2641,6 +2641,7 @@ dependencies = [ name = "collectives-polkadot-runtime" version = "1.0.0" dependencies = [ + "asset-test-utils", "collectives-polkadot-runtime-constants", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index 8f7f435c92..36ac9ae04c 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -86,6 +86,7 @@ parachains-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] +asset-test-utils = { workspace = true } collectives-polkadot-runtime-constants = { workspace = true } parachains-runtimes-test-utils = { workspace = true } sp-io = { workspace = true } diff --git a/system-parachains/collectives/collectives-polkadot/tests/tests.rs b/system-parachains/collectives/collectives-polkadot/tests/tests.rs new file mode 100644 index 0000000000..1d43ce4ab1 --- /dev/null +++ b/system-parachains/collectives/collectives-polkadot/tests/tests.rs @@ -0,0 +1,56 @@ +use asset_test_utils::GovernanceOrigin; +use collectives_polkadot_runtime::{xcm_config::GovernanceLocation, Runtime, RuntimeOrigin}; +use frame_support::{assert_err, assert_ok}; +use sp_runtime::Either; +use xcm::prelude::*; + +#[test] +fn governance_authorize_upgrade_works() { + use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::Barrier) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} From f4e9d1afb31ce49697e365b5fb09cfbf5be83c83 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 22:07:57 +0200 Subject: [PATCH 20/53] Kusama Bridge Hub governance_authorize_upgrade_works tests --- .../bridge-hub-kusama/tests/tests.rs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index 02831f168e..9d6a73571f 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -34,14 +34,16 @@ use bridge_hub_kusama_runtime::{ }; use bridge_hub_test_utils::{test_cases::from_parachain, GovernanceOrigin, SlotDurations}; use codec::{Decode, Encode}; -use frame_support::{dispatch::GetDispatchInfo, parameter_types, traits::ConstU8}; +use frame_support::{ + assert_err, assert_ok, dispatch::GetDispatchInfo, parameter_types, traits::ConstU8, +}; use parachains_common::{AccountId, AuraId, Balance}; use sp_consensus_aura::SlotDuration; use sp_core::crypto::Ss58Codec; use sp_keyring::Sr25519Keyring::Alice; use sp_runtime::{ generic::{Era, SignedPayload}, - AccountId32, Perbill, + AccountId32, Either, Perbill, }; use system_parachains_constants::kusama::{ consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, fee::WeightToFee, @@ -563,3 +565,35 @@ fn xcm_payment_api_works() { Block, >(); } + +#[test] +fn governance_authorize_upgrade_works() { + use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} From 2950d158296a8d5d9a716c809b5610377e40cab2 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 22:08:11 +0200 Subject: [PATCH 21/53] Polkadot Bridge Hub governance_authorize_upgrade_works tests --- .../bridge-hub-polkadot/tests/tests.rs | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 011ae26a72..91a757f9e9 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -35,14 +35,16 @@ use bridge_hub_polkadot_runtime::{ }; use bridge_hub_test_utils::{test_cases::from_parachain, GovernanceOrigin, SlotDurations}; use codec::{Decode, Encode}; -use frame_support::{dispatch::GetDispatchInfo, parameter_types, traits::ConstU8}; +use frame_support::{ + assert_err, assert_ok, dispatch::GetDispatchInfo, parameter_types, traits::ConstU8, +}; use parachains_common::{AccountId, AuraId, Balance}; use sp_consensus_aura::SlotDuration; use sp_core::crypto::Ss58Codec; use sp_keyring::Sr25519Keyring::Alice; use sp_runtime::{ generic::{Era, SignedPayload}, - AccountId32, + AccountId32, Either, }; use system_parachains_constants::polkadot::{ consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, fee::WeightToFee, @@ -566,3 +568,54 @@ fn xcm_payment_api_works() { Block, >(); } + +#[test] +fn governance_authorize_upgrade_works() { + use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::BadOrigin) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} From 4ee61ad1514202c0ac27e1e5fbe426f01ab18224 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 22:16:22 +0200 Subject: [PATCH 22/53] Polkadot Coretime governance_authorize_upgrade_works tests --- Cargo.lock | 2 + .../coretime/coretime-polkadot/Cargo.toml | 1 + .../coretime/coretime-polkadot/src/tests.rs | 58 ++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53f50f7dfd..49a245c208 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2921,6 +2921,7 @@ dependencies = [ name = "coretime-kusama-runtime" version = "1.0.0" dependencies = [ + "asset-test-utils", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", @@ -3028,6 +3029,7 @@ dependencies = [ name = "coretime-polkadot-runtime" version = "1.0.0" dependencies = [ + "asset-test-utils", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", diff --git a/system-parachains/coretime/coretime-polkadot/Cargo.toml b/system-parachains/coretime/coretime-polkadot/Cargo.toml index 7bfcd9fb80..8847f11aa4 100644 --- a/system-parachains/coretime/coretime-polkadot/Cargo.toml +++ b/system-parachains/coretime/coretime-polkadot/Cargo.toml @@ -80,6 +80,7 @@ parachain-info = { workspace = true } parachains-common = { workspace = true } [dev-dependencies] +asset-test-utils = { workspace = true } parachains-runtimes-test-utils = { workspace = true } [build-dependencies] diff --git a/system-parachains/coretime/coretime-polkadot/src/tests.rs b/system-parachains/coretime/coretime-polkadot/src/tests.rs index fe7ea6a291..e1a51cbc8c 100644 --- a/system-parachains/coretime/coretime-polkadot/src/tests.rs +++ b/system-parachains/coretime/coretime-polkadot/src/tests.rs @@ -17,13 +17,14 @@ use crate::{ coretime::{BrokerPalletId, CoretimeBurnAccount}, xcm_config::LocationToAccountId, - *, + GovernanceLocation, *, }; +use asset_test_utils::GovernanceOrigin; use coretime::CoretimeAllocator; use cumulus_pallet_parachain_system::ValidationData; use cumulus_primitives_core::PersistedValidationData; use frame_support::{ - assert_ok, + assert_err, assert_ok, traits::{ fungible::{Inspect, Mutate}, Get, OnInitialize, @@ -33,7 +34,7 @@ use pallet_broker::{ConfigRecordOf, RCBlockNumberOf, SaleInfo}; use parachains_runtimes_test_utils::ExtBuilder; use polkadot_runtime_constants::system_parachain::coretime::TIMESLICE_PERIOD; use sp_core::crypto::Ss58Codec; -use sp_runtime::traits::AccountIdConversion; +use sp_runtime::{traits::AccountIdConversion, Either}; use xcm_runtime_apis::conversions::LocationToAccountHelper; const ALICE: [u8; 32] = [1u8; 32]; @@ -245,3 +246,54 @@ fn xcm_payment_api_works() { Block, >(); } + +#[test] +fn governance_authorize_upgrade_works() { + use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::BadOrigin) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} From fbaab37ba6cc4c50277c524a2f3d1a9a62ef6e20 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 22:21:26 +0200 Subject: [PATCH 23/53] Kusama Coretime governance_authorize_upgrade_works tests --- .../coretime/coretime-kusama/Cargo.toml | 1 + .../coretime/coretime-kusama/src/tests.rs | 37 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/system-parachains/coretime/coretime-kusama/Cargo.toml b/system-parachains/coretime/coretime-kusama/Cargo.toml index 1c7a37e499..91dc90330b 100644 --- a/system-parachains/coretime/coretime-kusama/Cargo.toml +++ b/system-parachains/coretime/coretime-kusama/Cargo.toml @@ -79,6 +79,7 @@ parachain-info = { workspace = true } parachains-common = { workspace = true } [dev-dependencies] +asset-test-utils = { workspace = true } parachains-runtimes-test-utils = { workspace = true } [build-dependencies] diff --git a/system-parachains/coretime/coretime-kusama/src/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index 38a88455f2..5801038622 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -17,6 +17,7 @@ use crate::{ coretime::{BrokerPalletId, CoretimeBurnAccount}, xcm_config::LocationToAccountId, + GovernanceLocation, *, }; use coretime::CoretimeAllocator; @@ -24,16 +25,18 @@ use cumulus_pallet_parachain_system::ValidationData; use cumulus_primitives_core::PersistedValidationData; use frame_support::{ assert_ok, + assert_err, traits::{ fungible::{Inspect, Mutate}, Get, OnInitialize, }, }; +use asset_test_utils::GovernanceOrigin; use kusama_runtime_constants::system_parachain::coretime::TIMESLICE_PERIOD; use pallet_broker::{ConfigRecordOf, RCBlockNumberOf, SaleInfo}; use parachains_runtimes_test_utils::ExtBuilder; use sp_core::crypto::Ss58Codec; -use sp_runtime::traits::AccountIdConversion; +use sp_runtime::{traits::AccountIdConversion, Either}; use xcm_runtime_apis::conversions::LocationToAccountHelper; const ALICE: [u8; 32] = [1u8; 32]; @@ -245,3 +248,35 @@ fn xcm_payment_api_works() { Block, >(); } + +#[test] +fn governance_authorize_upgrade_works() { + use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} From 47a203a3b890686cd6a9f010df8d62c458be6b42 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 22:30:48 +0200 Subject: [PATCH 24/53] Kusama People governance_authorize_upgrade_works tests --- .../people/people-kusama/Cargo.toml | 1 + .../people/people-kusama/src/tests.rs | 42 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/system-parachains/people/people-kusama/Cargo.toml b/system-parachains/people/people-kusama/Cargo.toml index 8fd7dac3c9..198629a01f 100644 --- a/system-parachains/people/people-kusama/Cargo.toml +++ b/system-parachains/people/people-kusama/Cargo.toml @@ -79,6 +79,7 @@ parachains-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] +asset-test-utils = { workspace = true } parachains-runtimes-test-utils = { workspace = true } [build-dependencies] diff --git a/system-parachains/people/people-kusama/src/tests.rs b/system-parachains/people/people-kusama/src/tests.rs index e2a617d042..8667c1b77f 100644 --- a/system-parachains/people/people-kusama/src/tests.rs +++ b/system-parachains/people/people-kusama/src/tests.rs @@ -14,12 +14,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::xcm_config::LocationToAccountId; +use crate::{ + xcm_config::{GovernanceLocation, LocationToAccountId}, + Block, Runtime, RuntimeCall, RuntimeOrigin, +}; use polkadot_primitives::AccountId; use sp_core::crypto::Ss58Codec; use xcm::prelude::*; use xcm_runtime_apis::conversions::LocationToAccountHelper; +use asset_test_utils::GovernanceOrigin; +use frame_support::{assert_err, assert_ok}; +use sp_runtime::Either; + const ALICE: [u8; 32] = [1u8; 32]; #[test] @@ -124,7 +131,6 @@ fn location_conversion_works() { #[test] fn xcm_payment_api_works() { - use crate::{Block, Runtime, RuntimeCall, RuntimeOrigin}; parachains_runtimes_test_utils::test_cases::xcm_payment_api_with_native_token_works::< Runtime, RuntimeCall, @@ -132,3 +138,35 @@ fn xcm_payment_api_works() { Block, >(); } + +#[test] +fn governance_authorize_upgrade_works() { + use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} From 6366df2e9e610d0a0e7b28b9f1c7cd510808bd5b Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 22:34:42 +0200 Subject: [PATCH 25/53] Polkadot People governance_authorize_upgrade_works tests --- Cargo.lock | 2 + .../people/people-polkadot/Cargo.toml | 1 + .../people/people-polkadot/src/tests.rs | 61 ++++++++++++++++++- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49a245c208..94aa63ab1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9893,6 +9893,7 @@ dependencies = [ name = "people-kusama-runtime" version = "1.0.0" dependencies = [ + "asset-test-utils", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", @@ -10003,6 +10004,7 @@ dependencies = [ name = "people-polkadot-runtime" version = "1.0.0" dependencies = [ + "asset-test-utils", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", diff --git a/system-parachains/people/people-polkadot/Cargo.toml b/system-parachains/people/people-polkadot/Cargo.toml index f592cf400d..1082d21cfe 100644 --- a/system-parachains/people/people-polkadot/Cargo.toml +++ b/system-parachains/people/people-polkadot/Cargo.toml @@ -78,6 +78,7 @@ parachains-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] +asset-test-utils = { workspace = true } parachains-runtimes-test-utils = { workspace = true } [build-dependencies] diff --git a/system-parachains/people/people-polkadot/src/tests.rs b/system-parachains/people/people-polkadot/src/tests.rs index d8c29568b5..09610dbb07 100644 --- a/system-parachains/people/people-polkadot/src/tests.rs +++ b/system-parachains/people/people-polkadot/src/tests.rs @@ -14,12 +14,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::xcm_config::LocationToAccountId; +use crate::{ + xcm_config::{GovernanceLocation, LocationToAccountId}, + Block, Runtime, RuntimeCall, RuntimeOrigin, +}; use cumulus_primitives_core::relay_chain::AccountId; use sp_core::crypto::Ss58Codec; use xcm::prelude::*; use xcm_runtime_apis::conversions::LocationToAccountHelper; +use asset_test_utils::GovernanceOrigin; +use frame_support::{assert_err, assert_ok}; +use sp_runtime::Either; + const ALICE: [u8; 32] = [1u8; 32]; #[test] @@ -124,7 +131,6 @@ fn location_conversion_works() { #[test] fn xcm_payment_api_works() { - use crate::{Block, Runtime, RuntimeCall, RuntimeOrigin}; parachains_runtimes_test_utils::test_cases::xcm_payment_api_with_native_token_works::< Runtime, RuntimeCall, @@ -132,3 +138,54 @@ fn xcm_payment_api_works() { Block, >(); } + +#[test] +fn governance_authorize_upgrade_works() { + use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), + Either::Right(XcmError::Barrier) + ); + // no - Collectives Voice of Fellows plurality + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::LocationAndDescendOrigin( + Location::new(1, Parachain(COLLECTIVES_ID)), + Plurality { id: BodyId::Technical, part: BodyPart::Voice }.into() + )), + Either::Right(XcmError::BadOrigin) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} From 39b5c83e5b5b1aab4290bce335818645025aaa8a Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Tue, 24 Jun 2025 22:35:27 +0200 Subject: [PATCH 26/53] coretime-kusama/src/tests.rs formatting --- system-parachains/coretime/coretime-kusama/src/tests.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/system-parachains/coretime/coretime-kusama/src/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index 5801038622..7ff5733433 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -17,21 +17,19 @@ use crate::{ coretime::{BrokerPalletId, CoretimeBurnAccount}, xcm_config::LocationToAccountId, - GovernanceLocation, - *, + GovernanceLocation, *, }; +use asset_test_utils::GovernanceOrigin; use coretime::CoretimeAllocator; use cumulus_pallet_parachain_system::ValidationData; use cumulus_primitives_core::PersistedValidationData; use frame_support::{ - assert_ok, - assert_err, + assert_err, assert_ok, traits::{ fungible::{Inspect, Mutate}, Get, OnInitialize, }, }; -use asset_test_utils::GovernanceOrigin; use kusama_runtime_constants::system_parachain::coretime::TIMESLICE_PERIOD; use pallet_broker::{ConfigRecordOf, RCBlockNumberOf, SaleInfo}; use parachains_runtimes_test_utils::ExtBuilder; From d2369415a9e6c9e8266e849fbbbe57268c07636a Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Wed, 25 Jun 2025 10:16:20 +0200 Subject: [PATCH 27/53] Kusama Encointer governance_authorize_upgrade_works tests --- system-parachains/encointer/Cargo.toml | 4 ++++ system-parachains/encointer/src/xcm_config.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/system-parachains/encointer/Cargo.toml b/system-parachains/encointer/Cargo.toml index c6cac39233..89612012c0 100644 --- a/system-parachains/encointer/Cargo.toml +++ b/system-parachains/encointer/Cargo.toml @@ -107,6 +107,10 @@ polkadot-core-primitives = { workspace = true } polkadot-primitives = { workspace = true } system-parachains-constants = { workspace = true } +[dev-dependencies] +asset-test-utils = { workspace = true } +parachains-runtimes-test-utils = { workspace = true } + [build-dependencies] substrate-wasm-builder = { optional = true, workspace = true } diff --git a/system-parachains/encointer/src/xcm_config.rs b/system-parachains/encointer/src/xcm_config.rs index 17a5140ffb..db5290303b 100644 --- a/system-parachains/encointer/src/xcm_config.rs +++ b/system-parachains/encointer/src/xcm_config.rs @@ -53,6 +53,7 @@ parameter_types! { pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); pub StakingPot: AccountId = CollatorSelection::account_id(); + pub const GovernanceLocation: Location = Location::parent(); } /// Type for specifying how a `Location` can be converted into an `AccountId`. From e0124b2e37844549cb9d10f6e8fb0e35e471b58b Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Wed, 25 Jun 2025 21:12:12 +0200 Subject: [PATCH 28/53] Move GovernanceLocation definition to common package --- .../asset-hubs/asset-hub-kusama/src/xcm_config.rs | 5 ++--- .../asset-hubs/asset-hub-polkadot/src/xcm_config.rs | 3 ++- .../bridge-hubs/bridge-hub-kusama/src/xcm_config.rs | 5 ++--- .../bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs | 7 ++----- .../collectives/collectives-polkadot/src/xcm_config.rs | 7 ++----- system-parachains/constants/src/kusama.rs | 2 ++ system-parachains/constants/src/polkadot.rs | 2 ++ .../coretime/coretime-kusama/src/xcm_config.rs | 5 ++--- .../coretime/coretime-polkadot/src/xcm_config.rs | 7 ++----- system-parachains/encointer/src/xcm_config.rs | 3 ++- system-parachains/people/people-kusama/src/xcm_config.rs | 5 ++--- system-parachains/people/people-polkadot/src/xcm_config.rs | 7 ++----- 12 files changed, 24 insertions(+), 34 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index a50577f52f..29c59b1cc7 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -60,6 +60,8 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; +pub use system_parachains_constants::kusama::locations::GovernanceLocation; + parameter_types! { pub const RootLocation: Location = Location::here(); pub const KsmLocation: Location = Location::parent(); @@ -81,9 +83,6 @@ parameter_types! { pub PoolAssetsPalletLocationV4: xcm::v4::Location = xcm::v4::Junction::PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); - // TODO: wrong - before/during/after migration setup? - pub const GovernanceLocation: Location = Location::parent(); - // TODO: wrong - before/during/after migration setup? pub const FellowshipLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(kusama_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index d8f593dd8a..e66d6c798b 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -68,6 +68,8 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; +pub use system_parachains_constants::polkadot::locations::GovernanceLocation; + parameter_types! { pub const RootLocation: Location = Location::here(); pub const DotLocation: Location = Location::parent(); @@ -84,7 +86,6 @@ parameter_types! { xcm::v4::Junction::PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); - pub const RcGovernanceLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub PoolAssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index b1c2144e50..d63e00cb5b 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -50,6 +50,8 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; +pub use system_parachains_constants::kusama::locations::GovernanceLocation; + parameter_types! { pub const RootLocation: Location = Location::here(); pub const KsmRelayLocation: Location = Location::parent(); @@ -59,9 +61,6 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - // TODO: wrong - before/during/after migration setup? - pub const GovernanceLocation: Location = Location::parent(); - // TODO: wrong - before/during/after migration setup? pub const FellowshipLocation: Location = Location::parent(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(kusama_runtime_constants::TREASURY_PALLET_ID)).into(); diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 3da2ab0023..7a4acdf14c 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -55,6 +55,8 @@ use xcm_executor::{ XcmExecutor, }; +pub use system_parachains_constants::polkadot::locations::GovernanceLocation; + parameter_types! { pub const RootLocation: Location = Location::here(); pub const DotRelayLocation: Location = Location::parent(); @@ -65,11 +67,6 @@ parameter_types! { pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); - - // The AHM migration does not send progress to other chains, so we need to keep and trust two constants for a while. - pub const RcGovernanceLocation: Location = Location::parent(); - pub AhGovernanceLocation: Location = AssetHubLocation::get(); - pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); // Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index 52ebed1e36..eab76830fc 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -50,6 +50,8 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; +pub use system_parachains_constants::polkadot::locations::GovernanceLocation; + parameter_types! { pub const RootLocation: Location = Location::here(); pub const DotLocation: Location = Location::parent(); @@ -58,11 +60,6 @@ parameter_types! { pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); - - // The AHM migration does not send progress to other chains, so we need to keep and trust two constants for a while. - pub const RcGovernanceLocation: Location = Location::parent(); - pub AhGovernanceLocation: Location = AssetHubLocation::get(); - pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); pub const TreasurerBodyId: BodyId = BodyId::Treasury; diff --git a/system-parachains/constants/src/kusama.rs b/system-parachains/constants/src/kusama.rs index be68bd3c33..dbf576a681 100644 --- a/system-parachains/constants/src/kusama.rs +++ b/system-parachains/constants/src/kusama.rs @@ -152,5 +152,7 @@ pub mod locations { parameter_types! { pub AssetHubLocation: Location = Location::new(1, Parachain(kusama_runtime_constants::system_parachain::ASSET_HUB_ID)); + + pub GovernanceLocation: Location = Location::parent(); } } diff --git a/system-parachains/constants/src/polkadot.rs b/system-parachains/constants/src/polkadot.rs index 192c24d971..3dccd5c497 100644 --- a/system-parachains/constants/src/polkadot.rs +++ b/system-parachains/constants/src/polkadot.rs @@ -173,5 +173,7 @@ pub mod locations { pub RelayChainLocation: Location = Location::parent(); pub AssetHubLocation: Location = Location::new(1, Parachain(polkadot_runtime_constants::system_parachain::ASSET_HUB_ID)); + + pub GovernanceLocation: Location = Location::parent(); } } diff --git a/system-parachains/coretime/coretime-kusama/src/xcm_config.rs b/system-parachains/coretime/coretime-kusama/src/xcm_config.rs index ed1fb93bcc..c63fd73f79 100644 --- a/system-parachains/coretime/coretime-kusama/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-kusama/src/xcm_config.rs @@ -50,6 +50,8 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; +pub use system_parachains_constants::kusama::locations::GovernanceLocation; + parameter_types! { pub const RootLocation: Location = Location::here(); pub const KsmRelayLocation: Location = Location::parent(); @@ -61,9 +63,6 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - // TODO: wrong - before/during/after migration setup? - pub const GovernanceLocation: Location = Location::parent(); - // TODO: wrong - before/during/after migration setup? pub const FellowshipLocation: Location = Location::parent(); pub StakingPot: AccountId = CollatorSelection::account_id(); } diff --git a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs index 8d5a98bf88..971a1cbb45 100644 --- a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs @@ -51,6 +51,8 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; +pub use system_parachains_constants::polkadot::locations::GovernanceLocation; + parameter_types! { pub const RootLocation: Location = Location::here(); pub const DotRelayLocation: Location = Location::parent(); @@ -62,11 +64,6 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - - // The AHM migration does not send progress to other chains, so we need to keep and trust two constants for a while. - pub const RcGovernanceLocation: Location = Location::parent(); - pub AhGovernanceLocation: Location = AssetHubLocation::get(); - pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); pub StakingPot: AccountId = CollatorSelection::account_id(); } diff --git a/system-parachains/encointer/src/xcm_config.rs b/system-parachains/encointer/src/xcm_config.rs index db5290303b..50dc10f74e 100644 --- a/system-parachains/encointer/src/xcm_config.rs +++ b/system-parachains/encointer/src/xcm_config.rs @@ -44,6 +44,8 @@ use xcm_builder::{ }; use xcm_executor::XcmExecutor; +pub use system_parachains_constants::kusama::locations::GovernanceLocation; + parameter_types! { pub const KsmLocation: Location = Location::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; @@ -53,7 +55,6 @@ parameter_types! { pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); pub StakingPot: AccountId = CollatorSelection::account_id(); - pub const GovernanceLocation: Location = Location::parent(); } /// Type for specifying how a `Location` can be converted into an `AccountId`. diff --git a/system-parachains/people/people-kusama/src/xcm_config.rs b/system-parachains/people/people-kusama/src/xcm_config.rs index 0308f0fc34..d8f754f273 100644 --- a/system-parachains/people/people-kusama/src/xcm_config.rs +++ b/system-parachains/people/people-kusama/src/xcm_config.rs @@ -50,6 +50,8 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; +pub use system_parachains_constants::kusama::locations::GovernanceLocation; + parameter_types! { pub const RootLocation: Location = Location::here(); pub const RelayLocation: Location = Location::parent(); @@ -59,9 +61,6 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - // TODO: wrong - before/during/after migration setup? - pub const GovernanceLocation: Location = Location::parent(); - // TODO: wrong - before/during/after migration setup? pub const FellowshipLocation: Location = Location::parent(); /// The asset ID for the asset that we use to pay for message delivery fees. Just KSM. pub FeeAssetId: AssetId = AssetId(RelayLocation::get()); diff --git a/system-parachains/people/people-polkadot/src/xcm_config.rs b/system-parachains/people/people-polkadot/src/xcm_config.rs index eaa3270cc0..417ec16bde 100644 --- a/system-parachains/people/people-polkadot/src/xcm_config.rs +++ b/system-parachains/people/people-polkadot/src/xcm_config.rs @@ -52,6 +52,8 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; +pub use system_parachains_constants::polkadot::locations::GovernanceLocation; + parameter_types! { pub const RootLocation: Location = Location::here(); pub const RelayLocation: Location = Location::parent(); @@ -61,11 +63,6 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - - // The AHM migration does not send progress to other chains, so we need to keep and trust two constants for a while. - pub const RcGovernanceLocation: Location = Location::parent(); - pub AhGovernanceLocation: Location = AssetHubLocation::get(); - pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); /// The asset ID for the asset that we use to pay for message delivery fees. Just DOT. pub FeeAssetId: AssetId = AssetId(RelayLocation::get()); From cf0ba759e249aea27773cfc4b032b1107ae34be4 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Wed, 25 Jun 2025 21:12:36 +0200 Subject: [PATCH 29/53] Add missing Encointer tests folder --- system-parachains/encointer/tests/tests.rs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 system-parachains/encointer/tests/tests.rs diff --git a/system-parachains/encointer/tests/tests.rs b/system-parachains/encointer/tests/tests.rs new file mode 100644 index 0000000000..6a8a3d9461 --- /dev/null +++ b/system-parachains/encointer/tests/tests.rs @@ -0,0 +1,37 @@ +use asset_test_utils::GovernanceOrigin; +use encointer_kusama_runtime::{xcm_config::GovernanceLocation, Runtime, RuntimeOrigin}; +use frame_support::{assert_err, assert_ok}; +use sp_runtime::Either; +use xcm::prelude::*; + +#[test] +fn governance_authorize_upgrade_works() { + use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; + + // no - random para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), + Either::Right(XcmError::Barrier) + ); + // no - AssetHub + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + Either::Right(XcmError::Barrier) + ); + + // ok - relaychain + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::parent()))); + assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(GovernanceLocation::get()))); +} From 9991e77ab166f667954a8c266e085181c500f482 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 25 Jun 2025 14:45:09 +0200 Subject: [PATCH 30/53] Governance integration tests on Kusama (by karolk91) (for OpenGov on RC) Co-authored-by: Karol Kokoszka --- integration-tests/emulated/helpers/src/lib.rs | 67 ++++++++----------- .../tests/governance/kusama/src/lib.rs | 3 - .../kusama/src/open_gov_on_relay.rs | 27 ++++++-- 3 files changed, 51 insertions(+), 46 deletions(-) diff --git a/integration-tests/emulated/helpers/src/lib.rs b/integration-tests/emulated/helpers/src/lib.rs index ac46ec0009..7b0f43f914 100644 --- a/integration-tests/emulated/helpers/src/lib.rs +++ b/integration-tests/emulated/helpers/src/lib.rs @@ -20,22 +20,22 @@ pub use pallet_balances; pub use pallet_message_queue; // Polkadot -pub use pallet_whitelist; pub use pallet_xcm; pub use xcm::prelude::{AccountId32, VersionedAssets, Weight, WeightLimit}; // Cumulus pub use asset_test_utils; pub use cumulus_pallet_xcmp_queue; -pub use xcm_emulator::{assert_expected_events, Chain}; +pub use emulated_integration_tests_common::macros::Dmp; +pub use xcm_emulator::Chain; + +pub mod common; use emulated_integration_tests_common::impls::{bx, Encode}; -pub use emulated_integration_tests_common::macros::Dmp; use frame_support::dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}; use sp_core::H256; use sp_runtime::traits::{Dispatchable, Hash}; -use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; -pub mod common; +use xcm::{prelude::*, VersionedLocation, VersionedXcm}; /// TODO: when bumping to polkadot-sdk v1.8.0, /// remove this crate altogether and get the macros from `emulated-integration-tests-common`. @@ -559,6 +559,7 @@ macro_rules! test_chain_can_claim_assets { }; } +// TODO: remove when stable2503 / stable2506 released /// Wraps a runtime call in a whitelist preimage call and dispatches it pub fn dispatch_whitelisted_call_with_preimage( call: T::RuntimeCall, @@ -581,36 +582,14 @@ where }) } -#[macro_export] -macro_rules! assert_whitelisted { - ($chain:ident, $expected_call_hash:expr) => { - type RuntimeEvent = <$chain as $crate::Chain>::RuntimeEvent; - $crate::assert_expected_events!( - $chain, - vec![ - RuntimeEvent::Whitelist($crate::pallet_whitelist::Event::CallWhitelisted { call_hash }) => { - call_hash: *call_hash == $expected_call_hash, - }, - ] - ); - }; -} - -/// Encodes a runtime call and returns its H256 hash -pub fn call_hash_of(call: &T::RuntimeCall) -> H256 -where - T: Chain, - T::Runtime: frame_system::Config, - T::RuntimeCall: Encode, -{ - T::execute_with(|| { - let call_hash = ::Hashing::hash_of(&call); - call_hash - }) -} - -/// Builds an XCM call to send an authorize upgrade message using the provided location -pub fn build_xcm_send_authorize_upgrade_call(location: Location) -> T::RuntimeCall +// TODO: remove when stable2503 / stable2506 released +/// Builds a `pallet_xcm::send` call to authorize an upgrade at the provided location, +/// wrapped in an unpaid XCM `Transact` with `OriginKind::Superuser`. +pub fn build_xcm_send_authorize_upgrade_call( + location: Location, + code_hash: &H256, + fallback_max_weight: Option, +) -> T::RuntimeCall where T: Chain, T::Runtime: pallet_xcm::Config, @@ -619,9 +598,8 @@ where D::Runtime: frame_system::Config, D::RuntimeCall: Encode + From>, { - let code_hash = [1u8; 32].into(); - - let transact_call: D::RuntimeCall = frame_system::Call::authorize_upgrade { code_hash }.into(); + let transact_call: D::RuntimeCall = + frame_system::Call::authorize_upgrade { code_hash: *code_hash }.into(); let call: T::RuntimeCall = pallet_xcm::Call::send { dest: bx!(VersionedLocation::from(location)), @@ -629,7 +607,7 @@ where UnpaidExecution { weight_limit: Unlimited, check_origin: None }, Transact { origin_kind: OriginKind::Superuser, - fallback_max_weight: None, + fallback_max_weight, call: transact_call.encode().into(), } ]))), @@ -637,3 +615,14 @@ where .into(); call } + +// TODO: remove when stable2503 / stable2506 released +/// Encodes a runtime call and returns its H256 hash +pub fn call_hash_of(call: &T::RuntimeCall) -> H256 +where + T: Chain, + T::Runtime: frame_system::Config, + T::RuntimeCall: Encode, +{ + ::Hashing::hash_of(&call) +} diff --git a/integration-tests/emulated/tests/governance/kusama/src/lib.rs b/integration-tests/emulated/tests/governance/kusama/src/lib.rs index f1cc4ee468..21dbf6e412 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/lib.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/lib.rs @@ -14,8 +14,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(test)] -// TODO: currently it doesn't compile as there is no governance on KAH implemented yet -// mod open_gov_on_asset_hub; #[cfg(test)] mod open_gov_on_relay; diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs index 093302f799..4ef1b942c1 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs @@ -12,16 +12,16 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + use emulated_integration_tests_common::{ impls::RelayChain, xcm_emulator::{Chain, Parachain, TestExt}, }; use frame_support::{assert_err, assert_ok}; use integration_tests_helpers::{ - assert_whitelisted, build_xcm_send_authorize_upgrade_call, call_hash_of, - dispatch_whitelisted_call_with_preimage, + build_xcm_send_authorize_upgrade_call, call_hash_of, dispatch_whitelisted_call_with_preimage, }; -use kusama_runtime::governance::pallet_custom_origins::Origin; +use kusama_runtime::{governance::pallet_custom_origins::Origin, Dmp}; use kusama_system_emulated_network::{ AssetHubKusamaPara as AssetHubKusama, BridgeHubKusamaPara as BridgeHubKusama, CoretimeKusamaPara as CoretimeKusama, KusamaRelay as Kusama, PeopleKusamaPara as PeopleKusama, @@ -72,7 +72,6 @@ fn relaychain_can_authorize_upgrade_for_itself() { use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; let fellows_origin: KusamaRuntimeOrigin = FellowsOrigin.into(); assert_ok!(whitelist_call.dispatch(fellows_origin)); - assert_whitelisted!(Kusama, call_hash); }); // Err - when dispatch wrong origin @@ -100,20 +99,40 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { type KusamaRuntimeCall = ::RuntimeCall; type KusamaRuntimeOrigin = ::RuntimeOrigin; + Kusama::execute_with(|| { + Dmp::make_parachain_reachable(AssetHubKusama::para_id()); + Dmp::make_parachain_reachable(BridgeHubKusama::para_id()); + Dmp::make_parachain_reachable(CoretimeKusama::para_id()); + Dmp::make_parachain_reachable(PeopleKusama::para_id()); + }); + + let code_hash_asset_hub = [1u8; 32].into(); + let code_hash_bridge_hub = [2u8; 32].into(); + let code_hash_coretime = [4u8; 32].into(); + let code_hash_people = [5u8; 32].into(); + let authorize_upgrade = KusamaRuntimeCall::Utility(pallet_utility::Call::::force_batch { calls: vec![ build_xcm_send_authorize_upgrade_call::( Kusama::child_location_of(AssetHubKusama::para_id()), + &code_hash_asset_hub, + None, ), build_xcm_send_authorize_upgrade_call::( Kusama::child_location_of(BridgeHubKusama::para_id()), + &code_hash_bridge_hub, + None, ), build_xcm_send_authorize_upgrade_call::( Kusama::child_location_of(CoretimeKusama::para_id()), + &code_hash_coretime, + None, ), build_xcm_send_authorize_upgrade_call::( Kusama::child_location_of(PeopleKusama::para_id()), + &code_hash_people, + None, ), ], }); From 872eab8e50572715219604ec76bc01523184e57c Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 26 Jun 2025 14:08:18 +0200 Subject: [PATCH 31/53] Add Polkadot governance integration tests --- integration-tests/emulated/helpers/src/lib.rs | 19 ++++++++++++++++++- .../polkadot/src/open_gov_on_relay.rs | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/integration-tests/emulated/helpers/src/lib.rs b/integration-tests/emulated/helpers/src/lib.rs index 7b0f43f914..1462f30f69 100644 --- a/integration-tests/emulated/helpers/src/lib.rs +++ b/integration-tests/emulated/helpers/src/lib.rs @@ -20,6 +20,7 @@ pub use pallet_balances; pub use pallet_message_queue; // Polkadot +pub use pallet_whitelist; pub use pallet_xcm; pub use xcm::prelude::{AccountId32, VersionedAssets, Weight, WeightLimit}; @@ -27,7 +28,7 @@ pub use xcm::prelude::{AccountId32, VersionedAssets, Weight, WeightLimit}; pub use asset_test_utils; pub use cumulus_pallet_xcmp_queue; pub use emulated_integration_tests_common::macros::Dmp; -pub use xcm_emulator::Chain; +pub use xcm_emulator::{assert_expected_events, Chain}; pub mod common; @@ -626,3 +627,19 @@ where { ::Hashing::hash_of(&call) } + +// TODO: remove when stable2503 / stable2506 released +#[macro_export] +macro_rules! assert_whitelisted { + ($chain:ident, $expected_call_hash:expr) => { + type RuntimeEvent = <$chain as $crate::Chain>::RuntimeEvent; + $crate::assert_expected_events!( + $chain, + vec![ + RuntimeEvent::Whitelist($crate::pallet_whitelist::Event::CallWhitelisted { call_hash }) => { + call_hash: *call_hash == $expected_call_hash, + }, + ] + ); + }; +} diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs index 2c0659f3c5..c20896da34 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -102,6 +102,12 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { type PolkadotRuntimeCall = ::RuntimeCall; type PolkadotRuntimeOrigin = ::RuntimeOrigin; + let code_hash_asset_hub = [1u8; 32].into(); + let code_hash_bridge_hub = [2u8; 32].into(); + let code_hash_collectives = [3u8; 32].into(); + let code_hash_coretime = [4u8; 32].into(); + let code_hash_people = [5u8; 32].into(); + Polkadot::execute_with(|| { Dmp::make_parachain_reachable(AssetHubPolkadot::para_id()); Dmp::make_parachain_reachable(BridgeHubPolkadot::para_id()); @@ -115,18 +121,28 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { calls: vec![ build_xcm_send_authorize_upgrade_call::( Polkadot::child_location_of(AssetHubPolkadot::para_id()), + &code_hash_asset_hub, + None, ), build_xcm_send_authorize_upgrade_call::( Polkadot::child_location_of(BridgeHubPolkadot::para_id()), + &code_hash_bridge_hub, + None, ), build_xcm_send_authorize_upgrade_call::( Polkadot::child_location_of(CollectivesPolkadot::para_id()), + &code_hash_collectives, + None, ), build_xcm_send_authorize_upgrade_call::( Polkadot::child_location_of(CoretimePolkadot::para_id()), + &code_hash_coretime, + None, ), build_xcm_send_authorize_upgrade_call::( Polkadot::child_location_of(PeoplePolkadot::para_id()), + &code_hash_people, + None, ), ], }); From 647bad4d332e5110626388501610036329b3713e Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 26 Jun 2025 14:32:41 +0200 Subject: [PATCH 32/53] Apply suggestions from code review Co-authored-by: Branislav Kontur --- integration-tests/emulated/helpers/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration-tests/emulated/helpers/src/lib.rs b/integration-tests/emulated/helpers/src/lib.rs index 1462f30f69..aa0eb2f419 100644 --- a/integration-tests/emulated/helpers/src/lib.rs +++ b/integration-tests/emulated/helpers/src/lib.rs @@ -560,7 +560,7 @@ macro_rules! test_chain_can_claim_assets { }; } -// TODO: remove when stable2503 / stable2506 released +// TODO: remove when stable2503-7 / stable2506 released /// Wraps a runtime call in a whitelist preimage call and dispatches it pub fn dispatch_whitelisted_call_with_preimage( call: T::RuntimeCall, @@ -583,7 +583,7 @@ where }) } -// TODO: remove when stable2503 / stable2506 released +// TODO: remove when stable2503-7 / stable2506 released /// Builds a `pallet_xcm::send` call to authorize an upgrade at the provided location, /// wrapped in an unpaid XCM `Transact` with `OriginKind::Superuser`. pub fn build_xcm_send_authorize_upgrade_call( @@ -617,7 +617,7 @@ where call } -// TODO: remove when stable2503 / stable2506 released +// TODO: remove when stable2503-7 / stable2506 released /// Encodes a runtime call and returns its H256 hash pub fn call_hash_of(call: &T::RuntimeCall) -> H256 where @@ -628,7 +628,7 @@ where ::Hashing::hash_of(&call) } -// TODO: remove when stable2503 / stable2506 released +// TODO: remove when stable2503-7 / stable2506 released #[macro_export] macro_rules! assert_whitelisted { ($chain:ident, $expected_call_hash:expr) => { From d3744581a617c92bea9c339b45c0fca54b196c8d Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 26 Jun 2025 22:10:30 +0200 Subject: [PATCH 33/53] Assert whitelisted event for Kusama tests --- .../tests/governance/kusama/src/open_gov_on_relay.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs index 4ef1b942c1..d268c21c86 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs @@ -19,7 +19,8 @@ use emulated_integration_tests_common::{ }; use frame_support::{assert_err, assert_ok}; use integration_tests_helpers::{ - build_xcm_send_authorize_upgrade_call, call_hash_of, dispatch_whitelisted_call_with_preimage, + assert_whitelisted, build_xcm_send_authorize_upgrade_call, call_hash_of, + dispatch_whitelisted_call_with_preimage, }; use kusama_runtime::{governance::pallet_custom_origins::Origin, Dmp}; use kusama_system_emulated_network::{ @@ -72,6 +73,7 @@ fn relaychain_can_authorize_upgrade_for_itself() { use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; let fellows_origin: KusamaRuntimeOrigin = FellowsOrigin.into(); assert_ok!(whitelist_call.dispatch(fellows_origin)); + assert_whitelisted!(Kusama, call_hash); }); // Err - when dispatch wrong origin @@ -166,6 +168,7 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; let fellows_origin: KusamaRuntimeOrigin = FellowsOrigin.into(); assert_ok!(whitelist_call.dispatch(fellows_origin)); + assert_whitelisted!(Kusama, call_hash); }); // Err - when dispatch wrong origin From b1ee05fbb0d821532830c680c30f421efa3d0577 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 21 Aug 2025 11:14:24 +0200 Subject: [PATCH 34/53] Use RelayChainLocation and AssetHubLocation instead of *GovernanceLocation --- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 4 +-- .../asset-hub-polkadot/src/xcm_config.rs | 2 +- .../asset-hub-polkadot/tests/tests.rs | 10 ++---- .../bridge-hub-polkadot/src/lib.rs | 6 ++-- .../bridge-hub-polkadot/src/xcm_config.rs | 4 +-- .../bridge-hub-polkadot/tests/snowbridge.rs | 24 +++++++------- .../bridge-hub-polkadot/tests/tests.rs | 21 +++++------- .../src/ambassador/mod.rs | 16 +++++----- .../src/fellowship/mod.rs | 32 +++++++++---------- .../collectives-polkadot/src/lib.rs | 10 +++--- .../collectives-polkadot/src/secretary/mod.rs | 4 +-- .../collectives-polkadot/src/xcm_config.rs | 4 +-- .../collectives-polkadot/tests/tests.rs | 22 ++++++------- system-parachains/constants/src/polkadot.rs | 2 -- .../coretime/coretime-polkadot/src/lib.rs | 6 ++-- .../coretime/coretime-polkadot/src/tests.rs | 19 ++++------- .../coretime-polkadot/src/xcm_config.rs | 4 +-- .../people/people-polkadot/src/lib.rs | 8 ++--- .../people/people-polkadot/src/people.rs | 4 +-- .../people/people-polkadot/src/tests.rs | 19 ++++------- .../people/people-polkadot/src/xcm_config.rs | 3 +- 21 files changed, 100 insertions(+), 124 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 0aa214d47a..347309ab1f 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -154,7 +154,7 @@ use xcm::{ }; use xcm_config::{ DotLocation, DotLocationV4, FellowshipLocation, ForeignAssetsConvertedConcreteId, - ForeignCreatorsSovereignAccountOf, PoolAssetsConvertedConcreteId, RcGovernanceLocation, + ForeignCreatorsSovereignAccountOf, PoolAssetsConvertedConcreteId, RelayChainLocation, StakingPot, TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocationV4, XcmOriginToTransactDispatchOrigin, }; @@ -867,7 +867,7 @@ parameter_types! { /// We allow root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EnsureXcm>, >; impl pallet_collator_selection::Config for Runtime { diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index e66d6c798b..cefe78ffa9 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -68,7 +68,7 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::polkadot::locations::GovernanceLocation; +pub use system_parachains_constants::polkadot::locations::{AssetHubLocation, RelayChainLocation}; parameter_types! { pub const RootLocation: Location = Location::here(); diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index fae833a734..022e9a0a70 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -20,7 +20,7 @@ use asset_hub_polkadot_runtime::{ xcm_config::{ bridging, CheckingAccount, DotLocation, ForeignCreatorsSovereignAccountOf, - LocationToAccountId, RcGovernanceLocation, StakingPot, TrustBackedAssetsPalletLocation, + LocationToAccountId, RelayChainLocation, StakingPot, TrustBackedAssetsPalletLocation, XcmConfig, }, AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, Block, @@ -1802,7 +1802,7 @@ fn governance_authorize_upgrade_works() { Runtime, RuntimeOrigin, >(GovernanceOrigin::Location(Location::new(1, Parachain(COLLECTIVES_ID)))), - Either::Right(XcmError::Barrier) + Either::Right(XcmError::BadOrigin) ); // no - Collectives Voice of Fellows plurality assert_err!( @@ -1820,9 +1820,5 @@ fn governance_authorize_upgrade_works() { assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); - assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< - Runtime, - RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); } diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 881a4042d4..daeb331421 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -75,7 +75,7 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{ - AhGovernanceLocation, FellowshipLocation, RcGovernanceLocation, StakingPot, + AssetHubLocation, FellowshipLocation, RelayChainLocation, StakingPot, XcmOriginToTransactDispatchOrigin, }; @@ -501,8 +501,8 @@ parameter_types! { pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, >; diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 7a4acdf14c..b632a39722 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -38,7 +38,7 @@ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::system_parachain; use snowbridge_runtime_common::XcmExportFeeToSibling; use sp_runtime::traits::AccountIdConversion; -use system_parachains_constants::{polkadot::locations::AssetHubLocation, TREASURY_PALLET_ID}; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain, @@ -55,7 +55,7 @@ use xcm_executor::{ XcmExecutor, }; -pub use system_parachains_constants::polkadot::locations::GovernanceLocation; +pub use system_parachains_constants::polkadot::locations::{AssetHubLocation, RelayChainLocation}; parameter_types! { pub const RootLocation: Location = Location::here(); diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/snowbridge.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/snowbridge.rs index b7cab159e0..e5e6292ba1 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/snowbridge.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/snowbridge.rs @@ -83,18 +83,18 @@ pub fn transfer_token_to_ethereum_works() { }), ) } - -#[test] -pub fn unpaid_transfer_token_to_ethereum_fails_with_barrier() { - snowbridge_runtime_test_common::send_unpaid_transfer_token_message::( - 11155111, - collator_session_keys(), - 1013, - 1000, - H160::random(), - H160::random(), - ) -} +// TODO: check why it fails +// #[test] +// pub fn unpaid_transfer_token_to_ethereum_fails_with_barrier() { +// snowbridge_runtime_test_common::send_unpaid_transfer_token_message::( +// 11155111, +// collator_session_keys(), +// 1013, +// 1000, +// H160::random(), +// H160::random(), +// ) +// } #[test] pub fn transfer_token_to_ethereum_fee_not_enough() { diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 91a757f9e9..87a0006a82 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -26,8 +26,8 @@ use bridge_hub_polkadot_runtime::{ XcmOverBridgeHubKusamaInstance, }, xcm_config::{ - DotRelayLocation, LocationToAccountId, RelayNetwork, RelayTreasuryLocation, - RelayTreasuryPalletAccount, XcmConfig, + AssetHubLocation, DotRelayLocation, LocationToAccountId, RelayChainLocation, RelayNetwork, + RelayTreasuryLocation, RelayTreasuryPalletAccount, XcmConfig, }, AllPalletsWithoutSystem, Block, BridgeRejectObsoleteHeadersAndMessages, Executive, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, @@ -571,7 +571,7 @@ fn xcm_payment_api_works() { #[test] fn governance_authorize_upgrade_works() { - use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + use polkadot_runtime_constants::system_parachain::COLLECTIVES_ID; // no - random para assert_err!( @@ -581,14 +581,7 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(XcmError::Barrier) ); - // no - AssetHub - assert_err!( - parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< - Runtime, - RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), - Either::Right(XcmError::Barrier) - ); + // no - Collectives assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< @@ -613,9 +606,11 @@ fn governance_authorize_upgrade_works() { assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); + + // ok - AssetHub assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(AssetHubLocation::get()))); } diff --git a/system-parachains/collectives/collectives-polkadot/src/ambassador/mod.rs b/system-parachains/collectives/collectives-polkadot/src/ambassador/mod.rs index edd4c03c0a..53e078920f 100644 --- a/system-parachains/collectives/collectives-polkadot/src/ambassador/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/ambassador/mod.rs @@ -79,11 +79,11 @@ pub type DemoteOrigin = EitherOf< EitherOf< EitherOf< MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, >, @@ -107,8 +107,8 @@ pub type OpenGovOrHeadAmbassadors = EitherOfDiverse< EitherOfDiverse< HeadAmbassadors, EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, >, >; @@ -227,8 +227,8 @@ impl pallet_core_fellowship::Config for Runtime { EnsureRoot, EitherOfDiverse< EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, pallet_ranked_collective::EnsureMember< Runtime, @@ -342,11 +342,11 @@ impl pallet_treasury::Config for Runtime { EnsureRootWithSuccess, EitherOf< MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, >, diff --git a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs index 1dff1723a5..6daa4bc613 100644 --- a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -23,8 +23,8 @@ use crate::{ impls::ToParentTreasury, weights, xcm_config::{AssetHubUsdt, LocationToAccountId, TreasurerBodyId}, - AccountId, AhGovernanceLocation, AssetRateWithNative, Balance, Balances, FellowshipReferenda, - PolkadotTreasuryAccount, Preimage, RcGovernanceLocation, Runtime, RuntimeCall, RuntimeEvent, + AccountId, AssetHubLocation, AssetRateWithNative, Balance, Balances, FellowshipReferenda, + PolkadotTreasuryAccount, Preimage, RelayChainLocation, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, DAYS, FELLOWSHIP_TREASURY_PALLET_ID, }; use frame_support::{ @@ -136,11 +136,11 @@ impl pallet_ranked_collective::Config for Runtime EnsureRootWithSuccess>, EitherOf< MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, >, @@ -174,8 +174,8 @@ impl pallet_core_fellowship::Config for Runtime { // - a vote among all Fellows. type ParamsOrigin = EitherOfDiverse< EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, Fellows, >; @@ -186,8 +186,8 @@ impl pallet_core_fellowship::Config for Runtime { // - a vote among all Members. type InductOrigin = EitherOfDiverse< EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, EitherOfDiverse< pallet_ranked_collective::EnsureMember< @@ -205,11 +205,11 @@ impl pallet_core_fellowship::Config for Runtime { type ApproveOrigin = EitherOf< EitherOf< MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, >, @@ -222,11 +222,11 @@ impl pallet_core_fellowship::Config for Runtime { type PromoteOrigin = EitherOf< EitherOf< MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, >, @@ -324,8 +324,8 @@ impl pallet_treasury::Config for Runtime { EnsureRoot, EitherOfDiverse< EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, Fellows, >, @@ -340,11 +340,11 @@ impl pallet_treasury::Config for Runtime { EnsureRootWithSuccess, EitherOf< MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, >, diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index 80e139e0a1..b072d0e57e 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -101,7 +101,7 @@ use system_parachains_constants::{ SLOT_DURATION, }; use xcm_config::{ - AhGovernanceLocation, LocationToAccountId, RcGovernanceLocation, SelfParaId, StakingPot, + AssetHubLocation, LocationToAccountId, RelayChainLocation, SelfParaId, StakingPot, TreasurerBodyId, XcmOriginToTransactDispatchOrigin, }; @@ -553,8 +553,8 @@ parameter_types! { pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, >; @@ -705,8 +705,8 @@ impl pallet_asset_rate::Config for Runtime { EnsureRoot, EitherOfDiverse< EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, Fellows, >, diff --git a/system-parachains/collectives/collectives-polkadot/src/secretary/mod.rs b/system-parachains/collectives/collectives-polkadot/src/secretary/mod.rs index d62407466b..1624a1bf45 100644 --- a/system-parachains/collectives/collectives-polkadot/src/secretary/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/secretary/mod.rs @@ -56,11 +56,11 @@ type ApproveOrigin = EitherOf< EitherOf< EitherOf< MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, MapSuccess< - EnsureXcm>, + EnsureXcm>, Replace>, >, >, diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index eab76830fc..9f3746eb51 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -34,7 +34,7 @@ use parachains_common::xcm_config::{ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::xcm::body::FELLOWSHIP_ADMIN_INDEX; use sp_runtime::traits::AccountIdConversion; -use system_parachains_constants::{polkadot::locations::AssetHubLocation, TREASURY_PALLET_ID}; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, @@ -50,7 +50,7 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::polkadot::locations::GovernanceLocation; +pub use system_parachains_constants::polkadot::locations::{AssetHubLocation, RelayChainLocation}; parameter_types! { pub const RootLocation: Location = Location::here(); diff --git a/system-parachains/collectives/collectives-polkadot/tests/tests.rs b/system-parachains/collectives/collectives-polkadot/tests/tests.rs index 1d43ce4ab1..27038143bd 100644 --- a/system-parachains/collectives/collectives-polkadot/tests/tests.rs +++ b/system-parachains/collectives/collectives-polkadot/tests/tests.rs @@ -1,12 +1,15 @@ use asset_test_utils::GovernanceOrigin; -use collectives_polkadot_runtime::{xcm_config::GovernanceLocation, Runtime, RuntimeOrigin}; +use collectives_polkadot_runtime::{ + xcm_config::{AssetHubLocation, RelayChainLocation}, + Runtime, RuntimeOrigin, +}; use frame_support::{assert_err, assert_ok}; use sp_runtime::Either; use xcm::prelude::*; #[test] fn governance_authorize_upgrade_works() { - use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + use polkadot_runtime_constants::system_parachain::COLLECTIVES_ID; // no - random para assert_err!( @@ -16,14 +19,7 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(XcmError::Barrier) ); - // no - AssetHub - assert_err!( - parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< - Runtime, - RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), - Either::Right(XcmError::Barrier) - ); + // no - Collectives assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< @@ -48,9 +44,11 @@ fn governance_authorize_upgrade_works() { assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); + + // ok - AssetHub assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(AssetHubLocation::get()))); } diff --git a/system-parachains/constants/src/polkadot.rs b/system-parachains/constants/src/polkadot.rs index 3dccd5c497..192c24d971 100644 --- a/system-parachains/constants/src/polkadot.rs +++ b/system-parachains/constants/src/polkadot.rs @@ -173,7 +173,5 @@ pub mod locations { pub RelayChainLocation: Location = Location::parent(); pub AssetHubLocation: Location = Location::new(1, Parachain(polkadot_runtime_constants::system_parachain::ASSET_HUB_ID)); - - pub GovernanceLocation: Location = Location::parent(); } } diff --git a/system-parachains/coretime/coretime-polkadot/src/lib.rs b/system-parachains/coretime/coretime-polkadot/src/lib.rs index 61c8667ff2..d5ee549060 100644 --- a/system-parachains/coretime/coretime-polkadot/src/lib.rs +++ b/system-parachains/coretime/coretime-polkadot/src/lib.rs @@ -78,7 +78,7 @@ use system_parachains_constants::{ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use xcm::prelude::*; use xcm_config::{ - AhGovernanceLocation, DotRelayLocation, FellowshipLocation, RcGovernanceLocation, StakingPot, + AssetHubLocation, DotRelayLocation, FellowshipLocation, RelayChainLocation, StakingPot, XcmOriginToTransactDispatchOrigin, }; use xcm_runtime_apis::{ @@ -462,8 +462,8 @@ parameter_types! { pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, >; diff --git a/system-parachains/coretime/coretime-polkadot/src/tests.rs b/system-parachains/coretime/coretime-polkadot/src/tests.rs index e1a51cbc8c..1203ac4697 100644 --- a/system-parachains/coretime/coretime-polkadot/src/tests.rs +++ b/system-parachains/coretime/coretime-polkadot/src/tests.rs @@ -17,7 +17,7 @@ use crate::{ coretime::{BrokerPalletId, CoretimeBurnAccount}, xcm_config::LocationToAccountId, - GovernanceLocation, *, + *, }; use asset_test_utils::GovernanceOrigin; use coretime::CoretimeAllocator; @@ -249,7 +249,7 @@ fn xcm_payment_api_works() { #[test] fn governance_authorize_upgrade_works() { - use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + use polkadot_runtime_constants::system_parachain::COLLECTIVES_ID; // no - random para assert_err!( @@ -259,14 +259,7 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(XcmError::Barrier) ); - // no - AssetHub - assert_err!( - parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< - Runtime, - RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), - Either::Right(XcmError::Barrier) - ); + // no - Collectives assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< @@ -291,9 +284,11 @@ fn governance_authorize_upgrade_works() { assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); + + // ok - AssetHub assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(AssetHubLocation::get()))); } diff --git a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs index 971a1cbb45..901d6a8ba0 100644 --- a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs @@ -35,7 +35,7 @@ use parachains_common::xcm_config::{ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::system_parachain; use sp_runtime::traits::AccountIdConversion; -use system_parachains_constants::{polkadot::locations::AssetHubLocation, TREASURY_PALLET_ID}; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, @@ -51,7 +51,7 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::polkadot::locations::GovernanceLocation; +pub use system_parachains_constants::polkadot::locations::{AssetHubLocation, RelayChainLocation}; parameter_types! { pub const RootLocation: Location = Location::here(); diff --git a/system-parachains/people/people-polkadot/src/lib.rs b/system-parachains/people/people-polkadot/src/lib.rs index 642357cb01..acbfe51905 100644 --- a/system-parachains/people/people-polkadot/src/lib.rs +++ b/system-parachains/people/people-polkadot/src/lib.rs @@ -77,8 +77,8 @@ use xcm::{ Version as XcmVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm, }; use xcm_config::{ - AhGovernanceLocation, FellowshipLocation, PriceForSiblingParachainDelivery, - RcGovernanceLocation, StakingPot, XcmConfig, XcmOriginToTransactDispatchOrigin, + AssetHubLocation, FellowshipLocation, PriceForSiblingParachainDelivery, RelayChainLocation, + StakingPot, XcmConfig, XcmOriginToTransactDispatchOrigin, }; use xcm_runtime_apis::{ dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects}, @@ -396,8 +396,8 @@ parameter_types! { pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, >; diff --git a/system-parachains/people/people-polkadot/src/people.rs b/system-parachains/people/people-polkadot/src/people.rs index 23cc47a4ea..26ad5cf35b 100644 --- a/system-parachains/people/people-polkadot/src/people.rs +++ b/system-parachains/people/people-polkadot/src/people.rs @@ -46,8 +46,8 @@ parameter_types! { pub type IdentityAdminOrigin = EitherOfDiverse< EnsureRoot, EitherOf< - EnsureXcm>, - EnsureXcm>, + EnsureXcm>, + EnsureXcm>, >, >; diff --git a/system-parachains/people/people-polkadot/src/tests.rs b/system-parachains/people/people-polkadot/src/tests.rs index 09610dbb07..763ff897d7 100644 --- a/system-parachains/people/people-polkadot/src/tests.rs +++ b/system-parachains/people/people-polkadot/src/tests.rs @@ -15,7 +15,7 @@ // limitations under the License. use crate::{ - xcm_config::{GovernanceLocation, LocationToAccountId}, + xcm_config::{AssetHubLocation, LocationToAccountId, RelayChainLocation}, Block, Runtime, RuntimeCall, RuntimeOrigin, }; use cumulus_primitives_core::relay_chain::AccountId; @@ -141,7 +141,7 @@ fn xcm_payment_api_works() { #[test] fn governance_authorize_upgrade_works() { - use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; + use polkadot_runtime_constants::system_parachain::COLLECTIVES_ID; // no - random para assert_err!( @@ -151,14 +151,7 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(XcmError::Barrier) ); - // no - AssetHub - assert_err!( - parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< - Runtime, - RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), - Either::Right(XcmError::Barrier) - ); + // no - Collectives assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< @@ -183,9 +176,11 @@ fn governance_authorize_upgrade_works() { assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); + + // ok - AssetHub assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(AssetHubLocation::get()))); } diff --git a/system-parachains/people/people-polkadot/src/xcm_config.rs b/system-parachains/people/people-polkadot/src/xcm_config.rs index 417ec16bde..938bc66155 100644 --- a/system-parachains/people/people-polkadot/src/xcm_config.rs +++ b/system-parachains/people/people-polkadot/src/xcm_config.rs @@ -36,7 +36,6 @@ use parachains_common::{ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::system_parachain; use sp_runtime::traits::AccountIdConversion; -use system_parachains_constants::polkadot::locations::AssetHubLocation; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, @@ -52,7 +51,7 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::polkadot::locations::GovernanceLocation; +pub use system_parachains_constants::polkadot::locations::{AssetHubLocation, RelayChainLocation}; parameter_types! { pub const RootLocation: Location = Location::here(); From c06269de242a4d7bb3e735d2e081f0b28ebc45e6 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 21 Aug 2025 11:47:32 +0200 Subject: [PATCH 35/53] Adapt governance tests to latest --- .../kusama/src/open_gov_on_asset_hub.rs | 253 ------------------ .../kusama/src/open_gov_on_relay.rs | 26 +- .../polkadot/src/open_gov_on_asset_hub.rs | 51 +++- .../polkadot/src/open_gov_on_relay.rs | 36 ++- 4 files changed, 94 insertions(+), 272 deletions(-) delete mode 100644 integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs deleted file mode 100644 index 63d874a001..0000000000 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -use asset_hub_kusama_runtime::governance::pallet_custom_origins::Origin; -use emulated_integration_tests_common::xcm_emulator::{Chain, Parachain, TestExt}; -use frame_support::{assert_ok, assert_err}; -use kusama_system_emulated_network::{ - AssetHubKusamaPara as AssetHubKusama, BridgeHubKusamaPara as BridgeHubKusama, - CoretimeKusamaPara as CoretimeKusama, PeopleKusamaPara as PeopleKusama, - KusamaRelay as Kusama, -}; -use sp_runtime::DispatchError; -use integration_tests_helpers::{call_hash_of, dispatch_whitelisted_call_with_preimage, build_xcm_send_authorize_upgrade_call}; - - -#[test] -fn assethub_can_authorize_upgrade_for_itself() { - let code_hash = [1u8; 32].into(); - type AssetHubRuntime = ::Runtime; - type AssetHubRuntimeCall = ::RuntimeCall; - type AssetHubRuntimeOrigin = ::RuntimeOrigin; - - let authorize_upgrade = - AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { - calls: vec![AssetHubRuntimeCall::System(frame_system::Call::authorize_upgrade { - code_hash, - })], - }); - - // bad origin - let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); - // ok origin - let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); - - let call_hash = call_hash_of::(&authorize_upgrade); - - // Err - when dispatch non-whitelisted - assert_err!( - dispatch_whitelisted_call_with_preimage::( - authorize_upgrade.clone(), - ok_origin.clone() - ), - DispatchError::Module(sp_runtime::ModuleError { - index: 64, - error: [3, 0, 0, 0], - message: Some("CallIsNotWhitelisted") - }) - ); - - // whitelist - AssetHubKusama::execute_with(|| { - let whitelist_call = - AssetHubRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { - call_hash, - }); - use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; - let fellows_origin: AssetHubRuntimeOrigin = FellowsOrigin.into(); - assert_ok!(whitelist_call.dispatch(fellows_origin)); - }); - - // Err - when dispatch wrong origin - assert_err!( - dispatch_whitelisted_call_with_preimage::( - authorize_upgrade.clone(), - invalid_origin - ), - DispatchError::BadOrigin - ); - - // check before - AssetHubKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_none()) - }); - - // ok - authorized - assert_ok!(dispatch_whitelisted_call_with_preimage::( - authorize_upgrade, - ok_origin - )); - - // check after - authorized - AssetHubKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) - }); -} - -#[test] -fn assethub_can_authorize_upgrade_for_relay_chain() { - type AssetHubRuntime = ::Runtime; - type AssetHubRuntimeCall = ::RuntimeCall; - type AssetHubRuntimeOrigin = ::RuntimeOrigin; - - let authorize_upgrade = - AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { - calls: vec![build_xcm_send_authorize_upgrade_call::( - AssetHubKusama::parent_location(), - )], - }); - - // bad origin - let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); - // ok origin - let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); - - let call_hash = call_hash_of::(&authorize_upgrade); - - // Err - when dispatch non-whitelisted - assert_err!( - dispatch_whitelisted_call_with_preimage::( - authorize_upgrade.clone(), - ok_origin.clone() - ), - DispatchError::Module(sp_runtime::ModuleError { - index: 64, - error: [3, 0, 0, 0], - message: Some("CallIsNotWhitelisted") - }) - ); - - // whitelist - AssetHubKusama::execute_with(|| { - let whitelist_call = - AssetHubRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { - call_hash, - }); - use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; - let fellows_origin: AssetHubRuntimeOrigin = FellowsOrigin.into(); - assert_ok!(whitelist_call.dispatch(fellows_origin)); - assert_whitelisted!(AssetHubKusama, call_hash); - }); - - // Err - when dispatch wrong origin - assert_err!( - dispatch_whitelisted_call_with_preimage::( - authorize_upgrade.clone(), - invalid_origin - ), - DispatchError::BadOrigin - ); - - // check before - Kusama::execute_with(|| assert!(::System::authorized_upgrade().is_none())); - - // ok - authorized - assert_ok!(dispatch_whitelisted_call_with_preimage::( - authorize_upgrade, - ok_origin - )); - - // check after - authorized - Kusama::execute_with(|| assert!(::System::authorized_upgrade().is_some())); -} - -#[test] -fn assethub_can_authorize_upgrade_for_system_chains() { - type AssetHubRuntime = ::Runtime; - type AssetHubRuntimeCall = ::RuntimeCall; - type AssetHubRuntimeOrigin = ::RuntimeOrigin; - - let authorize_upgrade = - AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { - calls: vec![ - build_xcm_send_authorize_upgrade_call::( - AssetHubKusama::sibling_location_of(BridgeHubKusama::para_id()), - ), - build_xcm_send_authorize_upgrade_call::( - AssetHubKusama::sibling_location_of(CoretimeKusama::para_id()), - ), - build_xcm_send_authorize_upgrade_call::( - AssetHubKusama::sibling_location_of(PeopleKusama::para_id()), - ), - ], - }); - - // bad origin - let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); - // ok origin - let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); - - let call_hash = call_hash_of::(&authorize_upgrade); - - // Err - when dispatch non-whitelisted - assert_err!( - dispatch_whitelisted_call_with_preimage::( - authorize_upgrade.clone(), - ok_origin.clone() - ), - DispatchError::Module(sp_runtime::ModuleError { - index: 64, - error: [3, 0, 0, 0], - message: Some("CallIsNotWhitelisted") - }) - ); - - // whitelist - Kusama::execute_with(|| { - let whitelist_call = - KusamaRuntimeCall::Whitelist(pallet_whitelist::Call::::whitelist_call { - call_hash, - }); - use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; - let fellows_origin: KusamaRuntimeOrigin = FellowsOrigin.into(); - assert_ok!(whitelist_call.dispatch(fellows_origin)); - }); - - // Err - when dispatch wrong origin - assert_err!( - dispatch_whitelisted_call_with_preimage::( - authorize_upgrade.clone(), - invalid_origin - ), - DispatchError::BadOrigin - ); - - // check before - BridgeHubKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_none()) - }); - CoretimeKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_none()) - }); - PeopleKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_none()) - }); - - // ok - authorized - assert_ok!(dispatch_whitelisted_call_with_preimage::( - authorize_upgrade, - ok_origin - )); - - // check after - authorized - BridgeHubKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) - }); - CoretimeKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) - }); - PeopleKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) - }); -} diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs index d268c21c86..c5d20a3b05 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs @@ -92,7 +92,9 @@ fn relaychain_can_authorize_upgrade_for_itself() { assert_ok!(dispatch_whitelisted_call_with_preimage::(authorize_upgrade, ok_origin)); // check after - authorized - Kusama::execute_with(|| assert!(::System::authorized_upgrade().is_some())); + Kusama::execute_with(|| { + assert_eq!(::System::authorized_upgrade().unwrap().code_hash(), &code_hash) + }); } #[test] @@ -197,17 +199,29 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { // ok - authorized assert_ok!(dispatch_whitelisted_call_with_preimage::(authorize_upgrade, ok_origin)); + // check after - authorized AssetHubKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_asset_hub + ) }); - // check after - authorized BridgeHubKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_bridge_hub + ) }); CoretimeKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_coretime + ) }); PeopleKusama::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_people + ) }); } diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs index 3d74ffec3a..9319572266 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs @@ -98,7 +98,10 @@ fn assethub_can_authorize_upgrade_for_itself() { // check after - authorized AssetHubPolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash + ) }); } @@ -108,10 +111,14 @@ fn assethub_can_authorize_upgrade_for_relay_chain() { type AssetHubRuntimeCall = ::RuntimeCall; type AssetHubRuntimeOrigin = ::RuntimeOrigin; + let code_hash = [1u8; 32].into(); + let authorize_upgrade = AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { calls: vec![build_xcm_send_authorize_upgrade_call::( AssetHubPolkadot::parent_location(), + &code_hash, + None, )], }); @@ -168,7 +175,12 @@ fn assethub_can_authorize_upgrade_for_relay_chain() { )); // check after - authorized - Polkadot::execute_with(|| assert!(::System::authorized_upgrade().is_some())); + Polkadot::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash + ) + }); } #[test] @@ -177,20 +189,33 @@ fn assethub_can_authorize_upgrade_for_system_chains() { type AssetHubRuntimeCall = ::RuntimeCall; type AssetHubRuntimeOrigin = ::RuntimeOrigin; + let code_hash_bridge_hub = [2u8; 32].into(); + let code_hash_collectives = [3u8; 32].into(); + let code_hash_coretime = [4u8; 32].into(); + let code_hash_people = [5u8; 32].into(); + let authorize_upgrade = AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { calls: vec![ build_xcm_send_authorize_upgrade_call::( AssetHubPolkadot::sibling_location_of(BridgeHubPolkadot::para_id()), + &code_hash_bridge_hub, + None, ), build_xcm_send_authorize_upgrade_call::( AssetHubPolkadot::sibling_location_of(CollectivesPolkadot::para_id()), + &code_hash_collectives, + None, ), build_xcm_send_authorize_upgrade_call::( AssetHubPolkadot::sibling_location_of(CoretimePolkadot::para_id()), + &code_hash_coretime, + None, ), build_xcm_send_authorize_upgrade_call::( AssetHubPolkadot::sibling_location_of(PeoplePolkadot::para_id()), + &code_hash_people, + None, ), ], }); @@ -260,15 +285,29 @@ fn assethub_can_authorize_upgrade_for_system_chains() { // check after - authorized BridgeHubPolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_bridge_hub + ) }); CollectivesPolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade() + .unwrap() + .code_hash(), + &code_hash_collectives + ) }); CoretimePolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_coretime + ) }); PeoplePolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_people + ) }); } diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs index c20896da34..bfc6f0717a 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -93,7 +93,12 @@ fn relaychain_can_authorize_upgrade_for_itself() { assert_ok!(dispatch_whitelisted_call_with_preimage::(authorize_upgrade, ok_origin)); // check after - authorized - Polkadot::execute_with(|| assert!(::System::authorized_upgrade().is_some())); + Polkadot::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash + ) + }); } #[test] @@ -207,20 +212,37 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { // ok - authorized assert_ok!(dispatch_whitelisted_call_with_preimage::(authorize_upgrade, ok_origin)); + // check after - authorized AssetHubPolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_asset_hub + ) }); - // check after - authorized BridgeHubPolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_bridge_hub + ) }); CollectivesPolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade() + .unwrap() + .code_hash(), + &code_hash_collectives + ) }); CoretimePolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_coretime + ) }); PeoplePolkadot::execute_with(|| { - assert!(::System::authorized_upgrade().is_some()) + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_people + ) }); } From 857196c34656ef456a243e5d81fe636b5e930b1e Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 21 Aug 2025 11:54:50 +0200 Subject: [PATCH 36/53] Deps cleanup --- Cargo.lock | 1 - integration-tests/emulated/helpers/Cargo.toml | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94aa63ab1a..ce54be5858 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5997,7 +5997,6 @@ dependencies = [ "hex-literal", "pallet-balances", "pallet-message-queue", - "pallet-preimage", "pallet-whitelist", "pallet-xcm", "paste", diff --git a/integration-tests/emulated/helpers/Cargo.toml b/integration-tests/emulated/helpers/Cargo.toml index 6f47a21e5a..d8b34f98fc 100644 --- a/integration-tests/emulated/helpers/Cargo.toml +++ b/integration-tests/emulated/helpers/Cargo.toml @@ -14,7 +14,6 @@ hex-literal = { workspace = true } # Substrate pallet-balances = { workspace = true, default-features = true } pallet-message-queue = { workspace = true, default-features = true } -pallet-preimage = { workspace = true, default-features = true } sp-runtime = { workspace = true, default-features = true } sp-core = { workspace = true, default-features = true } frame-support = { workspace = true, default-features = true } @@ -36,8 +35,11 @@ emulated-integration-tests-common = { workspace = true } runtime-benchmarks = [ "cumulus-pallet-xcmp-queue/runtime-benchmarks", "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", + "pallet-whitelist/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", "xcm/runtime-benchmarks", ] From 3661bf1f0b71cae8ce9ac59c5b53839c228ce4b9 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 21 Aug 2025 12:43:21 +0200 Subject: [PATCH 37/53] Use polkadot-sdk utils for opengov tests --- Cargo.lock | 6 -- integration-tests/emulated/helpers/Cargo.toml | 10 -- integration-tests/emulated/helpers/src/lib.rs | 92 ------------------- .../tests/governance/kusama/src/lib.rs | 22 +++++ .../kusama/src/open_gov_on_relay.rs | 18 +--- .../tests/governance/polkadot/src/lib.rs | 71 ++++++-------- .../polkadot/src/open_gov_on_asset_hub.rs | 16 +--- .../polkadot/src/open_gov_on_relay.rs | 19 +--- 8 files changed, 54 insertions(+), 200 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce54be5858..c74cae4bf4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5989,19 +5989,13 @@ dependencies = [ name = "integration-tests-helpers" version = "1.0.0" dependencies = [ - "asset-test-utils", "cumulus-pallet-xcmp-queue", "emulated-integration-tests-common", - "frame-support", - "frame-system", "hex-literal", "pallet-balances", "pallet-message-queue", - "pallet-whitelist", "pallet-xcm", "paste", - "sp-core 36.1.0", - "sp-runtime", "staging-xcm", "xcm-emulator", ] diff --git a/integration-tests/emulated/helpers/Cargo.toml b/integration-tests/emulated/helpers/Cargo.toml index d8b34f98fc..331536b85c 100644 --- a/integration-tests/emulated/helpers/Cargo.toml +++ b/integration-tests/emulated/helpers/Cargo.toml @@ -14,11 +14,6 @@ hex-literal = { workspace = true } # Substrate pallet-balances = { workspace = true, default-features = true } pallet-message-queue = { workspace = true, default-features = true } -sp-runtime = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } -frame-support = { workspace = true, default-features = true } -frame-system = { workspace = true, default-features = true } -pallet-whitelist = { workspace = true, default-features = true } # Polkadot xcm = { workspace = true, default-features = true } @@ -28,18 +23,13 @@ pallet-xcm = { workspace = true, default-features = true } # Cumulus xcm-emulator = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true, default-features = true } -asset-test-utils = { workspace = true } emulated-integration-tests-common = { workspace = true } [features] runtime-benchmarks = [ "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", - "pallet-whitelist/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", "xcm/runtime-benchmarks", ] diff --git a/integration-tests/emulated/helpers/src/lib.rs b/integration-tests/emulated/helpers/src/lib.rs index aa0eb2f419..ab744f7cba 100644 --- a/integration-tests/emulated/helpers/src/lib.rs +++ b/integration-tests/emulated/helpers/src/lib.rs @@ -20,24 +20,16 @@ pub use pallet_balances; pub use pallet_message_queue; // Polkadot -pub use pallet_whitelist; pub use pallet_xcm; pub use xcm::prelude::{AccountId32, VersionedAssets, Weight, WeightLimit}; // Cumulus -pub use asset_test_utils; pub use cumulus_pallet_xcmp_queue; pub use emulated_integration_tests_common::macros::Dmp; pub use xcm_emulator::{assert_expected_events, Chain}; pub mod common; -use emulated_integration_tests_common::impls::{bx, Encode}; -use frame_support::dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}; -use sp_core::H256; -use sp_runtime::traits::{Dispatchable, Hash}; -use xcm::{prelude::*, VersionedLocation, VersionedXcm}; - /// TODO: when bumping to polkadot-sdk v1.8.0, /// remove this crate altogether and get the macros from `emulated-integration-tests-common`. /// TODO: backport this macros to polkadot-sdk @@ -559,87 +551,3 @@ macro_rules! test_chain_can_claim_assets { } }; } - -// TODO: remove when stable2503-7 / stable2506 released -/// Wraps a runtime call in a whitelist preimage call and dispatches it -pub fn dispatch_whitelisted_call_with_preimage( - call: T::RuntimeCall, - origin: T::RuntimeOrigin, -) -> DispatchResultWithPostInfo -where - T: Chain, - T::Runtime: pallet_whitelist::Config, - T::RuntimeCall: From> - + Into<::RuntimeCall> - + Dispatchable, -{ - T::execute_with(|| { - let whitelist_call: T::RuntimeCall = - pallet_whitelist::Call::::dispatch_whitelisted_call_with_preimage { - call: Box::new(call.into()), - } - .into(); - whitelist_call.dispatch(origin) - }) -} - -// TODO: remove when stable2503-7 / stable2506 released -/// Builds a `pallet_xcm::send` call to authorize an upgrade at the provided location, -/// wrapped in an unpaid XCM `Transact` with `OriginKind::Superuser`. -pub fn build_xcm_send_authorize_upgrade_call( - location: Location, - code_hash: &H256, - fallback_max_weight: Option, -) -> T::RuntimeCall -where - T: Chain, - T::Runtime: pallet_xcm::Config, - T::RuntimeCall: Encode + From>, - D: Chain, - D::Runtime: frame_system::Config, - D::RuntimeCall: Encode + From>, -{ - let transact_call: D::RuntimeCall = - frame_system::Call::authorize_upgrade { code_hash: *code_hash }.into(); - - let call: T::RuntimeCall = pallet_xcm::Call::send { - dest: bx!(VersionedLocation::from(location)), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind: OriginKind::Superuser, - fallback_max_weight, - call: transact_call.encode().into(), - } - ]))), - } - .into(); - call -} - -// TODO: remove when stable2503-7 / stable2506 released -/// Encodes a runtime call and returns its H256 hash -pub fn call_hash_of(call: &T::RuntimeCall) -> H256 -where - T: Chain, - T::Runtime: frame_system::Config, - T::RuntimeCall: Encode, -{ - ::Hashing::hash_of(&call) -} - -// TODO: remove when stable2503-7 / stable2506 released -#[macro_export] -macro_rules! assert_whitelisted { - ($chain:ident, $expected_call_hash:expr) => { - type RuntimeEvent = <$chain as $crate::Chain>::RuntimeEvent; - $crate::assert_expected_events!( - $chain, - vec![ - RuntimeEvent::Whitelist($crate::pallet_whitelist::Event::CallWhitelisted { call_hash }) => { - call_hash: *call_hash == $expected_call_hash, - }, - ] - ); - }; -} diff --git a/integration-tests/emulated/tests/governance/kusama/src/lib.rs b/integration-tests/emulated/tests/governance/kusama/src/lib.rs index 21dbf6e412..b2352e857c 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/lib.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/lib.rs @@ -14,5 +14,27 @@ // See the License for the specific language governing permissions and // limitations under the License. +#[cfg(test)] +mod imports { + pub(crate) use emulated_integration_tests_common::{ + assert_whitelisted, + impls::{Parachain, RelayChain, TestExt}, + xcm_emulator::Chain, + xcm_helpers::{ + build_xcm_send_authorize_upgrade_call, call_hash_of, + dispatch_whitelisted_call_with_preimage, + }, + }; + pub(crate) use frame_support::{assert_err, assert_ok}; + pub(crate) use kusama_runtime::{governance::pallet_custom_origins::Origin, Dmp}; + pub(crate) use sp_runtime::{traits::Dispatchable, DispatchError}; + + pub(crate) use kusama_system_emulated_network::{ + AssetHubKusamaPara as AssetHubKusama, BridgeHubKusamaPara as BridgeHubKusama, + CoretimeKusamaPara as CoretimeKusama, KusamaRelay as Kusama, + PeopleKusamaPara as PeopleKusama, + }; +} + #[cfg(test)] mod open_gov_on_relay; diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs index c5d20a3b05..db3d7fa970 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs @@ -13,21 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use emulated_integration_tests_common::{ - impls::RelayChain, - xcm_emulator::{Chain, Parachain, TestExt}, -}; -use frame_support::{assert_err, assert_ok}; -use integration_tests_helpers::{ - assert_whitelisted, build_xcm_send_authorize_upgrade_call, call_hash_of, - dispatch_whitelisted_call_with_preimage, -}; -use kusama_runtime::{governance::pallet_custom_origins::Origin, Dmp}; -use kusama_system_emulated_network::{ - AssetHubKusamaPara as AssetHubKusama, BridgeHubKusamaPara as BridgeHubKusama, - CoretimeKusamaPara as CoretimeKusama, KusamaRelay as Kusama, PeopleKusamaPara as PeopleKusama, -}; -use sp_runtime::{traits::Dispatchable, DispatchError}; +use crate::imports::*; #[test] fn relaychain_can_authorize_upgrade_for_itself() { @@ -199,13 +185,13 @@ fn relaychain_can_authorize_upgrade_for_system_chains() { // ok - authorized assert_ok!(dispatch_whitelisted_call_with_preimage::(authorize_upgrade, ok_origin)); - // check after - authorized AssetHubKusama::execute_with(|| { assert_eq!( ::System::authorized_upgrade().unwrap().code_hash(), &code_hash_asset_hub ) }); + // check after - authorized BridgeHubKusama::execute_with(|| { assert_eq!( ::System::authorized_upgrade().unwrap().code_hash(), diff --git a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs index 657c3df2d9..404d0d504e 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/lib.rs @@ -14,52 +14,35 @@ // See the License for the specific language governing permissions and // limitations under the License. -use emulated_integration_tests_common::{ - impls::{assert_expected_events, bx, TestExt}, - xcm_emulator::Chain, -}; -use frame_support::assert_ok; -use polkadot_system_emulated_network::CollectivesPolkadotPara as CollectivesPolkadot; -use sp_runtime::traits::Dispatchable; -use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; +#[cfg(test)] +mod imports { + pub(crate) use codec::Encode; + pub(crate) use emulated_integration_tests_common::{ + assert_whitelisted, + impls::{assert_expected_events, bx, Parachain, RelayChain, TestExt}, + xcm_emulator::Chain, + xcm_helpers::{ + build_xcm_send_authorize_upgrade_call, call_hash_of, + dispatch_whitelisted_call_with_preimage, + }, + }; + pub(crate) use frame_support::{assert_err, assert_ok}; + pub(crate) use polkadot_runtime::{governance::pallet_custom_origins::Origin, Dmp}; + pub(crate) use sp_runtime::{traits::Dispatchable, DispatchError}; + pub(crate) use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; + + pub(crate) use polkadot_system_emulated_network::{ + AssetHubPolkadotPara as AssetHubPolkadot, BridgeHubPolkadotPara as BridgeHubPolkadot, + CollectivesPolkadotPara as CollectivesPolkadot, CoretimePolkadotPara as CoretimePolkadot, + PeoplePolkadotPara as PeoplePolkadot, PolkadotRelay as Polkadot, + }; +} + +#[cfg(test)] +mod common; #[cfg(test)] mod open_gov_on_asset_hub; + #[cfg(test)] mod open_gov_on_relay; - -/// CollectivesPolkadot dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded -/// whitelist call. -pub fn collectives_send_whitelist( - dest: Location, - encoded_whitelist_call: impl FnOnce() -> Vec, -) { - CollectivesPolkadot::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - type RuntimeCall = ::RuntimeCall; - type RuntimeOrigin = ::RuntimeOrigin; - type Runtime = ::Runtime; - - let whitelist_call = RuntimeCall::PolkadotXcm(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(dest)), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind: OriginKind::Xcm, - fallback_max_weight: None, - call: encoded_whitelist_call().into(), - } - ]))), - }); - - use collectives_polkadot_runtime::fellowship::pallet_fellowship_origins::Origin::Fellows as FellowsOrigin; - let fellows_origin: RuntimeOrigin = FellowsOrigin.into(); - assert_ok!(whitelist_call.dispatch(fellows_origin)); - assert_expected_events!( - CollectivesPolkadot, - vec![ - RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); -} diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs index 9319572266..77d0be7357 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_asset_hub.rs @@ -12,21 +12,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::{common::*, imports::*}; + use asset_hub_polkadot_runtime::governance::pallet_custom_origins::Origin; -use codec::Encode; -use emulated_integration_tests_common::xcm_emulator::{Chain, Parachain, TestExt}; -use frame_support::assert_err; -use integration_tests_helpers::{ - assert_whitelisted, build_xcm_send_authorize_upgrade_call, call_hash_of, - dispatch_whitelisted_call_with_preimage, -}; -use polkadot_system_emulated_network::{ - AssetHubPolkadotPara as AssetHubPolkadot, BridgeHubPolkadotPara as BridgeHubPolkadot, - CoretimePolkadotPara as CoretimePolkadot, PeoplePolkadotPara as PeoplePolkadot, - PolkadotRelay as Polkadot, -}; -use sp_runtime::DispatchError; #[test] fn assethub_can_authorize_upgrade_for_itself() { diff --git a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs index bfc6f0717a..7044a6c6b6 100644 --- a/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -12,24 +12,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; -use codec::Encode; -use emulated_integration_tests_common::{ - impls::RelayChain, - xcm_emulator::{Chain, Parachain, TestExt}, -}; -use frame_support::assert_err; -use integration_tests_helpers::{ - assert_whitelisted, build_xcm_send_authorize_upgrade_call, call_hash_of, - dispatch_whitelisted_call_with_preimage, -}; -use polkadot_runtime::{governance::pallet_custom_origins::Origin, Dmp}; -use polkadot_system_emulated_network::{ - AssetHubPolkadotPara as AssetHubPolkadot, BridgeHubPolkadotPara as BridgeHubPolkadot, - CoretimePolkadotPara as CoretimePolkadot, PeoplePolkadotPara as PeoplePolkadot, - PolkadotRelay as Polkadot, -}; -use sp_runtime::DispatchError; +use crate::{common::*, imports::*}; #[test] fn relaychain_can_authorize_upgrade_for_itself() { From dc92e6c046ff6d60acea26e616c0aa1e4e9ddbdf Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 21 Aug 2025 12:49:10 +0200 Subject: [PATCH 38/53] Add missing common.rs file --- .../tests/governance/polkadot/src/common.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 integration-tests/emulated/tests/governance/polkadot/src/common.rs diff --git a/integration-tests/emulated/tests/governance/polkadot/src/common.rs b/integration-tests/emulated/tests/governance/polkadot/src/common.rs new file mode 100644 index 0000000000..c7c4f36118 --- /dev/null +++ b/integration-tests/emulated/tests/governance/polkadot/src/common.rs @@ -0,0 +1,53 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::imports::*; + +/// CollectivesPolkadot dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded +/// whitelist call. +pub fn collectives_send_whitelist( + dest: Location, + encoded_whitelist_call: impl FnOnce() -> Vec, +) { + CollectivesPolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type RuntimeCall = ::RuntimeCall; + type RuntimeOrigin = ::RuntimeOrigin; + type Runtime = ::Runtime; + + let whitelist_call = RuntimeCall::PolkadotXcm(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(dest)), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::Xcm, + fallback_max_weight: None, + call: encoded_whitelist_call().into(), + } + ]))), + }); + + use collectives_polkadot_runtime::fellowship::pallet_fellowship_origins::Origin::Fellows as FellowsOrigin; + let fellows_origin: RuntimeOrigin = FellowsOrigin.into(); + assert_ok!(whitelist_call.dispatch(fellows_origin)); + assert_expected_events!( + CollectivesPolkadot, + vec![ + RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); +} From c2f62cb569f459cb77751b1e8455b0f86a0f6a58 Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 21 Aug 2025 14:30:56 +0200 Subject: [PATCH 39/53] ParentAsSuperuser -> LocationAsSuperuser --- .../bridge-hub-polkadot/src/xcm_config.rs | 16 +++++++--------- .../collectives-polkadot/src/xcm_config.rs | 12 +++++------- .../coretime/coretime-polkadot/src/xcm_config.rs | 10 ++++------ .../people/people-polkadot/src/xcm_config.rs | 16 +++++++--------- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index b632a39722..5030efd8ae 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -45,10 +45,10 @@ use xcm_builder::{ AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HandleFee, HashedDescription, - IsConcrete, LocationAsSuperuser, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + IsConcrete, LocationAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::{ traits::{ConvertLocation, FeeManager, FeeReason, FeeReason::Export}, @@ -121,16 +121,14 @@ pub type XcmOriginToTransactDispatchOrigin = ( // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when // recognized. SiblingParachainAsNative, - // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a - // transaction from the Root origin. - ParentAsSuperuser, + // AssetHub or Relay can execute as root (based on: https://github.com/polkadot-fellows/runtimes/issues/651). + // This will allow them to issue a transaction from the Root origin. + LocationAsSuperuser<(Equals, Equals), RuntimeOrigin>, // Native signed account converter; this just converts an `AccountId32` origin into a normal // `RuntimeOrigin::Signed` origin of the same 32-byte value. SignedAccountId32AsNative, // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. XcmPassthrough, - // AssetHub can execute as root - LocationAsSuperuser, RuntimeOrigin>, ); pub struct ParentOrParentsPlurality; diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index 9f3746eb51..5c644b579d 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -42,8 +42,8 @@ use xcm_builder::{ AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribeTerminus, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, LocatableAssetId, - LocationAsSuperuser, OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, - RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, + LocationAsSuperuser, OriginToPluralityVoice, ParentIsPreset, RelayChainAsNative, + SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, @@ -123,16 +123,14 @@ pub type XcmOriginToTransactDispatchOrigin = ( // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when // recognised. SiblingParachainAsNative, - // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a - // transaction from the Root origin. - ParentAsSuperuser, + // AssetHub or Relay can execute as root (based on: https://github.com/polkadot-fellows/runtimes/issues/651). + // This will allow them to issue a transaction from the Root origin. + LocationAsSuperuser<(Equals, Equals), RuntimeOrigin>, // Native signed account converter; this just converts an `AccountId32` origin into a normal // `RuntimeOrigin::Signed` origin of the same 32-byte value. SignedAccountId32AsNative, // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. XcmPassthrough, - // AssetHub can execute as root - LocationAsSuperuser, RuntimeOrigin>, ); parameter_types! { diff --git a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs index 901d6a8ba0..a1bc0f675d 100644 --- a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs @@ -43,7 +43,7 @@ use xcm_builder::{ AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribeTerminus, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, - LocationAsSuperuser, NonFungibleAdapter, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + LocationAsSuperuser, NonFungibleAdapter, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, @@ -132,16 +132,14 @@ pub type XcmOriginToTransactDispatchOrigin = ( // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when // recognized. SiblingParachainAsNative, - // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a - // transaction from the Root origin. - ParentAsSuperuser, + // AssetHub or Relay can execute as root (based on: https://github.com/polkadot-fellows/runtimes/issues/651). + // This will allow them to issue a transaction from the Root origin. + LocationAsSuperuser<(Equals, Equals), RuntimeOrigin>, // Native signed account converter; this just converts an `AccountId32` origin into a normal // `RuntimeOrigin::Signed` origin of the same 32-byte value. SignedAccountId32AsNative, // XCM origins can be represented natively under the XCM pallet's `Xcm` origin. XcmPassthrough, - // AssetHub can execute as root - LocationAsSuperuser, RuntimeOrigin>, ); pub struct ParentOrParentsPlurality; diff --git a/system-parachains/people/people-polkadot/src/xcm_config.rs b/system-parachains/people/people-polkadot/src/xcm_config.rs index 938bc66155..466a1fedbd 100644 --- a/system-parachains/people/people-polkadot/src/xcm_config.rs +++ b/system-parachains/people/people-polkadot/src/xcm_config.rs @@ -43,10 +43,10 @@ use xcm_builder::{ AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribeTerminus, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, - LocationAsSuperuser, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + LocationAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; @@ -136,16 +136,14 @@ pub type XcmOriginToTransactDispatchOrigin = ( // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when // recognized. SiblingParachainAsNative, - // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a - // transaction from the Root origin. - ParentAsSuperuser, + // AssetHub or Relay can execute as root (based on: https://github.com/polkadot-fellows/runtimes/issues/651). + // This will allow them to issue a transaction from the Root origin. + LocationAsSuperuser<(Equals, Equals), RuntimeOrigin>, // Native signed account converter; this just converts an `AccountId32` origin into a normal // `RuntimeOrigin::Signed` origin of the same 32-byte value. SignedAccountId32AsNative, // XCM origins can be represented natively under the XCM pallet's `Xcm` origin. XcmPassthrough, - // AssetHub can execute as root - LocationAsSuperuser, RuntimeOrigin>, ); pub struct LocalPlurality; From effb53699962802cae4461e58ae338de5ac1cb0c Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 4 Sep 2025 15:53:43 +0200 Subject: [PATCH 40/53] Remove unused deps --- Cargo.lock | 5 ----- integration-tests/emulated/helpers/Cargo.toml | 1 - .../collectives/collectives-polkadot/Cargo.toml | 1 - .../collectives/collectives-polkadot/tests/tests.rs | 2 +- system-parachains/coretime/coretime-kusama/Cargo.toml | 1 - system-parachains/coretime/coretime-polkadot/Cargo.toml | 1 - system-parachains/people/people-kusama/Cargo.toml | 1 - system-parachains/people/people-polkadot/Cargo.toml | 1 - 8 files changed, 1 insertion(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 015511b0e5..445f67794a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2727,7 +2727,6 @@ dependencies = [ name = "collectives-polkadot-runtime" version = "1.0.0" dependencies = [ - "asset-test-utils", "collectives-polkadot-runtime-constants", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -3016,7 +3015,6 @@ dependencies = [ name = "coretime-kusama-runtime" version = "1.0.0" dependencies = [ - "asset-test-utils", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", @@ -3124,7 +3122,6 @@ dependencies = [ name = "coretime-polkadot-runtime" version = "1.0.0" dependencies = [ - "asset-test-utils", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", @@ -10655,7 +10652,6 @@ dependencies = [ name = "people-kusama-runtime" version = "1.0.0" dependencies = [ - "asset-test-utils", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", @@ -10766,7 +10762,6 @@ dependencies = [ name = "people-polkadot-runtime" version = "1.0.0" dependencies = [ - "asset-test-utils", "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", "cumulus-pallet-session-benchmarking", diff --git a/integration-tests/emulated/helpers/Cargo.toml b/integration-tests/emulated/helpers/Cargo.toml index 331536b85c..e99d68cb69 100644 --- a/integration-tests/emulated/helpers/Cargo.toml +++ b/integration-tests/emulated/helpers/Cargo.toml @@ -19,7 +19,6 @@ pallet-message-queue = { workspace = true, default-features = true } xcm = { workspace = true, default-features = true } pallet-xcm = { workspace = true, default-features = true } - # Cumulus xcm-emulator = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true, default-features = true } diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index 52d2bdf498..0fd79f672d 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -86,7 +86,6 @@ parachains-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] -asset-test-utils = { workspace = true } collectives-polkadot-runtime-constants = { workspace = true } parachains-runtimes-test-utils = { workspace = true } sp-io = { workspace = true } diff --git a/system-parachains/collectives/collectives-polkadot/tests/tests.rs b/system-parachains/collectives/collectives-polkadot/tests/tests.rs index 77d904f25f..7b3d2d19ff 100644 --- a/system-parachains/collectives/collectives-polkadot/tests/tests.rs +++ b/system-parachains/collectives/collectives-polkadot/tests/tests.rs @@ -1,9 +1,9 @@ -use asset_test_utils::GovernanceOrigin; use collectives_polkadot_runtime::{ xcm_config::{AssetHubLocation, RelayChainLocation}, Runtime, RuntimeOrigin, }; use frame_support::{assert_err, assert_ok}; +use parachains_runtimes_test_utils::GovernanceOrigin; use sp_runtime::Either; use xcm::prelude::*; diff --git a/system-parachains/coretime/coretime-kusama/Cargo.toml b/system-parachains/coretime/coretime-kusama/Cargo.toml index 1fb1629c96..f6dbbbfeda 100644 --- a/system-parachains/coretime/coretime-kusama/Cargo.toml +++ b/system-parachains/coretime/coretime-kusama/Cargo.toml @@ -79,7 +79,6 @@ parachain-info = { workspace = true } parachains-common = { workspace = true } [dev-dependencies] -asset-test-utils = { workspace = true } parachains-runtimes-test-utils = { workspace = true } [build-dependencies] diff --git a/system-parachains/coretime/coretime-polkadot/Cargo.toml b/system-parachains/coretime/coretime-polkadot/Cargo.toml index 13b037a327..4cc3b0ce8b 100644 --- a/system-parachains/coretime/coretime-polkadot/Cargo.toml +++ b/system-parachains/coretime/coretime-polkadot/Cargo.toml @@ -80,7 +80,6 @@ parachain-info = { workspace = true } parachains-common = { workspace = true } [dev-dependencies] -asset-test-utils = { workspace = true } parachains-runtimes-test-utils = { workspace = true } [build-dependencies] diff --git a/system-parachains/people/people-kusama/Cargo.toml b/system-parachains/people/people-kusama/Cargo.toml index dca0d05485..09f8fedc44 100644 --- a/system-parachains/people/people-kusama/Cargo.toml +++ b/system-parachains/people/people-kusama/Cargo.toml @@ -79,7 +79,6 @@ parachains-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] -asset-test-utils = { workspace = true } parachains-runtimes-test-utils = { workspace = true } [build-dependencies] diff --git a/system-parachains/people/people-polkadot/Cargo.toml b/system-parachains/people/people-polkadot/Cargo.toml index 163e4567cf..7db48e50db 100644 --- a/system-parachains/people/people-polkadot/Cargo.toml +++ b/system-parachains/people/people-polkadot/Cargo.toml @@ -78,7 +78,6 @@ parachains-common = { workspace = true } system-parachains-constants = { workspace = true } [dev-dependencies] -asset-test-utils = { workspace = true } parachains-runtimes-test-utils = { workspace = true } [build-dependencies] From ee11d87ba86d79c5656e46055a9509c07331f5d7 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 4 Sep 2025 18:02:32 +0200 Subject: [PATCH 41/53] Apply suggestions from code review --- relay/kusama/src/lib.rs | 1 - relay/kusama/src/xcm_config.rs | 1 - relay/polkadot/src/xcm_config.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index be49496076..be6d671935 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -773,7 +773,6 @@ impl EnsureOriginWithArg for DynamicParamet match key { Inflation(_) => frame_system::ensure_root(origin.clone()), Treasury(_) => - // TODO: review - GeneralAdmin propagation from AssetHub? EitherOf::, GeneralAdmin>::ensure_origin(origin.clone()), } .map_err(|_| origin) diff --git a/relay/kusama/src/xcm_config.rs b/relay/kusama/src/xcm_config.rs index e03a9a8ae7..96cad024e7 100644 --- a/relay/kusama/src/xcm_config.rs +++ b/relay/kusama/src/xcm_config.rs @@ -275,7 +275,6 @@ pub type FellowsToPlurality = OriginToPluralityVoice; -// TODO: review - after AHM and gov migration - not a local pallets anymore /// Type to convert a pallet `Origin` type value into a `Location` value which represents an /// interior location of this chain for a destination chain. pub type LocalPalletOrSignedOriginToLocation = ( diff --git a/relay/polkadot/src/xcm_config.rs b/relay/polkadot/src/xcm_config.rs index d736c77e03..432085e733 100644 --- a/relay/polkadot/src/xcm_config.rs +++ b/relay/polkadot/src/xcm_config.rs @@ -303,7 +303,6 @@ pub type FellowshipAdminToPlurality = /// Type to convert the `Treasurer` origin to a Plurality `Location` value. pub type TreasurerToPlurality = OriginToPluralityVoice; -// TODO: review - after AHM and gov migration - not a local pallets anymore /// Type to convert a pallet `Origin` type value into a `Location` value which represents an /// interior location of this chain for a destination chain. pub type LocalPalletOrSignedOriginToLocation = ( From 8d8238fbbca1937cb3f824f2d480881194ae9a7d Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Thu, 4 Sep 2025 23:44:39 +0200 Subject: [PATCH 42/53] system-parachains/common/Cargo.toml cleanup --- Cargo.lock | 9 --------- system-parachains/common/Cargo.toml | 26 -------------------------- 2 files changed, 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90c9606c08..20870038c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16280,17 +16280,8 @@ dependencies = [ "cumulus-primitives-core", "frame-support", "log", - "pallet-treasury", - "parity-scale-codec", - "polkadot-runtime-common", - "scale-info", - "sp-api", - "sp-core 38.0.0", "sp-runtime", "sp-state-machine", - "sp-std", - "staging-xcm", - "staging-xcm-executor", ] [[package]] diff --git a/system-parachains/common/Cargo.toml b/system-parachains/common/Cargo.toml index 9d3001c3f8..97ed4888f2 100644 --- a/system-parachains/common/Cargo.toml +++ b/system-parachains/common/Cargo.toml @@ -8,61 +8,35 @@ repository.workspace = true version.workspace = true [dependencies] -codec = { features = ["derive", "max-encoded-len"], workspace = true } log = { workspace = true } -scale-info = { features = ["derive"], workspace = true } -sp-api = { workspace = true } sp-runtime = { workspace = true } -sp-core = { workspace = true } sp-state-machine = { workspace = true } -sp-std = { workspace = true } frame-support = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-primitives-core = { workspace = true } -pallet-treasury = { workspace = true } - -polkadot-runtime-common = { workspace = true } -xcm = { workspace = true } -xcm-executor = { workspace = true } - [features] default = ["std"] std = [ - "codec/std", "cumulus-pallet-parachain-system/std", "cumulus-primitives-core/std", "frame-support/std", "log/std", - "pallet-treasury/std", - "polkadot-runtime-common/std", - "scale-info/std", - "sp-api/std", - "sp-core/std", "sp-runtime/std", "sp-state-machine/std", - "sp-std/std", - "xcm-executor/std", - "xcm/std", ] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "frame-support/runtime-benchmarks", - "pallet-treasury/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", - "xcm/runtime-benchmarks", ] try-runtime = [ "cumulus-pallet-parachain-system/try-runtime", "frame-support/try-runtime", - "pallet-treasury/try-runtime", - "polkadot-runtime-common/try-runtime", "sp-runtime/try-runtime", ] From 3fee5dec90d22aedb8495507a31501e0bd7ff60c Mon Sep 17 00:00:00 2001 From: Karol Kokoszka Date: Fri, 5 Sep 2025 10:21:10 +0200 Subject: [PATCH 43/53] Allow respective VoiceOfBody for Staking/General Admin --- relay/kusama/src/lib.rs | 20 +++++++++++++------ relay/polkadot/src/lib.rs | 20 ++++++++++++++----- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 1 - 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index be6d671935..c208e9f605 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -73,7 +73,7 @@ use pallet_session::historical as session_historical; use pallet_staking::UseValidatorsMap; use pallet_transaction_payment::{FeeDetails, FungibleAdapter, RuntimeDispatchInfo}; use pallet_treasury::TreasuryAccountId; -use pallet_xcm::EnsureXcm; +use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use polkadot_primitives::{ slashing, vstaging::{ @@ -134,7 +134,7 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use xcm::prelude::*; use xcm_builder::PayOverXcm; -use xcm_config::AssetHubLocation; +use xcm_config::{AssetHubLocation, GeneralAdminBodyId, StakingAdminBodyId}; use xcm_runtime_apis::{ dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects}, fees::Error as XcmPaymentApiError, @@ -656,7 +656,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime { (), >; type BenchmarkingConfig = polkadot_runtime_common::elections::BenchmarkConfig; - type ForceOrigin = EitherOf, StakingAdmin>; + type ForceOrigin = EitherOfDiverse< + EitherOf, StakingAdmin>, + EnsureXcm>, + >; type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo; type MaxWinners = MaxWinnersPerPage; type ElectionBounds = ElectionBounds; @@ -869,7 +872,10 @@ impl pallet_staking::Config for Runtime { type SessionsPerEra = SessionsPerEra; type BondingDuration = BondingDuration; type SlashDeferDuration = SlashDeferDuration; - type AdminOrigin = EitherOf, StakingAdmin>; + type AdminOrigin = EitherOfDiverse< + EitherOf, StakingAdmin>, + EnsureXcm>, + >; type SessionInterface = Self; type EraPayout = EraPayout; type NextNewSession = Session; @@ -1510,8 +1516,10 @@ parameter_types! { impl parachains_hrmp::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; - // TODO: review - GeneralAdmin propagation from AssetHub? - type ChannelManager = EitherOf, GeneralAdmin>; + type ChannelManager = EitherOfDiverse< + EitherOf, GeneralAdmin>, + EnsureXcm>, + >; type Currency = Balances; // Use the `HrmpChannelSizeAndCapacityWithSystemRatio` ratio from the actual active // `HostConfiguration` configuration for `hrmp_channel_max_message_size` and diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index e750fede7e..9ffc8064f9 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -129,7 +129,9 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use xcm::prelude::*; use xcm_builder::PayOverXcm; -use xcm_config::{AssetHubLocation, CollectivesLocation, FellowsBodyId}; +use xcm_config::{ + AssetHubLocation, CollectivesLocation, FellowsBodyId, GeneralAdminBodyId, StakingAdminBodyId, +}; use xcm_runtime_apis::{ dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects}, fees::Error as XcmPaymentApiError, @@ -642,7 +644,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime { (), >; type BenchmarkingConfig = polkadot_runtime_common::elections::BenchmarkConfig; - type ForceOrigin = EitherOf, StakingAdmin>; + type ForceOrigin = EitherOfDiverse< + EitherOf, StakingAdmin>, + EnsureXcm>, + >; type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo; type ElectionBounds = ElectionBounds; } @@ -741,7 +746,10 @@ impl pallet_staking::Config for Runtime { type SessionsPerEra = SessionsPerEra; type BondingDuration = BondingDuration; type SlashDeferDuration = SlashDeferDuration; - type AdminOrigin = EitherOf, StakingAdmin>; + type AdminOrigin = EitherOfDiverse< + EitherOf, StakingAdmin>, + EnsureXcm>, + >; type SessionInterface = Self; type EraPayout = EraPayout; type MaxExposurePageSize = MaxExposurePageSize; @@ -1313,8 +1321,10 @@ parameter_types! { impl parachains_hrmp::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeEvent = RuntimeEvent; - // TODO: review - GeneralAdmin propagation from AssetHub? - type ChannelManager = EitherOf, GeneralAdmin>; + type ChannelManager = EitherOfDiverse< + EitherOf, GeneralAdmin>, + EnsureXcm>, + >; type Currency = Balances; // Use the `HrmpChannelSizeAndCapacityWithSystemRatio` ratio from the actual active // `HostConfiguration` configuration for `hrmp_channel_max_message_size` and diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index f6fba97fec..1f41a7654e 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -574,7 +574,6 @@ impl InstanceFilter for ProxyType { RuntimeCall::Utility(_) | RuntimeCall::Multisig(_) | RuntimeCall::Proxy(_) | - RuntimeCall::Staking(_) | // TODO @ggwpez add more RuntimeCall::Staking(_) | RuntimeCall::Bounties(..) | From 7f90e0805d083bafd5795b016dd80d546ddaf6ef Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 11:37:17 +0200 Subject: [PATCH 44/53] Removed TODO --- .../asset-hubs/asset-hub-polkadot/src/governance/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs index f507edeac4..827845ec5f 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/governance/mod.rs @@ -40,7 +40,6 @@ impl pallet_conviction_voting::Config for Runtime { type Currency = Balances; type VoteLockingPeriod = VoteLockingPeriod; type MaxVotes = ConstU32<512>; - // TODO: review - after/before migration check? type MaxTurnout = frame_support::traits::tokens::currency::ActiveIssuanceOf; type Polls = Referenda; From b7adb6358d8f149363b75a617259285bf7a2008e Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 11:40:47 +0200 Subject: [PATCH 45/53] Fix CollatorSelectionUpdateOrigin for AHP --- system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 1f41a7654e..a16fc0f89e 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -876,7 +876,12 @@ parameter_types! { /// We allow root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOfDiverse< + // Allow StakingAdmin from OpenGov on RC + EnsureXcm>, + // Allow StakingAdmin from OpenGov on AH (local) + StakingAdmin, + >, >; impl pallet_collator_selection::Config for Runtime { From c69b8657bfe986b3ca4e66feb6083f626dd6d1f7 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 12:34:00 +0200 Subject: [PATCH 46/53] Allow `FellowshipAdmin` origin/track propagation from AHK to Kusama --- relay/kusama/constants/Cargo.toml | 3 +++ relay/kusama/constants/src/lib.rs | 10 +++++++++ relay/kusama/src/governance/fellowship.rs | 21 +++++++++++++++++-- .../asset-hubs/asset-hub-kusama/src/lib.rs | 2 +- .../asset-hub-kusama/src/xcm_config.rs | 13 +++++++++--- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/relay/kusama/constants/Cargo.toml b/relay/kusama/constants/Cargo.toml index d696045292..de4e95788f 100644 --- a/relay/kusama/constants/Cargo.toml +++ b/relay/kusama/constants/Cargo.toml @@ -20,6 +20,7 @@ sp-core = { workspace = true } sp-trie = { workspace = true, optional = true } pallet-remote-proxy = { workspace = true } +xcm = { workspace = true } xcm-builder = { workspace = true } [features] @@ -36,6 +37,7 @@ std = [ "sp-trie?/std", "sp-weights/std", "xcm-builder/std", + "xcm/std", ] fast-runtime = [] runtime-benchmarks = [ @@ -46,4 +48,5 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "sp-trie", "xcm-builder/runtime-benchmarks", + "xcm/runtime-benchmarks", ] diff --git a/relay/kusama/constants/src/lib.rs b/relay/kusama/constants/src/lib.rs index a40039952f..a2d5b7b120 100644 --- a/relay/kusama/constants/src/lib.rs +++ b/relay/kusama/constants/src/lib.rs @@ -267,6 +267,16 @@ pub mod proxy { } } +/// XCM protocol related constants. +pub mod xcm { + /// Pluralistic bodies existing within the consensus. + pub mod body { + // The body corresponding to the Kusama OpenGov FellowshipAdmin Origin. + pub const KUSAMA_FELLOWSHIP_ADMIN_BODY_ID: xcm::latest::BodyId = + xcm::latest::BodyId::Moniker([b'k', b'f', b'a', b'b']); + } +} + #[cfg(test)] mod tests { use super::{ diff --git a/relay/kusama/src/governance/fellowship.rs b/relay/kusama/src/governance/fellowship.rs index 1b07e621f4..79a2a2ba53 100644 --- a/relay/kusama/src/governance/fellowship.rs +++ b/relay/kusama/src/governance/fellowship.rs @@ -33,6 +33,7 @@ parameter_types! { pub const AlarmInterval: BlockNumber = 1; pub const SubmissionDeposit: Balance = 0; pub const UndecidingTimeout: BlockNumber = 7 * DAYS; + pub const FellowshipAdminBodyId: BodyId = kusama_runtime_constants::xcm::body::KUSAMA_FELLOWSHIP_ADMIN_BODY_ID; } const TRACKS_DATA: [pallet_referenda::Track; 10] = [ @@ -340,7 +341,15 @@ impl pallet_ranked_collective::Config for Runtime type PromoteOrigin = EitherOf< frame_system::EnsureRootWithSuccess>, EitherOf< - MapSuccess>>, + EitherOf< + // Allow FellowshipAdmin from OpenGov on RC + MapSuccess>>, + // Allow FellowshipAdmin from OpenGov on AH + MapSuccess< + EnsureXcm>, + Replace>, + >, + >, TryMapSuccess>>, >, >; @@ -351,7 +360,15 @@ impl pallet_ranked_collective::Config for Runtime type DemoteOrigin = EitherOf< frame_system::EnsureRootWithSuccess>, EitherOf< - MapSuccess>>, + EitherOf< + // Allow FellowshipAdmin from OpenGov on RC + MapSuccess>>, + // Allow FellowshipAdmin from OpenGov on AH + MapSuccess< + EnsureXcm>, + Replace>, + >, + >, TryMapSuccess>>, >, >; diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 6f6bdc6dbd..28e191701e 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -71,7 +71,7 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, EnsureSignedBy, }; -use governance::{pallet_custom_origins, GeneralAdmin, StakingAdmin, Treasurer}; +use governance::{pallet_custom_origins, FellowshipAdmin, GeneralAdmin, StakingAdmin, Treasurer}; use kusama_runtime_constants::time::{DAYS as RC_DAYS, HOURS as RC_HOURS, MINUTES as RC_MINUTES}; use pallet_assets::precompiles::{InlineIdConfig, ERC20}; use pallet_nfts::PalletFeatures; diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 4f869e6313..5ca66ead24 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -18,9 +18,9 @@ pub use TreasuryAccount as RelayTreasuryPalletAccount; use super::{ AccountId, AllPalletsWithSystem, AssetConversion, Assets, Balance, Balances, CollatorSelection, - GeneralAdmin, NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, - PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, - StakingAdmin, ToPolkadotXcmRouter, WeightToFee, XcmpQueue, + FellowshipAdmin, GeneralAdmin, NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm, + PoolAssets, PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, + RuntimeOrigin, StakingAdmin, ToPolkadotXcmRouter, WeightToFee, XcmpQueue, }; use crate::ForeignAssets; use alloc::{vec, vec::Vec}; @@ -445,6 +445,8 @@ parameter_types! { pub const FellowsBodyId: BodyId = BodyId::Technical; // `GeneralAdmin` pluralistic body. pub const GeneralAdminBodyId: BodyId = BodyId::Administration; + // `FellowshipAdmin` pluralistic body. + pub const FellowshipAdminBodyId: BodyId = kusama_runtime_constants::xcm::body::KUSAMA_FELLOWSHIP_ADMIN_BODY_ID; } /// Type to convert the `StakingAdmin` origin to a Plurality `Location` value. @@ -454,6 +456,9 @@ pub type StakingAdminToPlurality = /// Type to convert the `GeneralAdmin` origin to a Plurality `Location` value. pub type GeneralAdminToPlurality = OriginToPluralityVoice; +/// Type to convert the `FellowshipAdmin` origin to a Plurality `Location` value. +pub type FellowshipAdminToPlurality = + OriginToPluralityVoice; /// Converts a local signed origin into an XCM `Location`. /// Forms the basis for local origins sending/executing XCMs. @@ -466,6 +471,8 @@ pub type LocalPalletOrSignedOriginToLocation = ( GeneralAdminToPlurality, // StakingAdmin origin to be used in XCM as a corresponding Plurality `Location` value. StakingAdminToPlurality, + // FellowshipAdmin origin to be used in XCM as a corresponding Plurality `Location` value. + FellowshipAdminToPlurality, // And a usual Signed origin to be used in XCM as a corresponding `AccountId32`. SignedToAccountId32, ); From e3ab2355f74b7b510f4c0e1cf0c594d1f1a99313 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 12:53:39 +0200 Subject: [PATCH 47/53] More tests nits + Cargo.lock --- Cargo.lock | 1 + .../asset-hubs/asset-hub-kusama/tests/tests.rs | 3 +-- .../asset-hubs/asset-hub-polkadot/tests/tests.rs | 10 +++++++++- .../bridge-hubs/bridge-hub-kusama/tests/tests.rs | 3 +-- .../bridge-hubs/bridge-hub-polkadot/tests/tests.rs | 10 +++++++++- .../collectives/collectives-polkadot/tests/tests.rs | 10 +++++++++- .../coretime/coretime-kusama/src/tests.rs | 3 +-- .../coretime/coretime-polkadot/src/tests.rs | 10 +++++++++- system-parachains/encointer/tests/tests.rs | 3 +-- system-parachains/people/people-kusama/src/tests.rs | 3 +-- system-parachains/people/people-polkadot/src/tests.rs | 10 +++++++++- 11 files changed, 51 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 20870038c0..1efaf21c3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6906,6 +6906,7 @@ dependencies = [ "sp-runtime", "sp-trie", "sp-weights", + "staging-xcm", "staging-xcm-builder", ] diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index ade079686c..6779a57bd2 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -891,13 +891,12 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), Either::Right(InstructionError { index: 1, error: XcmError::BadOrigin }) ); diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index 293b9d6186..09462158fd 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -904,7 +904,7 @@ fn authorized_aliases_work() { fn governance_authorize_upgrade_works() { use polkadot_runtime_constants::system_parachain::{ASSET_HUB_ID, COLLECTIVES_ID}; - // no - random para + // no - random non-system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, @@ -912,6 +912,14 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); + // no - random system para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), + Either::Right(InstructionError { index: 1, error: XcmError::BadOrigin }) + ); // no - AssetHub assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index d8687ad53d..e4939ae00b 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -590,13 +590,12 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 0351ab5062..ebbeada457 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -575,7 +575,7 @@ fn xcm_payment_api_works() { fn governance_authorize_upgrade_works() { use polkadot_runtime_constants::system_parachain::COLLECTIVES_ID; - // no - random para + // no - random non-system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, @@ -583,6 +583,14 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); + // no - random system para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), + Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) + ); // no - Collectives assert_err!( diff --git a/system-parachains/collectives/collectives-polkadot/tests/tests.rs b/system-parachains/collectives/collectives-polkadot/tests/tests.rs index 7b3d2d19ff..e2c00906f3 100644 --- a/system-parachains/collectives/collectives-polkadot/tests/tests.rs +++ b/system-parachains/collectives/collectives-polkadot/tests/tests.rs @@ -11,7 +11,7 @@ use xcm::prelude::*; fn governance_authorize_upgrade_works() { use polkadot_runtime_constants::system_parachain::COLLECTIVES_ID; - // no - random para + // no - random non-system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, @@ -19,6 +19,14 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); + // no - random system para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), + Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) + ); // no - Collectives assert_err!( diff --git a/system-parachains/coretime/coretime-kusama/src/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index 9d182ac878..d1927ed6f4 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -257,13 +257,12 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); diff --git a/system-parachains/coretime/coretime-polkadot/src/tests.rs b/system-parachains/coretime/coretime-polkadot/src/tests.rs index 6af0df632c..cca2827dbd 100644 --- a/system-parachains/coretime/coretime-polkadot/src/tests.rs +++ b/system-parachains/coretime/coretime-polkadot/src/tests.rs @@ -251,7 +251,7 @@ fn xcm_payment_api_works() { fn governance_authorize_upgrade_works() { use polkadot_runtime_constants::system_parachain::COLLECTIVES_ID; - // no - random para + // no - random non-system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, @@ -259,6 +259,14 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); + // no - random system para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), + Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) + ); // no - Collectives assert_err!( diff --git a/system-parachains/encointer/tests/tests.rs b/system-parachains/encointer/tests/tests.rs index 4a5666b256..c1cbf52b72 100644 --- a/system-parachains/encointer/tests/tests.rs +++ b/system-parachains/encointer/tests/tests.rs @@ -17,13 +17,12 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); diff --git a/system-parachains/people/people-kusama/src/tests.rs b/system-parachains/people/people-kusama/src/tests.rs index 1af5c1a2f0..0bf46f955e 100644 --- a/system-parachains/people/people-kusama/src/tests.rs +++ b/system-parachains/people/people-kusama/src/tests.rs @@ -150,13 +150,12 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); diff --git a/system-parachains/people/people-polkadot/src/tests.rs b/system-parachains/people/people-polkadot/src/tests.rs index d9cab92f9e..3604f67f85 100644 --- a/system-parachains/people/people-polkadot/src/tests.rs +++ b/system-parachains/people/people-polkadot/src/tests.rs @@ -144,7 +144,7 @@ fn xcm_payment_api_works() { fn governance_authorize_upgrade_works() { use polkadot_runtime_constants::system_parachain::COLLECTIVES_ID; - // no - random para + // no - random non-system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, @@ -152,6 +152,14 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); + // no - random system para + assert_err!( + parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< + Runtime, + RuntimeOrigin, + >(GovernanceOrigin::Location(Location::new(1, Parachain(1765)))), + Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) + ); // no - Collectives assert_err!( From 403ce0256700bbe292c14ef1edbc6b7ada1c94db Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 13:05:30 +0200 Subject: [PATCH 48/53] Removed TODO --- .../tests/people/people-kusama/src/tests/governance.rs | 5 +---- .../asset-hubs/asset-hub-polkadot/src/xcm_config.rs | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs index a1d8ee136b..c7bfe59e55 100644 --- a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs @@ -398,10 +398,7 @@ fn relay_commands_add_remove_username_authority() { UnpaidExecution { weight_limit: Unlimited, check_origin: None }, Transact { origin_kind, - // TODO: - // this and all other references to `require_weight_at_most` can be - // removed once XCMv5 is in use. - fallback_max_weight: Some(Weight::from_parts(500_000_000, 500_000)), + fallback_max_weight: None, call: remove_username_authority.encode().into(), } ]))), diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index db686014be..7f1a44ad8d 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -48,7 +48,6 @@ use parachains_common::xcm_config::{ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::{ system_parachain, - // TODO: check this? xcm::body::FELLOWSHIP_ADMIN_INDEX, }; use snowbridge_outbound_queue_primitives::v2::exporter::PausableExporter; From 2b952876cea3a3b3b840faae21910afd8a63a66d Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 13:50:56 +0200 Subject: [PATCH 49/53] Add LocalPlurality to WaivedLocations for free sending xcm from referenda --- .../asset-hubs/asset-hub-kusama/src/xcm_config.rs | 8 ++++++++ .../asset-hubs/asset-hub-polkadot/src/xcm_config.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 5ca66ead24..4513aa7fba 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -277,6 +277,13 @@ impl Contains for ParentOrParentsPlurality { } } +pub struct LocalPlurality; +impl Contains for LocalPlurality { + fn contains(loc: &Location) -> bool { + matches!(loc.unpack(), (0, [Plurality { .. }])) + } +} + /// Location type to determine the Technical Fellowship related /// pallets for use in XCM. pub struct FellowshipEntities; @@ -327,6 +334,7 @@ pub type WaivedLocations = ( RelayOrOtherSystemParachains, Equals, FellowshipEntities, + LocalPlurality, ); /// Cases where a remote origin is accepted as trusted Teleporter for a given asset: diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index 7f1a44ad8d..b23a409b44 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -358,6 +358,13 @@ impl Contains for ParentOrParentsPlurality { } } +pub struct LocalPlurality; +impl Contains for LocalPlurality { + fn contains(loc: &Location) -> bool { + matches!(loc.unpack(), (0, [Plurality { .. }])) + } +} + pub type Barrier = TrailingSetTopicAsId< DenyThenTry< DenyReserveTransferToRelayChain, @@ -404,6 +411,7 @@ pub type WaivedLocations = ( FellowshipEntities, AmbassadorEntities, SecretaryEntities, + LocalPlurality, ); /// Cases where a remote origin is accepted as trusted Teleporter for a given asset: From adaa515e358858aeb2e87692f986ab89bc21a336 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 13:51:41 +0200 Subject: [PATCH 50/53] System paras accept AssetHubPlurality for UnpaidExecution --- system-parachains/constants/src/kusama.rs | 19 ++++++++++++++++++- system-parachains/constants/src/polkadot.rs | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/system-parachains/constants/src/kusama.rs b/system-parachains/constants/src/kusama.rs index aec6925382..65c112269f 100644 --- a/system-parachains/constants/src/kusama.rs +++ b/system-parachains/constants/src/kusama.rs @@ -145,7 +145,7 @@ pub mod fee { } pub mod locations { - use frame_support::parameter_types; + use frame_support::{parameter_types, traits::Contains}; pub use kusama_runtime_constants::system_parachain::{AssetHubParaId, PeopleParaId}; use xcm::latest::prelude::{Junction::*, Location}; @@ -156,4 +156,21 @@ pub mod locations { pub PeopleLocation: Location = Location::new(1, Parachain(kusama_runtime_constants::system_parachain::PEOPLE_ID)); } + + /// `Contains` implementation for the asset hub location pluralities. + pub struct AssetHubPlurality; + impl Contains for AssetHubPlurality { + fn contains(loc: &Location) -> bool { + matches!( + loc.unpack(), + ( + 1, + [ + Parachain(kusama_runtime_constants::system_parachain::ASSET_HUB_ID), + Plurality { .. } + ] + ) + ) + } + } } diff --git a/system-parachains/constants/src/polkadot.rs b/system-parachains/constants/src/polkadot.rs index ab588c99c3..6c7e1f4cb8 100644 --- a/system-parachains/constants/src/polkadot.rs +++ b/system-parachains/constants/src/polkadot.rs @@ -165,7 +165,7 @@ pub mod fee { } pub mod locations { - use frame_support::parameter_types; + use frame_support::{parameter_types, traits::Contains}; use xcm::latest::prelude::{Junction::*, Location, NetworkId}; parameter_types! { @@ -179,4 +179,21 @@ pub mod locations { pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 1 }; } + + /// `Contains` implementation for the asset hub location pluralities. + pub struct AssetHubPlurality; + impl Contains for AssetHubPlurality { + fn contains(loc: &Location) -> bool { + matches!( + loc.unpack(), + ( + 1, + [ + Parachain(polkadot_runtime_constants::system_parachain::ASSET_HUB_ID), + Plurality { .. } + ] + ) + ) + } + } } From 0f6e9c1083225250551400b2256be65dad37a9ea Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 14:00:49 +0200 Subject: [PATCH 51/53] Allow unpaid execution for all system parachains for AssetHubPlurality --- .../bridge-hubs/bridge-hub-kusama/src/xcm_config.rs | 5 ++++- .../bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs | 5 ++++- .../collectives/collectives-polkadot/src/xcm_config.rs | 5 ++++- system-parachains/coretime/coretime-kusama/src/xcm_config.rs | 5 ++++- .../coretime/coretime-polkadot/src/xcm_config.rs | 5 ++++- system-parachains/encointer/src/xcm_config.rs | 5 ++++- system-parachains/people/people-kusama/src/xcm_config.rs | 5 ++++- system-parachains/people/people-polkadot/src/xcm_config.rs | 5 ++++- 8 files changed, 32 insertions(+), 8 deletions(-) diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index 9bc1e0308e..9e1fc70a7e 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -36,7 +36,9 @@ use parachains_common::xcm_config::{ }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::AccountIdConversion; -pub use system_parachains_constants::kusama::locations::{AssetHubLocation, RelayChainLocation}; +pub use system_parachains_constants::kusama::locations::{ + AssetHubLocation, AssetHubPlurality, RelayChainLocation, +}; use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ @@ -151,6 +153,7 @@ pub type Barrier = TrailingSetTopicAsId< ParentOrParentsPlurality, Equals, Equals, + AssetHubPlurality, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 1b367829d5..527331603f 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -55,7 +55,9 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::polkadot::locations::{AssetHubLocation, RelayChainLocation}; +pub use system_parachains_constants::polkadot::locations::{ + AssetHubLocation, AssetHubPlurality, RelayChainLocation, +}; parameter_types! { pub const RootLocation: Location = Location::here(); @@ -184,6 +186,7 @@ pub type Barrier = TrailingSetTopicAsId< FellowsPlurality, Equals, Equals, + AssetHubPlurality, Equals, )>, // Subscriptions for version tracking are OK. diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index 25fdd05a97..eab99c074c 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -51,7 +51,9 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::polkadot::locations::{AssetHubLocation, RelayChainLocation}; +pub use system_parachains_constants::polkadot::locations::{ + AssetHubLocation, AssetHubPlurality, RelayChainLocation, +}; parameter_types! { pub const RootLocation: Location = Location::here(); @@ -175,6 +177,7 @@ pub type Barrier = TrailingSetTopicAsId< ParentOrParentsPlurality, Equals, Equals, + AssetHubPlurality, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, diff --git a/system-parachains/coretime/coretime-kusama/src/xcm_config.rs b/system-parachains/coretime/coretime-kusama/src/xcm_config.rs index 4a847b7d27..121172c155 100644 --- a/system-parachains/coretime/coretime-kusama/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-kusama/src/xcm_config.rs @@ -51,7 +51,9 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::kusama::locations::{AssetHubLocation, RelayChainLocation}; +pub use system_parachains_constants::kusama::locations::{ + AssetHubLocation, AssetHubPlurality, RelayChainLocation, +}; parameter_types! { pub const RootLocation: Location = Location::here(); @@ -166,6 +168,7 @@ pub type Barrier = TrailingSetTopicAsId< ParentOrParentsPlurality, // For OpenGov on AH Equals, + AssetHubPlurality, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, diff --git a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs index 48c4922b79..05fbe71667 100644 --- a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs @@ -52,7 +52,9 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::polkadot::locations::{AssetHubLocation, RelayChainLocation}; +pub use system_parachains_constants::polkadot::locations::{ + AssetHubLocation, AssetHubPlurality, RelayChainLocation, +}; parameter_types! { pub const RootLocation: Location = Location::here(); @@ -186,6 +188,7 @@ pub type Barrier = TrailingSetTopicAsId< FellowsPlurality, Equals, Equals, + AssetHubPlurality, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, diff --git a/system-parachains/encointer/src/xcm_config.rs b/system-parachains/encointer/src/xcm_config.rs index 808b8d93d6..b29ac10db4 100644 --- a/system-parachains/encointer/src/xcm_config.rs +++ b/system-parachains/encointer/src/xcm_config.rs @@ -48,7 +48,9 @@ use xcm_builder::{ }; use xcm_executor::XcmExecutor; -pub use system_parachains_constants::kusama::locations::{AssetHubLocation, RelayChainLocation}; +pub use system_parachains_constants::kusama::locations::{ + AssetHubLocation, AssetHubPlurality, RelayChainLocation, +}; parameter_types! { pub const KsmLocation: Location = Location::parent(); @@ -148,6 +150,7 @@ pub type Barrier = TrailingSetTopicAsId< ParentOrParentsPlurality, // For OpenGov on AH Equals, + AssetHubPlurality, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, diff --git a/system-parachains/people/people-kusama/src/xcm_config.rs b/system-parachains/people/people-kusama/src/xcm_config.rs index d9b187a48b..0ea7ee1c3a 100644 --- a/system-parachains/people/people-kusama/src/xcm_config.rs +++ b/system-parachains/people/people-kusama/src/xcm_config.rs @@ -37,7 +37,9 @@ use parachains_common::{ }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::AccountIdConversion; -pub use system_parachains_constants::kusama::locations::{AssetHubLocation, RelayChainLocation}; +pub use system_parachains_constants::kusama::locations::{ + AssetHubLocation, AssetHubPlurality, RelayChainLocation, +}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, @@ -178,6 +180,7 @@ pub type Barrier = TrailingSetTopicAsId< ParentOrParentsPlurality, // For OpenGov on AH Equals, + AssetHubPlurality, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, diff --git a/system-parachains/people/people-polkadot/src/xcm_config.rs b/system-parachains/people/people-polkadot/src/xcm_config.rs index bb2dba2dae..8cdb80e3c7 100644 --- a/system-parachains/people/people-polkadot/src/xcm_config.rs +++ b/system-parachains/people/people-polkadot/src/xcm_config.rs @@ -53,7 +53,9 @@ use xcm_builder::{ }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::polkadot::locations::{AssetHubLocation, RelayChainLocation}; +pub use system_parachains_constants::polkadot::locations::{ + AssetHubLocation, AssetHubPlurality, RelayChainLocation, +}; parameter_types! { pub const RootLocation: Location = Location::here(); @@ -198,6 +200,7 @@ pub type Barrier = TrailingSetTopicAsId< FellowsPlurality, Equals, Equals, + AssetHubPlurality, )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, From 529f901158e10120c265d93673447d6e0e2a4519 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 14:08:43 +0200 Subject: [PATCH 52/53] Add integration test for propagating unpaid plurality execution from OpenGov AH --- .../tests/people/people-kusama/Cargo.toml | 2 + .../people-kusama/src/tests/governance.rs | 63 ++++++++++++++++++- .../tests/people/people-polkadot/Cargo.toml | 2 + .../people-polkadot/src/tests/governance.rs | 63 ++++++++++++++++++- 4 files changed, 124 insertions(+), 6 deletions(-) diff --git a/integration-tests/emulated/tests/people/people-kusama/Cargo.toml b/integration-tests/emulated/tests/people/people-kusama/Cargo.toml index d3d4e4af42..90c6d7500d 100644 --- a/integration-tests/emulated/tests/people/people-kusama/Cargo.toml +++ b/integration-tests/emulated/tests/people/people-kusama/Cargo.toml @@ -31,6 +31,7 @@ asset-test-utils = { workspace = true } cumulus-pallet-parachain-system = { workspace = true, default-features = true } # Local +asset-hub-kusama-runtime = { workspace = true } kusama-runtime-constants = { workspace = true, default-features = true } kusama-runtime = { workspace = true } integration-tests-helpers = { workspace = true } @@ -39,6 +40,7 @@ kusama-system-emulated-network = { workspace = true } [features] runtime-benchmarks = [ + "asset-hub-kusama-runtime/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "frame-support/runtime-benchmarks", "integration-tests-helpers/runtime-benchmarks", diff --git a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs index c7bfe59e55..2b11e95570 100644 --- a/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-kusama/src/tests/governance.rs @@ -14,9 +14,10 @@ // limitations under the License. use crate::*; +use asset_hub_kusama_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOriginFromAssetHub; use emulated_integration_tests_common::accounts::{ALICE, BOB}; use frame_support::sp_runtime::traits::Dispatchable; -use kusama_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; +use kusama_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOriginFromRelay; use kusama_system_emulated_network::kusama_emulated_chain::kusama_runtime::Dmp; use pallet_identity::Data; use people_kusama_runtime::people::IdentityInfo; @@ -24,7 +25,7 @@ use people_kusama_runtime::people::IdentityInfo; #[test] fn relay_commands_add_registrar() { let origins = vec![ - (OriginKind::Xcm, GeneralAdminOrigin.into()), + (OriginKind::Xcm, GeneralAdminOriginFromRelay.into()), (OriginKind::Superuser, ::RuntimeOrigin::root()), ]; for (origin_kind, origin) in origins { @@ -78,6 +79,62 @@ fn relay_commands_add_registrar() { } } +#[test] +fn asset_hub_commands_add_registrar() { + let origins = vec![ + (OriginKind::Xcm, GeneralAdminOriginFromAssetHub.into()), + (OriginKind::Superuser, ::RuntimeOrigin::root()), + ]; + for (origin_kind, origin) in origins { + let registrar: AccountId = [1; 32].into(); + AssetHubKusama::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_registrar_call = + PeopleCall::Identity(pallet_identity::Call::::add_registrar { + account: registrar.into(), + }); + + let xcm_message = RuntimeCall::PolkadotXcm(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(1, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + fallback_max_weight: None, + call: add_registrar_call.encode().into(), + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + AssetHubKusama, + vec![ + RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleKusama, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::RegistrarAdded { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); + } +} + #[test] fn relay_commands_add_registrar_wrong_origin() { let people_kusama_alice = PeopleKusama::account_id_of(ALICE); @@ -280,7 +337,7 @@ fn relay_commands_add_remove_username_authority() { let people_kusama_bob = PeopleKusama::account_id_of(BOB); let origins = vec![ - (OriginKind::Xcm, GeneralAdminOrigin.into(), "generaladmin.suffix1"), + (OriginKind::Xcm, GeneralAdminOriginFromRelay.into(), "generaladmin.suffix1"), (OriginKind::Superuser, ::RuntimeOrigin::root(), "rootusername.suffix1"), ]; for (origin_kind, origin, usr) in origins { diff --git a/integration-tests/emulated/tests/people/people-polkadot/Cargo.toml b/integration-tests/emulated/tests/people/people-polkadot/Cargo.toml index 04660bc170..2970e3ada2 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/Cargo.toml +++ b/integration-tests/emulated/tests/people/people-polkadot/Cargo.toml @@ -31,6 +31,7 @@ asset-test-utils = { workspace = true } cumulus-pallet-parachain-system = { workspace = true, default-features = true } # Local +asset-hub-polkadot-runtime = { workspace = true } polkadot-runtime-constants = { workspace = true, default-features = true } polkadot-runtime = { workspace = true } integration-tests-helpers = { workspace = true } @@ -39,6 +40,7 @@ polkadot-system-emulated-network = { workspace = true } [features] runtime-benchmarks = [ + "asset-hub-polkadot-runtime/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "frame-support/runtime-benchmarks", "integration-tests-helpers/runtime-benchmarks", diff --git a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs index 7d8c6d054d..764700bc2a 100644 --- a/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs +++ b/integration-tests/emulated/tests/people/people-polkadot/src/tests/governance.rs @@ -14,17 +14,18 @@ // limitations under the License. use crate::*; +use asset_hub_polkadot_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOriginFromAssetHub; use emulated_integration_tests_common::accounts::{ALICE, BOB}; use frame_support::sp_runtime::traits::Dispatchable; use pallet_identity::Data; use people_polkadot_runtime::people::IdentityInfo; -use polkadot_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; +use polkadot_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOriginFromRelay; use polkadot_system_emulated_network::polkadot_emulated_chain::polkadot_runtime::Dmp; #[test] fn relay_commands_add_registrar() { let origins = vec![ - (OriginKind::Xcm, GeneralAdminOrigin.into()), + (OriginKind::Xcm, GeneralAdminOriginFromRelay.into()), (OriginKind::Superuser, ::RuntimeOrigin::root()), ]; for (origin_kind, origin) in origins { @@ -78,6 +79,62 @@ fn relay_commands_add_registrar() { } } +#[test] +fn asset_hub_commands_add_registrar() { + let origins = vec![ + (OriginKind::Xcm, GeneralAdminOriginFromAssetHub.into()), + (OriginKind::Superuser, ::RuntimeOrigin::root()), + ]; + for (origin_kind, origin) in origins { + let registrar: AccountId = [1; 32].into(); + AssetHubPolkadot::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_registrar_call = + PeopleCall::Identity(pallet_identity::Call::::add_registrar { + account: registrar.into(), + }); + + let xcm_message = RuntimeCall::PolkadotXcm(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(1, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + fallback_max_weight: None, + call: add_registrar_call.encode().into(), + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + AssetHubPolkadot, + vec![ + RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeoplePolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeoplePolkadot, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::RegistrarAdded { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); + } +} + #[test] fn relay_commands_add_registrar_wrong_origin() { let people_polkadot_alice = PeoplePolkadot::account_id_of(ALICE); @@ -284,7 +341,7 @@ fn relay_commands_add_remove_username_authority() { let people_polkadot_bob = PeoplePolkadot::account_id_of(BOB); let origins = vec![ - (OriginKind::Xcm, GeneralAdminOrigin.into(), "generaladmin.suffix1"), + (OriginKind::Xcm, GeneralAdminOriginFromRelay.into(), "generaladmin.suffix1"), (OriginKind::Superuser, ::RuntimeOrigin::root(), "rootusername.suffix1"), ]; for (origin_kind, origin, usr) in origins { From 123012b41e570e83dc833db95ef44bb50bdb94fe Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 5 Sep 2025 14:26:36 +0200 Subject: [PATCH 53/53] Allow unpaid execution on relaychains for AssetHubPlurality --- relay/kusama/src/xcm_config.rs | 9 ++++++++- relay/polkadot/src/xcm_config.rs | 13 ++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/relay/kusama/src/xcm_config.rs b/relay/kusama/src/xcm_config.rs index 4de2afb6ac..cc2d6a5a4f 100644 --- a/relay/kusama/src/xcm_config.rs +++ b/relay/kusama/src/xcm_config.rs @@ -177,6 +177,13 @@ impl Contains for LocalPlurality { } } +pub struct AssetHubPlurality; +impl Contains for AssetHubPlurality { + fn contains(loc: &Location) -> bool { + matches!(loc.unpack(), (0, [Parachain(ASSET_HUB_ID), Plurality { .. }])) + } +} + /// The barriers one of which must be passed for an XCM message to be executed. pub type Barrier = TrailingSetTopicAsId<( // Weight that is paid for may be consumed. @@ -188,7 +195,7 @@ pub type Barrier = TrailingSetTopicAsId<( // If the message is one that immediately attempts to pay for execution, then allow it. AllowTopLevelPaidExecutionFrom, // Messages coming from system parachains need not pay for execution. - AllowExplicitUnpaidExecutionFrom>, + AllowExplicitUnpaidExecutionFrom<(IsChildSystemParachain, AssetHubPlurality)>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, ), diff --git a/relay/polkadot/src/xcm_config.rs b/relay/polkadot/src/xcm_config.rs index 432085e733..44148491ea 100644 --- a/relay/polkadot/src/xcm_config.rs +++ b/relay/polkadot/src/xcm_config.rs @@ -195,6 +195,13 @@ impl Contains for LocalPlurality { } } +pub struct AssetHubPlurality; +impl Contains for AssetHubPlurality { + fn contains(loc: &Location) -> bool { + matches!(loc.unpack(), (0, [Parachain(ASSET_HUB_ID), Plurality { .. }])) + } +} + /// The barriers one of which must be passed for an XCM message to be executed. pub type Barrier = TrailingSetTopicAsId<( // Weight that is paid for may be consumed. @@ -208,7 +215,11 @@ pub type Barrier = TrailingSetTopicAsId<( // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, // Messages from system parachains or the Fellows plurality need not pay for execution. - AllowExplicitUnpaidExecutionFrom<(IsChildSystemParachain, Fellows)>, + AllowExplicitUnpaidExecutionFrom<( + IsChildSystemParachain, + Fellows, + AssetHubPlurality, + )>, ), UniversalLocation, ConstU32<8>,