Skip to content

Commit cfb2925

Browse files
bkonturNachoPal
andauthored
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](#1389) and [PR with more TODOs](#1693). --------- Co-authored-by: Ignacio Palacios <[email protected]>
1 parent 294e998 commit cfb2925

File tree

5 files changed

+89
-114
lines changed

5 files changed

+89
-114
lines changed

cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/reserve_transfer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ fn limited_reserve_transfer_asset_from_system_para_to_para() {
349349
ASSET_MIN_BALANCE,
350350
true,
351351
AssetHubWestendSender::get(),
352+
Some(Weight::from_parts(1_019_445_000, 200_000)),
352353
ASSET_MIN_BALANCE * 1000000,
353354
);
354355

@@ -384,6 +385,7 @@ fn reserve_transfer_asset_from_system_para_to_para() {
384385
ASSET_MIN_BALANCE,
385386
true,
386387
AssetHubWestendSender::get(),
388+
Some(Weight::from_parts(1_019_445_000, 200_000)),
387389
ASSET_MIN_BALANCE * 1000000,
388390
);
389391

cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/send.rs

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,16 @@
1616
use crate::*;
1717

1818
/// Relay Chain should be able to execute `Transact` instructions in System Parachain
19-
/// when `OriginKind::Superuser` and signer is `sudo`
19+
/// when `OriginKind::Superuser`.
2020
#[test]
21-
fn send_transact_sudo_from_relay_to_system_para_works() {
22-
// Init tests variables
23-
let root_origin = <Westend as Chain>::RuntimeOrigin::root();
24-
let system_para_destination = Westend::child_location_of(AssetHubWestend::para_id()).into();
25-
let asset_owner: AccountId = AssetHubWestendSender::get().into();
26-
let xcm = AssetHubWestend::force_create_asset_xcm(
27-
OriginKind::Superuser,
21+
fn send_transact_as_superuser_from_relay_to_system_para_works() {
22+
AssetHubWestend::force_create_asset_from_relay_as_root(
2823
ASSET_ID,
29-
asset_owner.clone(),
24+
ASSET_MIN_BALANCE,
3025
true,
31-
1000,
32-
);
33-
// Send XCM message from Relay Chain
34-
Westend::execute_with(|| {
35-
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
36-
root_origin,
37-
bx!(system_para_destination),
38-
bx!(xcm),
39-
));
40-
41-
Westend::assert_xcm_pallet_sent();
42-
});
43-
44-
// Receive XCM message in Assets Parachain
45-
AssetHubWestend::execute_with(|| {
46-
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
47-
48-
AssetHubWestend::assert_dmp_queue_complete(Some(Weight::from_parts(
49-
1_019_445_000,
50-
200_000,
51-
)));
52-
53-
assert_expected_events!(
54-
AssetHubWestend,
55-
vec![
56-
RuntimeEvent::Assets(pallet_assets::Event::ForceCreated { asset_id, owner }) => {
57-
asset_id: *asset_id == ASSET_ID,
58-
owner: *owner == asset_owner,
59-
},
60-
]
61-
);
62-
63-
assert!(<AssetHubWestend as AssetHubWestendPallet>::Assets::asset_exists(ASSET_ID));
64-
});
26+
AssetHubWestendSender::get().into(),
27+
Some(Weight::from_parts(1_019_445_000, 200_000)),
28+
)
6529
}
6630

6731
/// 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() {
7842
ASSET_MIN_BALANCE,
7943
true,
8044
para_sovereign_account.clone(),
45+
Some(Weight::from_parts(1_019_445_000, 200_000)),
8146
ASSET_MIN_BALANCE * 1000000000,
8247
);
8348

cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend/src/tests/set_xcm_versions.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,22 @@ fn relay_sets_system_para_xcm_supported_version() {
4747
#[test]
4848
fn system_para_sets_relay_xcm_supported_version() {
4949
// Init test variables
50-
let sudo_origin = <Westend as Chain>::RuntimeOrigin::root();
5150
let parent_location = AssetHubWestend::parent_location();
52-
let system_para_destination: VersionedMultiLocation =
53-
Westend::child_location_of(AssetHubWestend::para_id()).into();
54-
let call = <AssetHubWestend as Chain>::RuntimeCall::PolkadotXcm(pallet_xcm::Call::<
55-
<AssetHubWestend as Chain>::Runtime,
56-
>::force_xcm_version {
57-
location: bx!(parent_location),
58-
version: XCM_V3,
59-
})
60-
.encode()
61-
.into();
62-
let origin_kind = OriginKind::Superuser;
63-
64-
let xcm = xcm_transact_unpaid_execution(call, origin_kind);
65-
66-
// System Parachain sets supported version for Relay Chain throught it
67-
Westend::execute_with(|| {
68-
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
69-
sudo_origin,
70-
bx!(system_para_destination),
71-
bx!(xcm),
72-
));
51+
let force_xcm_version_call =
52+
<AssetHubWestend as Chain>::RuntimeCall::PolkadotXcm(pallet_xcm::Call::<
53+
<AssetHubWestend as Chain>::Runtime,
54+
>::force_xcm_version {
55+
location: bx!(parent_location),
56+
version: XCM_V3,
57+
})
58+
.encode()
59+
.into();
7360

74-
Westend::assert_xcm_pallet_sent();
75-
});
61+
// System Parachain sets supported version for Relay Chain through it
62+
Westend::send_unpaid_transact_to_parachain_as_root(
63+
AssetHubWestend::para_id(),
64+
force_xcm_version_call,
65+
);
7666

7767
// System Parachain receive the XCM message
7868
AssetHubWestend::execute_with(|| {

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

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub use polkadot_runtime_parachains::{
5454
inclusion::{AggregateMessageOrigin, UmpQueueId},
5555
};
5656
pub use xcm::{
57-
prelude::{OriginKind, Outcome, VersionedXcm, Weight},
57+
prelude::{MultiLocation, OriginKind, Outcome, VersionedXcm, Weight},
5858
v3::Error,
5959
DoubleEncoded,
6060
};
@@ -80,21 +80,11 @@ impl From<u32> for LaneIdWrapper {
8080
type BridgeHubRococoRuntime = <BridgeHubRococo as Chain>::Runtime;
8181
type BridgeHubWococoRuntime = <BridgeHubWococo as Chain>::Runtime;
8282

83-
// TODO: uncomment when https://github.com/paritytech/polkadot-sdk/pull/1352 is merged
84-
// type BridgeHubPolkadotRuntime = <BridgeHubPolkadot as Chain>::Runtime;
85-
// type BridgeHubKusamaRuntime = <BridgeHubKusama as Chain>::Runtime;
86-
8783
pub type RococoWococoMessageHandler =
8884
BridgeHubMessageHandler<BridgeHubRococoRuntime, BridgeHubWococoRuntime, Instance2>;
8985
pub type WococoRococoMessageHandler =
9086
BridgeHubMessageHandler<BridgeHubWococoRuntime, BridgeHubRococoRuntime, Instance2>;
9187

92-
// TODO: uncomment when https://github.com/paritytech/polkadot-sdk/pull/1352 is merged
93-
// pub type PolkadotKusamaMessageHandler
94-
// = BridgeHubMessageHandler<BridgeHubPolkadotRuntime, BridgeHubKusamaRuntime, Instance1>;
95-
// pub type KusamaPolkadotMessageHandler
96-
// = BridgeHubMessageHandler<BridgeHubKusamaRuntime, BridgeHubPolkadoRuntime, Instance1>;
97-
9888
impl<S, T, I> BridgeMessageHandler for BridgeHubMessageHandler<S, T, I>
9989
where
10090
S: Config<Instance1>,
@@ -356,6 +346,37 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain {
356346
};
357347
}
358348

349+
#[macro_export]
350+
macro_rules! impl_send_transact_helpers_for_relay_chain {
351+
( $chain:ident ) => {
352+
$crate::impls::paste::paste! {
353+
impl $chain {
354+
/// A root origin (as governance) sends `xcm::Transact` with `UnpaidExecution` and encoded `call` to child parachain.
355+
pub fn send_unpaid_transact_to_parachain_as_root(
356+
recipient: $crate::impls::ParaId,
357+
call: $crate::impls::DoubleEncoded<()>
358+
) {
359+
use $crate::impls::{bx, Chain, RelayChain};
360+
361+
<Self as $crate::impls::TestExt>::execute_with(|| {
362+
let root_origin = <Self as Chain>::RuntimeOrigin::root();
363+
let destination: $crate::impls::MultiLocation = <Self as RelayChain>::child_location_of(recipient);
364+
let xcm = $crate::impls::xcm_transact_unpaid_execution(call, $crate::impls::OriginKind::Superuser);
365+
366+
// Send XCM `Transact`
367+
$crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::XcmPallet::send(
368+
root_origin,
369+
bx!(destination.into()),
370+
bx!(xcm),
371+
));
372+
Self::assert_xcm_pallet_sent();
373+
});
374+
}
375+
}
376+
}
377+
};
378+
}
379+
359380
#[macro_export]
360381
macro_rules! impl_accounts_helpers_for_parachain {
361382
( $chain:ident ) => {
@@ -616,53 +637,58 @@ macro_rules! impl_assets_helpers_for_parachain {
616637
min_balance: u128,
617638
is_sufficient: bool,
618639
asset_owner: $crate::impls::AccountId,
640+
dmp_weight_threshold: Option<$crate::impls::Weight>,
619641
amount_to_mint: u128,
620642
) {
621-
use $crate::impls::{bx, Chain, RelayChain, Parachain, Inspect, TestExt};
622-
// Init values for Relay Chain
623-
let root_origin = <$relay_chain as Chain>::RuntimeOrigin::root();
624-
let destination = <$relay_chain>::child_location_of(<$chain>::para_id());
625-
let xcm = Self::force_create_asset_xcm(
626-
$crate::impls::OriginKind::Superuser,
643+
use $crate::impls::Chain;
644+
645+
// Force create asset
646+
Self::force_create_asset_from_relay_as_root(
627647
id,
628-
asset_owner.clone(),
629-
is_sufficient,
630648
min_balance,
649+
is_sufficient,
650+
asset_owner.clone(),
651+
dmp_weight_threshold
631652
);
632653

633-
<$relay_chain>::execute_with(|| {
634-
$crate::impls::assert_ok!(<$relay_chain as [<$relay_chain Pallet>]>::XcmPallet::send(
635-
root_origin,
636-
bx!(destination.into()),
637-
bx!(xcm),
638-
));
654+
// Mint asset for System Parachain's sender
655+
let signed_origin = <Self as Chain>::RuntimeOrigin::signed(asset_owner.clone());
656+
Self::mint_asset(signed_origin, id, asset_owner, amount_to_mint);
657+
}
639658

640-
<$relay_chain>::assert_xcm_pallet_sent();
641-
});
659+
/// Relay Chain sends `Transact` instruction with `force_create_asset` to Parachain with `Assets` instance of `pallet_assets` .
660+
pub fn force_create_asset_from_relay_as_root(
661+
id: u32,
662+
min_balance: u128,
663+
is_sufficient: bool,
664+
asset_owner: $crate::impls::AccountId,
665+
dmp_weight_threshold: Option<$crate::impls::Weight>,
666+
) {
667+
use $crate::impls::{Parachain, Inspect, TestExt};
642668

643-
Self::execute_with(|| {
644-
Self::assert_dmp_queue_complete(Some($crate::impls::Weight::from_parts(1_019_445_000, 200_000)));
669+
<$relay_chain>::send_unpaid_transact_to_parachain_as_root(
670+
Self::para_id(),
671+
Self::force_create_asset_call(id, asset_owner.clone(), is_sufficient, min_balance),
672+
);
645673

674+
// Receive XCM message in Assets Parachain
675+
Self::execute_with(|| {
646676
type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent;
647677

678+
Self::assert_dmp_queue_complete(dmp_weight_threshold);
679+
648680
$crate::impls::assert_expected_events!(
649681
Self,
650682
vec![
651-
// Asset has been created
652683
RuntimeEvent::Assets($crate::impls::pallet_assets::Event::ForceCreated { asset_id, owner }) => {
653684
asset_id: *asset_id == id,
654-
owner: *owner == asset_owner.clone(),
685+
owner: *owner == asset_owner,
655686
},
656687
]
657688
);
658689

659690
assert!(<Self as [<$chain Pallet>]>::Assets::asset_exists(id.into()));
660691
});
661-
662-
let signed_origin = <Self as Chain>::RuntimeOrigin::signed(asset_owner.clone());
663-
664-
// Mint asset for System Parachain's sender
665-
Self::mint_asset(signed_origin, id, asset_owner, amount_to_mint);
666692
}
667693
}
668694
}

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,30 +250,22 @@ decl_test_bridges! {
250250
target = BridgeHubRococo,
251251
handler = WococoRococoMessageHandler
252252
}
253-
// TODO: uncomment when https://github.com/paritytech/polkadot-sdk/pull/1352 is merged
254-
// pub struct PolkadotKusamaMockBridge {
255-
// source = BridgeHubPolkadot,
256-
// target = BridgeHubKusama,
257-
// handler = PolkadotKusamaMessageHandler
258-
// },
259-
// pub struct KusamaPolkadotMockBridge {
260-
// source = BridgeHubKusama,
261-
// target = BridgeHubPolkadot,
262-
// handler = KusamaPolkadotMessageHandler
263-
// }
264253
}
265254

266255
// Westend implementation
267256
impl_accounts_helpers_for_relay_chain!(Westend);
268257
impl_assert_events_helpers_for_relay_chain!(Westend);
258+
impl_send_transact_helpers_for_relay_chain!(Westend);
269259

270260
// Rococo implementation
271261
impl_accounts_helpers_for_relay_chain!(Rococo);
272262
impl_assert_events_helpers_for_relay_chain!(Rococo);
263+
impl_send_transact_helpers_for_relay_chain!(Rococo);
273264

274265
// Wococo implementation
275266
impl_accounts_helpers_for_relay_chain!(Wococo);
276267
impl_assert_events_helpers_for_relay_chain!(Wococo);
268+
impl_send_transact_helpers_for_relay_chain!(Wococo);
277269

278270
// AssetHubWestend implementation
279271
impl_accounts_helpers_for_parachain!(AssetHubWestend);

0 commit comments

Comments
 (0)