Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 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 @@ -283,6 +283,7 @@ members = [
"integration-tests/emulated/tests/collectives/collectives-polkadot",
"integration-tests/emulated/tests/coretime/coretime-kusama",
"integration-tests/emulated/tests/coretime/coretime-polkadot",
"integration-tests/emulated/tests/governance/kusama",
"integration-tests/emulated/tests/people/people-kusama",
"integration-tests/emulated/tests/people/people-polkadot",
"integration-tests/zombienet",
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/emulated/helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ hex-literal = { workspace = true }
frame-support = { workspace = true, default-features = true }
pallet-balances = { workspace = true, default-features = true }
pallet-message-queue = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
frame-system = { workspace = true, default-features = true }
pallet-whitelist = { workspace = true, default-features = true }

# Polkadot
xcm = { workspace = true, default-features = true }
Expand Down
74 changes: 74 additions & 0 deletions integration-tests/emulated/helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ pub use xcm_emulator::Chain;

pub mod common;

use emulated_integration_tests_common::impls::{bx, Encode};
use frame_support::dispatch::{DispatchResultWithPostInfo, PostDispatchInfo};
use sp_core::H256;
use sp_runtime::traits::{Dispatchable, Hash};
use xcm::{prelude::*, VersionedLocation, VersionedXcm};

/// TODO: when bumping to polkadot-sdk v1.8.0,
/// remove this crate altogether and get the macros from `emulated-integration-tests-common`.
/// TODO: backport this macros to polkadot-sdk
Expand Down Expand Up @@ -552,3 +558,71 @@ macro_rules! test_chain_can_claim_assets {
}
};
}

// TODO: remove when stable2503 / stable2506 released
/// Wraps a runtime call in a whitelist preimage call and dispatches it
pub fn dispatch_whitelisted_call_with_preimage<T>(
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)
})
}

// TODO: remove when stable2503 / stable2506 released
/// Builds a `pallet_xcm::send` call to authorize an upgrade at the provided location,
/// wrapped in an unpaid XCM `Transact` with `OriginKind::Superuser`.
pub fn build_xcm_send_authorize_upgrade_call<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
}

// TODO: remove when stable2503 / stable2506 released
/// 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)
}
28 changes: 28 additions & 0 deletions integration-tests/emulated/tests/governance/kusama/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
18 changes: 18 additions & 0 deletions integration-tests/emulated/tests/governance/kusama/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Loading