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
@@ -17,6 +17,7 @@ frame-support = { path = "../../../../../substrate/frame/support", default-featu
frame-system = { path = "../../../../../substrate/frame/system", default-features = false }
pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false }
pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-features = false }
pallet-session = { path = "../../../../../substrate/frame/session", default-features = false }
sp-io = { path = "../../../../../substrate/primitives/io", default-features = false }
sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false }
@@ -59,6 +60,7 @@ std = [
"pallet-balances/std",
"pallet-collator-selection/std",
"pallet-session/std",
"pallet-timestamp/std",
"pallet-xcm-bridge-hub-router/std",
"pallet-xcm/std",
"parachain-info/std",
@@ -70,7 +70,8 @@ pub fn teleports_for_native_asset_works<
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config,
+ cumulus_pallet_xcmp_queue::Config
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
@@ -350,7 +351,8 @@ pub fn teleports_for_foreign_assets_works<
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config
+ pallet_assets::Config<ForeignAssetsPalletInstance>,
+ pallet_assets::Config<ForeignAssetsPalletInstance>
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
@@ -701,7 +703,8 @@ pub fn asset_transactor_transfer_with_local_consensus_currency_works<Runtime, Xc
+ pallet_xcm::Config
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config,
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config,
AccountIdOf<Runtime>: Into<[u8; 32]>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
BalanceOf<Runtime>: From<Balance>,
@@ -826,7 +829,8 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works<
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ pallet_assets::Config<AssetsPalletInstance>,
+ pallet_assets::Config<AssetsPalletInstance>
+ pallet_timestamp::Config,
AccountIdOf<Runtime>: Into<[u8; 32]>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
BalanceOf<Runtime>: From<Balance>,
@@ -1093,7 +1097,8 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ pallet_assets::Config<ForeignAssetsPalletInstance>,
+ pallet_assets::Config<ForeignAssetsPalletInstance>
+ pallet_timestamp::Config,
AccountIdOf<Runtime>: Into<[u8; 32]>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
BalanceOf<Runtime>: From<Balance>,
@@ -1422,7 +1427,8 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config,
+ cumulus_pallet_xcmp_queue::Config
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
@@ -70,7 +70,8 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works<
+ parachain_info::Config
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config,
+ cumulus_pallet_xcmp_queue::Config
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
@@ -347,7 +348,8 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config
+ pallet_assets::Config<ForeignAssetsPalletInstance>,
+ pallet_assets::Config<ForeignAssetsPalletInstance>
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]> + From<[u8; 32]>,
@@ -510,7 +512,8 @@ pub fn report_bridge_status_from_xcm_bridge_router_works<
+ pallet_collator_selection::Config
+ cumulus_pallet_parachain_system::Config
+ cumulus_pallet_xcmp_queue::Config
+ pallet_xcm_bridge_hub_router::Config<XcmBridgeHubRouterInstance>,
+ pallet_xcm_bridge_hub_router::Config<XcmBridgeHubRouterInstance>
+ pallet_timestamp::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
AccountIdOf<Runtime>: Into<[u8; 32]>,
@@ -730,7 +730,7 @@ construct_runtime!(
// Message Queue. Importantly, is registered last so that messages are processed after
// the `on_initialize` hooks of bridging pallets.
MessageQueue: pallet_message_queue = 250,
MessageQueue: pallet_message_queue = 175,
}
);
@@ -20,9 +20,9 @@ use bp_polkadot_core::Signature;
use bridge_hub_rococo_runtime::{
bridge_to_bulletin_config::OnBridgeHubRococoRefundRococoBulletinMessages,
bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages,
xcm_config::XcmConfig, BridgeRejectObsoleteHeadersAndMessages, Executive,
MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, SignedExtra,
UncheckedExtrinsic,
xcm_config::XcmConfig, AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages,
Executive, MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, SessionKeys,
SignedExtra, UncheckedExtrinsic,
};
use codec::{Decode, Encode};
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees};
@@ -135,6 +135,32 @@ fn ethereum_to_polkadot_message_extrinsics_work() {
);
}
/// Tests that the digest items are as expected when a Ethereum Outbound message is received.
/// If the MessageQueue pallet is configured before (i.e. the MessageQueue pallet is listed before
/// the EthereumOutboundQueue in the construct_runtime macro) the EthereumOutboundQueue, this test
/// will fail.
#[test]
pub fn ethereum_outbound_queue_processes_messages_before_message_queue_works() {
snowbridge_runtime_test_common::ethereum_outbound_queue_processes_messages_before_message_queue_works::<
Runtime,
XcmConfig,
AllPalletsWithoutSystem,
>(
collator_session_keys(),
1013,
1000,
H160::random(),
H160::random(),
DefaultBridgeHubEthereumBaseFee::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Ok(RuntimeEvent::EthereumOutboundQueue(event)) => Some(event),
_ => None,
}
}),
)
}
fn construct_extrinsic(
sender: sp_keyring::AccountKeyring,
call: RuntimeCall,
@@ -25,6 +25,7 @@ sp-std = { path = "../../../../../substrate/primitives/std", default-features =
sp-tracing = { path = "../../../../../substrate/primitives/tracing" }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false }
pallet-utility = { path = "../../../../../substrate/frame/utility", default-features = false }
pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-features = false }
# Cumulus
asset-test-utils = { path = "../../assets/test-utils" }
@@ -73,6 +74,7 @@ std = [
"pallet-bridge-messages/std",
"pallet-bridge-parachains/std",
"pallet-bridge-relayers/std",
"pallet-timestamp/std",
"pallet-utility/std",
"parachains-common/std",
"parachains-runtimes-test-utils/std",
@@ -197,7 +197,9 @@ where
pub(crate) fn initialize_bridge_grandpa_pallet<Runtime, GPI>(
init_data: bp_header_chain::InitializationData<BridgedHeader<Runtime, GPI>>,
) where
Runtime: BridgeGrandpaConfig<GPI>,
Runtime: BridgeGrandpaConfig<GPI>
+ cumulus_pallet_parachain_system::Config
+ pallet_timestamp::Config,
{
pallet_bridge_grandpa::Pallet::<Runtime, GPI>::initialize(
RuntimeHelper::<Runtime>::root_origin(),
@@ -17,6 +17,7 @@ frame-support = { path = "../../../../substrate/frame/support", default-features
frame-system = { path = "../../../../substrate/frame/system", default-features = false }
pallet-balances = { path = "../../../../substrate/frame/balances", default-features = false }
pallet-session = { path = "../../../../substrate/frame/session", default-features = false }
pallet-timestamp = { path = "../../../../substrate/frame/timestamp", default-features = false }
sp-consensus-aura = { path = "../../../../substrate/primitives/consensus/aura", default-features = false }
sp-io = { path = "../../../../substrate/primitives/io", default-features = false }
sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false }
@@ -59,6 +60,7 @@ std = [
"pallet-balances/std",
"pallet-collator-selection/std",
"pallet-session/std",
"pallet-timestamp/std",
"pallet-xcm/std",
"parachain-info/std",
"polkadot-parachain-primitives/std",
@@ -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()