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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ decl_test_parachains! {
ParachainInfo: asset_hub_rococo_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
DigestProvider: (),
AdditionalInherentCode: (),
},
pallets = {
PolkadotXcm: asset_hub_rococo_runtime::PolkadotXcm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ decl_test_parachains! {
ParachainInfo: asset_hub_westend_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
DigestProvider: (),
AdditionalInherentCode: (),
},
pallets = {
PolkadotXcm: asset_hub_westend_runtime::PolkadotXcm,
Expand Down
22 changes: 20 additions & 2 deletions cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ where
}
}

// Implement optional inherent code to be executed
// This will be executed after on-initialize and before on-finalize
pub trait AdditionalInherentCode {
fn on_new_block() -> DispatchResult {
Ok(())
}
}

impl AdditionalInherentCode for () {}

pub trait TestExt {
fn build_new_ext(storage: Storage) -> TestExternalities;
fn new_ext() -> TestExternalities;
Expand Down Expand Up @@ -269,6 +279,7 @@ pub trait Parachain: Chain {
type ParachainSystem;
type MessageProcessor: ProcessMessage + ServiceQueues;
type DigestProvider: Convert<BlockNumberFor<Self::Runtime>, Digest>;
type AdditionalInherentCode: AdditionalInherentCode;

fn init();

Expand Down Expand Up @@ -604,7 +615,8 @@ macro_rules! decl_test_parachains {
LocationToAccountId: $location_to_account:path,
ParachainInfo: $parachain_info:path,
MessageOrigin: $message_origin:path,
$( DigestProvider: $digest_provider:ty, )?
$( DigestProvider: $digest_provider:ty,)?
$( AdditionalInherentCode: $additional_inherent_code:ty,)?
},
pallets = {
$($pallet_name:ident: $pallet_path:path,)*
Expand Down Expand Up @@ -646,6 +658,7 @@ macro_rules! decl_test_parachains {
type ParachainInfo = $parachain_info;
type MessageProcessor = $crate::DefaultParaMessageProcessor<$name<N>, $message_origin>;
$crate::decl_test_parachains!(@inner_digest_provider $($digest_provider)?);
$crate::decl_test_parachains!(@inner_additional_inherent_code $($additional_inherent_code)?);

// We run an empty block during initialisation to open HRMP channels
// and have them ready for the next block
Expand All @@ -666,7 +679,7 @@ macro_rules! decl_test_parachains {

fn new_block() {
use $crate::{
Dispatchable, Chain, Convert, TestExt, Zero,
Dispatchable, Chain, Convert, TestExt, Zero, AdditionalInherentCode
};

let para_id = Self::para_id().into();
Expand Down Expand Up @@ -713,6 +726,9 @@ macro_rules! decl_test_parachains {
$crate::assert_ok!(
timestamp_set.dispatch(<Self as Chain>::RuntimeOrigin::none())
);
$crate::assert_ok!(
<Self as Parachain>::AdditionalInherentCode::on_new_block()
);
});
}

Expand Down Expand Up @@ -775,6 +791,8 @@ macro_rules! decl_test_parachains {
};
( @inner_digest_provider $digest_provider:ty ) => { type DigestProvider = $digest_provider; };
( @inner_digest_provider /* none */ ) => { type DigestProvider = (); };
( @inner_additional_inherent_code $additional_inherent_code:ty ) => { type AdditionalInherentCode = $additional_inherent_code; };
( @inner_additional_inherent_code /* none */ ) => { type AdditionalInherentCode = (); };
}

#[macro_export]
Expand Down
10 changes: 10 additions & 0 deletions prdoc/pr_8809.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Add possibility of executing or mocking additional inherents in xcm-emulator
doc:
- audience: Runtime Dev
description: |-
This extends the `decl_test_parachains` macro to accept a `AdditionalInherentCode` type. This type needs to
implement the `AdditionalInherentCode` trait and will be called after `on_initialize` and before `on_finalize`.
It can be used to mock additional inherents.
crates:
- name: xcm-emulator
bump: minor
Loading