Xcm emulator nits (#1649)

# Desription

## Summary 

This PR introduces several nits and tweaks to xcm emulator tests for
system parachains.

## Explanation

**Deduplicate `XcmPallet::send(` with root origin code**
- Introduced `send_transact_to_parachain` which could be easily reuse
for scenarios like _governance call from relay chain to parachain_.

**Refactor `send_transact_sudo_from_relay_to_system_para_works`**
- Test covered just one use-case which was moved to the
`do_force_create_asset_from_relay_to_system_para`, so now we can extend
this test with more _governance-like_ senarios.
- Renamed to
`send_transact_as_superuser_from_relay_to_system_para_works`.

**Remove `send_transact_native_from_relay_to_system_para_fails` test**
- This test and/or description is kind of misleading, because system
paras support Native from relay chain by `RelayChainAsNative` with
correct xcm origin.
- It tested only sending on relay chain which should go directly to the
relay chain unit-tests (does not even need to be in xcm emulator level).

## Future directions

Check restructure parachains integration tests
[issue](https://github.com/paritytech/polkadot-sdk/issues/1389) and [PR
with more TODOs](https://github.com/paritytech/polkadot-sdk/pull/1693).

---------

Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com>
This commit is contained in:
Branislav Kontur
2023-10-11 10:32:49 +02:00
committed by GitHub
parent 294e99831d
commit cfb29254f7
5 changed files with 89 additions and 114 deletions
@@ -349,6 +349,7 @@ fn limited_reserve_transfer_asset_from_system_para_to_para() {
ASSET_MIN_BALANCE,
true,
AssetHubWestendSender::get(),
Some(Weight::from_parts(1_019_445_000, 200_000)),
ASSET_MIN_BALANCE * 1000000,
);
@@ -384,6 +385,7 @@ fn reserve_transfer_asset_from_system_para_to_para() {
ASSET_MIN_BALANCE,
true,
AssetHubWestendSender::get(),
Some(Weight::from_parts(1_019_445_000, 200_000)),
ASSET_MIN_BALANCE * 1000000,
);
@@ -16,52 +16,16 @@
use crate::*;
/// Relay Chain should be able to execute `Transact` instructions in System Parachain
/// when `OriginKind::Superuser` and signer is `sudo`
/// when `OriginKind::Superuser`.
#[test]
fn send_transact_sudo_from_relay_to_system_para_works() {
// Init tests variables
let root_origin = <Westend as Chain>::RuntimeOrigin::root();
let system_para_destination = Westend::child_location_of(AssetHubWestend::para_id()).into();
let asset_owner: AccountId = AssetHubWestendSender::get().into();
let xcm = AssetHubWestend::force_create_asset_xcm(
OriginKind::Superuser,
fn send_transact_as_superuser_from_relay_to_system_para_works() {
AssetHubWestend::force_create_asset_from_relay_as_root(
ASSET_ID,
asset_owner.clone(),
ASSET_MIN_BALANCE,
true,
1000,
);
// Send XCM message from Relay Chain
Westend::execute_with(|| {
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
root_origin,
bx!(system_para_destination),
bx!(xcm),
));
Westend::assert_xcm_pallet_sent();
});
// Receive XCM message in Assets Parachain
AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
AssetHubWestend::assert_dmp_queue_complete(Some(Weight::from_parts(
1_019_445_000,
200_000,
)));
assert_expected_events!(
AssetHubWestend,
vec![
RuntimeEvent::Assets(pallet_assets::Event::ForceCreated { asset_id, owner }) => {
asset_id: *asset_id == ASSET_ID,
owner: *owner == asset_owner,
},
]
);
assert!(<AssetHubWestend as AssetHubWestendPallet>::Assets::asset_exists(ASSET_ID));
});
AssetHubWestendSender::get().into(),
Some(Weight::from_parts(1_019_445_000, 200_000)),
)
}
/// Parachain should be able to send XCM paying its fee with sufficient asset
@@ -78,6 +42,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
ASSET_MIN_BALANCE,
true,
para_sovereign_account.clone(),
Some(Weight::from_parts(1_019_445_000, 200_000)),
ASSET_MIN_BALANCE * 1000000000,
);
@@ -47,32 +47,22 @@ fn relay_sets_system_para_xcm_supported_version() {
#[test]
fn system_para_sets_relay_xcm_supported_version() {
// Init test variables
let sudo_origin = <Westend as Chain>::RuntimeOrigin::root();
let parent_location = AssetHubWestend::parent_location();
let system_para_destination: VersionedMultiLocation =
Westend::child_location_of(AssetHubWestend::para_id()).into();
let call = <AssetHubWestend as Chain>::RuntimeCall::PolkadotXcm(pallet_xcm::Call::<
<AssetHubWestend as Chain>::Runtime,
>::force_xcm_version {
location: bx!(parent_location),
version: XCM_V3,
})
.encode()
.into();
let origin_kind = OriginKind::Superuser;
let force_xcm_version_call =
<AssetHubWestend as Chain>::RuntimeCall::PolkadotXcm(pallet_xcm::Call::<
<AssetHubWestend as Chain>::Runtime,
>::force_xcm_version {
location: bx!(parent_location),
version: XCM_V3,
})
.encode()
.into();
let xcm = xcm_transact_unpaid_execution(call, origin_kind);
// System Parachain sets supported version for Relay Chain throught it
Westend::execute_with(|| {
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
sudo_origin,
bx!(system_para_destination),
bx!(xcm),
));
Westend::assert_xcm_pallet_sent();
});
// System Parachain sets supported version for Relay Chain through it
Westend::send_unpaid_transact_to_parachain_as_root(
AssetHubWestend::para_id(),
force_xcm_version_call,
);
// System Parachain receive the XCM message
AssetHubWestend::execute_with(|| {