Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 1 addition & 2 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ decl_test_parachains! {
ForeignAssets: asset_hub_polkadot_runtime::ForeignAssets,
PoolAssets: asset_hub_polkadot_runtime::PoolAssets,
AssetConversion: asset_hub_polkadot_runtime::AssetConversion,
Preimage: asset_hub_polkadot_runtime::Preimage,
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sp-runtime = { workspace = true, default-features = true }
frame-support = { workspace = true, default-features = true }
frame-system = { workspace = true, default-features = true }
pallet-whitelist = { workspace = true, default-features = true }
pallet-preimage = { workspace = true, default-features = true }
pallet-utility = { workspace = true, default-features = true }

# Polkadot
Expand All @@ -27,9 +28,7 @@ emulated-integration-tests-common = { workspace = true }

# Local
asset-hub-polkadot-runtime = { workspace = true }
bridge-hub-polkadot-runtime = { workspace = true }
collectives-polkadot-runtime = { workspace = true }
coretime-polkadot-runtime = { workspace = true }
integration-tests-helpers = { workspace = true }
people-polkadot-runtime = { workspace = true }
polkadot-runtime = { workspace = true }
Expand Down
89 changes: 85 additions & 4 deletions integration-tests/emulated/tests/governance/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,99 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use emulated_integration_tests_common::impls::{assert_expected_events, bx, TestExt};
use frame_support::assert_ok;
use integration_tests_helpers::Chain;
use emulated_integration_tests_common::{
impls::{assert_expected_events, bx, Encode, TestExt},
xcm_emulator::Chain,
};
use frame_support::{
assert_ok,
dispatch::{DispatchResultWithPostInfo, PostDispatchInfo},
};
use polkadot_system_emulated_network::CollectivesPolkadotPara as CollectivesPolkadot;
use sp_runtime::traits::Dispatchable;
use sp_core::H256;
use sp_runtime::traits::{Dispatchable, Hash};
use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm};

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

/// Wraps a runtime call in a whitelist preimage call and dispatches it
pub fn dispatch_whitelisted_call_with_preimage<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)
})
}

/// Encodes a runtime call, stores its preimage (dispatch), and returns its H256 hash
pub fn dispatch_store_preimage_call<T>(call: T::RuntimeCall) -> H256
where
T: Chain,
T::Runtime: frame_system::Config<Hash = H256> + pallet_preimage::Config,
T::RuntimeCall: Encode
+ From<pallet_preimage::Call<T::Runtime>>
+ Dispatchable<RuntimeOrigin = T::RuntimeOrigin, PostInfo = PostDispatchInfo>,
T::RuntimeOrigin: From<<T::Runtime as frame_system::Config>::RuntimeOrigin>,
{
T::execute_with(|| {
let call_bytes = call.encode();
let call_hash = <T::Runtime as frame_system::Config>::Hashing::hash(&call_bytes);
let preimage_call: T::RuntimeCall =
pallet_preimage::Call::<T::Runtime>::note_preimage { bytes: call_bytes.clone() }.into();

let root_origin = T::RuntimeOrigin::from(frame_system::RawOrigin::Root.into());
assert_ok!(preimage_call.dispatch(root_origin));
call_hash
})
}

/// Builds an XCM call to send an authorize upgrade message using the provided location
pub fn build_xcm_send_authorize_upgrade_call<T, D>(location: Location) -> 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 code_hash = [1u8; 32].into();
// TODO: calculate real weight
let weight = Weight::from_parts(5_000_000_000, 500_000);

let transact_call: D::RuntimeCall = frame_system::Call::authorize_upgrade { code_hash }.into();

let call: T::RuntimeCall = pallet_xcm::Call::send {
dest: bx!(VersionedLocation::from(location)),
message: bx!(VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind: OriginKind::Superuser,
require_weight_at_most: weight,
call: transact_call.encode().into(),
}
]))),
}
.into();
call
}

/// CollectivesPolkadot dispatches `pallet_xcm::send` with `OriginKind:Xcm` to the dest with encoded
/// whitelist call.
pub fn collectives_send_whitelist(
Expand Down
Loading
Loading