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 8d4e6a034a7e..e0e75f093cfc 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 @@ -18,7 +18,7 @@ //! with remote GRANDPA chain. use crate::{ - test_cases::{helpers, run_test}, + test_cases::{bridges_prelude::*, helpers, run_test}, test_data, }; @@ -38,8 +38,6 @@ use bridge_runtime_common::{ }; 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, RuntimeCallOf, }; 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 fa1049cc6ec4..91bebb36b187 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 @@ -18,7 +18,7 @@ //! with remote parachain. use crate::{ - test_cases::{helpers, run_test}, + test_cases::{bridges_prelude::*, helpers, run_test}, test_data, }; @@ -39,12 +39,6 @@ use bridge_runtime_common::{ }; 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 pallet_bridge_parachains::{ - Call as BridgeParachainsCall, Config as BridgeParachainsConfig, RelayBlockHash, - RelayBlockNumber, -}; use parachains_runtimes_test_utils::{ AccountIdOf, BasicParachainRuntime, CollatorSessionKeys, RuntimeCallOf, }; 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 4f824129bf71..69aa61db3cc6 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 @@ -16,7 +16,7 @@ //! Module contains tests code, that is shared by all types of bridges -use crate::test_cases::{run_test, RuntimeHelper}; +use crate::test_cases::{bridges_prelude::*, run_test, RuntimeHelper}; use asset_test_utils::BasicParachainRuntime; use bp_messages::{LaneId, MessageNonce}; @@ -30,13 +30,16 @@ 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}; +use parachains_runtimes_test_utils::{ + mock_open_hrmp_channel, AccountIdOf, CollatorSessionKeys, RuntimeCallOf, +}; use sp_core::Get; use sp_keyring::AccountKeyring::*; use sp_runtime::{traits::TrailingZeroInput, AccountId32}; use sp_std::marker::PhantomData; use xcm::latest::prelude::*; +/// Verify that the transaction has succeeded. #[impl_trait_for_tuples::impl_for_tuples(30)] pub trait VerifyTransactionOutcome { fn verify_outcome(&self); @@ -51,7 +54,7 @@ impl VerifyTransactionOutcome for Box { /// Checks that the best finalized header hash in the bridge GRANDPA pallet equals to given one. pub struct VerifySubmitGrandpaFinalityProofOutcome where - Runtime: pallet_bridge_grandpa::Config, + Runtime: BridgeGrandpaConfig, GPI: 'static, { expected_best_hash: BridgedBlockHash, @@ -59,7 +62,7 @@ where impl VerifySubmitGrandpaFinalityProofOutcome where - Runtime: pallet_bridge_grandpa::Config, + Runtime: BridgeGrandpaConfig, GPI: 'static, { /// Expect given header hash to be the best after transaction. @@ -73,7 +76,7 @@ where impl VerifyTransactionOutcome for VerifySubmitGrandpaFinalityProofOutcome where - Runtime: pallet_bridge_grandpa::Config, + Runtime: BridgeGrandpaConfig, GPI: 'static, { fn verify_outcome(&self) { @@ -96,7 +99,7 @@ pub struct VerifySubmitParachainHeaderProofOutcome { impl VerifySubmitParachainHeaderProofOutcome where - Runtime: pallet_bridge_parachains::Config, + Runtime: BridgeParachainsConfig, PPI: 'static, { /// Expect given header hash to be the best after transaction. @@ -111,7 +114,7 @@ where impl VerifyTransactionOutcome for VerifySubmitParachainHeaderProofOutcome where - Runtime: pallet_bridge_parachains::Config, + Runtime: BridgeParachainsConfig, PPI: 'static, { fn verify_outcome(&self) { @@ -132,7 +135,7 @@ pub struct VerifySubmitMessagesProofOutcome { impl VerifySubmitMessagesProofOutcome where - Runtime: pallet_bridge_messages::Config, + Runtime: BridgeMessagesConfig, MPI: 'static, { /// Expect given delivered nonce to be the latest after transaction. @@ -146,7 +149,7 @@ where impl VerifyTransactionOutcome for VerifySubmitMessagesProofOutcome where - Runtime: pallet_bridge_messages::Config, + Runtime: BridgeMessagesConfig, MPI: 'static, { fn verify_outcome(&self) { @@ -194,7 +197,7 @@ where pub(crate) fn initialize_bridge_grandpa_pallet( init_data: bp_header_chain::InitializationData>, ) where - Runtime: pallet_bridge_grandpa::Config, + Runtime: BridgeGrandpaConfig, { pallet_bridge_grandpa::Pallet::::initialize( RuntimeHelper::::root_origin(), @@ -205,7 +208,7 @@ pub(crate) fn initialize_bridge_grandpa_pallet( /// Runtime calls and their verifiers. pub type CallsAndVerifiers = - Vec<(::RuntimeCall, Box)>; + Vec<(RuntimeCallOf, Box)>; /// Returns relayer id at the bridged chain. pub fn relayer_id_at_bridged_chain, MPI>( @@ -222,7 +225,7 @@ pub fn relayed_incoming_message_works( local_relay_chain_id: NetworkId, construct_and_apply_extrinsic: fn( sp_keyring::AccountKeyring, - ::RuntimeCall, + RuntimeCallOf, ) -> sp_runtime::DispatchOutcome, prepare_message_proof_import: impl FnOnce( Runtime::AccountId, @@ -232,9 +235,7 @@ pub fn relayed_incoming_message_works( Xcm<()>, ) -> CallsAndVerifiers, ) where - Runtime: BasicParachainRuntime - + cumulus_pallet_xcmp_queue::Config - + pallet_bridge_messages::Config, + Runtime: BasicParachainRuntime + cumulus_pallet_xcmp_queue::Config + BridgeMessagesConfig, AllPalletsWithoutSystem: OnInitialize> + OnFinalize>, MPI: 'static, @@ -251,7 +252,12 @@ pub fn relayed_incoming_message_works( runtime_para_id, vec![( relayer_id_on_target.clone().into(), - Runtime::ExistentialDeposit::get() * 100000u32.into(), + // this value should be enough to cover all transaction costs, but computing the actual + // value here is tricky - there are several transaction payment pallets and we don't + // want to introduce additional bounds and traits here just for that, so let's just + // select some presumably large value + sp_std::cmp::max::(Runtime::ExistentialDeposit::get(), 1u32.into()) * + 100_000_000u32.into(), )], || { let mut alice = [0u8; 32]; @@ -327,7 +333,7 @@ fn execute_and_verify_calls( submitter: sp_keyring::AccountKeyring, construct_and_apply_extrinsic: fn( sp_keyring::AccountKeyring, - ::RuntimeCall, + RuntimeCallOf, ) -> sp_runtime::DispatchOutcome, calls_and_verifiers: CallsAndVerifiers, ) { 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 11210841bd39..64ec87265992 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 @@ -24,7 +24,7 @@ pub mod from_parachain; pub(crate) mod helpers; -use crate::test_data; +use crate::{test_cases::bridges_prelude::*, test_data}; use asset_test_utils::BasicParachainRuntime; use bp_messages::{ @@ -38,12 +38,13 @@ use bridge_runtime_common::messages_xcm_extension::{ use codec::Encode; use frame_support::{ assert_ok, + dispatch::GetDispatchInfo, traits::{Get, OnFinalize, OnInitialize, OriginTrait}, }; use frame_system::pallet_prelude::BlockNumberFor; use parachains_common::AccountId; use parachains_runtimes_test_utils::{ - mock_open_hrmp_channel, AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, ValidatorIdOf, + mock_open_hrmp_channel, AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, RuntimeCallOf, XcmReceivedFrom, }; use sp_runtime::{traits::Zero, AccountId32}; @@ -54,6 +55,16 @@ use xcm_executor::{ XcmExecutor, }; +/// Common bridges exports. +pub(crate) mod bridges_prelude { + pub use pallet_bridge_grandpa::{Call as BridgeGrandpaCall, Config as BridgeGrandpaConfig}; + pub use pallet_bridge_messages::{Call as BridgeMessagesCall, Config as BridgeMessagesConfig}; + pub use pallet_bridge_parachains::{ + Call as BridgeParachainsCall, Config as BridgeParachainsConfig, RelayBlockHash, + RelayBlockNumber, + }; +} + // Re-export test_case from assets pub use asset_test_utils::include_teleports_for_native_asset_works; @@ -89,11 +100,10 @@ pub fn initialize_bridge_by_governance_works( collator_session_key: CollatorSessionKeys, runtime_para_id: u32, ) where - Runtime: BasicParachainRuntime + pallet_bridge_grandpa::Config, + Runtime: BasicParachainRuntime + BridgeGrandpaConfig, GrandpaPalletInstance: 'static, - ValidatorIdOf: From>, - ::RuntimeCall: - From>, + RuntimeCallOf: + GetDispatchInfo + From>, { run_test::(collator_session_key, runtime_para_id, vec![], || { // check mode before @@ -102,24 +112,18 @@ pub fn initialize_bridge_by_governance_works( Err(()) ); - // encode `initialize` call - let initialize_call = - ::RuntimeCall::from(pallet_bridge_grandpa::Call::< - Runtime, - GrandpaPalletInstance, - >::initialize { - init_data: test_data::initialization_data::(12345), - }) - .encode(); - - // overestimate - check weight for `pallet_bridge_grandpa::Pallet::initialize()` call - let require_weight_at_most = - ::DbWeight::get().reads_writes(7, 7); + // prepare the `initialize` call + let initialize_call = RuntimeCallOf::::from(BridgeGrandpaCall::< + Runtime, + GrandpaPalletInstance, + >::initialize { + init_data: test_data::initialization_data::(12345), + }); // execute XCM with Transacts to `initialize bridge` as governance does assert_ok!(RuntimeHelper::::execute_as_governance( - initialize_call, - require_weight_at_most + initialize_call.encode(), + initialize_call.get_dispatch_info().weight, ) .ensure_complete()); @@ -137,11 +141,10 @@ pub fn change_bridge_grandpa_pallet_mode_by_governance_works, runtime_para_id: u32, ) where - Runtime: BasicParachainRuntime + pallet_bridge_grandpa::Config, + Runtime: BasicParachainRuntime + BridgeGrandpaConfig, GrandpaPalletInstance: 'static, - ValidatorIdOf: From>, - ::RuntimeCall: - From>, + RuntimeCallOf: + GetDispatchInfo + From>, { run_test::(collator_session_key, runtime_para_id, vec![], || { let dispatch_set_operating_mode_call = |old_mode, new_mode| { @@ -151,23 +154,17 @@ pub fn change_bridge_grandpa_pallet_mode_by_governance_works::DbWeight::get().reads_writes(7, 7); - - // encode `set_operating_mode` call + // prepare the `set_operating_mode` call let set_operating_mode_call = ::RuntimeCall::from( pallet_bridge_grandpa::Call::::set_operating_mode { operating_mode: new_mode, }, - ) - .encode(); + ); // execute XCM with Transacts to `initialize bridge` as governance does assert_ok!(RuntimeHelper::::execute_as_governance( - set_operating_mode_call, - require_weight_at_most + set_operating_mode_call.encode(), + set_operating_mode_call.get_dispatch_info().weight, ) .ensure_complete()); @@ -195,11 +192,10 @@ pub fn change_bridge_parachains_pallet_mode_by_governance_works, runtime_para_id: u32, ) where - Runtime: BasicParachainRuntime + pallet_bridge_parachains::Config, + Runtime: BasicParachainRuntime + BridgeParachainsConfig, ParachainsPalletInstance: 'static, - ValidatorIdOf: From>, - ::RuntimeCall: - From>, + RuntimeCallOf: + GetDispatchInfo + From>, { run_test::(collator_session_key, runtime_para_id, vec![], || { let dispatch_set_operating_mode_call = |old_mode, new_mode| { @@ -209,23 +205,19 @@ pub fn change_bridge_parachains_pallet_mode_by_governance_works::DbWeight::get().reads_writes(7, 7); - - // encode `set_operating_mode` call - let set_operating_mode_call = ::RuntimeCall::from(pallet_bridge_parachains::Call::< - Runtime, - ParachainsPalletInstance, - >::set_operating_mode { - operating_mode: new_mode, - }).encode(); + // prepare the `set_operating_mode` call + let set_operating_mode_call = + RuntimeCallOf::::from(pallet_bridge_parachains::Call::< + Runtime, + ParachainsPalletInstance, + >::set_operating_mode { + operating_mode: new_mode, + }); // execute XCM with Transacts to `initialize bridge` as governance does assert_ok!(RuntimeHelper::::execute_as_governance( - set_operating_mode_call, - require_weight_at_most + set_operating_mode_call.encode(), + set_operating_mode_call.get_dispatch_info().weight, ) .ensure_complete()); @@ -253,11 +245,10 @@ pub fn change_bridge_messages_pallet_mode_by_governance_works, runtime_para_id: u32, ) where - Runtime: BasicParachainRuntime + pallet_bridge_messages::Config, + Runtime: BasicParachainRuntime + BridgeMessagesConfig, MessagesPalletInstance: 'static, - ValidatorIdOf: From>, - ::RuntimeCall: - From>, + RuntimeCallOf: + GetDispatchInfo + From>, { run_test::(collator_session_key, runtime_para_id, vec![], || { let dispatch_set_operating_mode_call = |old_mode, new_mode| { @@ -268,23 +259,18 @@ pub fn change_bridge_messages_pallet_mode_by_governance_works::DbWeight::get().reads_writes(7, 7); - // encode `set_operating_mode` call - let set_operating_mode_call = ::RuntimeCall::from(pallet_bridge_messages::Call::< + let set_operating_mode_call = RuntimeCallOf::::from(BridgeMessagesCall::< Runtime, MessagesPalletInstance, >::set_operating_mode { operating_mode: new_mode, - }).encode(); + }); // execute XCM with Transacts to `initialize bridge` as governance does assert_ok!(RuntimeHelper::::execute_as_governance( - set_operating_mode_call, - require_weight_at_most + set_operating_mode_call.encode(), + set_operating_mode_call.get_dispatch_info().weight, ) .ensure_complete()); @@ -337,10 +323,9 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works< maybe_paid_export_message: Option, prepare_configuration: impl Fn(), ) where - Runtime: BasicParachainRuntime + pallet_bridge_messages::Config, + Runtime: BasicParachainRuntime + BridgeMessagesConfig, XcmConfig: xcm_executor::Config, MessagesPalletInstance: 'static, - ValidatorIdOf: From>, { assert_ne!(runtime_para_id, sibling_parachain_id); let sibling_parachain_location = MultiLocation::new(1, Parachain(sibling_parachain_id)); @@ -446,15 +431,13 @@ pub fn message_dispatch_routing_works< ) where Runtime: BasicParachainRuntime + cumulus_pallet_xcmp_queue::Config - + pallet_bridge_messages::Config, + + BridgeMessagesConfig, AllPalletsWithoutSystem: OnInitialize> + OnFinalize>, - ::AccountId: - Into<<::RuntimeOrigin as OriginTrait>::AccountId>, + AccountIdOf: From + + Into<<::RuntimeOrigin as OriginTrait>::AccountId>, XcmConfig: xcm_executor::Config, MessagesPalletInstance: 'static, - ValidatorIdOf: From>, - ::AccountId: From, HrmpChannelOpener: frame_support::inherent::ProvideInherent< Call = cumulus_pallet_parachain_system::Call, >, @@ -488,9 +471,10 @@ pub fn message_dispatch_routing_works< NetworkWithParentCount, AlwaysLatest, >((RuntimeNetwork::get(), Here)); - let result = <>::MessageDispatch>::dispatch( - test_data::dispatch_message(expected_lane_id, 1, bridging_message) - ); + let result = + <>::MessageDispatch>::dispatch( + test_data::dispatch_message(expected_lane_id, 1, bridging_message), + ); assert_eq!( format!("{:?}", result.dispatch_level_result), format!("{:?}", XcmBlobMessageDispatchResult::Dispatched) @@ -515,11 +499,11 @@ pub fn message_dispatch_routing_works< // 2.1. WITHOUT opened hrmp channel -> RoutingError let result = - <>::MessageDispatch>::dispatch( + <>::MessageDispatch>::dispatch( DispatchMessage { key: MessageKey { lane_id: expected_lane_id, nonce: 1 }, data: DispatchMessageData { payload: Ok(bridging_message.clone()) }, - } + }, ); assert_eq!( format!("{:?}", result.dispatch_level_result), @@ -545,12 +529,13 @@ pub fn message_dispatch_routing_works< included_head, &alice, ); - let result = <>::MessageDispatch>::dispatch( - DispatchMessage { - key: MessageKey { lane_id: expected_lane_id, nonce: 1 }, - data: DispatchMessageData { payload: Ok(bridging_message) }, - } - ); + let result = + <>::MessageDispatch>::dispatch( + DispatchMessage { + key: MessageKey { lane_id: expected_lane_id, nonce: 1 }, + data: DispatchMessageData { payload: Ok(bridging_message) }, + }, + ); assert_eq!( format!("{:?}", result.dispatch_level_result), format!("{:?}", XcmBlobMessageDispatchResult::Dispatched)