BridgeHub[Rococo/Wococo] test batched relaying of messages and their dispatch (#2578)

Added some tests that aim to cover the runtime configuration
that is exercised when BH receives relayed complex message.

* checks correct importing of proofs for:
  bridged chain finality, bridged para heads, bridged messages,
* checks relayer extension correctly configured to reward
  submitting relayer,
* checks relayed message is successfully dispatched.

Also moved generic test-utils from
  `asset-test-utils: parachains/runtimes/assets/test-utils`
one level up to new crate
  `parachains-runtimes-test-utils: parachains/runtimes/test-utils`
to be reused by BridgeHubs.

Signed-off-by: acatangiu <adrian@parity.io>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
This commit is contained in:
Adrian Catangiu
2023-05-18 18:10:36 +03:00
committed by GitHub
parent 93cf3908e0
commit 4e4799927a
21 changed files with 1723 additions and 980 deletions
@@ -1,4 +1,4 @@
use asset_test_utils::{ExtBuilder, RuntimeHelper};
use asset_test_utils::{CollatorSessionKeys, ExtBuilder, RuntimeHelper};
use codec::{Decode, Encode};
use cumulus_primitives_utility::ChargeWeightInFungibles;
use frame_support::{
@@ -26,6 +26,14 @@ const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
type AssetIdForTrustBackedAssetsConvert =
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
fn collator_session_keys() -> CollatorSessionKeys<Runtime> {
CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
)
}
#[test]
fn test_asset_xcm_trader() {
ExtBuilder::<Runtime>::default()
@@ -472,11 +480,7 @@ asset_test_utils::include_teleports_for_native_asset_works!(
CheckingAccount,
WeightToFee,
ParachainSystem,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
@@ -501,11 +505,7 @@ asset_test_utils::include_teleports_for_foreign_assets_works!(
ParachainSystem,
ForeignCreatorsSovereignAccountOf,
ForeignAssetsInstance,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
@@ -524,11 +524,7 @@ asset_test_utils::include_teleports_for_foreign_assets_works!(
asset_test_utils::include_asset_transactor_transfer_with_local_consensus_currency_works!(
Runtime,
XcmConfig,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
Box::new(|| {
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
@@ -547,11 +543,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
TrustBackedAssetsInstance,
AssetIdForTrustBackedAssets,
AssetIdForTrustBackedAssetsConvert,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
12345,
Box::new(|| {
@@ -569,11 +561,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
ForeignAssetsInstance,
MultiLocation,
JustTry,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
MultiLocation { parents: 1, interior: X2(Parachain(1313), GeneralIndex(12345)) },
Box::new(|| {
@@ -592,11 +580,7 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
ForeignAssetsInstance,
MultiLocation,
JustTry,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
AssetDeposit::get(),
MetadataDepositBase::get(),
@@ -1,4 +1,4 @@
use asset_test_utils::{ExtBuilder, RuntimeHelper};
use asset_test_utils::{CollatorSessionKeys, ExtBuilder, RuntimeHelper};
use codec::Decode;
use cumulus_primitives_utility::ChargeWeightInFungibles;
use frame_support::{
@@ -26,6 +26,14 @@ const ALICE: [u8; 32] = [1u8; 32];
type AssetIdForTrustBackedAssetsConvert =
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
fn collator_session_keys() -> CollatorSessionKeys<Runtime> {
CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) },
)
}
#[test]
fn test_asset_xcm_trader() {
ExtBuilder::<Runtime>::default()
@@ -450,11 +458,7 @@ asset_test_utils::include_teleports_for_native_asset_works!(
CheckingAccount,
WeightToFee,
ParachainSystem,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
@@ -474,11 +478,7 @@ asset_test_utils::include_teleports_for_native_asset_works!(
asset_test_utils::include_asset_transactor_transfer_with_local_consensus_currency_works!(
Runtime,
XcmConfig,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
Box::new(|| {
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
@@ -495,11 +495,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
TrustBackedAssetsInstance,
AssetIdForTrustBackedAssets,
AssetIdForTrustBackedAssetsConvert,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
12345,
Box::new(|| {}),
@@ -31,6 +31,7 @@ cumulus-primitives-core = { path = "../../../../primitives/core", default-featur
cumulus-primitives-parachain-inherent = { path = "../../../../primitives/parachain-inherent", default-features = false }
cumulus-test-relay-sproof-builder = { path = "../../../../test/relay-sproof-builder", default-features = false }
parachain-info = { path = "../../../../parachains/pallets/parachain-info", default-features = false }
parachains-runtimes-test-utils = { path = "../../test-utils", default-features = false }
# Polkadot
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
@@ -61,6 +62,7 @@ std = [
"assets-common/std",
"parachains-common/std",
"parachain-info/std",
"parachains-runtimes-test-utils/std",
"polkadot-parachain/std",
"sp-consensus-aura/std",
"sp-io/std",
@@ -1,411 +1,20 @@
use sp_std::marker::PhantomData;
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
use cumulus_primitives_core::{AbridgedHrmpChannel, ParaId, PersistedValidationData};
use cumulus_primitives_parachain_inherent::ParachainInherentData;
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use frame_support::{
dispatch::{DispatchResult, RawOrigin, UnfilteredDispatchable},
inherent::{InherentData, ProvideInherent},
traits::{GenesisBuild, OriginTrait},
weights::Weight,
};
use parachains_common::AccountId;
use polkadot_parachain::primitives::{HrmpChannelId, RelayChainBlockNumber};
use sp_consensus_aura::AURA_ENGINE_ID;
use sp_core::Encode;
use sp_runtime::{Digest, DigestItem};
use xcm::{
latest::{MultiAsset, MultiLocation, XcmContext, XcmHash},
prelude::*,
};
use xcm_executor::{traits::TransactAsset, Assets};
// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
//! Module contains predefined test-case scenarios for `Runtime` with various assets.
pub mod test_cases;
pub use test_cases::CollatorSessionKeys;
pub type BalanceOf<Runtime> = <Runtime as pallet_balances::Config>::Balance;
pub type AccountIdOf<Runtime> = <Runtime as frame_system::Config>::AccountId;
pub type ValidatorIdOf<Runtime> = <Runtime as pallet_session::Config>::ValidatorId;
pub type SessionKeysOf<Runtime> = <Runtime as pallet_session::Config>::Keys;
// Basic builder based on balances, collators and pallet_sessopm
pub struct ExtBuilder<
Runtime: frame_system::Config
+ pallet_balances::Config
+ pallet_session::Config
+ pallet_xcm::Config
+ parachain_info::Config,
> {
// endowed accounts with balances
balances: Vec<(AccountIdOf<Runtime>, BalanceOf<Runtime>)>,
// collators to test block prod
collators: Vec<AccountIdOf<Runtime>>,
// keys added to pallet session
keys: Vec<(AccountIdOf<Runtime>, ValidatorIdOf<Runtime>, SessionKeysOf<Runtime>)>,
// safe xcm version for pallet_xcm
safe_xcm_version: Option<XcmVersion>,
// para id
para_id: Option<ParaId>,
_runtime: PhantomData<Runtime>,
}
impl<
Runtime: frame_system::Config
+ pallet_balances::Config
+ pallet_session::Config
+ pallet_xcm::Config
+ parachain_info::Config,
> Default for ExtBuilder<Runtime>
{
fn default() -> ExtBuilder<Runtime> {
ExtBuilder {
balances: vec![],
collators: vec![],
keys: vec![],
safe_xcm_version: None,
para_id: None,
_runtime: PhantomData,
}
}
}
impl<
Runtime: frame_system::Config
+ pallet_balances::Config
+ pallet_session::Config
+ pallet_xcm::Config
+ parachain_info::Config,
> ExtBuilder<Runtime>
{
pub fn with_balances(
mut self,
balances: Vec<(AccountIdOf<Runtime>, BalanceOf<Runtime>)>,
) -> Self {
self.balances = balances;
self
}
pub fn with_collators(mut self, collators: Vec<AccountIdOf<Runtime>>) -> Self {
self.collators = collators;
self
}
pub fn with_session_keys(
mut self,
keys: Vec<(AccountIdOf<Runtime>, ValidatorIdOf<Runtime>, SessionKeysOf<Runtime>)>,
) -> Self {
self.keys = keys;
self
}
pub fn with_tracing(self) -> Self {
frame_support::sp_tracing::try_init_simple();
self
}
pub fn with_safe_xcm_version(mut self, safe_xcm_version: XcmVersion) -> Self {
self.safe_xcm_version = Some(safe_xcm_version);
self
}
pub fn with_para_id(mut self, para_id: ParaId) -> Self {
self.para_id = Some(para_id);
self
}
pub fn build(self) -> sp_io::TestExternalities
where
Runtime:
pallet_collator_selection::Config + pallet_balances::Config + pallet_session::Config,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
{
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
<pallet_xcm::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
&pallet_xcm::GenesisConfig { safe_xcm_version: self.safe_xcm_version },
&mut t,
)
.unwrap();
if let Some(para_id) = self.para_id {
<parachain_info::GenesisConfig as frame_support::traits::GenesisBuild<Runtime>>::assimilate_storage(
&parachain_info::GenesisConfig { parachain_id: para_id },
&mut t,
)
.unwrap();
}
pallet_balances::GenesisConfig::<Runtime> { balances: self.balances }
.assimilate_storage(&mut t)
.unwrap();
pallet_collator_selection::GenesisConfig::<Runtime> {
invulnerables: self.collators.clone(),
candidacy_bond: Default::default(),
desired_candidates: Default::default(),
}
.assimilate_storage(&mut t)
.unwrap();
pallet_session::GenesisConfig::<Runtime> { keys: self.keys }
.assimilate_storage(&mut t)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
frame_system::Pallet::<Runtime>::set_block_number(1u32.into());
});
ext
}
}
pub struct RuntimeHelper<Runtime>(PhantomData<Runtime>);
/// Utility function that advances the chain to the desired block number.
/// If an author is provided, that author information is injected to all the blocks in the meantime.
impl<Runtime: frame_system::Config> RuntimeHelper<Runtime>
where
AccountIdOf<Runtime>:
Into<<<Runtime as frame_system::Config>::RuntimeOrigin as OriginTrait>::AccountId>,
{
pub fn run_to_block(n: u32, author: Option<AccountId>) {
while frame_system::Pallet::<Runtime>::block_number() < n.into() {
// Set the new block number and author
match author {
Some(ref author) => {
let pre_digest = Digest {
logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, author.encode())],
};
frame_system::Pallet::<Runtime>::reset_events();
frame_system::Pallet::<Runtime>::initialize(
&(frame_system::Pallet::<Runtime>::block_number() + 1u32.into()),
&frame_system::Pallet::<Runtime>::parent_hash(),
&pre_digest,
);
},
None => {
frame_system::Pallet::<Runtime>::set_block_number(
frame_system::Pallet::<Runtime>::block_number() + 1u32.into(),
);
},
}
}
}
pub fn root_origin() -> <Runtime as frame_system::Config>::RuntimeOrigin {
<Runtime as frame_system::Config>::RuntimeOrigin::root()
}
pub fn origin_of(
account_id: AccountIdOf<Runtime>,
) -> <Runtime as frame_system::Config>::RuntimeOrigin {
<Runtime as frame_system::Config>::RuntimeOrigin::signed(account_id.into())
}
}
impl<XcmConfig: xcm_executor::Config> RuntimeHelper<XcmConfig> {
pub fn do_transfer(
from: MultiLocation,
to: MultiLocation,
(asset, amount): (MultiLocation, u128),
) -> Result<Assets, XcmError> {
<XcmConfig::AssetTransactor as TransactAsset>::transfer_asset(
&MultiAsset { id: Concrete(asset), fun: Fungible(amount) },
&from,
&to,
// We aren't able to track the XCM that initiated the fee deposit, so we create a
// fake message hash here
&XcmContext::with_message_hash([0; 32]),
)
}
}
impl<Runtime: pallet_xcm::Config + cumulus_pallet_parachain_system::Config> RuntimeHelper<Runtime> {
pub fn do_teleport_assets<HrmpChannelOpener>(
origin: <Runtime as frame_system::Config>::RuntimeOrigin,
dest: MultiLocation,
beneficiary: MultiLocation,
(asset, amount): (MultiLocation, u128),
open_hrmp_channel: Option<(u32, u32)>,
) -> DispatchResult
where
HrmpChannelOpener: frame_support::inherent::ProvideInherent<
Call = cumulus_pallet_parachain_system::Call<Runtime>,
>,
{
// open hrmp (if needed)
if let Some((source_para_id, target_para_id)) = open_hrmp_channel {
mock_open_hrmp_channel::<Runtime, HrmpChannelOpener>(
source_para_id.into(),
target_para_id.into(),
);
}
// do teleport
<pallet_xcm::Pallet<Runtime>>::teleport_assets(
origin,
Box::new(dest.into()),
Box::new(beneficiary.into()),
Box::new((Concrete(asset), amount).into()),
0,
)
}
}
impl<Runtime: cumulus_pallet_dmp_queue::Config + cumulus_pallet_parachain_system::Config>
RuntimeHelper<Runtime>
{
pub fn execute_as_governance(call: Vec<u8>, require_weight_at_most: Weight) -> Outcome {
// prepare xcm as governance will do
let xcm = Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind: OriginKind::Superuser,
require_weight_at_most,
call: call.into(),
},
]);
// execute xcm as parent origin
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
<<Runtime as cumulus_pallet_dmp_queue::Config>::XcmExecutor>::execute_xcm(
MultiLocation::parent(),
xcm,
hash,
Self::xcm_max_weight(XcmReceivedFrom::Parent),
)
}
}
pub enum XcmReceivedFrom {
Parent,
Sibling,
}
impl<ParachainSystem: cumulus_pallet_parachain_system::Config> RuntimeHelper<ParachainSystem> {
pub fn xcm_max_weight(from: XcmReceivedFrom) -> Weight {
use frame_support::traits::Get;
match from {
XcmReceivedFrom::Parent => ParachainSystem::ReservedDmpWeight::get(),
XcmReceivedFrom::Sibling => ParachainSystem::ReservedXcmpWeight::get(),
}
}
}
impl<Runtime: frame_system::Config + pallet_xcm::Config> RuntimeHelper<Runtime> {
pub fn assert_pallet_xcm_event_outcome(
unwrap_pallet_xcm_event: &Box<dyn Fn(Vec<u8>) -> Option<pallet_xcm::Event<Runtime>>>,
assert_outcome: fn(Outcome),
) {
let outcome = <frame_system::Pallet<Runtime>>::events()
.into_iter()
.filter_map(|e| unwrap_pallet_xcm_event(e.event.encode()))
.find_map(|e| match e {
pallet_xcm::Event::Attempted(outcome) => Some(outcome),
_ => None,
})
.expect("No `pallet_xcm::Event::Attempted(outcome)` event found!");
assert_outcome(outcome);
}
}
impl<Runtime: frame_system::Config + cumulus_pallet_xcmp_queue::Config> RuntimeHelper<Runtime> {
pub fn xcmp_queue_message_sent(
unwrap_xcmp_queue_event: Box<
dyn Fn(Vec<u8>) -> Option<cumulus_pallet_xcmp_queue::Event<Runtime>>,
>,
) -> Option<XcmHash> {
<frame_system::Pallet<Runtime>>::events()
.into_iter()
.filter_map(|e| unwrap_xcmp_queue_event(e.event.encode()))
.find_map(|e| match e {
cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { message_hash } => message_hash,
_ => None,
})
}
}
pub fn assert_metadata<Fungibles, AccountId>(
asset_id: impl Into<Fungibles::AssetId> + Copy,
expected_name: &str,
expected_symbol: &str,
expected_decimals: u8,
) where
Fungibles: frame_support::traits::tokens::fungibles::metadata::Inspect<AccountId>
+ frame_support::traits::tokens::fungibles::Inspect<AccountId>,
{
assert_eq!(Fungibles::name(asset_id.into()), Vec::from(expected_name),);
assert_eq!(Fungibles::symbol(asset_id.into()), Vec::from(expected_symbol),);
assert_eq!(Fungibles::decimals(asset_id.into()), expected_decimals);
}
pub fn assert_total<Fungibles, AccountId>(
asset_id: impl Into<Fungibles::AssetId> + Copy,
expected_total_issuance: impl Into<Fungibles::Balance>,
expected_active_issuance: impl Into<Fungibles::Balance>,
) where
Fungibles: frame_support::traits::tokens::fungibles::metadata::Inspect<AccountId>
+ frame_support::traits::tokens::fungibles::Inspect<AccountId>,
{
assert_eq!(Fungibles::total_issuance(asset_id.into()), expected_total_issuance.into());
assert_eq!(Fungibles::active_issuance(asset_id.into()), expected_active_issuance.into());
}
/// Helper function which emulates opening HRMP channel which is needed for `XcmpQueue` to pass
pub fn mock_open_hrmp_channel<
C: cumulus_pallet_parachain_system::Config,
T: ProvideInherent<Call = cumulus_pallet_parachain_system::Call<C>>,
>(
sender: ParaId,
recipient: ParaId,
) {
let n = 1_u32;
let mut sproof_builder = RelayStateSproofBuilder {
para_id: sender,
hrmp_egress_channel_index: Some(vec![recipient]),
..Default::default()
};
sproof_builder.hrmp_channels.insert(
HrmpChannelId { sender, recipient },
AbridgedHrmpChannel {
max_capacity: 10,
max_total_size: 10_000_000_u32,
max_message_size: 10_000_000_u32,
msg_count: 0,
total_size: 0_u32,
mqc_head: None,
},
);
let (relay_parent_storage_root, relay_chain_state) = sproof_builder.into_state_root_and_proof();
let vfp = PersistedValidationData {
relay_parent_number: n as RelayChainBlockNumber,
relay_parent_storage_root,
..Default::default()
};
// It is insufficient to push the validation function params
// to storage; they must also be included in the inherent data.
let inherent_data = {
let mut inherent_data = InherentData::default();
let system_inherent_data = ParachainInherentData {
validation_data: vfp,
relay_chain_state,
downward_messages: Default::default(),
horizontal_messages: Default::default(),
};
inherent_data
.put_data(
cumulus_primitives_parachain_inherent::INHERENT_IDENTIFIER,
&system_inherent_data,
)
.expect("failed to put VFP inherent");
inherent_data
};
// execute the block
T::create_inherent(&inherent_data)
.expect("got an inherent")
.dispatch_bypass_filter(RawOrigin::None.into())
.expect("dispatch succeeded");
}
pub use parachains_runtimes_test_utils::*;
@@ -15,10 +15,6 @@
//! Module contains predefined test-case scenarios for `Runtime` with various assets.
use crate::{
assert_metadata, assert_total, AccountIdOf, BalanceOf, ExtBuilder, RuntimeHelper,
SessionKeysOf, ValidatorIdOf, XcmReceivedFrom,
};
use codec::Encode;
use frame_support::{
assert_noop, assert_ok,
@@ -26,6 +22,10 @@ use frame_support::{
weights::Weight,
};
use parachains_common::Balance;
use parachains_runtimes_test_utils::{
assert_metadata, assert_total, AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder,
RuntimeHelper, ValidatorIdOf, XcmReceivedFrom,
};
use sp_runtime::{
traits::{StaticLookup, Zero},
DispatchError, Saturating,
@@ -33,35 +33,6 @@ use sp_runtime::{
use xcm::latest::prelude::*;
use xcm_executor::{traits::Convert, XcmExecutor};
pub struct CollatorSessionKeys<
Runtime: frame_system::Config + pallet_balances::Config + pallet_session::Config,
> {
collator: AccountIdOf<Runtime>,
validator: ValidatorIdOf<Runtime>,
key: SessionKeysOf<Runtime>,
}
impl<Runtime: frame_system::Config + pallet_balances::Config + pallet_session::Config>
CollatorSessionKeys<Runtime>
{
pub fn new(
collator: AccountIdOf<Runtime>,
validator: ValidatorIdOf<Runtime>,
key: SessionKeysOf<Runtime>,
) -> Self {
Self { collator, validator, key }
}
pub fn collators(&self) -> Vec<AccountIdOf<Runtime>> {
vec![self.collator.clone()]
}
pub fn session_keys(
&self,
) -> Vec<(AccountIdOf<Runtime>, ValidatorIdOf<Runtime>, SessionKeysOf<Runtime>)> {
vec![(self.collator.clone(), self.validator.clone(), self.key.clone())]
}
}
/// Test-case makes sure that `Runtime` can receive native asset from relay chain
/// and can teleport it back and to the other parachains
pub fn teleports_for_native_asset_works<
@@ -1,4 +1,4 @@
use asset_test_utils::{ExtBuilder, RuntimeHelper, XcmReceivedFrom};
use asset_test_utils::{CollatorSessionKeys, ExtBuilder, RuntimeHelper, XcmReceivedFrom};
use codec::{Decode, DecodeLimit, Encode};
use cumulus_primitives_utility::ChargeWeightInFungibles;
use frame_support::{
@@ -33,6 +33,14 @@ const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
type AssetIdForTrustBackedAssetsConvert =
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
fn collator_session_keys() -> CollatorSessionKeys<Runtime> {
CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
)
}
#[test]
fn test_asset_xcm_trader() {
ExtBuilder::<Runtime>::default()
@@ -477,11 +485,7 @@ asset_test_utils::include_teleports_for_native_asset_works!(
CheckingAccount,
WeightToFee,
ParachainSystem,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
@@ -506,11 +510,7 @@ asset_test_utils::include_teleports_for_foreign_assets_works!(
ParachainSystem,
ForeignCreatorsSovereignAccountOf,
ForeignAssetsInstance,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
Box::new(|runtime_event_encoded: Vec<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
@@ -529,11 +529,7 @@ asset_test_utils::include_teleports_for_foreign_assets_works!(
asset_test_utils::include_asset_transactor_transfer_with_local_consensus_currency_works!(
Runtime,
XcmConfig,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
Box::new(|| {
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
@@ -552,11 +548,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
TrustBackedAssetsInstance,
AssetIdForTrustBackedAssets,
AssetIdForTrustBackedAssetsConvert,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
12345,
Box::new(|| {
@@ -574,11 +566,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
ForeignAssetsInstance,
MultiLocation,
JustTry,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
MultiLocation { parents: 1, interior: X2(Parachain(1313), GeneralIndex(12345)) },
Box::new(|| {
@@ -597,11 +585,7 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
ForeignAssetsInstance,
MultiLocation,
JustTry,
asset_test_utils::CollatorSessionKeys::new(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }
),
collator_session_keys(),
ExistentialDeposit::get(),
AssetDeposit::get(),
MetadataDepositBase::get(),