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
Prev Previous commit
Next Next commit
Fix: xcm_simulator tests
  • Loading branch information
Anny0nn committed Apr 2, 2024
commit f2d8dc2032ecbaa756eff7dcf2d2d7ea3df34f8c
23 changes: 12 additions & 11 deletions tinkernet/runtime/src/xcm_simulator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod parachain;
mod relay_chain;

use frame_support::sp_tracing;
use frame_support::__private::sp_tracing;
use sp_runtime::{traits::TryConvert, BuildStorage};
use xcm::prelude::*;
use xcm_executor::traits::Convert;
use xcm_executor::traits::ConvertLocation;
use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt};

pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]);
Expand Down Expand Up @@ -56,7 +57,7 @@ decl_test_network! {

pub fn child_account_id(para: u32) -> relay_chain::AccountId {
let location = (Parachain(para),);
relay_chain::LocationToAccountId::convert(location.into()).unwrap()
relay_chain::LocationToAccountId::convert_location(&MultiLocation::from(location)).unwrap()
}

pub fn child_account_account_id(para: u32, who: sp_runtime::AccountId32) -> relay_chain::AccountId {
Expand All @@ -67,7 +68,7 @@ pub fn child_account_account_id(para: u32, who: sp_runtime::AccountId32) -> rela
id: who.into(),
},
);
relay_chain::LocationToAccountId::convert(location.into()).unwrap()
relay_chain::LocationToAccountId::convert_location(&MultiLocation::from(location)).unwrap()
}

pub fn sibling_core_account_id(core: u32) -> parachain::AccountId {
Expand All @@ -82,14 +83,14 @@ pub fn sibling_core_account_id(core: u32) -> parachain::AccountId {
),
};

parachain::HashedDescription::convert(location.into()).unwrap()
parachain::HashedDescription::try_convert(location.into()).unwrap()
}

pub fn tinkernet_ext(para_id: u32) -> sp_io::TestExternalities {
use crate::{PolkadotXcm, Runtime, RuntimeOrigin, System};

let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
Expand Down Expand Up @@ -119,8 +120,8 @@ pub fn tinkernet_ext(para_id: u32) -> sp_io::TestExternalities {
pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {
use parachain::{MsgQueue, PolkadotXcm, Runtime, RuntimeOrigin, System};

let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
Expand All @@ -141,8 +142,8 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {
pub fn relay_ext() -> sp_io::TestExternalities {
use relay_chain::{Runtime, RuntimeOrigin, System};

let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
Expand Down
31 changes: 21 additions & 10 deletions tinkernet/runtime/src/xcm_simulator/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ use polkadot_parachain::primitives::{
use scale_info::TypeInfo;
use sp_core::{blake2_256, ConstU32, H256};
use sp_runtime::{
testing::Header,
traits::{Hash, IdentityLookup},
traits::{Hash, IdentityLookup, TryConvert},
AccountId32,
};
use sp_std::prelude::*;
use xcm::{latest::prelude::*, VersionedXcm};
use xcm_builder::{
Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom,
CurrencyAdapter as XcmCurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds,
IsConcrete, NativeAsset, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation,
AccountId32Aliases, AllowUnpaidExecutionFrom, EnsureXcmOrigin, FixedRateOfFungible,
FixedWeightBounds, FungibleAdapter as XcmCurrencyAdapter, IsConcrete, NativeAsset,
ParentAsSuperuser, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation,
};
use xcm_executor::{traits::Convert, Config, XcmExecutor};
use xcm_executor::{traits::ConvertLocation, Config, XcmExecutor};
use xcm_simulator::PhantomData;

pub type SovereignAccountOf = (
Expand Down Expand Up @@ -142,8 +140,8 @@ impl<Suffix: DescribeLocation> DescribeLocation for DescribeFamily<Suffix> {
}

pub struct HashedDescription;
impl Convert<MultiLocation, AccountId> for HashedDescription {
fn convert(value: MultiLocation) -> Result<AccountId, MultiLocation> {
impl TryConvert<MultiLocation, AccountId> for HashedDescription {
fn try_convert(value: MultiLocation) -> Result<AccountId, MultiLocation> {
log::trace!(target: "xcm::HashedDescription", "HashedDescription: location: {:?}", value);
if let Some(l) = DescribeFamily::<DescribeBodyTerminal>::describe_location(&value) {
let a: AccountId = blake2_256(&l).into();
Expand All @@ -156,6 +154,19 @@ impl Convert<MultiLocation, AccountId> for HashedDescription {
}
}

impl ConvertLocation<AccountId> for HashedDescription {
fn convert_location(location: &MultiLocation) -> Option<AccountId> {
if let Some(l) = DescribeFamily::<DescribeBodyTerminal>::describe_location(&location) {
let a: AccountId = blake2_256(&l).into();
log::trace!(target: "xcm::HashedDescription", "HashedDescription Some: location: {:?} account: {:?}", location, a);
Some(a)
} else {
log::trace!(target: "xcm::HashedDescription", "HashedDescription None");
None
}
}
}

pub type LocationToAccountId = (
ParentIsPreset<AccountId>,
SiblingParachainConvertsVia<Sibling, AccountId>,
Expand Down
8 changes: 4 additions & 4 deletions tinkernet/runtime/src/xcm_simulator/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use polkadot_runtime_parachains::{
use xcm::latest::prelude::*;
use xcm_builder::{
Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative,
ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, FixedWeightBounds, IsConcrete,
ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, FixedRateOfFungible,
FixedWeightBounds, FungibleAdapter as XcmCurrencyAdapter, IsConcrete,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
};
use xcm_executor::{Config, XcmExecutor};
Expand Down Expand Up @@ -76,8 +76,8 @@ impl pallet_balances::Config for Runtime {
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
type RuntimeHoldReason = [u8; 8];
type RuntimeFreezeReason = [u8; 8];
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
}

impl shared::Config for Runtime {}
Expand Down