Skip to content

Commit 16ff6db

Browse files
paritytech-release-backport-bot[bot]karolk91github-actions[bot]bkontur
authored
[stable2506] Backport #8787 (#8914)
Backport #8787 into `stable2506` from karolk91. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Co-authored-by: Karol Kokoszka <karol.k91@gmail.com> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Branislav Kontur <bkontur@gmail.com>
1 parent 7b03c8b commit 16ff6db

File tree

13 files changed

+501
-2
lines changed

13 files changed

+501
-2
lines changed

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ members = [
112112
"cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend",
113113
"cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-rococo",
114114
"cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-westend",
115+
"cumulus/parachains/integration-tests/emulated/tests/governance/westend",
115116
"cumulus/parachains/integration-tests/emulated/tests/people/people-rococo",
116117
"cumulus/parachains/integration-tests/emulated/tests/people/people-westend",
117118
"cumulus/parachains/pallets/collective-content",

cumulus/parachains/integration-tests/emulated/common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ paste = { workspace = true, default-features = true }
1818

1919
# Substrate
2020
frame-support = { workspace = true, default-features = true }
21+
frame-system = { workspace = true, default-features = true }
2122
pallet-asset-conversion = { workspace = true, default-features = true }
2223
pallet-assets = { workspace = true, default-features = true }
2324
pallet-balances = { workspace = true, default-features = true }
2425
pallet-message-queue = { workspace = true, default-features = true }
26+
pallet-whitelist = { workspace = true, default-features = true }
2527
sc-consensus-grandpa = { workspace = true, default-features = true }
2628
sp-authority-discovery = { workspace = true, default-features = true }
2729
sp-consensus-babe = { workspace = true, default-features = true }

cumulus/parachains/integration-tests/emulated/common/src/macros.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub use pallet_asset_conversion;
2121
pub use pallet_assets;
2222
pub use pallet_balances;
2323
pub use pallet_message_queue;
24+
pub use pallet_whitelist;
2425
pub use pallet_xcm;
2526

2627
pub use frame_support::assert_ok;
@@ -1113,3 +1114,18 @@ macro_rules! create_pool_with_native_on {
11131114
}
11141115
};
11151116
}
1117+
1118+
#[macro_export]
1119+
macro_rules! assert_whitelisted {
1120+
($chain:ident, $expected_call_hash:expr) => {
1121+
type RuntimeEvent = <$chain as $crate::macros::Chain>::RuntimeEvent;
1122+
$crate::macros::assert_expected_events!(
1123+
$chain,
1124+
vec![
1125+
RuntimeEvent::Whitelist($crate::macros::pallet_whitelist::Event::CallWhitelisted { call_hash }) => {
1126+
call_hash: *call_hash == $expected_call_hash,
1127+
},
1128+
]
1129+
);
1130+
};
1131+
}

cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ use sp_core::H256;
2121
use xcm::{prelude::*, DoubleEncoded};
2222
use xcm_emulator::Chain;
2323

24+
use crate::impls::{bx, Encode};
25+
use frame_support::dispatch::{DispatchResultWithPostInfo, PostDispatchInfo};
26+
use sp_runtime::traits::{Dispatchable, Hash};
27+
use xcm::{VersionedLocation, VersionedXcm};
28+
2429
/// Helper method to build a XCM with a `Transact` instruction and paying for its execution
2530
pub fn xcm_transact_paid_execution(
2631
call: DoubleEncoded<()>,
@@ -112,3 +117,68 @@ where
112117
{
113118
pallet_xcm::xcm_helpers::find_xcm_sent_message_id::<<C as Chain>::Runtime>(C::events())
114119
}
120+
121+
/// Wraps a runtime call in a whitelist preimage call and dispatches it
122+
pub fn dispatch_whitelisted_call_with_preimage<T>(
123+
call: T::RuntimeCall,
124+
origin: T::RuntimeOrigin,
125+
) -> DispatchResultWithPostInfo
126+
where
127+
T: Chain,
128+
T::Runtime: pallet_whitelist::Config,
129+
T::RuntimeCall: From<pallet_whitelist::Call<T::Runtime>>
130+
+ Into<<T::Runtime as pallet_whitelist::Config>::RuntimeCall>
131+
+ Dispatchable<RuntimeOrigin = T::RuntimeOrigin, PostInfo = PostDispatchInfo>,
132+
{
133+
T::execute_with(|| {
134+
let whitelist_call: T::RuntimeCall =
135+
pallet_whitelist::Call::<T::Runtime>::dispatch_whitelisted_call_with_preimage {
136+
call: Box::new(call.into()),
137+
}
138+
.into();
139+
whitelist_call.dispatch(origin)
140+
})
141+
}
142+
143+
/// Builds a `pallet_xcm::send` call to authorize an upgrade at the provided location,
144+
/// wrapped in an unpaid XCM `Transact` with `OriginKind::Superuser`.
145+
pub fn build_xcm_send_authorize_upgrade_call<T, D>(
146+
location: Location,
147+
code_hash: &H256,
148+
fallback_max_weight: Option<Weight>,
149+
) -> T::RuntimeCall
150+
where
151+
T: Chain,
152+
T::Runtime: pallet_xcm::Config,
153+
T::RuntimeCall: Encode + From<pallet_xcm::Call<T::Runtime>>,
154+
D: Chain,
155+
D::Runtime: frame_system::Config<Hash = H256>,
156+
D::RuntimeCall: Encode + From<frame_system::Call<D::Runtime>>,
157+
{
158+
let transact_call: D::RuntimeCall =
159+
frame_system::Call::authorize_upgrade { code_hash: *code_hash }.into();
160+
161+
let call: T::RuntimeCall = pallet_xcm::Call::send {
162+
dest: bx!(VersionedLocation::from(location)),
163+
message: bx!(VersionedXcm::from(Xcm(vec![
164+
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
165+
Transact {
166+
origin_kind: OriginKind::Superuser,
167+
fallback_max_weight,
168+
call: transact_call.encode().into(),
169+
}
170+
]))),
171+
}
172+
.into();
173+
call
174+
}
175+
176+
/// Encodes a runtime call and returns its H256 hash
177+
pub fn call_hash_of<T>(call: &T::RuntimeCall) -> H256
178+
where
179+
T: Chain,
180+
T::Runtime: frame_system::Config<Hash = H256>,
181+
T::RuntimeCall: Encode,
182+
{
183+
<T::Runtime as frame_system::Config>::Hashing::hash_of(&call)
184+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "governance-westend-integration-tests"
3+
version = "0.0.0"
4+
authors.workspace = true
5+
edition.workspace = true
6+
license = "Apache-2.0"
7+
description = "Westend governance integration tests with xcm-emulator"
8+
publish = false
9+
10+
[lints]
11+
workspace = true
12+
13+
[dependencies]
14+
codec = { workspace = true, default-features = true }
15+
16+
# Substrate
17+
frame-support = { workspace = true, default-features = true }
18+
frame-system = { workspace = true, default-features = true }
19+
pallet-utility = { workspace = true, default-features = true }
20+
pallet-whitelist = { workspace = true, default-features = true }
21+
sp-core = { workspace = true, default-features = true }
22+
sp-runtime = { workspace = true, default-features = true }
23+
24+
pallet-xcm = { workspace = true, default-features = true }
25+
xcm = { workspace = true, default-features = true }
26+
27+
emulated-integration-tests-common = { workspace = true }
28+
29+
# Local
30+
collectives-westend-runtime = { workspace = true }
31+
westend-runtime = { workspace = true }
32+
westend-system-emulated-network = { workspace = true }
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md
2+
// for a list of specific contributors.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
use crate::imports::*;
18+
19+
/// CollectivesWestend dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded
20+
/// whitelist call.
21+
#[cfg(test)]
22+
pub fn collectives_send_whitelist(
23+
dest: Location,
24+
encoded_whitelist_call: impl FnOnce() -> Vec<u8>,
25+
) {
26+
CollectivesWestend::execute_with(|| {
27+
type RuntimeEvent = <CollectivesWestend as Chain>::RuntimeEvent;
28+
type RuntimeCall = <CollectivesWestend as Chain>::RuntimeCall;
29+
type RuntimeOrigin = <CollectivesWestend as Chain>::RuntimeOrigin;
30+
type Runtime = <CollectivesWestend as Chain>::Runtime;
31+
32+
let send_whitelist_call = RuntimeCall::PolkadotXcm(pallet_xcm::Call::<Runtime>::send {
33+
dest: bx!(VersionedLocation::from(dest)),
34+
message: bx!(VersionedXcm::from(Xcm(vec![
35+
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
36+
Transact {
37+
origin_kind: OriginKind::Xcm,
38+
fallback_max_weight: None,
39+
call: encoded_whitelist_call().into(),
40+
}
41+
]))),
42+
});
43+
44+
use collectives_westend_runtime::fellowship::pallet_fellowship_origins::Origin::Fellows as FellowsOrigin;
45+
let fellows_origin: RuntimeOrigin = FellowsOrigin.into();
46+
assert_ok!(send_whitelist_call.dispatch(fellows_origin));
47+
assert_expected_events!(
48+
CollectivesWestend,
49+
vec![
50+
RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {},
51+
]
52+
);
53+
});
54+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md
2+
// for a list of specific contributors.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#[cfg(test)]
18+
mod imports {
19+
pub(crate) use emulated_integration_tests_common::{
20+
impls::{assert_expected_events, bx, TestExt},
21+
xcm_emulator::Chain,
22+
};
23+
pub(crate) use frame_support::assert_ok;
24+
pub(crate) use sp_runtime::traits::Dispatchable;
25+
pub(crate) use westend_system_emulated_network::CollectivesWestendPara as CollectivesWestend;
26+
pub(crate) use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm};
27+
}
28+
29+
#[cfg(test)]
30+
mod common;
31+
32+
#[cfg(test)]
33+
mod open_gov_on_relay;

0 commit comments

Comments
 (0)