-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Xcm emulator nits #1649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xcm emulator nits #1649
Changes from 13 commits
3db426d
7aae466
75d966a
d48af15
0df5489
d30a121
20c0e56
7bd3b19
39361b2
c30119c
2453019
f80a3fc
4acfffb
db80302
4478f4b
b51a207
b796743
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,7 @@ pub use polkadot_runtime_parachains::{ | |
| inclusion::{AggregateMessageOrigin, UmpQueueId}, | ||
| }; | ||
| pub use xcm::{ | ||
| prelude::{OriginKind, Outcome, VersionedXcm, Weight}, | ||
| prelude::{MultiLocation, OriginKind, Outcome, VersionedXcm, Weight}, | ||
| v3::Error, | ||
| DoubleEncoded, | ||
| }; | ||
|
|
@@ -80,21 +80,11 @@ impl From<u32> for LaneIdWrapper { | |
| type BridgeHubRococoRuntime = <BridgeHubRococo as Chain>::Runtime; | ||
| type BridgeHubWococoRuntime = <BridgeHubWococo as Chain>::Runtime; | ||
|
|
||
| // TODO: uncomment when https://github.com/paritytech/polkadot-sdk/pull/1352 is merged | ||
| // type BridgeHubPolkadotRuntime = <BridgeHubPolkadot as Chain>::Runtime; | ||
| // type BridgeHubKusamaRuntime = <BridgeHubKusama as Chain>::Runtime; | ||
|
|
||
| pub type RococoWococoMessageHandler = | ||
| BridgeHubMessageHandler<BridgeHubRococoRuntime, BridgeHubWococoRuntime, Instance2>; | ||
| pub type WococoRococoMessageHandler = | ||
| BridgeHubMessageHandler<BridgeHubWococoRuntime, BridgeHubRococoRuntime, Instance2>; | ||
|
|
||
| // TODO: uncomment when https://github.com/paritytech/polkadot-sdk/pull/1352 is merged | ||
| // pub type PolkadotKusamaMessageHandler | ||
| // = BridgeHubMessageHandler<BridgeHubPolkadotRuntime, BridgeHubKusamaRuntime, Instance1>; | ||
| // pub type KusamaPolkadotMessageHandler | ||
| // = BridgeHubMessageHandler<BridgeHubKusamaRuntime, BridgeHubPolkadoRuntime, Instance1>; | ||
|
|
||
| impl<S, T, I> BridgeMessageHandler for BridgeHubMessageHandler<S, T, I> | ||
| where | ||
| S: Config<Instance1>, | ||
|
|
@@ -356,6 +346,37 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain { | |
| }; | ||
| } | ||
|
|
||
| #[macro_export] | ||
| macro_rules! impl_send_transact_helpers_for_relay_chain { | ||
| ( $chain:ident ) => { | ||
| $crate::impls::paste::paste! { | ||
| impl $chain { | ||
| /// A root origin (as governance) sends `xcm::Transact` with `UnpaidExecution` and encoded `call` to child parachain. | ||
| pub fn send_unpaid_transact_to_parachain_as_root( | ||
| recipient: $crate::impls::ParaId, | ||
| call: $crate::impls::DoubleEncoded<()> | ||
| ) { | ||
| use $crate::impls::{bx, Chain, RelayChain}; | ||
|
|
||
| <Self as $crate::impls::TestExt>::execute_with(|| { | ||
| let root_origin = <Self as Chain>::RuntimeOrigin::root(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we assuming that is going to be always
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this is meant for governance-like calls from relay to para with If we want it make it more general, then yes I think, for me, I am inclined to keep it as it is :). @NachoPal wdyt?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't realise about the hardcoded Sorry, I sometimes use pub fn send_transact_to_parachain_as_root(
recipient: $crate::impls::ParaId,
call: $crate::impls::DoubleEncoded<()>
)What I am trying to avoid is to impl a method that is only meant to work for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I renamed to |
||
| let destination: $crate::impls::MultiLocation = <Self as RelayChain>::child_location_of(recipient); | ||
| let xcm = $crate::impls::xcm_transact_unpaid_execution(call, $crate::impls::OriginKind::Superuser); | ||
|
|
||
| // Send XCM `Transact` | ||
| $crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::XcmPallet::send( | ||
| root_origin, | ||
| bx!(destination.into()), | ||
| bx!(xcm), | ||
| )); | ||
| Self::assert_xcm_pallet_sent(); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| #[macro_export] | ||
| macro_rules! impl_accounts_helpers_for_parachain { | ||
| ( $chain:ident ) => { | ||
|
|
@@ -600,53 +621,58 @@ macro_rules! impl_assets_helpers_for_parachain { | |
| min_balance: u128, | ||
| is_sufficient: bool, | ||
| asset_owner: $crate::impls::AccountId, | ||
| dmp_weight_threshold: Option<$crate::impls::Weight>, | ||
| amount_to_mint: u128, | ||
| ) { | ||
| use $crate::impls::{bx, Chain, RelayChain, Parachain, Inspect, TestExt}; | ||
| // Init values for Relay Chain | ||
| let root_origin = <$relay_chain as Chain>::RuntimeOrigin::root(); | ||
| let destination = <$relay_chain>::child_location_of(<$chain>::para_id()); | ||
| let xcm = Self::force_create_asset_xcm( | ||
| $crate::impls::OriginKind::Superuser, | ||
| use $crate::impls::Chain; | ||
|
|
||
| // Force create asset | ||
| Self::do_force_create_asset_from_relay_as_root( | ||
|
NachoPal marked this conversation as resolved.
Outdated
|
||
| id, | ||
| asset_owner.clone(), | ||
| is_sufficient, | ||
| min_balance, | ||
| is_sufficient, | ||
| asset_owner.clone(), | ||
| dmp_weight_threshold | ||
| ); | ||
|
|
||
| <$relay_chain>::execute_with(|| { | ||
| $crate::impls::assert_ok!(<$relay_chain as [<$relay_chain Pallet>]>::XcmPallet::send( | ||
| root_origin, | ||
| bx!(destination.into()), | ||
| bx!(xcm), | ||
| )); | ||
| // Mint asset for System Parachain's sender | ||
| let signed_origin = <Self as Chain>::RuntimeOrigin::signed(asset_owner.clone()); | ||
| Self::mint_asset(signed_origin, id, asset_owner, amount_to_mint); | ||
| } | ||
|
|
||
| <$relay_chain>::assert_xcm_pallet_sent(); | ||
| }); | ||
| /// Relay Chain sends `Transact` instruction with `force_create_asset` to Parachain with `Assets` instance of `pallet_assets` . | ||
| pub fn do_force_create_asset_from_relay_as_root( | ||
|
NachoPal marked this conversation as resolved.
Outdated
|
||
| id: u32, | ||
| min_balance: u128, | ||
| is_sufficient: bool, | ||
| asset_owner: $crate::impls::AccountId, | ||
| dmp_weight_threshold: Option<$crate::impls::Weight>, | ||
| ) { | ||
| use $crate::impls::{Parachain, Inspect, TestExt}; | ||
|
|
||
| Self::execute_with(|| { | ||
| Self::assert_dmp_queue_complete(Some($crate::impls::Weight::from_parts(1_019_445_000, 200_000))); | ||
| <$relay_chain>::send_unpaid_transact_to_parachain_as_root( | ||
| Self::para_id(), | ||
| Self::force_create_asset_call(id, asset_owner.clone(), is_sufficient, min_balance), | ||
| ); | ||
|
|
||
| // Receive XCM message in Assets Parachain | ||
| Self::execute_with(|| { | ||
| type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; | ||
|
|
||
| Self::assert_dmp_queue_complete(dmp_weight_threshold); | ||
|
|
||
| $crate::impls::assert_expected_events!( | ||
| Self, | ||
| vec![ | ||
| // Asset has been created | ||
| RuntimeEvent::Assets($crate::impls::pallet_assets::Event::ForceCreated { asset_id, owner }) => { | ||
| asset_id: *asset_id == id, | ||
| owner: *owner == asset_owner.clone(), | ||
| owner: *owner == asset_owner, | ||
| }, | ||
| ] | ||
| ); | ||
|
|
||
| assert!(<Self as [<$chain Pallet>]>::Assets::asset_exists(id.into())); | ||
| }); | ||
|
|
||
| let signed_origin = <Self as Chain>::RuntimeOrigin::signed(asset_owner.clone()); | ||
|
|
||
| // Mint asset for System Parachain's sender | ||
| Self::mint_asset(signed_origin, id, asset_owner, amount_to_mint); | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.