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

Parametrize SlotDurations for system parachain tests (because of mock_open_hrmp_channel) #2864

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 @@ -191,7 +191,7 @@ std = [
"cumulus-pallet-session-benchmarking/std",
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-primitives-aura/std", # TODO: guide is missing this step
"cumulus-primitives-aura/std", # TODO: guide is missing this step
"cumulus-primitives-core/std",
"cumulus-primitives-utility/std",
"frame-benchmarking?/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ use frame_system::{
};
use pallet_asset_conversion_tx_payment::AssetConversionAdapter;
use pallet_nfts::PalletFeatures;
pub use parachains_common as common;
use parachains_common::{
impls::DealWithFees,
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
Expand Down Expand Up @@ -149,7 +148,7 @@ const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
/// number of blocks authored per slot.
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked about this here: #2826 (comment)


/// This determines the average expected block time that we are targeting.
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ pub use asset_hub_rococo_runtime::{
TrustBackedAssetsInstance, XcmpQueue,
};
use asset_test_utils::{
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder,
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys,
ExtBuilder, SlotDurations,
};
use codec::{Decode, Encode};
use cumulus_primitives_utility::ChargeWeightInFungibles;
Expand All @@ -44,6 +45,7 @@ use frame_support::{
use parachains_common::{
rococo::fee::WeightToFee, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance,
};
use sp_consensus_aura::SlotDuration;
use sp_runtime::traits::MaybeEquivalence;
use xcm::latest::prelude::*;
use xcm_executor::traits::{Identity, JustTry, WeightTrader};
Expand All @@ -68,6 +70,15 @@ fn collator_session_keys() -> CollatorSessionKeys<Runtime> {
CollatorSessionKeys::default().add(collator_session_key(ALICE))
}

fn slot_durations() -> SlotDurations {
SlotDurations {
relay: SlotDuration::from_millis(
asset_hub_rococo_runtime::RELAY_CHAIN_SLOT_DURATION_MILLIS.into(),
),
para: SlotDuration::from_millis(asset_hub_rococo_runtime::SLOT_DURATION),
}
}

#[test]
fn test_asset_xcm_trader() {
ExtBuilder::<Runtime>::default()
Expand Down Expand Up @@ -522,6 +533,7 @@ asset_test_utils::include_teleports_for_native_asset_works!(
WeightToFee,
ParachainSystem,
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Expand All @@ -542,6 +554,7 @@ asset_test_utils::include_teleports_for_foreign_assets_works!(
ForeignCreatorsSovereignAccountOf,
ForeignAssetsInstance,
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Expand Down Expand Up @@ -650,6 +663,7 @@ fn limited_reserve_transfer_assets_for_native_asset_over_bridge_works(
LocationToAccountId,
>(
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
AccountId::from(ALICE),
Box::new(|runtime_event_encoded: Vec<u8>| {
Expand Down Expand Up @@ -821,6 +835,7 @@ mod asset_hub_rococo_tests {
LocationToAccountId,
>(
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
AccountId::from(ALICE),
Box::new(|runtime_event_encoded: Vec<u8>| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ use frame_system::{
use pallet_asset_conversion_tx_payment::AssetConversionAdapter;
use pallet_nfts::{DestroyWitness, PalletFeatures};
use pallet_xcm::EnsureXcm;
pub use parachains_common as common;
use parachains_common::{
impls::DealWithFees,
message_queue::*,
westend::{consensus::*, currency::*, fee::WeightToFee},
AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, Header, Nonce,
Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT,
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
NORMAL_DISPATCH_RATIO,
};
pub use parachains_common::{westend::consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, SLOT_DURATION};
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use asset_hub_westend_runtime::{
ToRococoXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue,
};
use asset_test_utils::{
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder,
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys,
ExtBuilder, SlotDurations,
};
use codec::{Decode, Encode};
use cumulus_primitives_utility::ChargeWeightInFungibles;
Expand All @@ -41,6 +42,7 @@ use frame_support::{
use parachains_common::{
westend::fee::WeightToFee, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance,
};
use sp_consensus_aura::SlotDuration;
use sp_runtime::traits::MaybeEquivalence;
use std::convert::Into;
use xcm::latest::prelude::*;
Expand All @@ -66,6 +68,15 @@ fn collator_session_keys() -> CollatorSessionKeys<Runtime> {
CollatorSessionKeys::default().add(collator_session_key(ALICE))
}

fn slot_durations() -> SlotDurations {
SlotDurations {
relay: SlotDuration::from_millis(
asset_hub_westend_runtime::RELAY_CHAIN_SLOT_DURATION_MILLIS.into(),
),
para: SlotDuration::from_millis(asset_hub_westend_runtime::SLOT_DURATION),
}
}

#[test]
fn test_asset_xcm_trader() {
ExtBuilder::<Runtime>::default()
Expand Down Expand Up @@ -518,6 +529,7 @@ asset_test_utils::include_teleports_for_native_asset_works!(
WeightToFee,
ParachainSystem,
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Expand All @@ -538,6 +550,7 @@ asset_test_utils::include_teleports_for_foreign_assets_works!(
ForeignCreatorsSovereignAccountOf,
ForeignAssetsInstance,
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Expand Down Expand Up @@ -660,6 +673,7 @@ fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_rococo_works()
LocationToAccountId,
>(
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
AccountId::from(ALICE),
Box::new(|runtime_event_encoded: Vec<u8>| {
Expand Down Expand Up @@ -827,6 +841,7 @@ fn reserve_transfer_native_asset_to_non_teleport_para_works() {
LocationToAccountId,
>(
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
AccountId::from(ALICE),
Box::new(|runtime_event_encoded: Vec<u8>| {
Expand Down
13 changes: 12 additions & 1 deletion cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use frame_system::pallet_prelude::BlockNumberFor;
use parachains_common::{AccountId, Balance};
use parachains_runtimes_test_utils::{
assert_metadata, assert_total, mock_open_hrmp_channel, AccountIdOf, BalanceOf,
CollatorSessionKeys, ExtBuilder, ValidatorIdOf, XcmReceivedFrom,
CollatorSessionKeys, ExtBuilder, SlotDurations, ValidatorIdOf, XcmReceivedFrom,
};
use sp_runtime::{
traits::{MaybeEquivalence, StaticLookup, Zero},
Expand All @@ -57,6 +57,7 @@ pub fn teleports_for_native_asset_works<
HrmpChannelOpener,
>(
collator_session_keys: CollatorSessionKeys<Runtime>,
slot_durations: SlotDurations,
existential_deposit: BalanceOf<Runtime>,
target_account: AccountIdOf<Runtime>,
unwrap_pallet_xcm_event: Box<dyn Fn(Vec<u8>) -> Option<pallet_xcm::Event<Runtime>>>,
Expand Down Expand Up @@ -203,6 +204,7 @@ pub fn teleports_for_native_asset_works<
None,
included_head.clone(),
&alice,
&slot_durations,
));

// check balances
Expand Down Expand Up @@ -254,6 +256,7 @@ pub fn teleports_for_native_asset_works<
Some((runtime_para_id, other_para_id)),
included_head,
&alice,
&slot_durations,
),
Err(DispatchError::Module(sp_runtime::ModuleError {
index: 31,
Expand Down Expand Up @@ -285,6 +288,7 @@ macro_rules! include_teleports_for_native_asset_works(
$weight_to_fee:path,
$hrmp_channel_opener:path,
$collator_session_key:expr,
$slot_durations:expr,
$existential_deposit:expr,
$unwrap_pallet_xcm_event:expr,
$runtime_para_id:expr
Expand All @@ -303,6 +307,7 @@ macro_rules! include_teleports_for_native_asset_works(
$hrmp_channel_opener
>(
$collator_session_key,
$slot_durations,
$existential_deposit,
target_account,
$unwrap_pallet_xcm_event,
Expand All @@ -325,6 +330,7 @@ pub fn teleports_for_foreign_assets_works<
ForeignAssetsPalletInstance,
>(
collator_session_keys: CollatorSessionKeys<Runtime>,
slot_durations: SlotDurations,
target_account: AccountIdOf<Runtime>,
existential_deposit: BalanceOf<Runtime>,
asset_owner: AccountIdOf<Runtime>,
Expand Down Expand Up @@ -582,6 +588,7 @@ pub fn teleports_for_foreign_assets_works<
Some((runtime_para_id, foreign_para_id)),
included_head,
&alice,
&slot_durations,
));

// check balances
Expand Down Expand Up @@ -634,6 +641,7 @@ macro_rules! include_teleports_for_foreign_assets_works(
$sovereign_account_of:path,
$assets_pallet_instance:path,
$collator_session_key:expr,
$slot_durations:expr,
$existential_deposit:expr,
$unwrap_pallet_xcm_event:expr,
$unwrap_xcmp_queue_event:expr
Expand All @@ -656,6 +664,7 @@ macro_rules! include_teleports_for_foreign_assets_works(
$assets_pallet_instance
>(
$collator_session_key,
$slot_durations,
target_account,
$existential_deposit,
asset_owner,
Expand Down Expand Up @@ -1388,6 +1397,7 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
LocationToAccountId,
>(
collator_session_keys: CollatorSessionKeys<Runtime>,
slot_durations: SlotDurations,
existential_deposit: BalanceOf<Runtime>,
alice_account: AccountIdOf<Runtime>,
unwrap_pallet_xcm_event: Box<dyn Fn(Vec<u8>) -> Option<pallet_xcm::Event<Runtime>>>,
Expand Down Expand Up @@ -1461,6 +1471,7 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
other_para_id.into(),
included_head,
&alice,
&slot_durations,
);

// we calculate exact delivery fees _after_ sending the message by weighing the sent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use frame_system::pallet_prelude::BlockNumberFor;
use parachains_common::{AccountId, Balance};
use parachains_runtimes_test_utils::{
mock_open_hrmp_channel, AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, RuntimeHelper,
ValidatorIdOf, XcmReceivedFrom,
SlotDurations, ValidatorIdOf, XcmReceivedFrom,
};
use sp_runtime::{traits::StaticLookup, Saturating};
use xcm::{latest::prelude::*, VersionedMultiAssets};
Expand All @@ -51,6 +51,7 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works<
LocationToAccountId,
>(
collator_session_keys: CollatorSessionKeys<Runtime>,
slot_durations: SlotDurations,
existential_deposit: BalanceOf<Runtime>,
alice_account: AccountIdOf<Runtime>,
unwrap_pallet_xcm_event: Box<dyn Fn(Vec<u8>) -> Option<pallet_xcm::Event<Runtime>>>,
Expand Down Expand Up @@ -124,6 +125,7 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works<
local_bridge_hub_para_id.into(),
included_head,
&alice,
&slot_durations,
);

// we calculate exact delivery fees _after_ sending the message by weighing the sent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ use parachains_common::{
impls::DealWithFees,
rococo::{consensus::*, currency::*, fee::WeightToFee},
AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO,
HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO,
};
pub use parachains_common::{rococo::consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, SLOT_DURATION};

#[cfg(feature = "runtime-benchmarks")]
use crate::xcm_config::benchmark_helpers::DoNothingRouter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ use bridge_hub_rococo_runtime::{
Executive, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall,
RuntimeEvent, RuntimeOrigin, SessionKeys, SignedExtra, TransactionPayment, UncheckedExtrinsic,
};
use bridge_hub_test_utils::SlotDurations;
use codec::{Decode, Encode};
use frame_support::{dispatch::GetDispatchInfo, parameter_types, traits::ConstU8};
use parachains_common::{rococo::fee::WeightToFee, AccountId, AuraId, Balance};
use sp_consensus_aura::SlotDuration;
use sp_core::H160;
use sp_keyring::AccountKeyring::Alice;
use sp_runtime::{
Expand Down Expand Up @@ -95,6 +97,15 @@ fn collator_session_keys() -> bridge_hub_test_utils::CollatorSessionKeys<Runtime
)
}

fn slot_durations() -> SlotDurations {
SlotDurations {
relay: SlotDuration::from_millis(
bridge_hub_rococo_runtime::RELAY_CHAIN_SLOT_DURATION_MILLIS.into(),
),
para: SlotDuration::from_millis(bridge_hub_rococo_runtime::SLOT_DURATION),
}
}

bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!(
Runtime,
AllPalletsWithoutSystem,
Expand All @@ -103,6 +114,7 @@ bridge_hub_test_utils::test_cases::include_teleports_for_native_asset_works!(
WeightToFee,
ParachainSystem,
collator_session_keys(),
slot_durations(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Expand Down Expand Up @@ -264,6 +276,7 @@ mod bridge_hub_westend_tests {
ConstU8<2>,
>(
collator_session_keys(),
slot_durations(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
SIBLING_PARACHAIN_ID,
Box::new(|runtime_event_encoded: Vec<u8>| {
Expand All @@ -288,6 +301,7 @@ mod bridge_hub_westend_tests {
// from Westend
from_parachain::relayed_incoming_message_works::<RuntimeTestsAdapter>(
collator_session_keys(),
slot_durations(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID,
BridgeHubWestendChainId::get(),
Expand All @@ -304,6 +318,7 @@ mod bridge_hub_westend_tests {
// for Westend
from_parachain::complex_relay_extrinsic_works::<RuntimeTestsAdapter>(
collator_session_keys(),
slot_durations(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID,
SIBLING_PARACHAIN_ID,
Expand Down Expand Up @@ -459,6 +474,7 @@ mod bridge_hub_bulletin_tests {
ConstU8<2>,
>(
collator_session_keys(),
slot_durations(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
SIBLING_PARACHAIN_ID,
Box::new(|runtime_event_encoded: Vec<u8>| {
Expand All @@ -483,6 +499,7 @@ mod bridge_hub_bulletin_tests {
// from Bulletin
from_grandpa_chain::relayed_incoming_message_works::<RuntimeTestsAdapter>(
collator_session_keys(),
slot_durations(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
RococoBulletinChainId::get(),
SIBLING_PARACHAIN_ID,
Expand All @@ -498,6 +515,7 @@ mod bridge_hub_bulletin_tests {
// for Bulletin
from_grandpa_chain::complex_relay_extrinsic_works::<RuntimeTestsAdapter>(
collator_session_keys(),
slot_durations(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
SIBLING_PARACHAIN_ID,
RococoBulletinChainId::get(),
Expand Down
Loading