Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ members = [
"cumulus/parachains/integration-tests/emulated/tests/collectives/collectives-westend",
"cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-rococo",
"cumulus/parachains/integration-tests/emulated/tests/coretime/coretime-westend",
"cumulus/parachains/integration-tests/emulated/tests/governance/westend",
"cumulus/parachains/integration-tests/emulated/tests/people/people-rococo",
"cumulus/parachains/integration-tests/emulated/tests/people/people-westend",
"cumulus/parachains/pallets/collective-content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ paste = { workspace = true, default-features = true }

# Substrate
frame-support = { workspace = true, default-features = true }
frame-system = { workspace = true, default-features = true }
pallet-asset-conversion = { workspace = true, default-features = true }
pallet-assets = { workspace = true, default-features = true }
pallet-balances = { workspace = true, default-features = true }
pallet-message-queue = { workspace = true, default-features = true }
pallet-whitelist = { workspace = true, default-features = true }
sc-consensus-grandpa = { workspace = true, default-features = true }
sp-authority-discovery = { workspace = true, default-features = true }
sp-consensus-babe = { workspace = true, default-features = true }
Expand Down
16 changes: 16 additions & 0 deletions cumulus/parachains/integration-tests/emulated/common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub use pallet_asset_conversion;
pub use pallet_assets;
pub use pallet_balances;
pub use pallet_message_queue;
pub use pallet_whitelist;
pub use pallet_xcm;

pub use frame_support::assert_ok;
Expand Down Expand Up @@ -1113,3 +1114,18 @@ macro_rules! create_pool_with_native_on {
}
};
}

#[macro_export]
macro_rules! assert_whitelisted {
($chain:ident, $expected_call_hash:expr) => {
type RuntimeEvent = <$chain as $crate::macros::Chain>::RuntimeEvent;
$crate::macros::assert_expected_events!(
$chain,
vec![
RuntimeEvent::Whitelist($crate::macros::pallet_whitelist::Event::CallWhitelisted { call_hash }) => {
call_hash: *call_hash == $expected_call_hash,
},
]
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ use sp_core::H256;
use xcm::{prelude::*, DoubleEncoded};
use xcm_emulator::Chain;

use crate::impls::{bx, Encode};
use frame_support::dispatch::{DispatchResultWithPostInfo, PostDispatchInfo};
use sp_runtime::traits::{Dispatchable, Hash};
use xcm::{VersionedLocation, VersionedXcm};

/// Helper method to build a XCM with a `Transact` instruction and paying for its execution
pub fn xcm_transact_paid_execution(
call: DoubleEncoded<()>,
Expand Down Expand Up @@ -112,3 +117,68 @@ where
{
pallet_xcm::xcm_helpers::find_xcm_sent_message_id::<<C as Chain>::Runtime>(C::events())
}

/// Wraps a runtime call in a whitelist preimage call and dispatches it
pub fn dispatch_whitelisted_call_with_preimage<T>(
Copy link
Copy Markdown
Contributor

@bkontur bkontur Jun 16, 2025

Choose a reason for hiding this comment

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

@karolk91 I think it should be ready and okay, but please double-check and confirm that all the newly added common components will work without any changes for the open_gov_on_asset_hub.rs tests (to avoid any backports later).

(Other words, when we merge this, we will just add tests for AHM cfg setup.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

do you mean AHM tests on Westend or Polkadot/Kusama ?

I will port/sync these changes right away to both when we merge this, or I can modify PRs above before we merge

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@karolk91 I am thinking about extracting all these changes for integration-tests/emulated/common to the separate PR on master and when merged, just backport it to stable2503 / stable2506 - because it is a new stuff, so after the next patch-release we can use them directly in fellows, we don't need to wait for master stable release

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sorry @bkontur , maybe I misunderstood something - this PR here is targeting master. We can add backport labels since these are only minor and patch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sorry @bkontur , maybe I misunderstood something - this PR here is targeting master. We can add backport labels since these are only minor and patch

oh, sorry, sorry, my bad, I though it is PR to some ahm branch :D,
no need to do anything :)

call: T::RuntimeCall,
origin: T::RuntimeOrigin,
) -> DispatchResultWithPostInfo
where
T: Chain,
T::Runtime: pallet_whitelist::Config,
T::RuntimeCall: From<pallet_whitelist::Call<T::Runtime>>
+ Into<<T::Runtime as pallet_whitelist::Config>::RuntimeCall>
+ Dispatchable<RuntimeOrigin = T::RuntimeOrigin, PostInfo = PostDispatchInfo>,
{
T::execute_with(|| {
let whitelist_call: T::RuntimeCall =
pallet_whitelist::Call::<T::Runtime>::dispatch_whitelisted_call_with_preimage {
call: Box::new(call.into()),
}
.into();
whitelist_call.dispatch(origin)
})
}

/// 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<T, D>(
location: Location,
code_hash: &H256,
fallback_max_weight: Option<Weight>,
) -> T::RuntimeCall
where
T: Chain,
T::Runtime: pallet_xcm::Config,
T::RuntimeCall: Encode + From<pallet_xcm::Call<T::Runtime>>,
D: Chain,
D::Runtime: frame_system::Config<Hash = H256>,
D::RuntimeCall: Encode + From<frame_system::Call<D::Runtime>>,
{
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
}

/// Encodes a runtime call and returns its H256 hash
pub fn call_hash_of<T>(call: &T::RuntimeCall) -> H256
where
T: Chain,
T::Runtime: frame_system::Config<Hash = H256>,
T::RuntimeCall: Encode,
{
<T::Runtime as frame_system::Config>::Hashing::hash_of(&call)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "governance-westend-integration-tests"
version = "0.0.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
description = "Westend governance integration tests with xcm-emulator"
publish = false

[lints]
workspace = true

[dependencies]
codec = { workspace = true, default-features = true }

# Substrate
frame-support = { workspace = true, default-features = true }
frame-system = { workspace = true, default-features = true }
pallet-utility = { workspace = true, default-features = true }
pallet-whitelist = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }

pallet-xcm = { workspace = true, default-features = true }
xcm = { workspace = true, default-features = true }

emulated-integration-tests-common = { workspace = true }

# Local
collectives-westend-runtime = { workspace = true }
westend-runtime = { workspace = true }
westend-system-emulated-network = { workspace = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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::*;

/// CollectivesWestend dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded
/// whitelist call.
#[cfg(test)]
pub fn collectives_send_whitelist(
dest: Location,
encoded_whitelist_call: impl FnOnce() -> Vec<u8>,
) {
CollectivesWestend::execute_with(|| {
type RuntimeEvent = <CollectivesWestend as Chain>::RuntimeEvent;
type RuntimeCall = <CollectivesWestend as Chain>::RuntimeCall;
type RuntimeOrigin = <CollectivesWestend as Chain>::RuntimeOrigin;
type Runtime = <CollectivesWestend as Chain>::Runtime;

let send_whitelist_call = RuntimeCall::PolkadotXcm(pallet_xcm::Call::<Runtime>::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_westend_runtime::fellowship::pallet_fellowship_origins::Origin::Fellows as FellowsOrigin;
let fellows_origin: RuntimeOrigin = FellowsOrigin.into();
assert_ok!(send_whitelist_call.dispatch(fellows_origin));
assert_expected_events!(
CollectivesWestend,
vec![
RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {},
]
);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 imports {
pub(crate) use emulated_integration_tests_common::{
impls::{assert_expected_events, bx, TestExt},
xcm_emulator::Chain,
};
pub(crate) use frame_support::assert_ok;
pub(crate) use sp_runtime::traits::Dispatchable;
pub(crate) use westend_system_emulated_network::CollectivesWestendPara as CollectivesWestend;
pub(crate) use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm};
}

#[cfg(test)]
mod common;

#[cfg(test)]
mod open_gov_on_relay;
Loading
Loading