Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final nits for bridge-hub-test-utils #2788

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! with remote GRANDPA chain.

use crate::{
test_cases::{helpers, run_test},
test_cases::{bridges_prelude::*, helpers, run_test},
test_data,
};

Expand All @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! with remote parachain.

use crate::{
test_cases::{helpers, run_test},
test_cases::{bridges_prelude::*, helpers, run_test},
test_data,
};

Expand All @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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);
Expand All @@ -51,15 +54,15 @@ impl VerifyTransactionOutcome for Box<dyn VerifyTransactionOutcome> {
/// Checks that the best finalized header hash in the bridge GRANDPA pallet equals to given one.
pub struct VerifySubmitGrandpaFinalityProofOutcome<Runtime, GPI>
where
Runtime: pallet_bridge_grandpa::Config<GPI>,
Runtime: BridgeGrandpaConfig<GPI>,
GPI: 'static,
{
expected_best_hash: BridgedBlockHash<Runtime, GPI>,
}

impl<Runtime, GPI> VerifySubmitGrandpaFinalityProofOutcome<Runtime, GPI>
where
Runtime: pallet_bridge_grandpa::Config<GPI>,
Runtime: BridgeGrandpaConfig<GPI>,
GPI: 'static,
{
/// Expect given header hash to be the best after transaction.
Expand All @@ -73,7 +76,7 @@ where
impl<Runtime, GPI> VerifyTransactionOutcome
for VerifySubmitGrandpaFinalityProofOutcome<Runtime, GPI>
where
Runtime: pallet_bridge_grandpa::Config<GPI>,
Runtime: BridgeGrandpaConfig<GPI>,
GPI: 'static,
{
fn verify_outcome(&self) {
Expand All @@ -96,7 +99,7 @@ pub struct VerifySubmitParachainHeaderProofOutcome<Runtime, PPI> {

impl<Runtime, PPI> VerifySubmitParachainHeaderProofOutcome<Runtime, PPI>
where
Runtime: pallet_bridge_parachains::Config<PPI>,
Runtime: BridgeParachainsConfig<PPI>,
PPI: 'static,
{
/// Expect given header hash to be the best after transaction.
Expand All @@ -111,7 +114,7 @@ where
impl<Runtime, PPI> VerifyTransactionOutcome
for VerifySubmitParachainHeaderProofOutcome<Runtime, PPI>
where
Runtime: pallet_bridge_parachains::Config<PPI>,
Runtime: BridgeParachainsConfig<PPI>,
PPI: 'static,
{
fn verify_outcome(&self) {
Expand All @@ -132,7 +135,7 @@ pub struct VerifySubmitMessagesProofOutcome<Runtime, MPI> {

impl<Runtime, MPI> VerifySubmitMessagesProofOutcome<Runtime, MPI>
where
Runtime: pallet_bridge_messages::Config<MPI>,
Runtime: BridgeMessagesConfig<MPI>,
MPI: 'static,
{
/// Expect given delivered nonce to be the latest after transaction.
Expand All @@ -146,7 +149,7 @@ where

impl<Runtime, MPI> VerifyTransactionOutcome for VerifySubmitMessagesProofOutcome<Runtime, MPI>
where
Runtime: pallet_bridge_messages::Config<MPI>,
Runtime: BridgeMessagesConfig<MPI>,
MPI: 'static,
{
fn verify_outcome(&self) {
Expand Down Expand Up @@ -194,7 +197,7 @@ where
pub(crate) fn initialize_bridge_grandpa_pallet<Runtime, GPI>(
init_data: bp_header_chain::InitializationData<BridgedHeader<Runtime, GPI>>,
) where
Runtime: pallet_bridge_grandpa::Config<GPI>,
Runtime: BridgeGrandpaConfig<GPI>,
{
pallet_bridge_grandpa::Pallet::<Runtime, GPI>::initialize(
RuntimeHelper::<Runtime>::root_origin(),
Expand All @@ -205,7 +208,7 @@ pub(crate) fn initialize_bridge_grandpa_pallet<Runtime, GPI>(

/// Runtime calls and their verifiers.
pub type CallsAndVerifiers<Runtime> =
Vec<(<Runtime as frame_system::Config>::RuntimeCall, Box<dyn VerifyTransactionOutcome>)>;
Vec<(RuntimeCallOf<Runtime>, Box<dyn VerifyTransactionOutcome>)>;

/// Returns relayer id at the bridged chain.
pub fn relayer_id_at_bridged_chain<Runtime: pallet_bridge_messages::Config<MPI>, MPI>(
Expand All @@ -222,7 +225,7 @@ pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, MPI>(
local_relay_chain_id: NetworkId,
construct_and_apply_extrinsic: fn(
sp_keyring::AccountKeyring,
<Runtime as frame_system::Config>::RuntimeCall,
RuntimeCallOf<Runtime>,
) -> sp_runtime::DispatchOutcome,
prepare_message_proof_import: impl FnOnce(
Runtime::AccountId,
Expand All @@ -232,9 +235,7 @@ pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, MPI>(
Xcm<()>,
) -> CallsAndVerifiers<Runtime>,
) where
Runtime: BasicParachainRuntime
+ cumulus_pallet_xcmp_queue::Config
+ pallet_bridge_messages::Config<MPI>,
Runtime: BasicParachainRuntime + cumulus_pallet_xcmp_queue::Config + BridgeMessagesConfig<MPI>,
AllPalletsWithoutSystem:
OnInitialize<BlockNumberFor<Runtime>> + OnFinalize<BlockNumberFor<Runtime>>,
MPI: 'static,
Expand All @@ -251,7 +252,12 @@ pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, MPI>(
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::Balance>(Runtime::ExistentialDeposit::get(), 1u32.into()) *
100_000_000u32.into(),
)],
|| {
let mut alice = [0u8; 32];
Expand Down Expand Up @@ -327,7 +333,7 @@ fn execute_and_verify_calls<Runtime: frame_system::Config>(
submitter: sp_keyring::AccountKeyring,
construct_and_apply_extrinsic: fn(
sp_keyring::AccountKeyring,
<Runtime as frame_system::Config>::RuntimeCall,
RuntimeCallOf<Runtime>,
) -> sp_runtime::DispatchOutcome,
calls_and_verifiers: CallsAndVerifiers<Runtime>,
) {
Expand Down
Loading