Cleanup bridges tests: with-grandpa-chain case (#2763)

related to
https://github.com/paritytech/parity-bridges-common/issues/2739

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
This commit is contained in:
Svyatoslav Nikolsky
2023-12-21 10:37:24 +03:00
committed by GitHub
parent d84e135bbf
commit 9f5221cc2f
7 changed files with 225 additions and 254 deletions
+1 -1
View File
@@ -199,7 +199,7 @@ pub trait Chain: Send + Sync + 'static {
} }
/// A trait that provides the type of the underlying chain. /// A trait that provides the type of the underlying chain.
pub trait UnderlyingChainProvider { pub trait UnderlyingChainProvider: Send + Sync + 'static {
/// Underlying chain type. /// Underlying chain type.
type Chain: Chain; type Chain: Chain;
} }
@@ -373,6 +373,7 @@ mod bridge_hub_westend_tests {
mod bridge_hub_bulletin_tests { mod bridge_hub_bulletin_tests {
use super::*; use super::*;
use bridge_common_config::BridgeGrandpaRococoBulletinInstance; use bridge_common_config::BridgeGrandpaRococoBulletinInstance;
use bridge_hub_test_utils::test_cases::from_grandpa_chain;
use bridge_to_bulletin_config::{ use bridge_to_bulletin_config::{
RococoBulletinChainId, RococoBulletinGlobalConsensusNetwork, RococoBulletinChainId, RococoBulletinGlobalConsensusNetwork,
RococoBulletinGlobalConsensusNetworkLocation, WithRococoBulletinMessageBridge, RococoBulletinGlobalConsensusNetworkLocation, WithRococoBulletinMessageBridge,
@@ -382,6 +383,15 @@ mod bridge_hub_bulletin_tests {
// Para id of sibling chain used in tests. // Para id of sibling chain used in tests.
pub const SIBLING_PARACHAIN_ID: u32 = rococo_runtime_constants::system_parachain::PEOPLE_ID; 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] #[test]
fn initialize_bridge_by_governance_works() { fn initialize_bridge_by_governance_works() {
// for Bulletin finality // for Bulletin finality
@@ -474,14 +484,7 @@ mod bridge_hub_bulletin_tests {
#[test] #[test]
fn relayed_incoming_message_works() { fn relayed_incoming_message_works() {
// from Bulletin // from Bulletin
bridge_hub_test_utils::test_cases::from_grandpa_chain::relayed_incoming_message_works::< from_grandpa_chain::relayed_incoming_message_works::<RuntimeTestsAdapter>(
Runtime,
AllPalletsWithoutSystem,
ParachainSystem,
BridgeGrandpaRococoBulletinInstance,
WithRococoBulletinMessagesInstance,
WithRococoBulletinMessageBridge,
>(
collator_session_keys(), collator_session_keys(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
RococoBulletinChainId::get(), RococoBulletinChainId::get(),
@@ -496,15 +499,7 @@ mod bridge_hub_bulletin_tests {
#[test] #[test]
pub fn complex_relay_extrinsic_works() { pub fn complex_relay_extrinsic_works() {
// for Bulletin // for Bulletin
bridge_hub_test_utils::test_cases::from_grandpa_chain::complex_relay_extrinsic_works::< from_grandpa_chain::complex_relay_extrinsic_works::<RuntimeTestsAdapter>(
Runtime,
AllPalletsWithoutSystem,
XcmConfig,
ParachainSystem,
BridgeGrandpaRococoBulletinInstance,
WithRococoBulletinMessagesInstance,
WithRococoBulletinMessageBridge,
>(
collator_session_keys(), collator_session_keys(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
SIBLING_PARACHAIN_ID, SIBLING_PARACHAIN_ID,
@@ -536,15 +531,10 @@ mod bridge_hub_bulletin_tests {
#[test] #[test]
pub fn can_calculate_fee_for_complex_message_delivery_transaction() { 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::< let estimated =
Runtime, from_grandpa_chain::can_calculate_fee_for_complex_message_delivery_transaction::<
BridgeGrandpaRococoBulletinInstance, RuntimeTestsAdapter,
WithRococoBulletinMessagesInstance, >(collator_session_keys(), construct_and_estimate_extrinsic_fee);
WithRococoBulletinMessageBridge,
>(
collator_session_keys(),
construct_and_estimate_extrinsic_fee
);
// check if estimated value is sane // check if estimated value is sane
let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs::get(); let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs::get();
@@ -558,15 +548,10 @@ mod bridge_hub_bulletin_tests {
#[test] #[test]
pub fn can_calculate_fee_for_complex_message_confirmation_transaction() { 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::< let estimated =
Runtime, from_grandpa_chain::can_calculate_fee_for_complex_message_confirmation_transaction::<
BridgeGrandpaRococoBulletinInstance, RuntimeTestsAdapter,
WithRococoBulletinMessagesInstance, >(collator_session_keys(), construct_and_estimate_extrinsic_fee);
WithRococoBulletinMessageBridge,
>(
collator_session_keys(),
construct_and_estimate_extrinsic_fee
);
// check if estimated value is sane // check if estimated value is sane
let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs::get(); let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs::get();
@@ -36,27 +36,79 @@ use bridge_runtime_common::{
}, },
messages_xcm_extension::XcmAsPlainPayload, 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 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::{ use parachains_runtimes_test_utils::{
AccountIdOf, BasicParachainRuntime, CollatorSessionKeys, ValidatorIdOf, AccountIdOf, BasicParachainRuntime, CollatorSessionKeys, RuntimeCallOf,
}; };
use sp_keyring::AccountKeyring::*; use sp_keyring::AccountKeyring::*;
use sp_runtime::{traits::Header as HeaderT, AccountId32}; use sp_runtime::{traits::Header as HeaderT, AccountId32};
use xcm::latest::prelude::*; 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<MessageBridgedChain<Self::MB>>,
> + BridgeMessagesConfig<
Self::MPI,
InboundPayload = XcmAsPlainPayload,
InboundRelayer = bp_runtime::AccountIdOf<MessageBridgedChain<Self::MB>>,
OutboundPayload = XcmAsPlainPayload,
> + pallet_bridge_relayers::Config;
/// All pallets of this chain, excluding system pallet.
type AllPalletsWithoutSystem: OnInitialize<BlockNumberFor<Self::Runtime>>
+ OnFinalize<BlockNumberFor<Self::Runtime>>;
/// 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<Runtime, AllPalletsWithoutSystem, GPI, MPI, MB>(
sp_std::marker::PhantomData<(Runtime, AllPalletsWithoutSystem, GPI, MPI, MB)>,
);
impl<Runtime, AllPalletsWithoutSystem, GPI, MPI, MB> WithRemoteGrandpaChainHelper
for WithRemoteGrandpaChainHelperAdapter<Runtime, AllPalletsWithoutSystem, GPI, MPI, MB>
where
Runtime: BasicParachainRuntime
+ cumulus_pallet_xcmp_queue::Config
+ BridgeGrandpaConfig<GPI, BridgedChain = UnderlyingChainOf<MessageBridgedChain<MB>>>
+ BridgeMessagesConfig<
MPI,
InboundPayload = XcmAsPlainPayload,
InboundRelayer = bp_runtime::AccountIdOf<MessageBridgedChain<MB>>,
OutboundPayload = XcmAsPlainPayload,
> + pallet_bridge_relayers::Config,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
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, /// Test-case makes sure that Runtime can dispatch XCM messages submitted by relayer,
/// with proofs (finality, message) independently submitted. /// with proofs (finality, message) independently submitted.
/// Also verifies relayer transaction signed extensions work as intended. /// Also verifies relayer transaction signed extensions work as intended.
pub fn relayed_incoming_message_works< pub fn relayed_incoming_message_works<RuntimeHelper>(
Runtime, collator_session_key: CollatorSessionKeys<RuntimeHelper::Runtime>,
AllPalletsWithoutSystem,
HrmpChannelOpener,
GPI,
MPI,
MB,
>(
collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32, runtime_para_id: u32,
bridged_chain_id: bp_runtime::ChainId, bridged_chain_id: bp_runtime::ChainId,
sibling_parachain_id: u32, sibling_parachain_id: u32,
@@ -65,44 +117,25 @@ pub fn relayed_incoming_message_works<
prepare_configuration: impl Fn(), prepare_configuration: impl Fn(),
construct_and_apply_extrinsic: fn( construct_and_apply_extrinsic: fn(
sp_keyring::AccountKeyring, sp_keyring::AccountKeyring,
<Runtime as frame_system::Config>::RuntimeCall, RuntimeCallOf<RuntimeHelper::Runtime>,
) -> sp_runtime::DispatchOutcome, ) -> sp_runtime::DispatchOutcome,
) where ) where
Runtime: BasicParachainRuntime RuntimeHelper: WithRemoteGrandpaChainHelper,
+ cumulus_pallet_xcmp_queue::Config AccountIdOf<RuntimeHelper::Runtime>: From<AccountId32>,
+ pallet_bridge_grandpa::Config< RuntimeCallOf<RuntimeHelper::Runtime>: From<BridgeGrandpaCall<RuntimeHelper::Runtime, RuntimeHelper::GPI>>
GPI, + From<BridgeMessagesCall<RuntimeHelper::Runtime, RuntimeHelper::MPI>>,
BridgedChain = UnderlyingChainOf<MessageBridgedChain<MB>>, UnderlyingChainOf<MessageBridgedChain<RuntimeHelper::MB>>: ChainWithGrandpa,
> + pallet_bridge_messages::Config<MPI> <RuntimeHelper::Runtime as BridgeMessagesConfig<RuntimeHelper::MPI>>::SourceHeaderChain:
+ pallet_bridge_relayers::Config, SourceHeaderChain<
AllPalletsWithoutSystem: MessagesProof = FromBridgedChainMessagesProof<
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>, HashOf<MessageBridgedChain<RuntimeHelper::MB>>,
GPI: 'static, >,
MPI: 'static, >,
MB: MessageBridge,
<MB as MessageBridge>::BridgedChain: Send + Sync + 'static,
<MB as MessageBridge>::ThisChain: Send + Sync + 'static,
UnderlyingChainOf<MessageBridgedChain<MB>>: ChainWithGrandpa,
HrmpChannelOpener: frame_support::inherent::ProvideInherent<
Call = cumulus_pallet_parachain_system::Call<Runtime>,
>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as pallet_bridge_messages::Config<MPI>>::SourceHeaderChain: SourceHeaderChain<
MessagesProof = FromBridgedChainMessagesProof<HashOf<MessageBridgedChain<MB>>>,
>,
<Runtime as frame_system::Config>::AccountId:
Into<<<Runtime as frame_system::Config>::RuntimeOrigin as OriginTrait>::AccountId>,
<Runtime as frame_system::Config>::AccountId: From<AccountId32>,
AccountIdOf<Runtime>: From<sp_core::sr25519::Public>,
<Runtime as pallet_bridge_messages::Config<MPI>>::InboundRelayer: From<AccountId32>,
<Runtime as frame_system::Config>::RuntimeCall: From<pallet_bridge_grandpa::Call<Runtime, GPI>>
+ From<pallet_bridge_messages::Call<Runtime, MPI>>,
{ {
helpers::relayed_incoming_message_works::< helpers::relayed_incoming_message_works::<
Runtime, RuntimeHelper::Runtime,
AllPalletsWithoutSystem, RuntimeHelper::AllPalletsWithoutSystem,
HrmpChannelOpener, RuntimeHelper::MPI,
MPI,
>( >(
collator_session_key, collator_session_key,
runtime_para_id, runtime_para_id,
@@ -119,40 +152,42 @@ pub fn relayed_incoming_message_works<
prepare_configuration(); prepare_configuration();
// start with bridged relay chain block#0 // start with bridged relay chain block#0
helpers::initialize_bridge_grandpa_pallet::<Runtime, GPI>( helpers::initialize_bridge_grandpa_pallet::<RuntimeHelper::Runtime, RuntimeHelper::GPI>(
test_data::initialization_data::<Runtime, GPI>(0), test_data::initialization_data::<RuntimeHelper::Runtime, RuntimeHelper::GPI>(0),
); );
// generate bridged relay chain finality, parachain heads and message proofs, // generate bridged relay chain finality, parachain heads and message proofs,
// to be submitted by relayer to this chain. // to be submitted by relayer to this chain.
let (relay_chain_header, grandpa_justification, message_proof) = let (relay_chain_header, grandpa_justification, message_proof) =
test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::<MB, ()>( test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::<
lane_id, RuntimeHelper::MB,
xcm.into(), (),
message_nonce, >(lane_id, xcm.into(), message_nonce, message_destination, relay_header_number);
message_destination,
relay_header_number,
);
let relay_chain_header_hash = relay_chain_header.hash(); let relay_chain_header_hash = relay_chain_header.hash();
vec![ vec![
( (
pallet_bridge_grandpa::Call::<Runtime, GPI>::submit_finality_proof { BridgeGrandpaCall::<RuntimeHelper::Runtime, RuntimeHelper::GPI>::submit_finality_proof {
finality_target: Box::new(relay_chain_header), finality_target: Box::new(relay_chain_header),
justification: grandpa_justification, justification: grandpa_justification,
}.into(), }.into(),
helpers::VerifySubmitGrandpaFinalityProofOutcome::<Runtime, GPI>::expect_best_header_hash(relay_chain_header_hash), helpers::VerifySubmitGrandpaFinalityProofOutcome::<RuntimeHelper::Runtime, RuntimeHelper::GPI>::expect_best_header_hash(
relay_chain_header_hash,
),
), ),
( (
pallet_bridge_messages::Call::<Runtime, MPI>::receive_messages_proof { BridgeMessagesCall::<RuntimeHelper::Runtime, RuntimeHelper::MPI>::receive_messages_proof {
relayer_id_at_bridged_chain, relayer_id_at_bridged_chain,
proof: message_proof, proof: message_proof,
messages_count: 1, messages_count: 1,
dispatch_weight: Weight::from_parts(1000000000, 0), dispatch_weight: Weight::from_parts(1000000000, 0),
}.into(), }.into(),
Box::new(( Box::new((
helpers::VerifySubmitMessagesProofOutcome::<Runtime, MPI>::expect_last_delivered_nonce(lane_id, 1), helpers::VerifySubmitMessagesProofOutcome::<RuntimeHelper::Runtime, RuntimeHelper::MPI>::expect_last_delivered_nonce(
helpers::VerifyRelayerRewarded::<Runtime>::expect_relayer_reward( lane_id,
1,
),
helpers::VerifyRelayerRewarded::<RuntimeHelper::Runtime>::expect_relayer_reward(
relayer_id_at_this_chain, relayer_id_at_this_chain,
RewardsAccountParams::new( RewardsAccountParams::new(
lane_id, 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, /// Test-case makes sure that Runtime can dispatch XCM messages submitted by relayer,
/// with proofs (finality, message) batched together in signed extrinsic. /// with proofs (finality, message) batched together in signed extrinsic.
/// Also verifies relayer transaction signed extensions work as intended. /// Also verifies relayer transaction signed extensions work as intended.
pub fn complex_relay_extrinsic_works< pub fn complex_relay_extrinsic_works<RuntimeHelper>(
Runtime, collator_session_key: CollatorSessionKeys<RuntimeHelper::Runtime>,
AllPalletsWithoutSystem,
XcmConfig,
HrmpChannelOpener,
GPI,
MPI,
MB,
>(
collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32, runtime_para_id: u32,
sibling_parachain_id: u32, sibling_parachain_id: u32,
bridged_chain_id: bp_runtime::ChainId, bridged_chain_id: bp_runtime::ChainId,
@@ -188,46 +215,28 @@ pub fn complex_relay_extrinsic_works<
prepare_configuration: impl Fn(), prepare_configuration: impl Fn(),
construct_and_apply_extrinsic: fn( construct_and_apply_extrinsic: fn(
sp_keyring::AccountKeyring, sp_keyring::AccountKeyring,
<Runtime as frame_system::Config>::RuntimeCall, RuntimeCallOf<RuntimeHelper::Runtime>,
) -> sp_runtime::DispatchOutcome, ) -> sp_runtime::DispatchOutcome,
) where ) where
Runtime: BasicParachainRuntime RuntimeHelper: WithRemoteGrandpaChainHelper,
+ cumulus_pallet_xcmp_queue::Config RuntimeHelper::Runtime:
+ pallet_bridge_grandpa::Config< pallet_utility::Config<RuntimeCall = RuntimeCallOf<RuntimeHelper::Runtime>>,
GPI, AccountIdOf<RuntimeHelper::Runtime>: From<AccountId32>,
BridgedChain = UnderlyingChainOf<MessageBridgedChain<MB>>, RuntimeCallOf<RuntimeHelper::Runtime>: From<BridgeGrandpaCall<RuntimeHelper::Runtime, RuntimeHelper::GPI>>
> + pallet_bridge_messages::Config<MPI> + From<BridgeMessagesCall<RuntimeHelper::Runtime, RuntimeHelper::MPI>>
+ pallet_bridge_relayers::Config + From<pallet_utility::Call<RuntimeHelper::Runtime>>,
+ pallet_utility::Config, UnderlyingChainOf<MessageBridgedChain<RuntimeHelper::MB>>: ChainWithGrandpa,
AllPalletsWithoutSystem: <RuntimeHelper::Runtime as BridgeMessagesConfig<RuntimeHelper::MPI>>::SourceHeaderChain:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>, SourceHeaderChain<
GPI: 'static, MessagesProof = FromBridgedChainMessagesProof<
MPI: 'static, HashOf<MessageBridgedChain<RuntimeHelper::MB>>,
MB: MessageBridge, >,
<MB as MessageBridge>::BridgedChain: Send + Sync + 'static, >,
<MB as MessageBridge>::ThisChain: Send + Sync + 'static,
UnderlyingChainOf<MessageBridgedChain<MB>>: ChainWithGrandpa,
HrmpChannelOpener: frame_support::inherent::ProvideInherent<
Call = cumulus_pallet_parachain_system::Call<Runtime>,
>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as pallet_bridge_messages::Config<MPI>>::SourceHeaderChain: SourceHeaderChain<
MessagesProof = FromBridgedChainMessagesProof<HashOf<MessageBridgedChain<MB>>>,
>,
<Runtime as frame_system::Config>::AccountId:
Into<<<Runtime as frame_system::Config>::RuntimeOrigin as OriginTrait>::AccountId>,
<Runtime as frame_system::Config>::AccountId: From<AccountId32>,
AccountIdOf<Runtime>: From<sp_core::sr25519::Public>,
<Runtime as pallet_bridge_messages::Config<MPI>>::InboundRelayer: From<AccountId32>,
<Runtime as pallet_utility::Config>::RuntimeCall: From<pallet_bridge_grandpa::Call<Runtime, GPI>>
+ From<pallet_bridge_messages::Call<Runtime, MPI>>,
<Runtime as frame_system::Config>::RuntimeCall: From<pallet_utility::Call<Runtime>>,
{ {
helpers::relayed_incoming_message_works::< helpers::relayed_incoming_message_works::<
Runtime, RuntimeHelper::Runtime,
AllPalletsWithoutSystem, RuntimeHelper::AllPalletsWithoutSystem,
HrmpChannelOpener, RuntimeHelper::MPI,
MPI,
>( >(
collator_session_key, collator_session_key,
runtime_para_id, runtime_para_id,
@@ -244,41 +253,45 @@ pub fn complex_relay_extrinsic_works<
prepare_configuration(); prepare_configuration();
// start with bridged relay chain block#0 // start with bridged relay chain block#0
helpers::initialize_bridge_grandpa_pallet::<Runtime, GPI>( helpers::initialize_bridge_grandpa_pallet::<RuntimeHelper::Runtime, RuntimeHelper::GPI>(
test_data::initialization_data::<Runtime, GPI>(0), test_data::initialization_data::<RuntimeHelper::Runtime, RuntimeHelper::GPI>(0),
); );
// generate bridged relay chain finality, parachain heads and message proofs, // generate bridged relay chain finality, parachain heads and message proofs,
// to be submitted by relayer to this chain. // to be submitted by relayer to this chain.
let (relay_chain_header, grandpa_justification, message_proof) = let (relay_chain_header, grandpa_justification, message_proof) =
test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::<MB, ()>( test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::<
lane_id, RuntimeHelper::MB,
xcm.into(), (),
message_nonce, >(lane_id, xcm.into(), message_nonce, message_destination, relay_header_number);
message_destination,
relay_header_number,
);
let relay_chain_header_hash = relay_chain_header.hash(); let relay_chain_header_hash = relay_chain_header.hash();
vec![( vec![(
pallet_utility::Call::<Runtime>::batch_all { pallet_utility::Call::<RuntimeHelper::Runtime>::batch_all {
calls: vec![ calls: vec![
pallet_bridge_grandpa::Call::<Runtime, GPI>::submit_finality_proof { BridgeGrandpaCall::<RuntimeHelper::Runtime, RuntimeHelper::GPI>::submit_finality_proof {
finality_target: Box::new(relay_chain_header), finality_target: Box::new(relay_chain_header),
justification: grandpa_justification, justification: grandpa_justification,
}.into(), }.into(),
pallet_bridge_messages::Call::<Runtime, MPI>::receive_messages_proof { BridgeMessagesCall::<RuntimeHelper::Runtime, RuntimeHelper::MPI>::receive_messages_proof {
relayer_id_at_bridged_chain, relayer_id_at_bridged_chain,
proof: message_proof, proof: message_proof,
messages_count: 1, messages_count: 1,
dispatch_weight: Weight::from_parts(1000000000, 0), dispatch_weight: Weight::from_parts(1000000000, 0),
}.into(), }.into(),
], ],
}.into(), }
.into(),
Box::new(( Box::new((
helpers::VerifySubmitGrandpaFinalityProofOutcome::<Runtime, GPI>::expect_best_header_hash(relay_chain_header_hash), helpers::VerifySubmitGrandpaFinalityProofOutcome::<
helpers::VerifySubmitMessagesProofOutcome::<Runtime, MPI>::expect_last_delivered_nonce(lane_id, 1), RuntimeHelper::Runtime,
helpers::VerifyRelayerRewarded::<Runtime>::expect_relayer_reward( 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::<RuntimeHelper::Runtime>::expect_relayer_reward(
relayer_id_at_this_chain, relayer_id_at_this_chain,
RewardsAccountParams::new( RewardsAccountParams::new(
lane_id, lane_id,
@@ -294,35 +307,25 @@ pub fn complex_relay_extrinsic_works<
/// Estimates transaction fee for default message delivery transaction (batched with required /// Estimates transaction fee for default message delivery transaction (batched with required
/// proofs) from bridged GRANDPA chain. /// proofs) from bridged GRANDPA chain.
pub fn can_calculate_fee_for_complex_message_delivery_transaction<Runtime, GPI, MPI, MB>( pub fn can_calculate_fee_for_complex_message_delivery_transaction<RuntimeHelper>(
collator_session_key: CollatorSessionKeys<Runtime>, collator_session_key: CollatorSessionKeys<RuntimeHelper::Runtime>,
compute_extrinsic_fee: fn(pallet_utility::Call<Runtime>) -> u128, compute_extrinsic_fee: fn(pallet_utility::Call<RuntimeHelper::Runtime>) -> u128,
) -> u128 ) -> u128
where where
Runtime: BasicParachainRuntime RuntimeHelper: WithRemoteGrandpaChainHelper,
+ pallet_bridge_grandpa::Config< RuntimeHelper::Runtime:
GPI, pallet_utility::Config<RuntimeCall = RuntimeCallOf<RuntimeHelper::Runtime>>,
BridgedChain = UnderlyingChainOf<MessageBridgedChain<MB>>, RuntimeCallOf<RuntimeHelper::Runtime>: From<BridgeGrandpaCall<RuntimeHelper::Runtime, RuntimeHelper::GPI>>
> + pallet_bridge_messages::Config< + From<BridgeMessagesCall<RuntimeHelper::Runtime, RuntimeHelper::MPI>>,
MPI, UnderlyingChainOf<MessageBridgedChain<RuntimeHelper::MB>>: ChainWithGrandpa,
InboundPayload = XcmAsPlainPayload, <RuntimeHelper::Runtime as BridgeMessagesConfig<RuntimeHelper::MPI>>::SourceHeaderChain:
InboundRelayer = bp_runtime::AccountIdOf<MessageBridgedChain<MB>>, SourceHeaderChain<
> + pallet_utility::Config, MessagesProof = FromBridgedChainMessagesProof<
GPI: 'static, HashOf<MessageBridgedChain<RuntimeHelper::MB>>,
MPI: 'static, >,
MB: MessageBridge, >,
<MB as MessageBridge>::BridgedChain: Send + Sync + 'static,
<MB as MessageBridge>::ThisChain: Send + Sync + 'static,
UnderlyingChainOf<MessageBridgedChain<MB>>: bp_runtime::Chain + ChainWithGrandpa,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as pallet_bridge_messages::Config<MPI>>::SourceHeaderChain: SourceHeaderChain<
MessagesProof = FromBridgedChainMessagesProof<HashOf<MessageBridgedChain<MB>>>,
>,
bp_runtime::AccountIdOf<MessageBridgedChain<MB>>: From<sp_core::sr25519::Public>,
<Runtime as pallet_utility::Config>::RuntimeCall: From<pallet_bridge_grandpa::Call<Runtime, GPI>>
+ From<pallet_bridge_messages::Call<Runtime, MPI>>,
{ {
run_test::<Runtime, _>(collator_session_key, 1000, vec![], || { run_test::<RuntimeHelper::Runtime, _>(collator_session_key, 1000, vec![], || {
// generate bridged relay chain finality, parachain heads and message proofs, // generate bridged relay chain finality, parachain heads and message proofs,
// to be submitted by relayer to this chain. // 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 // do not need to have a large message here, because we're charging for every byte of
// the message additionally // the message additionally
let (relay_chain_header, grandpa_justification, message_proof) = let (relay_chain_header, grandpa_justification, message_proof) =
test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::<MB, ()>( test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::<
RuntimeHelper::MB,
(),
>(
LaneId::default(), LaneId::default(),
vec![xcm::v3::Instruction::<()>::ClearOrigin; 1_024].into(), vec![xcm::v3::Instruction::<()>::ClearOrigin; 1_024].into(),
1, 1,
@@ -341,14 +347,14 @@ where
// generate batch call that provides finality for bridged relay and parachains + message // generate batch call that provides finality for bridged relay and parachains + message
// proof // proof
let batch = test_data::from_grandpa_chain::make_complex_relayer_delivery_batch::< let batch = test_data::from_grandpa_chain::make_complex_relayer_delivery_batch::<
Runtime, RuntimeHelper::Runtime,
GPI, RuntimeHelper::GPI,
MPI, RuntimeHelper::MPI,
>( >(
relay_chain_header, relay_chain_header,
grandpa_justification, grandpa_justification,
message_proof, message_proof,
Dave.public().into(), helpers::relayer_id_at_bridged_chain::<RuntimeHelper::Runtime, RuntimeHelper::MPI>(),
); );
let estimated_fee = compute_extrinsic_fee(batch); let estimated_fee = compute_extrinsic_fee(batch);
@@ -356,7 +362,7 @@ where
target: "bridges::estimate", target: "bridges::estimate",
"Estimate fee: {:?} for single message delivery for runtime: {:?}", "Estimate fee: {:?} for single message delivery for runtime: {:?}",
estimated_fee, estimated_fee,
Runtime::Version::get(), <RuntimeHelper::Runtime as frame_system::Config>::Version::get(),
); );
estimated_fee estimated_fee
@@ -365,42 +371,30 @@ where
/// Estimates transaction fee for default message confirmation transaction (batched with required /// Estimates transaction fee for default message confirmation transaction (batched with required
/// proofs) from bridged GRANDPA chain. /// proofs) from bridged GRANDPA chain.
pub fn can_calculate_fee_for_complex_message_confirmation_transaction<Runtime, GPI, MPI, MB>( pub fn can_calculate_fee_for_complex_message_confirmation_transaction<RuntimeHelper>(
collator_session_key: CollatorSessionKeys<Runtime>, collator_session_key: CollatorSessionKeys<RuntimeHelper::Runtime>,
compute_extrinsic_fee: fn(pallet_utility::Call<Runtime>) -> u128, compute_extrinsic_fee: fn(pallet_utility::Call<RuntimeHelper::Runtime>) -> u128,
) -> u128 ) -> u128
where where
Runtime: BasicParachainRuntime RuntimeHelper: WithRemoteGrandpaChainHelper,
+ pallet_bridge_grandpa::Config< AccountIdOf<RuntimeHelper::Runtime>: From<AccountId32>,
GPI, RuntimeHelper::Runtime:
BridgedChain = UnderlyingChainOf<MessageBridgedChain<MB>>, pallet_utility::Config<RuntimeCall = RuntimeCallOf<RuntimeHelper::Runtime>>,
> + pallet_bridge_messages::Config<MPI, OutboundPayload = XcmAsPlainPayload> MessageThisChain<RuntimeHelper::MB>:
+ pallet_utility::Config, bp_runtime::Chain<AccountId = AccountIdOf<RuntimeHelper::Runtime>>,
GPI: 'static, RuntimeCallOf<RuntimeHelper::Runtime>: From<BridgeGrandpaCall<RuntimeHelper::Runtime, RuntimeHelper::GPI>>
MPI: 'static, + From<BridgeMessagesCall<RuntimeHelper::Runtime, RuntimeHelper::MPI>>,
MB: MessageBridge, UnderlyingChainOf<MessageBridgedChain<RuntimeHelper::MB>>: ChainWithGrandpa,
<MB as MessageBridge>::BridgedChain: Send + Sync + 'static, <RuntimeHelper::Runtime as BridgeMessagesConfig<RuntimeHelper::MPI>>::TargetHeaderChain:
<MB as MessageBridge>::ThisChain: Send + Sync + 'static, TargetHeaderChain<
<<MB as MessageBridge>::ThisChain as bp_runtime::Chain>::AccountId: From<AccountId32>, XcmAsPlainPayload,
UnderlyingChainOf<MessageBridgedChain<MB>>: ChainWithGrandpa, AccountIdOf<RuntimeHelper::Runtime>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>, MessagesDeliveryProof = FromBridgedChainMessagesDeliveryProof<
<Runtime as frame_system::Config>::AccountId: HashOf<UnderlyingChainOf<MessageBridgedChain<RuntimeHelper::MB>>>,
Into<<<Runtime as frame_system::Config>::RuntimeOrigin as OriginTrait>::AccountId>, >,
<Runtime as frame_system::Config>::AccountId: From<AccountId32>,
AccountIdOf<Runtime>: From<sp_core::sr25519::Public>,
<Runtime as pallet_bridge_messages::Config<MPI>>::InboundRelayer: From<AccountId32>,
<Runtime as pallet_bridge_messages::Config<MPI>>::TargetHeaderChain: TargetHeaderChain<
XcmAsPlainPayload,
Runtime::AccountId,
MessagesDeliveryProof = FromBridgedChainMessagesDeliveryProof<
HashOf<UnderlyingChainOf<MessageBridgedChain<MB>>>,
>, >,
>,
<Runtime as pallet_utility::Config>::RuntimeCall: From<pallet_bridge_grandpa::Call<Runtime, GPI>>
+ From<pallet_bridge_messages::Call<Runtime, MPI>>,
bp_runtime::AccountIdOf<MessageThisChain<MB>>: From<sp_core::sr25519::Public>,
{ {
run_test::<Runtime, _>(collator_session_key, 1000, vec![], || { run_test::<RuntimeHelper::Runtime, _>(collator_session_key, 1000, vec![], || {
// generate bridged relay chain finality, parachain heads and message proofs, // generate bridged relay chain finality, parachain heads and message proofs,
// to be submitted by relayer to this chain. // to be submitted by relayer to this chain.
let unrewarded_relayers = UnrewardedRelayersState { let unrewarded_relayers = UnrewardedRelayersState {
@@ -409,19 +403,22 @@ where
..Default::default() ..Default::default()
}; };
let (relay_chain_header, grandpa_justification, message_delivery_proof) = let (relay_chain_header, grandpa_justification, message_delivery_proof) =
test_data::from_grandpa_chain::make_complex_relayer_confirmation_proofs::<MB, ()>( test_data::from_grandpa_chain::make_complex_relayer_confirmation_proofs::<
RuntimeHelper::MB,
(),
>(
LaneId::default(), LaneId::default(),
1u32.into(), 1u32.into(),
Alice.public().into(), AccountId32::from(Alice.public()).into(),
unrewarded_relayers.clone(), unrewarded_relayers.clone(),
); );
// generate batch call that provides finality for bridged relay and parachains + message // generate batch call that provides finality for bridged relay and parachains + message
// proof // proof
let batch = test_data::from_grandpa_chain::make_complex_relayer_confirmation_batch::< let batch = test_data::from_grandpa_chain::make_complex_relayer_confirmation_batch::<
Runtime, RuntimeHelper::Runtime,
GPI, RuntimeHelper::GPI,
MPI, RuntimeHelper::MPI,
>( >(
relay_chain_header, relay_chain_header,
grandpa_justification, grandpa_justification,
@@ -434,7 +431,7 @@ where
target: "bridges::estimate", target: "bridges::estimate",
"Estimate fee: {:?} for single message confirmation for runtime: {:?}", "Estimate fee: {:?} for single message confirmation for runtime: {:?}",
estimated_fee, estimated_fee,
Runtime::Version::get(), <RuntimeHelper::Runtime as frame_system::Config>::Version::get(),
); );
estimated_fee estimated_fee
@@ -107,12 +107,7 @@ pub fn relayed_incoming_message_works<
+ From<pallet_bridge_parachains::Call<Runtime, PPI>> + From<pallet_bridge_parachains::Call<Runtime, PPI>>
+ From<pallet_bridge_messages::Call<Runtime, MPI>>, + From<pallet_bridge_messages::Call<Runtime, MPI>>,
{ {
helpers::relayed_incoming_message_works::< helpers::relayed_incoming_message_works::<Runtime, AllPalletsWithoutSystem, MPI>(
Runtime,
AllPalletsWithoutSystem,
HrmpChannelOpener,
MPI,
>(
collator_session_key, collator_session_key,
runtime_para_id, runtime_para_id,
sibling_parachain_id, sibling_parachain_id,
@@ -263,12 +258,7 @@ pub fn complex_relay_extrinsic_works<
+ From<pallet_bridge_messages::Call<Runtime, MPI>>, + From<pallet_bridge_messages::Call<Runtime, MPI>>,
<Runtime as frame_system::Config>::RuntimeCall: From<pallet_utility::Call<Runtime>>, <Runtime as frame_system::Config>::RuntimeCall: From<pallet_utility::Call<Runtime>>,
{ {
helpers::relayed_incoming_message_works::< helpers::relayed_incoming_message_works::<Runtime, AllPalletsWithoutSystem, MPI>(
Runtime,
AllPalletsWithoutSystem,
HrmpChannelOpener,
MPI,
>(
collator_session_key, collator_session_key,
runtime_para_id, runtime_para_id,
sibling_parachain_id, sibling_parachain_id,
@@ -22,6 +22,7 @@ use asset_test_utils::BasicParachainRuntime;
use bp_messages::{LaneId, MessageNonce}; use bp_messages::{LaneId, MessageNonce};
use bp_polkadot_core::parachains::{ParaHash, ParaId}; use bp_polkadot_core::parachains::{ParaHash, ParaId};
use bp_relayers::RewardsAccountParams; use bp_relayers::RewardsAccountParams;
use codec::Decode;
use frame_support::{ use frame_support::{
assert_ok, assert_ok,
traits::{OnFinalize, OnInitialize, PalletInfoAccess}, traits::{OnFinalize, OnInitialize, PalletInfoAccess},
@@ -29,12 +30,10 @@ use frame_support::{
use frame_system::pallet_prelude::BlockNumberFor; use frame_system::pallet_prelude::BlockNumberFor;
use pallet_bridge_grandpa::{BridgedBlockHash, BridgedHeader}; use pallet_bridge_grandpa::{BridgedBlockHash, BridgedHeader};
use parachains_common::AccountId; use parachains_common::AccountId;
use parachains_runtimes_test_utils::{ use parachains_runtimes_test_utils::{mock_open_hrmp_channel, AccountIdOf, CollatorSessionKeys};
mock_open_hrmp_channel, AccountIdOf, CollatorSessionKeys, ValidatorIdOf,
};
use sp_core::Get; use sp_core::Get;
use sp_keyring::AccountKeyring::*; use sp_keyring::AccountKeyring::*;
use sp_runtime::AccountId32; use sp_runtime::{traits::TrailingZeroInput, AccountId32};
use sp_std::marker::PhantomData; use sp_std::marker::PhantomData;
use xcm::latest::prelude::*; use xcm::latest::prelude::*;
@@ -208,9 +207,15 @@ pub(crate) fn initialize_bridge_grandpa_pallet<Runtime, GPI>(
pub type CallsAndVerifiers<Runtime> = pub type CallsAndVerifiers<Runtime> =
Vec<(<Runtime as frame_system::Config>::RuntimeCall, Box<dyn VerifyTransactionOutcome>)>; Vec<(<Runtime as frame_system::Config>::RuntimeCall, Box<dyn VerifyTransactionOutcome>)>;
/// Returns relayer id at the bridged chain.
pub fn relayer_id_at_bridged_chain<Runtime: pallet_bridge_messages::Config<MPI>, MPI>(
) -> Runtime::InboundRelayer {
Runtime::InboundRelayer::decode(&mut TrailingZeroInput::zeroes()).unwrap()
}
/// Test-case makes sure that Runtime can dispatch XCM messages submitted by relayer, /// Test-case makes sure that Runtime can dispatch XCM messages submitted by relayer,
/// with proofs (finality, message) independently submitted. /// with proofs (finality, message) independently submitted.
pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, HrmpChannelOpener, MPI>( pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, MPI>(
collator_session_key: CollatorSessionKeys<Runtime>, collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32, runtime_para_id: u32,
sibling_parachain_id: u32, sibling_parachain_id: u32,
@@ -232,18 +237,12 @@ pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, HrmpChan
+ pallet_bridge_messages::Config<MPI>, + pallet_bridge_messages::Config<MPI>,
AllPalletsWithoutSystem: AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>, OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
HrmpChannelOpener: frame_support::inherent::ProvideInherent<
Call = cumulus_pallet_parachain_system::Call<Runtime>,
>,
MPI: 'static, MPI: 'static,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>, AccountIdOf<Runtime>: From<AccountId32>,
AccountIdOf<Runtime>: From<AccountId32> + From<sp_core::sr25519::Public>,
<Runtime as pallet_bridge_messages::Config<MPI>>::InboundRelayer: From<AccountId32>,
{ {
let relayer_at_target = Bob; let relayer_at_target = Bob;
let relayer_id_on_target: AccountId32 = relayer_at_target.public().into(); let relayer_id_on_target: AccountId32 = relayer_at_target.public().into();
let relayer_at_source = Dave; let relayer_id_on_source = relayer_id_at_bridged_chain::<Runtime, MPI>();
let relayer_id_on_source: AccountId32 = relayer_at_source.public().into();
assert_ne!(runtime_para_id, sibling_parachain_id); assert_ne!(runtime_para_id, sibling_parachain_id);
@@ -262,7 +261,7 @@ pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, HrmpChan
2, 2,
AccountId::from(alice).into(), AccountId::from(alice).into(),
); );
mock_open_hrmp_channel::<Runtime, HrmpChannelOpener>( mock_open_hrmp_channel::<Runtime, cumulus_pallet_parachain_system::Pallet<Runtime>>(
runtime_para_id.into(), runtime_para_id.into(),
sibling_parachain_id.into(), sibling_parachain_id.into(),
included_head, included_head,
@@ -72,7 +72,6 @@ pub fn run_test<Runtime, T>(
) -> T ) -> T
where where
Runtime: BasicParachainRuntime, Runtime: BasicParachainRuntime,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
{ {
ExtBuilder::<Runtime>::default() ExtBuilder::<Runtime>::default()
.with_collators(collator_session_key.collators()) .with_collators(collator_session_key.collators())
@@ -47,6 +47,7 @@ pub mod test_cases;
pub type BalanceOf<Runtime> = <Runtime as pallet_balances::Config>::Balance; pub type BalanceOf<Runtime> = <Runtime as pallet_balances::Config>::Balance;
pub type AccountIdOf<Runtime> = <Runtime as frame_system::Config>::AccountId; pub type AccountIdOf<Runtime> = <Runtime as frame_system::Config>::AccountId;
pub type RuntimeCallOf<Runtime> = <Runtime as frame_system::Config>::RuntimeCall;
pub type ValidatorIdOf<Runtime> = <Runtime as pallet_session::Config>::ValidatorId; pub type ValidatorIdOf<Runtime> = <Runtime as pallet_session::Config>::ValidatorId;
pub type SessionKeysOf<Runtime> = <Runtime as pallet_session::Config>::Keys; pub type SessionKeysOf<Runtime> = <Runtime as pallet_session::Config>::Keys;