diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c3e9c8821..9cc2ca6003 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added + +- Test cases for all system chains to verify if parachain is able to process authorize_upgrade call as if it was received from governance chain ([polkadot-fellows/runtimes/pull/783](https://github.com/polkadot-fellows/runtimes/pull/783)) + ### Changed - Add foreign-consensus cousin Asset Hub as trusted aliaser to allow XCMv5 origin preservation for foreign-consensus parachains [polkadot-fellows/runtimes/pull/794](https://github.com/polkadot-fellows/runtimes/pull/794)) diff --git a/Cargo.lock b/Cargo.lock index 0f0eeefacc..4364fc8e11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2464,8 +2464,8 @@ dependencies = [ "people-kusama-runtime", "people-polkadot-runtime", "polkadot-runtime", - "sc-chain-spec", - "sc-network", + "sc-chain-spec 43.0.0", + "sc-network 0.50.0", "serde", "serde_json", "staging-kusama-runtime", @@ -4092,9 +4092,9 @@ dependencies = [ [[package]] name = "emulated-integration-tests-common" -version = "20.1.0" +version = "21.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daa3822a02baa47f54bbf4c28a78b4908a415e375b4c594be93104770f16d651" +checksum = "8c1d258cac4c41066778df0d033ad7a6001630daed5ef0b531a22d5d60eb16fe" dependencies = [ "asset-test-utils", "bp-messages", @@ -4103,11 +4103,13 @@ dependencies = [ "cumulus-pallet-xcmp-queue", "cumulus-primitives-core", "frame-support", + "frame-system", "hex-literal", "pallet-assets", "pallet-balances", "pallet-bridge-messages", "pallet-message-queue", + "pallet-whitelist", "pallet-xcm", "pallet-xcm-bridge-hub", "parachains-common", @@ -4116,7 +4118,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-runtime-parachains", - "sc-consensus-grandpa", + "sc-consensus-grandpa 0.35.0", "sp-authority-discovery", "sp-consensus-babe", "sp-consensus-beefy", @@ -4243,6 +4245,7 @@ dependencies = [ "pallet-xcm", "pallet-xcm-benchmarks", "parachains-common", + "parachains-runtimes-test-utils", "parity-scale-codec", "polkadot-core-primitives", "polkadot-parachain-primitives", @@ -4419,7 +4422,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -4928,9 +4931,9 @@ dependencies = [ [[package]] name = "frame-system" -version = "40.1.0" +version = "40.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfc20d95c35bad22eb8b8d7ef91197a439483458237b176e621d9210f2fbff15" +checksum = "d1e700f225f5cfe5d89f564ab23b6c609c144228d4d9871956ef209b20c9df98" dependencies = [ "cfg-if", "docify", @@ -5286,6 +5289,44 @@ 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", + "staging-kusama-runtime", +] + +[[package]] +name = "governance-polkadot-integration-tests" +version = "1.0.0" +dependencies = [ + "asset-hub-polkadot-runtime", + "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-runtime", + "staging-xcm", +] + [[package]] name = "group" version = "0.13.0" @@ -6165,7 +6206,6 @@ dependencies = [ "asset-test-utils", "cumulus-pallet-xcmp-queue", "emulated-integration-tests-common", - "frame-support", "hex-literal", "pallet-balances", "pallet-message-queue", @@ -6218,7 +6258,7 @@ checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" dependencies = [ "hermit-abi 0.5.1", "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -6635,7 +6675,7 @@ dependencies = [ "kusama-runtime-constants", "parachains-common", "polkadot-primitives", - "sc-consensus-grandpa", + "sc-consensus-grandpa 0.34.0", "sp-authority-discovery", "sp-consensus-babe", "sp-consensus-beefy", @@ -8337,9 +8377,9 @@ dependencies = [ [[package]] name = "pallet-balances" -version = "41.1.0" +version = "41.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd7bf033312c976e0c044a80b4cd8b88471d7371baae6fea67b3f42eba288b" +checksum = "58e04ed6c01cd829731ec7bcec0de4e49cd806195ca2448a1887c5493efd8262" dependencies = [ "docify", "frame-benchmarking", @@ -10535,7 +10575,7 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime", "polkadot-runtime-constants", - "sc-consensus-grandpa", + "sc-consensus-grandpa 0.34.0", "sp-authority-discovery", "sp-consensus-babe", "sp-consensus-beefy", @@ -11495,7 +11535,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -12045,7 +12085,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -12058,7 +12098,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -12158,7 +12198,7 @@ dependencies = [ "security-framework 3.2.0", "security-framework-sys", "webpki-root-certs 0.26.11", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -12310,7 +12350,34 @@ dependencies = [ "sc-chain-spec-derive", "sc-client-api", "sc-executor", - "sc-network", + "sc-network 0.49.2", + "sc-telemetry", + "serde", + "serde_json", + "sp-blockchain", + "sp-core 36.1.0", + "sp-crypto-hashing", + "sp-genesis-builder", + "sp-io", + "sp-runtime", + "sp-state-machine", + "sp-tracing", +] + +[[package]] +name = "sc-chain-spec" +version = "43.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e6d5be3cdebfc34277aaa5656f4adfcbf13bcba048e23dd172efffec8f07cb1" +dependencies = [ + "array-bytes", + "docify", + "memmap2", + "parity-scale-codec", + "sc-chain-spec-derive", + "sc-client-api", + "sc-executor", + "sc-network 0.50.0", "sc-telemetry", "serde", "serde_json", @@ -12375,7 +12442,31 @@ dependencies = [ "mockall", "parking_lot 0.12.3", "sc-client-api", - "sc-network-types", + "sc-network-types 0.15.4", + "sc-utils", + "serde", + "sp-blockchain", + "sp-consensus", + "sp-core 36.1.0", + "sp-runtime", + "sp-state-machine", + "substrate-prometheus-endpoint", + "thiserror 1.0.69", +] + +[[package]] +name = "sc-consensus" +version = "0.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52f56b45b0dfd53de9474c52e16da653463310cf0e7c9ea6f11f0774162bdafc" +dependencies = [ + "async-trait", + "futures", + "log", + "mockall", + "parking_lot 0.12.3", + "sc-client-api", + "sc-network-types 0.16.0", "sc-utils", "serde", "sp-blockchain", @@ -12406,14 +12497,59 @@ dependencies = [ "parking_lot 0.12.3", "rand 0.8.5", "sc-block-builder", - "sc-chain-spec", + "sc-chain-spec 42.0.0", + "sc-client-api", + "sc-consensus 0.48.0", + "sc-network 0.49.2", + "sc-network-common", + "sc-network-gossip 0.49.0", + "sc-network-sync 0.48.0", + "sc-network-types 0.15.4", + "sc-telemetry", + "sc-transaction-pool-api", + "sc-utils", + "serde_json", + "sp-api", + "sp-application-crypto", + "sp-arithmetic", + "sp-blockchain", + "sp-consensus", + "sp-consensus-grandpa", + "sp-core 36.1.0", + "sp-crypto-hashing", + "sp-keystore", + "sp-runtime", + "substrate-prometheus-endpoint", + "thiserror 1.0.69", +] + +[[package]] +name = "sc-consensus-grandpa" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a52fb3d0b8659cc6620be386c62d927d085dddd3cd6af8ee17d0750bfb44702" +dependencies = [ + "ahash", + "array-bytes", + "async-trait", + "dyn-clone", + "finality-grandpa", + "fork-tree", + "futures", + "futures-timer", + "log", + "parity-scale-codec", + "parking_lot 0.12.3", + "rand 0.8.5", + "sc-block-builder", + "sc-chain-spec 43.0.0", "sc-client-api", - "sc-consensus", - "sc-network", + "sc-consensus 0.49.0", + "sc-network 0.50.0", "sc-network-common", - "sc-network-gossip", - "sc-network-sync", - "sc-network-types", + "sc-network-gossip 0.50.0", + "sc-network-sync 0.49.0", + "sc-network-types 0.16.0", "sc-telemetry", "sc-transaction-pool-api", "sc-utils", @@ -12516,8 +12652,8 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.3", "sc-client-api", - "sc-network", - "sc-network-types", + "sc-network 0.49.2", + "sc-network-types 0.15.4", "sc-transaction-pool-api", "sp-api", "sp-consensus", @@ -12559,7 +12695,58 @@ dependencies = [ "rand 0.8.5", "sc-client-api", "sc-network-common", - "sc-network-types", + "sc-network-types 0.15.4", + "sc-utils", + "schnellru", + "serde", + "serde_json", + "smallvec", + "sp-arithmetic", + "sp-blockchain", + "sp-core 36.1.0", + "sp-runtime", + "substrate-prometheus-endpoint", + "thiserror 1.0.69", + "tokio", + "tokio-stream", + "unsigned-varint 0.7.2", + "void", + "wasm-timer", + "zeroize", +] + +[[package]] +name = "sc-network" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3678912485114281204f8fbc2c4cb81120f10488fa8732f7f4850c45ed91fe98" +dependencies = [ + "array-bytes", + "async-channel 1.9.0", + "async-trait", + "asynchronous-codec 0.6.2", + "bytes", + "cid 0.9.0", + "either", + "fnv", + "futures", + "futures-timer", + "ip_network", + "libp2p", + "linked_hash_set", + "litep2p", + "log", + "mockall", + "parity-scale-codec", + "parking_lot 0.12.3", + "partial_sort", + "pin-project", + "prost 0.12.6", + "prost-build", + "rand 0.8.5", + "sc-client-api", + "sc-network-common", + "sc-network-types 0.16.0", "sc-utils", "schnellru", "serde", @@ -12600,10 +12787,30 @@ dependencies = [ "futures", "futures-timer", "log", - "sc-network", + "sc-network 0.49.2", "sc-network-common", - "sc-network-sync", - "sc-network-types", + "sc-network-sync 0.48.0", + "sc-network-types 0.15.4", + "schnellru", + "sp-runtime", + "substrate-prometheus-endpoint", + "tracing", +] + +[[package]] +name = "sc-network-gossip" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7685fcc9a1413196232a09509732cd6b09d6b77e989eedf6f5e59e5e75ae4516" +dependencies = [ + "ahash", + "futures", + "futures-timer", + "log", + "sc-network 0.50.0", + "sc-network-common", + "sc-network-sync 0.49.0", + "sc-network-types 0.16.0", "schnellru", "sp-runtime", "substrate-prometheus-endpoint", @@ -12627,10 +12834,46 @@ dependencies = [ "prost 0.12.6", "prost-build", "sc-client-api", - "sc-consensus", - "sc-network", + "sc-consensus 0.48.0", + "sc-network 0.49.2", "sc-network-common", - "sc-network-types", + "sc-network-types 0.15.4", + "sc-utils", + "schnellru", + "smallvec", + "sp-arithmetic", + "sp-blockchain", + "sp-consensus", + "sp-consensus-grandpa", + "sp-core 36.1.0", + "sp-runtime", + "substrate-prometheus-endpoint", + "thiserror 1.0.69", + "tokio", + "tokio-stream", +] + +[[package]] +name = "sc-network-sync" +version = "0.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "406652d26d2805db3e97d3745c8346aafcd23d570c6477bdecdff1b2b31b4af9" +dependencies = [ + "array-bytes", + "async-channel 1.9.0", + "async-trait", + "fork-tree", + "futures", + "log", + "mockall", + "parity-scale-codec", + "prost 0.12.6", + "prost-build", + "sc-client-api", + "sc-consensus 0.49.0", + "sc-network 0.50.0", + "sc-network-common", + "sc-network-types 0.16.0", "sc-utils", "schnellru", "smallvec", @@ -12666,6 +12909,26 @@ dependencies = [ "zeroize", ] +[[package]] +name = "sc-network-types" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c249bdcdb0ad0772626f66a59ce245676a244f093a411ca36dcb4113064f39ae" +dependencies = [ + "bs58", + "bytes", + "ed25519-dalek", + "libp2p-identity", + "libp2p-kad", + "litep2p", + "log", + "multiaddr 0.18.2", + "multihash 0.19.3", + "rand 0.8.5", + "thiserror 1.0.69", + "zeroize", +] + [[package]] name = "sc-rpc-api" version = "0.48.0" @@ -12674,7 +12937,7 @@ checksum = "9ed810a156f70cf5f7ab8fb5d9cf818999a72821c570aba4f4699aa4eea59e01" dependencies = [ "jsonrpsee", "parity-scale-codec", - "sc-chain-spec", + "sc-chain-spec 42.0.0", "sc-mixnet", "sc-transaction-pool-api", "scale-info", @@ -15503,7 +15766,7 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix 1.0.7", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -16837,7 +17100,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d18bca61da..979b20f6f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ cumulus-pallet-xcmp-queue = { version = "0.20.0", default-features = false } cumulus-primitives-aura = { version = "0.17.0", default-features = false } cumulus-primitives-core = { version = "0.18.1", default-features = false } cumulus-primitives-utility = { version = "0.20.0", default-features = false } -emulated-integration-tests-common = { version = "20.1.0" } +emulated-integration-tests-common = { version = "21.0.0" } encointer-balances-tx-payment = { version = "~16.1.0", default-features = false } encointer-balances-tx-payment-rpc-runtime-api = { version = "~16.1.0", default-features = false } encointer-kusama-runtime = { path = "system-parachains/encointer" } @@ -65,7 +65,7 @@ frame-benchmarking = { version = "40.2.0", default-features = false } frame-election-provider-support = { version = "40.1.1", default-features = false } frame-executive = { version = "40.0.1", default-features = false } frame-support = { version = "40.1.0", default-features = false } -frame-system = { version = "40.1.0", default-features = false } +frame-system = { version = "40.2.0", default-features = false } frame-system-benchmarking = { version = "40.0.0", default-features = false } frame-system-rpc-runtime-api = { version = "36.0.0", default-features = false } frame-try-runtime = { version = "0.46.0", default-features = false } @@ -193,8 +193,8 @@ primitive-types = { version = "0.12.2", default-features = false } frame-metadata-hash-extension = { version = "0.8.0", default-features = false } remote-externalities = { version = "0.50.0", package = "frame-remote-externalities" } runtime-parachains = { version = "19.2.0", default-features = false, package = "polkadot-runtime-parachains" } -sc-chain-spec = { version = "42.0.0" } -sc-network = { version = "0.49.2" } +sc-chain-spec = { version = "43.0.0" } +sc-network = { version = "0.50.0" } scale-info = { version = "2.10.0", default-features = false } separator = { version = "0.4.1" } serde = { version = "1.0.196" } @@ -283,6 +283,8 @@ 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", "integration-tests/zombienet", diff --git a/integration-tests/emulated/helpers/Cargo.toml b/integration-tests/emulated/helpers/Cargo.toml index d502a10342..bcdb425db0 100644 --- a/integration-tests/emulated/helpers/Cargo.toml +++ b/integration-tests/emulated/helpers/Cargo.toml @@ -12,7 +12,6 @@ paste = { workspace = true } hex-literal = { workspace = true } # Substrate -frame-support = { workspace = true, default-features = true } pallet-balances = { workspace = true, default-features = true } pallet-message-queue = { workspace = true, default-features = true } @@ -29,7 +28,6 @@ emulated-integration-tests-common = { workspace = true } [features] runtime-benchmarks = [ "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "frame-support/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", 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..21dbf6e412 --- /dev/null +++ b/integration-tests/emulated/tests/governance/kusama/src/lib.rs @@ -0,0 +1,18 @@ +// 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)] +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 new file mode 100644 index 0000000000..7aea763133 --- /dev/null +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs @@ -0,0 +1,228 @@ +// 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::{ + assert_whitelisted, + impls::RelayChain, + xcm_emulator::{Chain, Parachain, TestExt}, + xcm_helpers::{ + build_xcm_send_authorize_upgrade_call, call_hash_of, + dispatch_whitelisted_call_with_preimage, + }, +}; +use frame_support::{assert_err, assert_ok}; +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}; + +#[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(); + + 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: 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)); + assert_whitelisted!(Kusama, 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_eq!(::System::authorized_upgrade().unwrap().code_hash(), &code_hash) + }); +} + +#[test] +fn relaychain_can_authorize_upgrade_for_system_chains() { + type KusamaRuntime = ::Runtime; + 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, + ), + ], + }); + + // bad origin + let invalid_origin: KusamaRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: KusamaRuntimeOrigin = 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: 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)); + assert_whitelisted!(Kusama, call_hash); + }); + + // 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_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(), + &code_hash_bridge_hub + ) + }); + CoretimeKusama::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_coretime + ) + }); + PeopleKusama::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_people + ) + }); +} 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..c7a7c92415 --- /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-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 +asset-hub-polkadot-runtime = { workspace = true } +collectives-polkadot-runtime = { workspace = true } +integration-tests-helpers = { 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 new file mode 100644 index 0000000000..94a3886f8b --- /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}, + 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 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_relay.rs b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs new file mode 100644 index 0000000000..e44ca2e0d7 --- /dev/null +++ b/integration-tests/emulated/tests/governance/polkadot/src/open_gov_on_relay.rs @@ -0,0 +1,249 @@ +// 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::*; +use codec::Encode; +use emulated_integration_tests_common::{ + assert_whitelisted, + impls::RelayChain, + xcm_emulator::{Chain, Parachain, TestExt}, + xcm_helpers::{ + build_xcm_send_authorize_upgrade_call, call_hash_of, + dispatch_whitelisted_call_with_preimage, + }, +}; +use frame_support::assert_err; +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; + +#[test] +fn relaychain_can_authorize_upgrade_for_itself() { + let code_hash = [1u8; 32].into(); + type PolkadotRuntime = ::Runtime; + type PolkadotRuntimeCall = ::RuntimeCall; + type PolkadotRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + PolkadotRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![ + // upgrade the relaychain + PolkadotRuntimeCall::System(frame_system::Call::authorize_upgrade { code_hash }), + ], + }); + + // bad origin + let invalid_origin: PolkadotRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: PolkadotRuntimeOrigin = 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: 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() + }); + Polkadot::execute_with(|| { + assert_whitelisted!(Polkadot, call_hash); + }); + + // 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_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash + ) + }); +} + +#[test] +fn relaychain_can_authorize_upgrade_for_system_chains() { + type PolkadotRuntime = ::Runtime; + 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()); + 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![ + 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, + ), + ], + }); + + // bad origin + let invalid_origin: PolkadotRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: PolkadotRuntimeOrigin = 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: 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() + }); + Polkadot::execute_with(|| { + assert_whitelisted!(Polkadot, call_hash); + }); + + // 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()) + }); + 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)); + + AssetHubPolkadot::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_asset_hub + ) + }); + // check after - authorized + BridgeHubPolkadot::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_bridge_hub + ) + }); + CollectivesPolkadot::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade() + .unwrap() + .code_hash(), + &code_hash_collectives + ) + }); + CoretimePolkadot::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_coretime + ) + }); + PeoplePolkadot::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_people + ) + }); +} 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 26739512cf..9913cb4da2 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 @@ -61,6 +61,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(); @@ -76,7 +78,6 @@ parameter_types! { pub PoolAssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); - pub const GovernanceLocation: Location = Location::parent(); 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-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index b21ae18761..50a1c212c8 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -43,11 +43,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, TryRuntimeError}; +use sp_runtime::{traits::MaybeEquivalence, Either, TryRuntimeError}; use system_parachains_constants::kusama::{ consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, fee::WeightToFee, }; @@ -810,3 +810,35 @@ fn test_xcm_v4_to_v5_works() { assert_eq!(encoded_v4, decoded_v5.encode(), "V4 encoded should match V5 re-encoded"); } } + +#[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()))); +} 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 d1e03c5f38..4b5d05f314 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 @@ -61,6 +61,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(); @@ -74,7 +76,6 @@ parameter_types! { PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub FellowshipLocation: Location = Location::new(1, Parachain(system_parachain::COLLECTIVES_ID)); - 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(); pub PoolAssetsPalletLocation: Location = 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 df4eaccc04..6e5e1bb9f7 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -40,13 +40,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_err, assert_ok, 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, TryRuntimeError}; +use sp_runtime::{traits::MaybeEquivalence, Either, TryRuntimeError}; use system_parachains_constants::{ kusama::consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, polkadot::fee::WeightToFee, }; @@ -842,3 +842,54 @@ fn test_xcm_v4_to_v5_works() { assert_eq!(encoded_v4, decoded_v5.encode(), "V4 encoded should match V5 re-encoded"); } } + +#[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()))); +} 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 aa060cd0e8..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,7 +61,6 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub const GovernanceLocation: Location = Location::parent(); 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-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()))); +} 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 27351c49f4..f4d83302d1 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,7 +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)); - 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(); // Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location 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..c6aaadb231 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, @@ -564,3 +566,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()))); +} diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index 4be36b6cee..668a32bc9c 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,7 +60,6 @@ parameter_types! { pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); - 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(); pub const TreasurerBodyId: BodyId = BodyId::Treasury; 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..b552cd5c86 --- /dev/null +++ b/system-parachains/collectives/collectives-polkadot/tests/tests.rs @@ -0,0 +1,56 @@ +use collectives_polkadot_runtime::{xcm_config::GovernanceLocation, Runtime, RuntimeOrigin}; +use frame_support::{assert_err, assert_ok}; +use parachains_runtimes_test_utils::GovernanceOrigin; +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()))); +} 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 deef399f31..b49d1443b0 100644 --- a/system-parachains/constants/src/polkadot.rs +++ b/system-parachains/constants/src/polkadot.rs @@ -162,5 +162,7 @@ pub mod locations { parameter_types! { 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/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index 38a88455f2..3ecae5e643 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -17,13 +17,13 @@ use crate::{ coretime::{BrokerPalletId, CoretimeBurnAccount}, xcm_config::LocationToAccountId, - *, + GovernanceLocation, *, }; 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, @@ -31,9 +31,9 @@ use frame_support::{ }; use kusama_runtime_constants::system_parachain::coretime::TIMESLICE_PERIOD; use pallet_broker::{ConfigRecordOf, RCBlockNumberOf, SaleInfo}; -use parachains_runtimes_test_utils::ExtBuilder; +use parachains_runtimes_test_utils::{ExtBuilder, GovernanceOrigin}; 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 +245,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()))); +} diff --git a/system-parachains/coretime/coretime-kusama/src/xcm_config.rs b/system-parachains/coretime/coretime-kusama/src/xcm_config.rs index c493969129..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,7 +63,6 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub const GovernanceLocation: Location = Location::parent(); pub const FellowshipLocation: Location = Location::parent(); pub StakingPot: AccountId = CollatorSelection::account_id(); } diff --git a/system-parachains/coretime/coretime-polkadot/src/tests.rs b/system-parachains/coretime/coretime-polkadot/src/tests.rs index fe7ea6a291..790da3e5b7 100644 --- a/system-parachains/coretime/coretime-polkadot/src/tests.rs +++ b/system-parachains/coretime/coretime-polkadot/src/tests.rs @@ -17,23 +17,23 @@ use crate::{ coretime::{BrokerPalletId, CoretimeBurnAccount}, xcm_config::LocationToAccountId, - *, + GovernanceLocation, *, }; 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, }, }; use pallet_broker::{ConfigRecordOf, RCBlockNumberOf, SaleInfo}; -use parachains_runtimes_test_utils::ExtBuilder; +use parachains_runtimes_test_utils::{ExtBuilder, GovernanceOrigin}; 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 +245,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()))); +} diff --git a/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs b/system-parachains/coretime/coretime-polkadot/src/xcm_config.rs index 0f9d2c8f0d..2181d27d86 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,7 +64,6 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - 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/encointer/Cargo.toml b/system-parachains/encointer/Cargo.toml index c6cac39233..c622767266 100644 --- a/system-parachains/encointer/Cargo.toml +++ b/system-parachains/encointer/Cargo.toml @@ -107,6 +107,9 @@ polkadot-core-primitives = { workspace = true } polkadot-primitives = { workspace = true } system-parachains-constants = { workspace = true } +[dev-dependencies] +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..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; diff --git a/system-parachains/encointer/tests/tests.rs b/system-parachains/encointer/tests/tests.rs new file mode 100644 index 0000000000..5491b676e4 --- /dev/null +++ b/system-parachains/encointer/tests/tests.rs @@ -0,0 +1,37 @@ +use encointer_kusama_runtime::{xcm_config::GovernanceLocation, Runtime, RuntimeOrigin}; +use frame_support::{assert_err, assert_ok}; +use parachains_runtimes_test_utils::GovernanceOrigin; +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()))); +} diff --git a/system-parachains/people/people-kusama/src/tests.rs b/system-parachains/people/people-kusama/src/tests.rs index e2a617d042..43d72dd23a 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 frame_support::{assert_err, assert_ok}; +use parachains_runtimes_test_utils::GovernanceOrigin; +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()))); +} diff --git a/system-parachains/people/people-kusama/src/xcm_config.rs b/system-parachains/people/people-kusama/src/xcm_config.rs index 5a59157c95..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,7 +61,6 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub const GovernanceLocation: Location = Location::parent(); 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/tests.rs b/system-parachains/people/people-polkadot/src/tests.rs index d8c29568b5..59755f701e 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 frame_support::{assert_err, assert_ok}; +use parachains_runtimes_test_utils::GovernanceOrigin; +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()))); +} diff --git a/system-parachains/people/people-polkadot/src/xcm_config.rs b/system-parachains/people/people-polkadot/src/xcm_config.rs index b0976fc5d3..fab18cb565 100644 --- a/system-parachains/people/people-polkadot/src/xcm_config.rs +++ b/system-parachains/people/people-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 RelayLocation: Location = Location::parent(); @@ -60,7 +62,6 @@ parameter_types! { [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - 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. pub FeeAssetId: AssetId = AssetId(RelayLocation::get());