Snowbridge - Test pallet order (#3381)

- Adds a test to check the correct digest for Snowbridge outbound
messages. For the correct digest to be in the block, the the
MessageQueue pallet should be configured after the EthereumOutbound
queue pallet. The added test fails if the EthereumOutbound is configured
after the MessageQueue pallet.
- Adds a helper method `run_to_block_with_finalize` to simulate the
block finalizing. The existing `run_to_block` method does not finalize
and so it cannot successfully test this condition.

Closes: https://github.com/paritytech/polkadot-sdk/issues/3208

---------

Co-authored-by: claravanstaden <Cats 4 life!>
This commit is contained in:
Clara van Staden
2024-02-21 16:48:40 +02:00
committed by GitHub
parent bf7c49b33c
commit 5a06771ecc
16 changed files with 332 additions and 155 deletions
@@ -34,7 +34,7 @@ use polkadot_parachain_primitives::primitives::{
};
use sp_consensus_aura::{SlotDuration, AURA_ENGINE_ID};
use sp_core::{Encode, U256};
use sp_runtime::{traits::Header, BuildStorage, Digest, DigestItem};
use sp_runtime::{traits::Header, BuildStorage, Digest, DigestItem, SaturatedConversion};
use xcm::{
latest::{Asset, Location, XcmContext, XcmHash},
prelude::*,
@@ -129,6 +129,7 @@ pub trait BasicParachainRuntime:
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config
{
}
@@ -140,7 +141,8 @@ where
+ pallet_xcm::Config
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config,
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config,
ValidatorIdOf<T>: From<AccountIdOf<T>>,
{
}
@@ -259,8 +261,10 @@ pub struct RuntimeHelper<Runtime, AllPalletsWithoutSystem>(
);
/// Utility function that advances the chain to the desired block number.
/// If an author is provided, that author information is injected to all the blocks in the meantime.
impl<Runtime: frame_system::Config, AllPalletsWithoutSystem>
RuntimeHelper<Runtime, AllPalletsWithoutSystem>
impl<
Runtime: frame_system::Config + cumulus_pallet_parachain_system::Config + pallet_timestamp::Config,
AllPalletsWithoutSystem,
> RuntimeHelper<Runtime, AllPalletsWithoutSystem>
where
AccountIdOf<Runtime>:
Into<<<Runtime as frame_system::Config>::RuntimeOrigin as OriginTrait>::AccountId>,
@@ -296,6 +300,65 @@ where
last_header.expect("run_to_block empty block range")
}
pub fn run_to_block_with_finalize(n: u32) -> HeaderFor<Runtime> {
let mut last_header = None;
loop {
let block_number = frame_system::Pallet::<Runtime>::block_number();
if block_number >= n.into() {
break
}
// Set the new block number and author
let header = frame_system::Pallet::<Runtime>::finalize();
let pre_digest = Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, block_number.encode())],
};
frame_system::Pallet::<Runtime>::reset_events();
let next_block_number = block_number + 1u32.into();
frame_system::Pallet::<Runtime>::initialize(
&next_block_number,
&header.hash(),
&pre_digest,
);
AllPalletsWithoutSystem::on_initialize(next_block_number);
let parent_head = HeadData(header.encode());
let sproof_builder = RelayStateSproofBuilder {
para_id: <Runtime>::SelfParaId::get(),
included_para_head: parent_head.clone().into(),
..Default::default()
};
let (relay_parent_storage_root, relay_chain_state) =
sproof_builder.into_state_root_and_proof();
let inherent_data = ParachainInherentData {
validation_data: PersistedValidationData {
parent_head,
relay_parent_number: (block_number.saturated_into::<u32>() * 2 + 1).into(),
relay_parent_storage_root,
max_pov_size: 100_000_000,
},
relay_chain_state,
downward_messages: Default::default(),
horizontal_messages: Default::default(),
};
let _ = cumulus_pallet_parachain_system::Pallet::<Runtime>::set_validation_data(
Runtime::RuntimeOrigin::none(),
inherent_data,
);
let _ = pallet_timestamp::Pallet::<Runtime>::set(
Runtime::RuntimeOrigin::none(),
300_u32.into(),
);
AllPalletsWithoutSystem::on_finalize(next_block_number);
let header = frame_system::Pallet::<Runtime>::finalize();
last_header = Some(header);
}
last_header.expect("run_to_block empty block range")
}
pub fn root_origin() -> <Runtime as frame_system::Config>::RuntimeOrigin {
<Runtime as frame_system::Config>::RuntimeOrigin::root()
}
@@ -37,7 +37,8 @@ pub fn change_storage_constant_by_governance_works<Runtime, StorageConstant, Sto
+ pallet_xcm::Config
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config,
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
StorageConstant: Get<StorageConstantType>,
StorageConstantType: Encode + PartialEq + std::fmt::Debug,
@@ -107,7 +108,8 @@ pub fn set_storage_keys_by_governance_works<Runtime>(
+ pallet_xcm::Config
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config,
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
{
let mut runtime = ExtBuilder::<Runtime>::default()