diff --git a/bridges/primitives/runtime/src/chain.rs b/bridges/primitives/runtime/src/chain.rs index 469c839ba151..81a2070bece5 100644 --- a/bridges/primitives/runtime/src/chain.rs +++ b/bridges/primitives/runtime/src/chain.rs @@ -199,7 +199,7 @@ pub trait Chain: Send + Sync + 'static { } /// A trait that provides the type of the underlying chain. -pub trait UnderlyingChainProvider { +pub trait UnderlyingChainProvider: Send + Sync + 'static { /// Underlying chain type. type Chain: Chain; } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs index 0ba5fb37aef0..390ac449f8cc 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs @@ -373,6 +373,7 @@ mod bridge_hub_westend_tests { mod bridge_hub_bulletin_tests { use super::*; use bridge_common_config::BridgeGrandpaRococoBulletinInstance; + use bridge_hub_test_utils::test_cases::from_grandpa_chain; use bridge_to_bulletin_config::{ RococoBulletinChainId, RococoBulletinGlobalConsensusNetwork, RococoBulletinGlobalConsensusNetworkLocation, WithRococoBulletinMessageBridge, @@ -382,6 +383,15 @@ mod bridge_hub_bulletin_tests { // Para id of sibling chain used in tests. pub const SIBLING_PARACHAIN_ID: u32 = rococo_runtime_constants::system_parachain::PEOPLE_ID; + // Runtime from tests PoV + type RuntimeTestsAdapter = from_grandpa_chain::WithRemoteGrandpaChainHelperAdapter< + Runtime, + AllPalletsWithoutSystem, + BridgeGrandpaRococoBulletinInstance, + WithRococoBulletinMessagesInstance, + WithRococoBulletinMessageBridge, + >; + #[test] fn initialize_bridge_by_governance_works() { // for Bulletin finality @@ -474,14 +484,7 @@ mod bridge_hub_bulletin_tests { #[test] fn relayed_incoming_message_works() { // from Bulletin - bridge_hub_test_utils::test_cases::from_grandpa_chain::relayed_incoming_message_works::< - Runtime, - AllPalletsWithoutSystem, - ParachainSystem, - BridgeGrandpaRococoBulletinInstance, - WithRococoBulletinMessagesInstance, - WithRococoBulletinMessageBridge, - >( + from_grandpa_chain::relayed_incoming_message_works::( collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, RococoBulletinChainId::get(), @@ -496,15 +499,7 @@ mod bridge_hub_bulletin_tests { #[test] pub fn complex_relay_extrinsic_works() { // for Bulletin - bridge_hub_test_utils::test_cases::from_grandpa_chain::complex_relay_extrinsic_works::< - Runtime, - AllPalletsWithoutSystem, - XcmConfig, - ParachainSystem, - BridgeGrandpaRococoBulletinInstance, - WithRococoBulletinMessagesInstance, - WithRococoBulletinMessageBridge, - >( + from_grandpa_chain::complex_relay_extrinsic_works::( collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, SIBLING_PARACHAIN_ID, @@ -536,15 +531,10 @@ mod bridge_hub_bulletin_tests { #[test] pub fn can_calculate_fee_for_complex_message_delivery_transaction() { - let estimated = bridge_hub_test_utils::test_cases::from_grandpa_chain::can_calculate_fee_for_complex_message_delivery_transaction::< - Runtime, - BridgeGrandpaRococoBulletinInstance, - WithRococoBulletinMessagesInstance, - WithRococoBulletinMessageBridge, - >( - collator_session_keys(), - construct_and_estimate_extrinsic_fee - ); + let estimated = + from_grandpa_chain::can_calculate_fee_for_complex_message_delivery_transaction::< + RuntimeTestsAdapter, + >(collator_session_keys(), construct_and_estimate_extrinsic_fee); // check if estimated value is sane let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs::get(); @@ -558,15 +548,10 @@ mod bridge_hub_bulletin_tests { #[test] pub fn can_calculate_fee_for_complex_message_confirmation_transaction() { - let estimated = bridge_hub_test_utils::test_cases::from_grandpa_chain::can_calculate_fee_for_complex_message_confirmation_transaction::< - Runtime, - BridgeGrandpaRococoBulletinInstance, - WithRococoBulletinMessagesInstance, - WithRococoBulletinMessageBridge, - >( - collator_session_keys(), - construct_and_estimate_extrinsic_fee - ); + let estimated = + from_grandpa_chain::can_calculate_fee_for_complex_message_confirmation_transaction::< + RuntimeTestsAdapter, + >(collator_session_keys(), construct_and_estimate_extrinsic_fee); // check if estimated value is sane let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs::get(); diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/from_grandpa_chain.rs b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/from_grandpa_chain.rs index 3a0bbf8f5711..e6407e60989e 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/from_grandpa_chain.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/from_grandpa_chain.rs @@ -36,27 +36,79 @@ use bridge_runtime_common::{ }, messages_xcm_extension::XcmAsPlainPayload, }; -use frame_support::traits::{Get, OnFinalize, OnInitialize, OriginTrait}; +use frame_support::traits::{Get, OnFinalize, OnInitialize}; use frame_system::pallet_prelude::BlockNumberFor; +use pallet_bridge_grandpa::{Call as BridgeGrandpaCall, Config as BridgeGrandpaConfig}; +use pallet_bridge_messages::{Call as BridgeMessagesCall, Config as BridgeMessagesConfig}; use parachains_runtimes_test_utils::{ - AccountIdOf, BasicParachainRuntime, CollatorSessionKeys, ValidatorIdOf, + AccountIdOf, BasicParachainRuntime, CollatorSessionKeys, RuntimeCallOf, }; use sp_keyring::AccountKeyring::*; use sp_runtime::{traits::Header as HeaderT, AccountId32}; use xcm::latest::prelude::*; +/// Helper trait to test bridges with remote GRANDPA chain. +/// +/// This is only used to decrease amount of lines, dedicated to bounds +pub trait WithRemoteGrandpaChainHelper { + /// This chaiin runtime. + type Runtime: BasicParachainRuntime + + cumulus_pallet_xcmp_queue::Config + + BridgeGrandpaConfig< + Self::GPI, + BridgedChain = UnderlyingChainOf>, + > + BridgeMessagesConfig< + Self::MPI, + InboundPayload = XcmAsPlainPayload, + InboundRelayer = bp_runtime::AccountIdOf>, + OutboundPayload = XcmAsPlainPayload, + > + pallet_bridge_relayers::Config; + /// All pallets of this chain, excluding system pallet. + type AllPalletsWithoutSystem: OnInitialize> + + OnFinalize>; + /// Instance of the `pallet-bridge-grandpa`, used to bridge with remote GRANDPA chain. + type GPI: 'static; + /// Instance of the `pallet-bridge-messages`, used to bridge with remote GRANDPA chain. + type MPI: 'static; + /// Messages bridge definition. + type MB: MessageBridge; +} + +/// Adapter struct that implements `WithRemoteGrandpaChainHelper` +pub struct WithRemoteGrandpaChainHelperAdapter( + sp_std::marker::PhantomData<(Runtime, AllPalletsWithoutSystem, GPI, MPI, MB)>, +); + +impl WithRemoteGrandpaChainHelper + for WithRemoteGrandpaChainHelperAdapter +where + Runtime: BasicParachainRuntime + + cumulus_pallet_xcmp_queue::Config + + BridgeGrandpaConfig>> + + BridgeMessagesConfig< + MPI, + InboundPayload = XcmAsPlainPayload, + InboundRelayer = bp_runtime::AccountIdOf>, + OutboundPayload = XcmAsPlainPayload, + > + pallet_bridge_relayers::Config, + AllPalletsWithoutSystem: + OnInitialize> + OnFinalize>, + GPI: 'static, + MPI: 'static, + MB: MessageBridge, +{ + type Runtime = Runtime; + type AllPalletsWithoutSystem = AllPalletsWithoutSystem; + type GPI = GPI; + type MPI = MPI; + type MB = MB; +} + /// Test-case makes sure that Runtime can dispatch XCM messages submitted by relayer, /// with proofs (finality, message) independently submitted. /// Also verifies relayer transaction signed extensions work as intended. -pub fn relayed_incoming_message_works< - Runtime, - AllPalletsWithoutSystem, - HrmpChannelOpener, - GPI, - MPI, - MB, ->( - collator_session_key: CollatorSessionKeys, +pub fn relayed_incoming_message_works( + collator_session_key: CollatorSessionKeys, runtime_para_id: u32, bridged_chain_id: bp_runtime::ChainId, sibling_parachain_id: u32, @@ -65,44 +117,25 @@ pub fn relayed_incoming_message_works< prepare_configuration: impl Fn(), construct_and_apply_extrinsic: fn( sp_keyring::AccountKeyring, - ::RuntimeCall, + RuntimeCallOf, ) -> sp_runtime::DispatchOutcome, ) where - Runtime: BasicParachainRuntime - + cumulus_pallet_xcmp_queue::Config - + pallet_bridge_grandpa::Config< - GPI, - BridgedChain = UnderlyingChainOf>, - > + pallet_bridge_messages::Config - + pallet_bridge_relayers::Config, - AllPalletsWithoutSystem: - OnInitialize> + OnFinalize>, - GPI: 'static, - MPI: 'static, - MB: MessageBridge, - ::BridgedChain: Send + Sync + 'static, - ::ThisChain: Send + Sync + 'static, - UnderlyingChainOf>: ChainWithGrandpa, - HrmpChannelOpener: frame_support::inherent::ProvideInherent< - Call = cumulus_pallet_parachain_system::Call, - >, - ValidatorIdOf: From>, - >::SourceHeaderChain: SourceHeaderChain< - MessagesProof = FromBridgedChainMessagesProof>>, - >, - ::AccountId: - Into<<::RuntimeOrigin as OriginTrait>::AccountId>, - ::AccountId: From, - AccountIdOf: From, - >::InboundRelayer: From, - ::RuntimeCall: From> - + From>, + RuntimeHelper: WithRemoteGrandpaChainHelper, + AccountIdOf: From, + RuntimeCallOf: From> + + From>, + UnderlyingChainOf>: ChainWithGrandpa, + >::SourceHeaderChain: + SourceHeaderChain< + MessagesProof = FromBridgedChainMessagesProof< + HashOf>, + >, + >, { helpers::relayed_incoming_message_works::< - Runtime, - AllPalletsWithoutSystem, - HrmpChannelOpener, - MPI, + RuntimeHelper::Runtime, + RuntimeHelper::AllPalletsWithoutSystem, + RuntimeHelper::MPI, >( collator_session_key, runtime_para_id, @@ -119,40 +152,42 @@ pub fn relayed_incoming_message_works< prepare_configuration(); // start with bridged relay chain block#0 - helpers::initialize_bridge_grandpa_pallet::( - test_data::initialization_data::(0), + helpers::initialize_bridge_grandpa_pallet::( + test_data::initialization_data::(0), ); // generate bridged relay chain finality, parachain heads and message proofs, // to be submitted by relayer to this chain. let (relay_chain_header, grandpa_justification, message_proof) = - test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::( - lane_id, - xcm.into(), - message_nonce, - message_destination, - relay_header_number, - ); + test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::< + RuntimeHelper::MB, + (), + >(lane_id, xcm.into(), message_nonce, message_destination, relay_header_number); let relay_chain_header_hash = relay_chain_header.hash(); vec![ ( - pallet_bridge_grandpa::Call::::submit_finality_proof { + BridgeGrandpaCall::::submit_finality_proof { finality_target: Box::new(relay_chain_header), justification: grandpa_justification, }.into(), - helpers::VerifySubmitGrandpaFinalityProofOutcome::::expect_best_header_hash(relay_chain_header_hash), + helpers::VerifySubmitGrandpaFinalityProofOutcome::::expect_best_header_hash( + relay_chain_header_hash, + ), ), ( - pallet_bridge_messages::Call::::receive_messages_proof { + BridgeMessagesCall::::receive_messages_proof { relayer_id_at_bridged_chain, proof: message_proof, messages_count: 1, dispatch_weight: Weight::from_parts(1000000000, 0), }.into(), Box::new(( - helpers::VerifySubmitMessagesProofOutcome::::expect_last_delivered_nonce(lane_id, 1), - helpers::VerifyRelayerRewarded::::expect_relayer_reward( + helpers::VerifySubmitMessagesProofOutcome::::expect_last_delivered_nonce( + lane_id, + 1, + ), + helpers::VerifyRelayerRewarded::::expect_relayer_reward( relayer_id_at_this_chain, RewardsAccountParams::new( lane_id, @@ -170,16 +205,8 @@ pub fn relayed_incoming_message_works< /// Test-case makes sure that Runtime can dispatch XCM messages submitted by relayer, /// with proofs (finality, message) batched together in signed extrinsic. /// Also verifies relayer transaction signed extensions work as intended. -pub fn complex_relay_extrinsic_works< - Runtime, - AllPalletsWithoutSystem, - XcmConfig, - HrmpChannelOpener, - GPI, - MPI, - MB, ->( - collator_session_key: CollatorSessionKeys, +pub fn complex_relay_extrinsic_works( + collator_session_key: CollatorSessionKeys, runtime_para_id: u32, sibling_parachain_id: u32, bridged_chain_id: bp_runtime::ChainId, @@ -188,46 +215,28 @@ pub fn complex_relay_extrinsic_works< prepare_configuration: impl Fn(), construct_and_apply_extrinsic: fn( sp_keyring::AccountKeyring, - ::RuntimeCall, + RuntimeCallOf, ) -> sp_runtime::DispatchOutcome, ) where - Runtime: BasicParachainRuntime - + cumulus_pallet_xcmp_queue::Config - + pallet_bridge_grandpa::Config< - GPI, - BridgedChain = UnderlyingChainOf>, - > + pallet_bridge_messages::Config - + pallet_bridge_relayers::Config - + pallet_utility::Config, - AllPalletsWithoutSystem: - OnInitialize> + OnFinalize>, - GPI: 'static, - MPI: 'static, - MB: MessageBridge, - ::BridgedChain: Send + Sync + 'static, - ::ThisChain: Send + Sync + 'static, - UnderlyingChainOf>: ChainWithGrandpa, - HrmpChannelOpener: frame_support::inherent::ProvideInherent< - Call = cumulus_pallet_parachain_system::Call, - >, - ValidatorIdOf: From>, - >::SourceHeaderChain: SourceHeaderChain< - MessagesProof = FromBridgedChainMessagesProof>>, - >, - ::AccountId: - Into<<::RuntimeOrigin as OriginTrait>::AccountId>, - ::AccountId: From, - AccountIdOf: From, - >::InboundRelayer: From, - ::RuntimeCall: From> - + From>, - ::RuntimeCall: From>, + RuntimeHelper: WithRemoteGrandpaChainHelper, + RuntimeHelper::Runtime: + pallet_utility::Config>, + AccountIdOf: From, + RuntimeCallOf: From> + + From> + + From>, + UnderlyingChainOf>: ChainWithGrandpa, + >::SourceHeaderChain: + SourceHeaderChain< + MessagesProof = FromBridgedChainMessagesProof< + HashOf>, + >, + >, { helpers::relayed_incoming_message_works::< - Runtime, - AllPalletsWithoutSystem, - HrmpChannelOpener, - MPI, + RuntimeHelper::Runtime, + RuntimeHelper::AllPalletsWithoutSystem, + RuntimeHelper::MPI, >( collator_session_key, runtime_para_id, @@ -244,41 +253,45 @@ pub fn complex_relay_extrinsic_works< prepare_configuration(); // start with bridged relay chain block#0 - helpers::initialize_bridge_grandpa_pallet::( - test_data::initialization_data::(0), + helpers::initialize_bridge_grandpa_pallet::( + test_data::initialization_data::(0), ); // generate bridged relay chain finality, parachain heads and message proofs, // to be submitted by relayer to this chain. let (relay_chain_header, grandpa_justification, message_proof) = - test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::( - lane_id, - xcm.into(), - message_nonce, - message_destination, - relay_header_number, - ); + test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::< + RuntimeHelper::MB, + (), + >(lane_id, xcm.into(), message_nonce, message_destination, relay_header_number); let relay_chain_header_hash = relay_chain_header.hash(); vec![( - pallet_utility::Call::::batch_all { + pallet_utility::Call::::batch_all { calls: vec![ - pallet_bridge_grandpa::Call::::submit_finality_proof { + BridgeGrandpaCall::::submit_finality_proof { finality_target: Box::new(relay_chain_header), justification: grandpa_justification, }.into(), - pallet_bridge_messages::Call::::receive_messages_proof { + BridgeMessagesCall::::receive_messages_proof { relayer_id_at_bridged_chain, proof: message_proof, messages_count: 1, dispatch_weight: Weight::from_parts(1000000000, 0), }.into(), ], - }.into(), + } + .into(), Box::new(( - helpers::VerifySubmitGrandpaFinalityProofOutcome::::expect_best_header_hash(relay_chain_header_hash), - helpers::VerifySubmitMessagesProofOutcome::::expect_last_delivered_nonce(lane_id, 1), - helpers::VerifyRelayerRewarded::::expect_relayer_reward( + helpers::VerifySubmitGrandpaFinalityProofOutcome::< + RuntimeHelper::Runtime, + RuntimeHelper::GPI, + >::expect_best_header_hash(relay_chain_header_hash), + helpers::VerifySubmitMessagesProofOutcome::< + RuntimeHelper::Runtime, + RuntimeHelper::MPI, + >::expect_last_delivered_nonce(lane_id, 1), + helpers::VerifyRelayerRewarded::::expect_relayer_reward( relayer_id_at_this_chain, RewardsAccountParams::new( lane_id, @@ -294,35 +307,25 @@ pub fn complex_relay_extrinsic_works< /// Estimates transaction fee for default message delivery transaction (batched with required /// proofs) from bridged GRANDPA chain. -pub fn can_calculate_fee_for_complex_message_delivery_transaction( - collator_session_key: CollatorSessionKeys, - compute_extrinsic_fee: fn(pallet_utility::Call) -> u128, +pub fn can_calculate_fee_for_complex_message_delivery_transaction( + collator_session_key: CollatorSessionKeys, + compute_extrinsic_fee: fn(pallet_utility::Call) -> u128, ) -> u128 where - Runtime: BasicParachainRuntime - + pallet_bridge_grandpa::Config< - GPI, - BridgedChain = UnderlyingChainOf>, - > + pallet_bridge_messages::Config< - MPI, - InboundPayload = XcmAsPlainPayload, - InboundRelayer = bp_runtime::AccountIdOf>, - > + pallet_utility::Config, - GPI: 'static, - MPI: 'static, - MB: MessageBridge, - ::BridgedChain: Send + Sync + 'static, - ::ThisChain: Send + Sync + 'static, - UnderlyingChainOf>: bp_runtime::Chain + ChainWithGrandpa, - ValidatorIdOf: From>, - >::SourceHeaderChain: SourceHeaderChain< - MessagesProof = FromBridgedChainMessagesProof>>, - >, - bp_runtime::AccountIdOf>: From, - ::RuntimeCall: From> - + From>, + RuntimeHelper: WithRemoteGrandpaChainHelper, + RuntimeHelper::Runtime: + pallet_utility::Config>, + RuntimeCallOf: From> + + From>, + UnderlyingChainOf>: ChainWithGrandpa, + >::SourceHeaderChain: + SourceHeaderChain< + MessagesProof = FromBridgedChainMessagesProof< + HashOf>, + >, + >, { - run_test::(collator_session_key, 1000, vec![], || { + run_test::(collator_session_key, 1000, vec![], || { // generate bridged relay chain finality, parachain heads and message proofs, // to be submitted by relayer to this chain. // @@ -330,7 +333,10 @@ where // do not need to have a large message here, because we're charging for every byte of // the message additionally let (relay_chain_header, grandpa_justification, message_proof) = - test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::( + test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::< + RuntimeHelper::MB, + (), + >( LaneId::default(), vec![xcm::v3::Instruction::<()>::ClearOrigin; 1_024].into(), 1, @@ -341,14 +347,14 @@ where // generate batch call that provides finality for bridged relay and parachains + message // proof let batch = test_data::from_grandpa_chain::make_complex_relayer_delivery_batch::< - Runtime, - GPI, - MPI, + RuntimeHelper::Runtime, + RuntimeHelper::GPI, + RuntimeHelper::MPI, >( relay_chain_header, grandpa_justification, message_proof, - Dave.public().into(), + helpers::relayer_id_at_bridged_chain::(), ); let estimated_fee = compute_extrinsic_fee(batch); @@ -356,7 +362,7 @@ where target: "bridges::estimate", "Estimate fee: {:?} for single message delivery for runtime: {:?}", estimated_fee, - Runtime::Version::get(), + ::Version::get(), ); estimated_fee @@ -365,42 +371,30 @@ where /// Estimates transaction fee for default message confirmation transaction (batched with required /// proofs) from bridged GRANDPA chain. -pub fn can_calculate_fee_for_complex_message_confirmation_transaction( - collator_session_key: CollatorSessionKeys, - compute_extrinsic_fee: fn(pallet_utility::Call) -> u128, +pub fn can_calculate_fee_for_complex_message_confirmation_transaction( + collator_session_key: CollatorSessionKeys, + compute_extrinsic_fee: fn(pallet_utility::Call) -> u128, ) -> u128 where - Runtime: BasicParachainRuntime - + pallet_bridge_grandpa::Config< - GPI, - BridgedChain = UnderlyingChainOf>, - > + pallet_bridge_messages::Config - + pallet_utility::Config, - GPI: 'static, - MPI: 'static, - MB: MessageBridge, - ::BridgedChain: Send + Sync + 'static, - ::ThisChain: Send + Sync + 'static, - <::ThisChain as bp_runtime::Chain>::AccountId: From, - UnderlyingChainOf>: ChainWithGrandpa, - ValidatorIdOf: From>, - ::AccountId: - Into<<::RuntimeOrigin as OriginTrait>::AccountId>, - ::AccountId: From, - AccountIdOf: From, - >::InboundRelayer: From, - >::TargetHeaderChain: TargetHeaderChain< - XcmAsPlainPayload, - Runtime::AccountId, - MessagesDeliveryProof = FromBridgedChainMessagesDeliveryProof< - HashOf>>, + RuntimeHelper: WithRemoteGrandpaChainHelper, + AccountIdOf: From, + RuntimeHelper::Runtime: + pallet_utility::Config>, + MessageThisChain: + bp_runtime::Chain>, + RuntimeCallOf: From> + + From>, + UnderlyingChainOf>: ChainWithGrandpa, + >::TargetHeaderChain: + TargetHeaderChain< + XcmAsPlainPayload, + AccountIdOf, + MessagesDeliveryProof = FromBridgedChainMessagesDeliveryProof< + HashOf>>, + >, >, - >, - ::RuntimeCall: From> - + From>, - bp_runtime::AccountIdOf>: From, { - run_test::(collator_session_key, 1000, vec![], || { + run_test::(collator_session_key, 1000, vec![], || { // generate bridged relay chain finality, parachain heads and message proofs, // to be submitted by relayer to this chain. let unrewarded_relayers = UnrewardedRelayersState { @@ -409,19 +403,22 @@ where ..Default::default() }; let (relay_chain_header, grandpa_justification, message_delivery_proof) = - test_data::from_grandpa_chain::make_complex_relayer_confirmation_proofs::( + test_data::from_grandpa_chain::make_complex_relayer_confirmation_proofs::< + RuntimeHelper::MB, + (), + >( LaneId::default(), 1u32.into(), - Alice.public().into(), + AccountId32::from(Alice.public()).into(), unrewarded_relayers.clone(), ); // generate batch call that provides finality for bridged relay and parachains + message // proof let batch = test_data::from_grandpa_chain::make_complex_relayer_confirmation_batch::< - Runtime, - GPI, - MPI, + RuntimeHelper::Runtime, + RuntimeHelper::GPI, + RuntimeHelper::MPI, >( relay_chain_header, grandpa_justification, @@ -434,7 +431,7 @@ where target: "bridges::estimate", "Estimate fee: {:?} for single message confirmation for runtime: {:?}", estimated_fee, - Runtime::Version::get(), + ::Version::get(), ); estimated_fee diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/from_parachain.rs b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/from_parachain.rs index 7e4ff8f874dc..dff71d23df87 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/from_parachain.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/from_parachain.rs @@ -107,12 +107,7 @@ pub fn relayed_incoming_message_works< + From> + From>, { - helpers::relayed_incoming_message_works::< - Runtime, - AllPalletsWithoutSystem, - HrmpChannelOpener, - MPI, - >( + helpers::relayed_incoming_message_works::( collator_session_key, runtime_para_id, sibling_parachain_id, @@ -263,12 +258,7 @@ pub fn complex_relay_extrinsic_works< + From>, ::RuntimeCall: From>, { - helpers::relayed_incoming_message_works::< - Runtime, - AllPalletsWithoutSystem, - HrmpChannelOpener, - MPI, - >( + helpers::relayed_incoming_message_works::( collator_session_key, runtime_para_id, sibling_parachain_id, diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/helpers.rs b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/helpers.rs index 192aa017fff1..4f824129bf71 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/helpers.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/helpers.rs @@ -22,6 +22,7 @@ use asset_test_utils::BasicParachainRuntime; use bp_messages::{LaneId, MessageNonce}; use bp_polkadot_core::parachains::{ParaHash, ParaId}; use bp_relayers::RewardsAccountParams; +use codec::Decode; use frame_support::{ assert_ok, traits::{OnFinalize, OnInitialize, PalletInfoAccess}, @@ -29,12 +30,10 @@ use frame_support::{ use frame_system::pallet_prelude::BlockNumberFor; use pallet_bridge_grandpa::{BridgedBlockHash, BridgedHeader}; use parachains_common::AccountId; -use parachains_runtimes_test_utils::{ - mock_open_hrmp_channel, AccountIdOf, CollatorSessionKeys, ValidatorIdOf, -}; +use parachains_runtimes_test_utils::{mock_open_hrmp_channel, AccountIdOf, CollatorSessionKeys}; use sp_core::Get; use sp_keyring::AccountKeyring::*; -use sp_runtime::AccountId32; +use sp_runtime::{traits::TrailingZeroInput, AccountId32}; use sp_std::marker::PhantomData; use xcm::latest::prelude::*; @@ -208,9 +207,15 @@ pub(crate) fn initialize_bridge_grandpa_pallet( pub type CallsAndVerifiers = Vec<(::RuntimeCall, Box)>; +/// Returns relayer id at the bridged chain. +pub fn relayer_id_at_bridged_chain, MPI>( +) -> Runtime::InboundRelayer { + Runtime::InboundRelayer::decode(&mut TrailingZeroInput::zeroes()).unwrap() +} + /// Test-case makes sure that Runtime can dispatch XCM messages submitted by relayer, /// with proofs (finality, message) independently submitted. -pub fn relayed_incoming_message_works( +pub fn relayed_incoming_message_works( collator_session_key: CollatorSessionKeys, runtime_para_id: u32, sibling_parachain_id: u32, @@ -232,18 +237,12 @@ pub fn relayed_incoming_message_works, AllPalletsWithoutSystem: OnInitialize> + OnFinalize>, - HrmpChannelOpener: frame_support::inherent::ProvideInherent< - Call = cumulus_pallet_parachain_system::Call, - >, MPI: 'static, - ValidatorIdOf: From>, - AccountIdOf: From + From, - >::InboundRelayer: From, + AccountIdOf: From, { let relayer_at_target = Bob; let relayer_id_on_target: AccountId32 = relayer_at_target.public().into(); - let relayer_at_source = Dave; - let relayer_id_on_source: AccountId32 = relayer_at_source.public().into(); + let relayer_id_on_source = relayer_id_at_bridged_chain::(); assert_ne!(runtime_para_id, sibling_parachain_id); @@ -262,7 +261,7 @@ pub fn relayed_incoming_message_works( + mock_open_hrmp_channel::>( runtime_para_id.into(), sibling_parachain_id.into(), included_head, diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs index c12a12548c71..11210841bd39 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs @@ -72,7 +72,6 @@ pub fn run_test( ) -> T where Runtime: BasicParachainRuntime, - ValidatorIdOf: From>, { ExtBuilder::::default() .with_collators(collator_session_key.collators()) diff --git a/cumulus/parachains/runtimes/test-utils/src/lib.rs b/cumulus/parachains/runtimes/test-utils/src/lib.rs index ca1e1633d4ff..6d43875a8868 100644 --- a/cumulus/parachains/runtimes/test-utils/src/lib.rs +++ b/cumulus/parachains/runtimes/test-utils/src/lib.rs @@ -47,6 +47,7 @@ pub mod test_cases; pub type BalanceOf = ::Balance; pub type AccountIdOf = ::AccountId; +pub type RuntimeCallOf = ::RuntimeCall; pub type ValidatorIdOf = ::ValidatorId; pub type SessionKeysOf = ::Keys;