Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -19,8 +19,12 @@ use super::{
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
TransactionByteFee, WeightToFee, XcmpQueue,
};
use crate::bridge_common_config::{
BridgeGrandpaWestendInstance, DeliveryRewardInBalance, RequiredStakeForStakeAndSlash,
use crate::{
bridge_common_config::{
BridgeGrandpaWestendInstance, BridgeParachainWestendInstance, DeliveryRewardInBalance,
RequiredStakeForStakeAndSlash,
},
bridge_to_westend_config::WithBridgeHubWestendMessagesInstance,
};
use bp_messages::LaneId;
use bp_relayers::{PayRewardFromAccount, RewardsAccountOwner, RewardsAccountParams};
Expand Down Expand Up @@ -184,7 +188,19 @@ impl Contains<RuntimeCall> for SafeCallFilter {
RuntimeCall::BridgeWestendGrandpa(pallet_bridge_grandpa::Call::<
Runtime,
BridgeGrandpaWestendInstance,
>::initialize { .. })
>::initialize { .. }) |
RuntimeCall::BridgeWestendGrandpa(pallet_bridge_grandpa::Call::<
Runtime,
BridgeGrandpaWestendInstance,
>::set_operating_mode { .. }) |
RuntimeCall::BridgeWestendParachains(pallet_bridge_parachains::Call::<
Runtime,
BridgeParachainWestendInstance,
>::set_operating_mode { .. }) |
RuntimeCall::BridgeWestendMessages(pallet_bridge_messages::Call::<
Runtime,
WithBridgeHubWestendMessagesInstance,
>::set_operating_mode { .. })
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,34 @@ mod bridge_hub_rococo_tests {
bridge_hub_test_utils::test_cases::initialize_bridge_by_governance_works::<
Runtime,
BridgeGrandpaWestendInstance,
>(
collator_session_keys(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
Box::new(|call| RuntimeCall::BridgeWestendGrandpa(call).encode()),
)
>(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID)
}

#[test]
fn change_bridge_grandpa_pallet_mode_by_governance_works() {
// for Westend finality
bridge_hub_test_utils::test_cases::change_bridge_grandpa_pallet_mode_by_governance_works::<
Runtime,
BridgeGrandpaWestendInstance,
>(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID)
}

#[test]
fn change_bridge_parachains_pallet_mode_by_governance_works() {
// for Westend finality
bridge_hub_test_utils::test_cases::change_bridge_parachains_pallet_mode_by_governance_works::<
Runtime,
BridgeParachainWestendInstance,
>(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID)
}

#[test]
fn change_bridge_messages_pallet_mode_by_governance_works() {
// for Westend finality
bridge_hub_test_utils::test_cases::change_bridge_messages_pallet_mode_by_governance_works::<
Runtime,
WithBridgeHubWestendMessagesInstance,
>(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID)
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,19 @@ impl Contains<RuntimeCall> for SafeCallFilter {
RuntimeCall::BridgeRococoGrandpa(pallet_bridge_grandpa::Call::<
Runtime,
crate::bridge_to_rococo_config::BridgeGrandpaRococoInstance,
>::initialize { .. })
>::initialize { .. }) |
RuntimeCall::BridgeRococoGrandpa(pallet_bridge_grandpa::Call::<
Runtime,
crate::bridge_to_rococo_config::BridgeGrandpaRococoInstance,
>::set_operating_mode { .. }) |
RuntimeCall::BridgeRococoParachains(pallet_bridge_parachains::Call::<
Runtime,
crate::bridge_to_rococo_config::BridgeParachainRococoInstance,
>::set_operating_mode { .. }) |
RuntimeCall::BridgeRococoMessages(pallet_bridge_messages::Call::<
Runtime,
crate::bridge_to_rococo_config::WithBridgeHubRococoMessagesInstance,
>::set_operating_mode { .. })
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,31 @@ fn initialize_bridge_by_governance_works() {
bridge_hub_test_utils::test_cases::initialize_bridge_by_governance_works::<
Runtime,
BridgeGrandpaRococoInstance,
>(
collator_session_keys(),
bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID,
Box::new(|call| RuntimeCall::BridgeRococoGrandpa(call).encode()),
)
>(collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID)
}

#[test]
fn change_bridge_grandpa_pallet_mode_by_governance_works() {
bridge_hub_test_utils::test_cases::change_bridge_grandpa_pallet_mode_by_governance_works::<
Runtime,
BridgeGrandpaRococoInstance,
>(collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID)
}

#[test]
fn change_bridge_parachains_pallet_mode_by_governance_works() {
bridge_hub_test_utils::test_cases::change_bridge_parachains_pallet_mode_by_governance_works::<
Runtime,
BridgeParachainRococoInstance,
>(collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID)
}

#[test]
fn change_bridge_messages_pallet_mode_by_governance_works() {
bridge_hub_test_utils::test_cases::change_bridge_messages_pallet_mode_by_governance_works::<
Runtime,
WithBridgeHubRococoMessagesInstance,
>(collator_session_keys(), bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID)
}

#[test]
Expand Down
210 changes: 199 additions & 11 deletions cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use crate::test_data;
use asset_test_utils::BasicParachainRuntime;
use bp_messages::{
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
LaneId, MessageKey, OutboundLaneData,
LaneId, MessageKey, MessagesOperatingMode, OutboundLaneData,
};
use bp_runtime::BasicOperatingMode;
use bridge_runtime_common::messages_xcm_extension::{
XcmAsPlainPayload, XcmBlobMessageDispatchResult,
};
Expand Down Expand Up @@ -88,13 +89,12 @@ where
pub fn initialize_bridge_by_governance_works<Runtime, GrandpaPalletInstance>(
collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32,
runtime_call_encode: Box<
dyn Fn(pallet_bridge_grandpa::Call<Runtime, GrandpaPalletInstance>) -> Vec<u8>,
>,
) where
Runtime: BasicParachainRuntime + pallet_bridge_grandpa::Config<GrandpaPalletInstance>,
GrandpaPalletInstance: 'static,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as frame_system::Config>::RuntimeCall:
From<pallet_bridge_grandpa::Call<Runtime, GrandpaPalletInstance>>,
{
run_test::<Runtime, _>(collator_session_key, runtime_para_id, vec![], || {
// check mode before
Expand All @@ -104,12 +104,14 @@ pub fn initialize_bridge_by_governance_works<Runtime, GrandpaPalletInstance>(
);

// encode `initialize` call
let initialize_call = runtime_call_encode(pallet_bridge_grandpa::Call::<
Runtime,
GrandpaPalletInstance,
>::initialize {
init_data: test_data::initialization_data::<Runtime, GrandpaPalletInstance>(12345),
});
let initialize_call =
<Runtime as frame_system::Config>::RuntimeCall::from(pallet_bridge_grandpa::Call::<
Runtime,
GrandpaPalletInstance,
>::initialize {
init_data: test_data::initialization_data::<Runtime, GrandpaPalletInstance>(12345),
})
.encode();

// overestimate - check weight for `pallet_bridge_grandpa::Pallet::initialize()` call
let require_weight_at_most =
Expand All @@ -125,11 +127,197 @@ pub fn initialize_bridge_by_governance_works<Runtime, GrandpaPalletInstance>(
// check mode after
assert_eq!(
pallet_bridge_grandpa::PalletOperatingMode::<Runtime, GrandpaPalletInstance>::try_get(),
Ok(bp_runtime::BasicOperatingMode::Normal)
Ok(BasicOperatingMode::Normal)
);
})
}

/// Test-case makes sure that `Runtime` can change bridge GRANDPA pallet operating mode via
/// governance-like call.
pub fn change_bridge_grandpa_pallet_mode_by_governance_works<Runtime, GrandpaPalletInstance>(
collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32,
) where
Runtime: BasicParachainRuntime + pallet_bridge_grandpa::Config<GrandpaPalletInstance>,
GrandpaPalletInstance: 'static,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as frame_system::Config>::RuntimeCall:
From<pallet_bridge_grandpa::Call<Runtime, GrandpaPalletInstance>>,
{
run_test::<Runtime, _>(collator_session_key, runtime_para_id, vec![], || {
let dispatch_set_operating_mode_call = |old_mode, new_mode| {
// check old mode
assert_eq!(
pallet_bridge_grandpa::PalletOperatingMode::<Runtime, GrandpaPalletInstance>::get(),
old_mode,
);

// overestimate - check weight for `pallet_bridge_grandpa::Pallet::set_operating_mode()`
// call
let require_weight_at_most =
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(7, 7);

// encode `set_operating_mode` call
let set_operating_mode_call = <Runtime as frame_system::Config>::RuntimeCall::from(
pallet_bridge_grandpa::Call::<Runtime, GrandpaPalletInstance>::set_operating_mode {
operating_mode: new_mode,
},
)
.encode();

// execute XCM with Transacts to `initialize bridge` as governance does
assert_ok!(RuntimeHelper::<Runtime>::execute_as_governance(
set_operating_mode_call,
require_weight_at_most
)
.ensure_complete());

// check mode after
assert_eq!(
pallet_bridge_grandpa::PalletOperatingMode::<Runtime, GrandpaPalletInstance>::try_get(),
Ok(new_mode)
);
};

// check mode before
assert_eq!(
pallet_bridge_grandpa::PalletOperatingMode::<Runtime, GrandpaPalletInstance>::try_get(),
Err(())
);

dispatch_set_operating_mode_call(BasicOperatingMode::Normal, BasicOperatingMode::Halted);
dispatch_set_operating_mode_call(BasicOperatingMode::Halted, BasicOperatingMode::Normal);
});
}

/// Test-case makes sure that `Runtime` can change bridge parachains pallet operating mode via
/// governance-like call.
pub fn change_bridge_parachains_pallet_mode_by_governance_works<Runtime, ParachainsPalletInstance>(
collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32,
) where
Runtime: BasicParachainRuntime + pallet_bridge_parachains::Config<ParachainsPalletInstance>,
ParachainsPalletInstance: 'static,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as frame_system::Config>::RuntimeCall:
From<pallet_bridge_parachains::Call<Runtime, ParachainsPalletInstance>>,
{
run_test::<Runtime, _>(collator_session_key, runtime_para_id, vec![], || {
let dispatch_set_operating_mode_call = |old_mode, new_mode| {
// check old mode
assert_eq!(
pallet_bridge_parachains::PalletOperatingMode::<Runtime, ParachainsPalletInstance>::get(),
old_mode,
);

// overestimate - check weight for
// `pallet_bridge_parachains::Pallet::set_operating_mode()` call
let require_weight_at_most =
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(7, 7);

// encode `set_operating_mode` call
let set_operating_mode_call = <Runtime as frame_system::Config>::RuntimeCall::from(pallet_bridge_parachains::Call::<
Runtime,
ParachainsPalletInstance,
>::set_operating_mode {
operating_mode: new_mode,
}).encode();

// execute XCM with Transacts to `initialize bridge` as governance does
assert_ok!(RuntimeHelper::<Runtime>::execute_as_governance(
set_operating_mode_call,
require_weight_at_most
)
.ensure_complete());

// check mode after
assert_eq!(
pallet_bridge_parachains::PalletOperatingMode::<Runtime, ParachainsPalletInstance>::try_get(),
Ok(new_mode)
);
};

// check mode before
assert_eq!(
pallet_bridge_parachains::PalletOperatingMode::<Runtime, ParachainsPalletInstance>::try_get(),
Err(())
);

dispatch_set_operating_mode_call(BasicOperatingMode::Normal, BasicOperatingMode::Halted);
dispatch_set_operating_mode_call(BasicOperatingMode::Halted, BasicOperatingMode::Normal);
});
}

/// Test-case makes sure that `Runtime` can change bridge messaging pallet operating mode via
/// governance-like call.
pub fn change_bridge_messages_pallet_mode_by_governance_works<Runtime, MessagesPalletInstance>(
collator_session_key: CollatorSessionKeys<Runtime>,
runtime_para_id: u32,
) where
Runtime: BasicParachainRuntime + pallet_bridge_messages::Config<MessagesPalletInstance>,
MessagesPalletInstance: 'static,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
<Runtime as frame_system::Config>::RuntimeCall:
From<pallet_bridge_messages::Call<Runtime, MessagesPalletInstance>>,
{
run_test::<Runtime, _>(collator_session_key, runtime_para_id, vec![], || {
let dispatch_set_operating_mode_call = |old_mode, new_mode| {
// check old mode
assert_eq!(
pallet_bridge_messages::PalletOperatingMode::<Runtime, MessagesPalletInstance>::get(
),
old_mode,
);

// overestimate - check weight for
// `pallet_bridge_messages::Pallet::set_operating_mode()` call
let require_weight_at_most =
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(7, 7);

// encode `set_operating_mode` call
let set_operating_mode_call = <Runtime as frame_system::Config>::RuntimeCall::from(pallet_bridge_messages::Call::<
Runtime,
MessagesPalletInstance,
>::set_operating_mode {
operating_mode: new_mode,
}).encode();

// execute XCM with Transacts to `initialize bridge` as governance does
assert_ok!(RuntimeHelper::<Runtime>::execute_as_governance(
set_operating_mode_call,
require_weight_at_most
)
.ensure_complete());

// check mode after
assert_eq!(
pallet_bridge_messages::PalletOperatingMode::<Runtime, MessagesPalletInstance>::try_get(),
Ok(new_mode)
);
};

// check mode before
assert_eq!(
pallet_bridge_messages::PalletOperatingMode::<Runtime, MessagesPalletInstance>::try_get(
),
Err(())
);

dispatch_set_operating_mode_call(
MessagesOperatingMode::Basic(BasicOperatingMode::Normal),
MessagesOperatingMode::RejectingOutboundMessages,
);
dispatch_set_operating_mode_call(
MessagesOperatingMode::RejectingOutboundMessages,
MessagesOperatingMode::Basic(BasicOperatingMode::Halted),
);
dispatch_set_operating_mode_call(
MessagesOperatingMode::Basic(BasicOperatingMode::Halted),
MessagesOperatingMode::Basic(BasicOperatingMode::Normal),
);
});
}

/// Test-case makes sure that `Runtime` can handle xcm `ExportMessage`:
/// Checks if received XCM messages is correctly added to the message outbound queue for delivery.
/// For SystemParachains we expect unpaid execution.
Expand Down