diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs index ceb4d23c294f6..052d7eb074475 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs @@ -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, diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs index 0ae7067025fa4..6465e4fece3fd 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs @@ -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, diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index d5a1d6ed5992d..e62d19393a0d4 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -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; @@ -269,6 +279,7 @@ pub trait Parachain: Chain { type ParachainSystem; type MessageProcessor: ProcessMessage + ServiceQueues; type DigestProvider: Convert, Digest>; + type AdditionalInherentCode: AdditionalInherentCode; fn init(); @@ -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,)* @@ -646,6 +658,7 @@ macro_rules! decl_test_parachains { type ParachainInfo = $parachain_info; type MessageProcessor = $crate::DefaultParaMessageProcessor<$name, $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 @@ -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(); @@ -713,6 +726,9 @@ macro_rules! decl_test_parachains { $crate::assert_ok!( timestamp_set.dispatch(::RuntimeOrigin::none()) ); + $crate::assert_ok!( + ::AdditionalInherentCode::on_new_block() + ); }); } @@ -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] diff --git a/prdoc/pr_8809.prdoc b/prdoc/pr_8809.prdoc new file mode 100644 index 0000000000000..eebbd8675a285 --- /dev/null +++ b/prdoc/pr_8809.prdoc @@ -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