From 3fa6ec1044f59a62101be075e63e860f560328bc Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Wed, 22 Oct 2025 11:30:03 +0800 Subject: [PATCH 1/2] remove MigrationPhase --- Cargo.dev.toml | 1 + xtokens/Cargo.toml | 1 + xtokens/README.md | 2 +- xtokens/src/lib.rs | 124 ++++------- xtokens/src/mock/asset_hub.rs | 189 ++++++++++++++++ xtokens/src/mock/mod.rs | 40 +++- xtokens/src/mock/para.rs | 21 +- xtokens/src/mock/para_relative_view.rs | 17 +- xtokens/src/mock/para_teleport.rs | 17 +- xtokens/src/mock/relay.rs | 10 +- xtokens/src/tests.rs | 293 ++++++++++--------------- 11 files changed, 434 insertions(+), 281 deletions(-) create mode 100644 xtokens/src/mock/asset_hub.rs diff --git a/Cargo.dev.toml b/Cargo.dev.toml index 13a411d59..8c6d93fd7 100644 --- a/Cargo.dev.toml +++ b/Cargo.dev.toml @@ -41,6 +41,7 @@ cumulus-primitives-core = { version = "0.19.0", default-features = false } frame-benchmarking = { version = "41.0.0", default-features = false } frame-support = { version = "41.0.0", default-features = false } frame-system = { version = "41.0.0", default-features = false } +parachains-common = { version = "22.0.0", default-features = false } pallet-balances = { version = "42.0.0", default-features = false } pallet-elections-phragmen = { version = "42.0.0", default-features = false } pallet-message-queue = { version = "44.0.0", default-features = false } diff --git a/xtokens/Cargo.toml b/xtokens/Cargo.toml index 58ed7711d..b88683721 100644 --- a/xtokens/Cargo.toml +++ b/xtokens/Cargo.toml @@ -38,6 +38,7 @@ pallet-message-queue = { workspace = true, features = ["std"] } # cumulus cumulus-pallet-xcm = { workspace = true, features = ["std"] } cumulus-primitives-core = { workspace = true, features = ["std"] } +parachains-common = { workspace = true, features = ["std"] } # polkadot polkadot-parachain-primitives = { workspace = true, features = ["std"] } diff --git a/xtokens/README.md b/xtokens/README.md index f6ff491f8..fc083a338 100644 --- a/xtokens/README.md +++ b/xtokens/README.md @@ -54,7 +54,7 @@ parameter_type_with_key! { pub MinXcmReserveFee: |location: Location| -> Option { #[allow(clippy::match_ref_pats)] // false positive match (location.parents, location.first_interior()) { - (1, Some(Parachain(parachains::statemine::ID))) => Some(4_000_000_000), + (1, Some(Parachain(parachains::assethub::ID))) => Some(4_000_000_000), _ => None, } }; diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index 5c1eafb60..dd23f95dd 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -71,19 +71,6 @@ enum TransferKind { } use TransferKind::*; -#[derive( - scale_info::TypeInfo, Default, Encode, Decode, Clone, Eq, PartialEq, Debug, MaxEncodedLen, DecodeWithMemTracking, -)] -pub enum MigrationPhase { - /// Not started - #[default] - NotStarted, - /// Started - InProgress, - /// Completed - Completed, -} - #[frame_support::pallet] pub mod module { use super::*; @@ -148,14 +135,8 @@ pub mod module { /// The id of the RateLimiter. #[pallet::constant] type RateLimiterId: Get<::RateLimiterId>; - - /// The origin that can change the migration phase. - type MigrationPhaseUpdateOrigin: EnsureOrigin; } - #[pallet::storage] - pub type MigrationStatus = StorageValue<_, MigrationPhase, ValueQuery>; - #[pallet::event] #[pallet::generate_deposit(fn deposit_event)] pub enum Event { @@ -166,8 +147,6 @@ pub mod module { fee: Asset, dest: Location, }, - /// Migration phase changed. - MigrationPhaseChanged { migration_phase: MigrationPhase }, } #[pallet::error] @@ -416,17 +395,9 @@ pub mod module { Self::do_transfer_assets(who, assets.clone(), fee.clone(), dest, dest_weight_limit).map(|_| ()) } - #[pallet::call_index(6)] - #[pallet::weight(frame_support::weights::Weight::from_parts(10000, 0))] - pub fn set_migration_phase(origin: OriginFor, migration_phase: MigrationPhase) -> DispatchResult { - T::MigrationPhaseUpdateOrigin::ensure_origin(origin)?; - - MigrationStatus::::set(migration_phase.clone()); - - Self::deposit_event(Event::::MigrationPhaseChanged { migration_phase }); - - Ok(()) - } + // #[pallet::call_index(6)] + // pub fn set_migration_phase(origin: OriginFor, migration_phase: + // MigrationPhase) -> DispatchResult {} } impl Pallet { @@ -598,7 +569,7 @@ pub mod module { if asset_len > 1 && fee_reserve != non_fee_reserve { // Current only support `ToReserve` with relay-chain asset as fee. other case // like `NonReserve` or `SelfReserve` with relay-chain fee is not support. - ensure!(non_fee_reserve == Self::chain_part(&dest), Error::::InvalidAsset); + ensure!(non_fee_reserve == chain_part(&dest), Error::::InvalidAsset); let reserve_location = non_fee_reserve.clone().ok_or(Error::::AssetHasNoReserve)?; let min_xcm_fee = T::MinXcmFee::get(&reserve_location).ok_or(Error::::MinXcmFeeNotDefined)?; @@ -623,7 +594,7 @@ pub mod module { let mut override_recipient = T::SelfLocation::get(); if override_recipient == Location::here() { - let dest_chain_part = Self::chain_part(&dest).ok_or(Error::::InvalidDest)?; + let dest_chain_part = chain_part(&dest).ok_or(Error::::InvalidDest)?; let ancestry = T::UniversalLocation::get(); let _ = override_recipient .reanchor(&dest_chain_part, &ancestry) @@ -633,7 +604,7 @@ pub mod module { // First xcm sent to fee reserve chain and routed to dest chain. // We can use `MinXcmFee` configuration to decide which target parachain use // teleport. But as current there's only one case which is Parachain send back - // asset to Statemine/t, So we set `use_teleport` to always `true` in this case. + // asset to AssetHub, So we set `use_teleport` to always `true` in this case. Self::execute_and_send_reserve_kind_xcm( origin_location.clone(), assets_to_fee_reserve, @@ -717,10 +688,12 @@ pub mod module { let mut hash = msg.using_encoded(sp_io::hashing::blake2_256); let weight = T::Weigher::weight(&mut msg, Weight::MAX).map_err(|_| Error::::UnweighableMessage)?; - T::XcmExecutor::prepare_and_execute(origin_location, msg, &mut hash, weight, weight) + T::XcmExecutor::prepare_and_execute(origin_location.clone(), msg.clone(), &mut hash, weight, weight) .ensure_complete() .map_err(|error| { - log::error!("Failed execute transfer message with {error:?}"); + log::error!( + "Failed execute transfer message with {error:?}, origin: {origin_location:?}, msg: {msg:?}" + ); Error::::XcmExecutionFailed })?; @@ -850,7 +823,7 @@ pub mod module { /// Ensure has the `dest` has chain part and recipient part. fn ensure_valid_dest(dest: &Location) -> Result<(Location, Location), DispatchError> { - if let (Some(dest), Some(recipient)) = (Self::chain_part(dest), Self::non_chain_part(dest)) { + if let (Some(dest), Some(recipient)) = (chain_part(dest), non_chain_part(dest)) { Ok((dest, recipient)) } else { Err(Error::::InvalidDest.into()) @@ -896,41 +869,6 @@ pub mod module { let asset = assets.get(reserve_idx); asset.and_then(T::ReserveProvider::reserve) } - - /// Returns the "chain" location part. It could be parent, sibling - /// parachain, or child parachain. - pub fn chain_part(location: &Location) -> Option { - match (location.parents, location.first_interior()) { - // sibling parachain - (1, Some(Parachain(id))) => Some(Location::new(1, [Parachain(*id)])), - // parent - (1, _) => match MigrationStatus::::get() { - // RelayChain - MigrationPhase::NotStarted => Some(Location::parent()), - // Disable transfer when migration is in progress - MigrationPhase::InProgress => None, - // AssetHub - MigrationPhase::Completed => Some(Location::new(1, [Parachain(ASSET_HUB_ID)])), - }, - // children parachain - (0, Some(Parachain(id))) => Some(Location::new(0, [Parachain(*id)])), - _ => None, - } - } - - /// Returns "non-chain" location part. - pub fn non_chain_part(location: &Location) -> Option { - let mut junctions = location.interior().clone(); - while is_chain_junction(junctions.first()) { - let _ = junctions.take_first(); - } - - if junctions != Here { - Some(Location::new(0, junctions)) - } else { - None - } - } } pub struct XtokensWeight(PhantomData); @@ -1140,26 +1078,54 @@ fn is_chain_junction(junction: Option<&Junction>) -> bool { } // Provide reserve in absolute path view -pub struct AbsoluteReserveProviderMigrationPhase(PhantomData); +pub struct AbsoluteReserveProvider; -impl Reserve for AbsoluteReserveProviderMigrationPhase { +impl Reserve for AbsoluteReserveProvider { fn reserve(asset: &Asset) -> Option { let AssetId(location) = &asset.id; - Pallet::::chain_part(location) + chain_part(location) } } // Provide reserve in relative path view // Self tokens are represeneted as Here -pub struct RelativeReserveProviderMigrationPhase(PhantomData); +pub struct RelativeReserveProvider; -impl Reserve for RelativeReserveProviderMigrationPhase { +impl Reserve for RelativeReserveProvider { fn reserve(asset: &Asset) -> Option { let AssetId(location) = &asset.id; if location.parents == 0 && !is_chain_junction(location.first_interior()) { Some(Location::here()) } else { - Pallet::::chain_part(location) + chain_part(location) } } } + +/// Returns the "chain" location part. It could be parent, sibling +/// parachain, or child parachain. +pub fn chain_part(location: &Location) -> Option { + match (location.parents, location.first_interior()) { + // sibling parachain + (1, Some(Parachain(id))) => Some(Location::new(1, [Parachain(*id)])), + // parent -> assethub + (1, _) => Some(Location::new(1, [Parachain(ASSET_HUB_ID)])), + // children parachain + (0, Some(Parachain(id))) => Some(Location::new(0, [Parachain(*id)])), + _ => None, + } +} + +/// Returns "non-chain" location part. +pub fn non_chain_part(location: &Location) -> Option { + let mut junctions = location.interior().clone(); + while is_chain_junction(junctions.first()) { + let _ = junctions.take_first(); + } + + if junctions != Here { + Some(Location::new(0, junctions)) + } else { + None + } +} diff --git a/xtokens/src/mock/asset_hub.rs b/xtokens/src/mock/asset_hub.rs new file mode 100644 index 000000000..7237181ca --- /dev/null +++ b/xtokens/src/mock/asset_hub.rs @@ -0,0 +1,189 @@ +use super::{AbsoluteReserveProvider, AllowTopLevelPaidExecution, Balance, ParachainXcmRouter}; + +use frame_support::{ + construct_runtime, derive_impl, parameter_types, + traits::{ConstU128, ConstU32, ContainsPair, Everything, Get, Nothing}, +}; +use frame_system::EnsureRoot; +use pallet_xcm::XcmPassthrough; +use parachains_common::xcm_config::ConcreteAssetFromSystem; +use polkadot_parachain_primitives::primitives::Sibling; +use sp_runtime::{traits::IdentityLookup, AccountId32}; +use sp_std::marker::PhantomData; +use xcm::v5::{prelude::*, Weight}; +use xcm_builder::{ + AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, FungibleAdapter, IsConcrete, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, +}; +use xcm_executor::{Config, XcmExecutor}; + +use crate::mock::{AllTokensAreCreatedEqualToWeight, KsmLocation}; +use orml_traits::location::Reserve; + +pub type AccountId = AccountId32; + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] +impl frame_system::Config for Runtime { + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type AccountData = pallet_balances::AccountData; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = ConstU32<50>; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ConstU128<1>; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = ConstU32<50>; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = [u8; 8]; + type MaxFreezes = (); + type DoneSlashHandler = (); +} + +parameter_types! { + pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub const RelayLocation: Location = Location::parent(); + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::get().into())].into(); +} + +pub type LocationToAccountId = ( + ParentIsPreset, + SiblingParachainConvertsVia, + AccountId32Aliases, +); + +pub type XcmOriginToCallOrigin = ( + SovereignSignedViaLocation, + RelayChainAsNative, + SiblingParachainAsNative, + SignedAccountId32AsNative, + XcmPassthrough, +); + +pub type LocalAssetTransactor = + FungibleAdapter, LocationToAccountId, AccountId, ()>; + +pub type XcmRouter = ParachainXcmRouter; +pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecution); + +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); + pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub struct MultiNativeAsset(PhantomData); +impl ContainsPair for MultiNativeAsset +where + ReserveProvider: Reserve, +{ + fn contains(asset: &Asset, origin: &Location) -> bool { + if let Some(ref reserve) = ReserveProvider::reserve(asset) { + if reserve == origin { + return true; + } + } + // allow parachain to be reserved of relay to bypass https://github.com/paritytech/polkadot-sdk/pull/5660 + if asset.id.0 == Location::parent() { + return true; + } + false + } +} + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToCallOrigin; + type IsReserve = MultiNativeAsset; + type IsTeleporter = ConcreteAssetFromSystem; + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = AllTokensAreCreatedEqualToWeight; + type ResponseHandler = (); + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type AssetLocker = PolkadotXcm; + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = (); + type TransactionalProcessor = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); + type XcmRecorder = (); + type XcmEventEmitter = (); +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Everything; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AuthorizedAliasConsideration = (); +} + +impl orml_xcm_mock_message_queue::Config for Runtime { + type XcmExecutor = XcmExecutor; +} + +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + + MsgQueue: orml_xcm_mock_message_queue, + CumulusXcm: cumulus_pallet_xcm, + + PolkadotXcm: pallet_xcm, + } +); diff --git a/xtokens/src/mock/mod.rs b/xtokens/src/mock/mod.rs index 2bcdc5490..5e06e431f 100644 --- a/xtokens/src/mock/mod.rs +++ b/xtokens/src/mock/mod.rs @@ -3,6 +3,7 @@ use super::*; use crate as orml_xtokens; +use frame_support::parameter_types; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; use sp_io::TestExternalities; @@ -13,6 +14,7 @@ use xcm_executor::AssetsInHolding; use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, ProcessMessageError, TestExt}; +pub mod asset_hub; pub mod para; pub mod para_relative_view; pub mod para_teleport; @@ -23,6 +25,10 @@ pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); pub const CHARLIE: AccountId32 = AccountId32::new([2u8; 32]); +parameter_types! { + pub KsmLocation: Location = Parent.into(); +} + #[derive( Encode, Decode, @@ -220,6 +226,15 @@ decl_test_parachain! { } } +decl_test_parachain! { + pub struct AssetHub { + Runtime = asset_hub::Runtime, + XcmpMessageHandler = asset_hub::MsgQueue, + DmpMessageHandler = asset_hub::MsgQueue, + new_ext = asset_hub_ext(ASSET_HUB_ID), + } +} + decl_test_relay_chain! { pub struct Relay { Runtime = relay::Runtime, @@ -236,6 +251,7 @@ decl_test_network! { pub struct TestNet { relay_chain = Relay, parachains = vec![ + (ASSET_HUB_ID, AssetHub), (1, ParaA), (2, ParaB), (3, ParaC), @@ -244,9 +260,9 @@ decl_test_network! { } } -pub type RelayBalances = pallet_balances::Pallet; pub type ParaTokens = orml_tokens::Pallet; pub type ParaXTokens = orml_xtokens::Pallet; +pub type AssetHubBalances = pallet_balances::Pallet; pub type ParaRelativeTokens = orml_tokens::Pallet; pub type ParaRelativeXTokens = orml_xtokens::Pallet; @@ -295,6 +311,28 @@ pub fn para_teleport_ext(para_id: u32) -> TestExternalities { ext } +pub fn asset_hub_ext(para_id: u32) -> sp_io::TestExternalities { + use asset_hub::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(ALICE, 1_000)], + ..Default::default() + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + pub fn relay_ext() -> sp_io::TestExternalities { use relay::{Runtime, System}; diff --git a/xtokens/src/mock/para.rs b/xtokens/src/mock/para.rs index 3f11e3987..4e4e336cd 100644 --- a/xtokens/src/mock/para.rs +++ b/xtokens/src/mock/para.rs @@ -1,5 +1,5 @@ use super::{ - AbsoluteReserveProviderMigrationPhase, AllowTopLevelPaidExecution, Amount, Balance, CurrencyId, CurrencyIdConvert, + AbsoluteReserveProvider, AllowTopLevelPaidExecution, Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter, RateLimiter, CHARLIE, }; use crate as orml_xtokens; @@ -10,6 +10,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; +use parachains_common::xcm_config::ConcreteAssetFromSystem; use parity_scale_codec::Encode; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::{ @@ -19,14 +20,17 @@ use sp_runtime::{ use sp_std::{cell::RefCell, marker::PhantomData}; use xcm::v5::{prelude::*, Weight}; use xcm_builder::{ - AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, NativeAsset, ParentIsPreset, RelayChainAsNative, + AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, }; use xcm_executor::{Config, XcmExecutor}; -use crate::mock::AllTokensAreCreatedEqualToWeight; -use orml_traits::{location::Reserve, parameter_type_with_key, RateLimiterError}; +use crate::mock::{AllTokensAreCreatedEqualToWeight, KsmLocation}; +use orml_traits::{ + location::{Reserve, ASSET_HUB_ID}, + parameter_type_with_key, RateLimiterError, +}; use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter}; pub type AccountId = AccountId32; @@ -142,8 +146,8 @@ impl Config for XcmConfig { type XcmSender = XcmRouter; type AssetTransactor = LocalAssetTransactor; type OriginConverter = XcmOriginToCallOrigin; - type IsReserve = MultiNativeAsset>; - type IsTeleporter = NativeAsset; + type IsReserve = MultiNativeAsset; + type IsTeleporter = ConcreteAssetFromSystem; type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds; @@ -232,6 +236,7 @@ impl Contains for ParentOrParachains { | (1, [Parachain(3), Junction::AccountId32 { .. }]) | (1, [Parachain(4), Junction::AccountId32 { .. }]) | (1, [Parachain(100), Junction::AccountId32 { .. }]) + | (1, [Parachain(ASSET_HUB_ID), Junction::AccountId32 { .. }]) ) } } @@ -241,6 +246,7 @@ parameter_type_with_key! { #[allow(clippy::match_ref_pats)] // false positive match (location.parents, location.first_interior()) { (1, Some(Parachain(3))) => Some(50), + (1, Some(Parachain(ASSET_HUB_ID))) => Some(50), _ => None, } }; @@ -303,10 +309,9 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; - type ReserveProvider = AbsoluteReserveProviderMigrationPhase; + type ReserveProvider = AbsoluteReserveProvider; type RateLimiter = MockRateLimiter; type RateLimiterId = XtokensRateLimiterId; - type MigrationPhaseUpdateOrigin = EnsureRoot; } impl orml_xcm::Config for Runtime { diff --git a/xtokens/src/mock/para_relative_view.rs b/xtokens/src/mock/para_relative_view.rs index c1ff52a1f..1a1a7a8c2 100644 --- a/xtokens/src/mock/para_relative_view.rs +++ b/xtokens/src/mock/para_relative_view.rs @@ -1,8 +1,9 @@ use super::{ - AbsoluteReserveProviderMigrationPhase, Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter, - RelativeReserveProviderMigrationPhase, + AbsoluteReserveProvider, Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter, + RelativeReserveProvider, }; use crate as orml_xtokens; +use orml_xtokens::ASSET_HUB_ID; use frame_support::{ construct_runtime, derive_impl, parameter_types, @@ -10,6 +11,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; +use parachains_common::xcm_config::ConcreteAssetFromSystem; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::{ traits::{Convert, IdentityLookup}, @@ -24,7 +26,7 @@ use xcm_builder::{ }; use xcm_executor::{Config, XcmExecutor}; -use crate::mock::AllTokensAreCreatedEqualToWeight; +use crate::mock::{AllTokensAreCreatedEqualToWeight, KsmLocation}; use orml_traits::{location::Reserve, parameter_type_with_key}; use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter}; @@ -141,8 +143,8 @@ impl Config for XcmConfig { type XcmSender = XcmRouter; type AssetTransactor = LocalAssetTransactor; type OriginConverter = XcmOriginToCallOrigin; - type IsReserve = MultiNativeAsset>; - type IsTeleporter = (); + type IsReserve = MultiNativeAsset; + type IsTeleporter = ConcreteAssetFromSystem; type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds; @@ -350,6 +352,7 @@ impl Contains for ParentOrParachains { | (1, [Parachain(3), Junction::AccountId32 { .. }]) | (1, [Parachain(4), Junction::AccountId32 { .. }]) | (1, [Parachain(100), Junction::AccountId32 { .. }]) + | (1, [Parachain(ASSET_HUB_ID), Junction::AccountId32 { .. }]) ) } } @@ -360,6 +363,7 @@ parameter_type_with_key! { match (location.parents, location.first_interior()) { (1, Some(Parachain(2))) => Some(50), (1, Some(Parachain(3))) => Some(50), + (1, Some(Parachain(ASSET_HUB_ID))) => Some(50), _ => None, } }; @@ -378,10 +382,9 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; - type ReserveProvider = RelativeReserveProviderMigrationPhase; + type ReserveProvider = RelativeReserveProvider; type RateLimiter = (); type RateLimiterId = (); - type MigrationPhaseUpdateOrigin = EnsureRoot; } impl orml_xcm::Config for Runtime { diff --git a/xtokens/src/mock/para_teleport.rs b/xtokens/src/mock/para_teleport.rs index a68090781..7ee19feaa 100644 --- a/xtokens/src/mock/para_teleport.rs +++ b/xtokens/src/mock/para_teleport.rs @@ -1,5 +1,5 @@ use super::{ - AbsoluteReserveProviderMigrationPhase, AllowTopLevelPaidExecution, Amount, Balance, CurrencyId, CurrencyIdConvert, + AbsoluteReserveProvider, AllowTopLevelPaidExecution, Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter, }; use crate as orml_xtokens; @@ -10,6 +10,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; +use parachains_common::xcm_config::ConcreteAssetFromSystem; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::{ traits::{Convert, IdentityLookup}, @@ -17,14 +18,15 @@ use sp_runtime::{ }; use xcm::v5::{prelude::*, Weight}; use xcm_builder::{ - AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, NativeAsset, ParentIsPreset, RelayChainAsNative, + AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, }; use xcm_executor::{Config, XcmExecutor}; -use crate::mock::teleport_currency_adapter::MultiTeleportCurrencyAdapter; -use crate::mock::AllTokensAreCreatedEqualToWeight; +use crate::mock::{ + teleport_currency_adapter::MultiTeleportCurrencyAdapter, AllTokensAreCreatedEqualToWeight, KsmLocation, +}; use orml_traits::parameter_type_with_key; use orml_xcm_support::{DisabledParachainFee, IsNativeConcrete, MultiNativeAsset}; @@ -122,8 +124,8 @@ impl Config for XcmConfig { type XcmSender = XcmRouter; type AssetTransactor = LocalAssetTransactor; type OriginConverter = XcmOriginToCallOrigin; - type IsReserve = MultiNativeAsset>; - type IsTeleporter = NativeAsset; + type IsReserve = MultiNativeAsset; + type IsTeleporter = ConcreteAssetFromSystem; type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds; @@ -229,10 +231,9 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; - type ReserveProvider = AbsoluteReserveProviderMigrationPhase; + type ReserveProvider = AbsoluteReserveProvider; type RateLimiter = (); type RateLimiterId = (); - type MigrationPhaseUpdateOrigin = EnsureRoot; } impl orml_xcm::Config for Runtime { diff --git a/xtokens/src/mock/relay.rs b/xtokens/src/mock/relay.rs index b033c0903..d476f058a 100644 --- a/xtokens/src/mock/relay.rs +++ b/xtokens/src/mock/relay.rs @@ -6,7 +6,8 @@ use frame_support::{ use frame_system::EnsureRoot; use sp_runtime::{traits::IdentityLookup, AccountId32}; -use crate::Weight; +use crate::mock::KsmLocation; +use crate::{Weight, ASSET_HUB_ID}; use cumulus_primitives_core::ParaId; use polkadot_runtime_parachains::{ configuration, @@ -58,7 +59,6 @@ impl configuration::Config for Runtime { } parameter_types! { - pub KsmLocation: Location = Here.into(); pub const KusamaNetwork: NetworkId = NetworkId::Kusama; pub UniversalLocation: InteriorLocation = [GlobalConsensus(KusamaNetwork::get())].into(); } @@ -81,11 +81,11 @@ pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom parameter_types! { pub Kusama: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(KsmLocation::get()) }); - pub Statemine: Location = Parachain(3).into(); - pub KusamaForStatemine: (AssetFilter, Location) = (Kusama::get(), Statemine::get()); + pub AssetHub: Location = Parachain(ASSET_HUB_ID).into(); + pub KusamaForAssetHub: (AssetFilter, Location) = (Kusama::get(), AssetHub::get()); } -pub type TrustedTeleporters = xcm_builder::Case; +pub type TrustedTeleporters = xcm_builder::Case; parameter_types! { pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); diff --git a/xtokens/src/tests.rs b/xtokens/src/tests.rs index 8a65a33c7..4b08ff146 100644 --- a/xtokens/src/tests.rs +++ b/xtokens/src/tests.rs @@ -1,7 +1,6 @@ #![cfg(test)] use super::*; -use cumulus_primitives_core::ParaId; use frame_support::traits::ContainsPair; use frame_support::{assert_err, assert_noop, assert_ok, traits::Currency}; use mock::*; @@ -13,18 +12,6 @@ use sp_runtime::{traits::AccountIdConversion, AccountId32}; use xcm::{v5::OriginKind::SovereignAccount, VersionedXcm}; use xcm_simulator::TestExt; -fn para_a_account() -> AccountId32 { - ParaId::from(1).into_account_truncating() -} - -fn para_b_account() -> AccountId32 { - ParaId::from(2).into_account_truncating() -} - -fn para_d_account() -> AccountId32 { - ParaId::from(4).into_account_truncating() -} - fn sibling_a_account() -> AccountId32 { Sibling::from(1).into_account_truncating() } @@ -52,11 +39,11 @@ fn print_events(name: &'static str) { } #[test] -fn send_relay_chain_asset_to_relay_chain() { +fn send_relay_chain_asset_to_asset_hub() { TestNet::reset(); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1_000); }); ParaA::execute_with(|| { @@ -67,10 +54,13 @@ fn send_relay_chain_asset_to_relay_chain() { Box::new( Location::new( 1, - [Junction::AccountId32 { - network: None, - id: BOB.into(), - }] + [ + Parachain(ASSET_HUB_ID), + Junction::AccountId32 { + network: None, + id: BOB.into(), + } + ] ) .into() ), @@ -79,18 +69,18 @@ fn send_relay_chain_asset_to_relay_chain() { assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500); }); - Relay::execute_with(|| { - assert_eq!(RelayBalances::free_balance(¶_a_account()), 500); - assert_eq!(RelayBalances::free_balance(&BOB), 450); + AssetHub::execute_with(|| { + assert_eq!(AssetHubBalances::free_balance(&sibling_a_account()), 500); + assert_eq!(AssetHubBalances::free_balance(&BOB), 450); }); } #[test] -fn send_relay_chain_asset_to_relay_chain_with_fee() { +fn send_relay_chain_asset_to_asset_hub_with_fee() { TestNet::reset(); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1_000); }); ParaA::execute_with(|| { @@ -102,10 +92,13 @@ fn send_relay_chain_asset_to_relay_chain_with_fee() { Box::new( Location::new( 1, - [Junction::AccountId32 { - network: None, - id: BOB.into(), - }] + [ + Parachain(ASSET_HUB_ID), + Junction::AccountId32 { + network: None, + id: BOB.into(), + } + ] ) .into() ), @@ -115,9 +108,9 @@ fn send_relay_chain_asset_to_relay_chain_with_fee() { }); // It should use 50 for weight, so 450 should reach destination - Relay::execute_with(|| { - assert_eq!(RelayBalances::free_balance(¶_a_account()), 500); - assert_eq!(RelayBalances::free_balance(&BOB), 450); + AssetHub::execute_with(|| { + assert_eq!(AssetHubBalances::free_balance(&sibling_a_account()), 500); + assert_eq!(AssetHubBalances::free_balance(&BOB), 450); }); } @@ -156,8 +149,8 @@ fn cannot_lost_fund_on_send_failed() { fn send_relay_chain_asset_to_sibling() { TestNet::reset(); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1000); }); ParaA::execute_with(|| { @@ -183,9 +176,9 @@ fn send_relay_chain_asset_to_sibling() { assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500); }); - Relay::execute_with(|| { - assert_eq!(RelayBalances::free_balance(¶_a_account()), 500); - assert_eq!(RelayBalances::free_balance(¶_b_account()), 450); + AssetHub::execute_with(|| { + assert_eq!(AssetHubBalances::free_balance(&sibling_a_account()), 500); + assert_eq!(AssetHubBalances::free_balance(&sibling_b_account()), 450); }); ParaB::execute_with(|| { @@ -197,8 +190,8 @@ fn send_relay_chain_asset_to_sibling() { fn send_relay_chain_asset_to_sibling_with_fee() { TestNet::reset(); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1000); }); ParaA::execute_with(|| { @@ -226,9 +219,9 @@ fn send_relay_chain_asset_to_sibling_with_fee() { }); // It should use 50 weight - Relay::execute_with(|| { - assert_eq!(RelayBalances::free_balance(¶_a_account()), 500); - assert_eq!(RelayBalances::free_balance(¶_b_account()), 450); + AssetHub::execute_with(|| { + assert_eq!(AssetHubBalances::free_balance(&sibling_a_account()), 500); + assert_eq!(AssetHubBalances::free_balance(&sibling_b_account()), 450); }); // It should use another 50 weight in paraB @@ -658,10 +651,13 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works() { ParaC::execute_with(|| { assert_ok!(ParaTeleportTokens::deposit(CurrencyId::C, &sibling_a_account(), 1_000)); + // ParaC might process the message before AssetHub teleports the asset to ParaC. + // This is why sibling_d_account needs to have R asset available. + assert_ok!(ParaTeleportTokens::deposit(CurrencyId::R, &sibling_a_account(), 1_000)); }); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1_000); }); let fee_amount: u128 = 300; @@ -690,16 +686,16 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works() { assert_eq!(1000 - fee_amount, ParaTokens::free_balance(CurrencyId::R, &ALICE)); }); - Relay::execute_with(|| { + AssetHub::execute_with(|| { assert_eq!( 1000 - (fee_amount - dest_weight), - RelayBalances::free_balance(¶_a_account()) + AssetHubBalances::free_balance(&sibling_a_account()) ); }); ParaC::execute_with(|| { assert_eq!( - fee_amount - dest_weight * 4, + 1000 + fee_amount - dest_weight * 4, ParaTeleportTokens::free_balance(CurrencyId::R, &sibling_a_account()) ); @@ -718,10 +714,13 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works_with_relative_s ParaC::execute_with(|| { assert_ok!(ParaTeleportTokens::deposit(CurrencyId::C, &sibling_d_account(), 1_000)); + // ParaC might process the message before AssetHub teleports the asset to ParaC. + // This is why sibling_d_account needs to have R asset available. + assert_ok!(ParaTeleportTokens::deposit(CurrencyId::R, &sibling_d_account(), 1_000)); }); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_d_account(), 1_000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_d_account(), 1_000); }); let fee_amount: u128 = 300; @@ -753,16 +752,16 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works_with_relative_s ); }); - Relay::execute_with(|| { + AssetHub::execute_with(|| { assert_eq!( 1000 - (fee_amount - dest_weight), - RelayBalances::free_balance(¶_d_account()) + AssetHubBalances::free_balance(&sibling_d_account()) ); }); ParaC::execute_with(|| { assert_eq!( - fee_amount - dest_weight * 4, + 1000 + fee_amount - dest_weight * 4, ParaTeleportTokens::free_balance(CurrencyId::R, &sibling_d_account()) ); @@ -783,8 +782,8 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_not_enough() { assert_ok!(ParaTokens::deposit(CurrencyId::C, &sibling_a_account(), 1_000)); }); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1_000); }); let fee_amount: u128 = 159; @@ -813,10 +812,10 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_not_enough() { assert_eq!(1000 - fee_amount, ParaTokens::free_balance(CurrencyId::R, &ALICE)); }); - Relay::execute_with(|| { + AssetHub::execute_with(|| { assert_eq!( 1000 - (fee_amount - dest_weight), - RelayBalances::free_balance(¶_a_account()) + AssetHubBalances::free_balance(&sibling_a_account()) ); }); @@ -1020,18 +1019,18 @@ fn transfer_to_invalid_dest_fails() { fn send_as_sovereign() { TestNet::reset(); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000_000_000_000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1_000_000_000_000); }); ParaA::execute_with(|| { let call = relay::RuntimeCall::System(frame_system::Call::::remark_with_event { remark: vec![1, 1, 1], }); - let assets: Asset = (Here, 1_000_000_000_000u128).into(); + let assets: Asset = (Parent, 1_000_000_000_000u128).into(); assert_ok!(para::OrmlXcm::send_as_sovereign( para::RuntimeOrigin::root(), - Box::new(Parent.into()), + Box::new(VersionedLocation::from(Location::new(1, [Parachain(ASSET_HUB_ID)]))), Box::new(VersionedXcm::from(Xcm(vec![ WithdrawAsset(assets.clone().into()), BuyExecution { @@ -1047,11 +1046,14 @@ fn send_as_sovereign() { )); }); - Relay::execute_with(|| { - assert!(relay::System::events().iter().any(|r| { + AssetHub::execute_with(|| { + assert!(asset_hub::System::events().iter().any(|r| { matches!( r.event, - relay::RuntimeEvent::System(frame_system::Event::::Remarked { sender: _, hash: _ }) + asset_hub::RuntimeEvent::System(frame_system::Event::::Remarked { + sender: _, + hash: _ + }) ) })); }) @@ -1061,19 +1063,19 @@ fn send_as_sovereign() { fn send_as_sovereign_fails_if_bad_origin() { TestNet::reset(); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000_000_000_000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1_000_000_000_000); }); ParaA::execute_with(|| { let call = relay::RuntimeCall::System(frame_system::Call::::remark_with_event { remark: vec![1, 1, 1], }); - let assets: Asset = (Here, 1_000_000_000_000u128).into(); + let assets: Asset = (Parent, 1_000_000_000_000u128).into(); assert_err!( para::OrmlXcm::send_as_sovereign( para::RuntimeOrigin::signed(ALICE), - Box::new(Parent.into()), + Box::new(VersionedLocation::from(Location::new(1, [Parachain(ASSET_HUB_ID)]))), Box::new(VersionedXcm::from(Xcm(vec![ WithdrawAsset(assets.clone().into()), BuyExecution { @@ -1238,8 +1240,8 @@ fn specifying_more_than_assets_limit_should_error() { assert_ok!(ParaTokens::deposit(CurrencyId::B2, &sibling_a_account(), 1_000)); }); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1_000); }); ParaA::execute_with(|| { @@ -1284,8 +1286,8 @@ fn sending_non_fee_assets_with_different_reserve_should_fail() { assert_ok!(ParaTokens::deposit(CurrencyId::B, &sibling_a_account(), 1_000)); }); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1_000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1_000); }); ParaA::execute_with(|| { @@ -1563,8 +1565,8 @@ fn send_relative_view_sibling_asset_to_non_reserve_sibling() { fn send_relay_chain_asset_to_relative_view_sibling() { TestNet::reset(); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 1000); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 1000); }); ParaA::execute_with(|| { @@ -1590,9 +1592,9 @@ fn send_relay_chain_asset_to_relative_view_sibling() { assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), 500); }); - Relay::execute_with(|| { - assert_eq!(RelayBalances::free_balance(¶_a_account()), 500); - assert_eq!(RelayBalances::free_balance(¶_d_account()), 450); + AssetHub::execute_with(|| { + assert_eq!(AssetHubBalances::free_balance(&sibling_a_account()), 500); + assert_eq!(AssetHubBalances::free_balance(&sibling_d_account()), 450); }); ParaD::execute_with(|| { @@ -1728,11 +1730,11 @@ fn send_with_insufficient_weight_limit() { fn send_relay_chain_asset_to_relay_chain_at_rate_limit() { TestNet::reset(); - Relay::execute_with(|| { - let _ = RelayBalances::deposit_creating(¶_a_account(), 4000); - assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000); - assert_eq!(RelayBalances::free_balance(&ALICE), 1000); - assert_eq!(RelayBalances::free_balance(&BOB), 0); + AssetHub::execute_with(|| { + let _ = AssetHubBalances::deposit_creating(&sibling_a_account(), 4000); + assert_eq!(AssetHubBalances::free_balance(&sibling_a_account()), 4000); + assert_eq!(AssetHubBalances::free_balance(&ALICE), 1000); + assert_eq!(AssetHubBalances::free_balance(&BOB), 0); }); ParaA::execute_with(|| { @@ -1828,10 +1830,10 @@ fn send_relay_chain_asset_to_relay_chain_at_rate_limit() { assert_eq!(R_ACCUMULATION.with(|v| *v.borrow()), 2000); }); - Relay::execute_with(|| { - assert_eq!(RelayBalances::free_balance(¶_a_account()), 1799); - assert_eq!(RelayBalances::free_balance(&ALICE), 1151); - assert_eq!(RelayBalances::free_balance(&CHARLIE), 1900); + AssetHub::execute_with(|| { + assert_eq!(AssetHubBalances::free_balance(&sibling_a_account()), 1799); + assert_eq!(AssetHubBalances::free_balance(&ALICE), 1151); + assert_eq!(AssetHubBalances::free_balance(&CHARLIE), 1900); }); } @@ -1932,36 +1934,7 @@ fn nfts_cannot_be_fee_assets() { }); } -#[test] -fn set_migration_phase_should_work() { - TestNet::reset(); - - ParaA::execute_with(|| { - assert_eq!(MigrationPhase::NotStarted, MigrationStatus::::get()); - assert_ok!(ParaXTokens::set_migration_phase( - para::RuntimeOrigin::root(), - MigrationPhase::InProgress - )); - assert!(para::System::events().iter().any(|r| { - matches!( - r.event, - para::RuntimeEvent::XTokens(Event::MigrationPhaseChanged { - migration_phase: MigrationPhase::InProgress - }) - ) - })); - - assert_eq!(MigrationPhase::InProgress, MigrationStatus::::get()); - assert_ok!(ParaXTokens::set_migration_phase( - para::RuntimeOrigin::root(), - MigrationPhase::Completed - )); - assert_eq!(MigrationPhase::Completed, MigrationStatus::::get()); - }); -} - -// AbsoluteReserveProviderMigrationPhase and -// RelativeReserveProviderMigrationPhase +// AbsoluteReserveProvider and RelativeReserveProvider const PARACHAIN: Junction = Parachain(1); const GENERAL_INDEX: Junction = GeneralIndex(1); @@ -1975,18 +1948,12 @@ fn parent_as_reserve_chain() { ParaA::execute_with(|| { assert_eq!( - AbsoluteReserveProviderMigrationPhase::::reserve(&concrete_fungible(Location::new( - 1, - [GENERAL_INDEX] - ))), - Some(Location::parent()) + AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(1, [GENERAL_INDEX]))), + Some(Location::new(1, Parachain(ASSET_HUB_ID))) ); assert_eq!( - RelativeReserveProviderMigrationPhase::::reserve(&concrete_fungible(Location::new( - 1, - [GENERAL_INDEX] - ))), - Some(Location::parent()) + RelativeReserveProvider::reserve(&concrete_fungible(Location::new(1, [GENERAL_INDEX]))), + Some(Location::new(1, Parachain(ASSET_HUB_ID))) ); }); } @@ -1997,17 +1964,11 @@ fn sibling_parachain_as_reserve_chain() { ParaA::execute_with(|| { assert_eq!( - AbsoluteReserveProviderMigrationPhase::::reserve(&concrete_fungible(Location::new( - 1, - [PARACHAIN, GENERAL_INDEX] - ))), + AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(1, [PARACHAIN, GENERAL_INDEX]))), Some(Location::new(1, [PARACHAIN])) ); assert_eq!( - RelativeReserveProviderMigrationPhase::::reserve(&concrete_fungible(Location::new( - 1, - [PARACHAIN, GENERAL_INDEX] - ))), + RelativeReserveProvider::reserve(&concrete_fungible(Location::new(1, [PARACHAIN, GENERAL_INDEX]))), Some(Location::new(1, [PARACHAIN])) ); }); @@ -2019,17 +1980,11 @@ fn child_parachain_as_reserve_chain() { ParaA::execute_with(|| { assert_eq!( - AbsoluteReserveProviderMigrationPhase::::reserve(&concrete_fungible(Location::new( - 0, - [PARACHAIN, GENERAL_INDEX] - ))), + AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(0, [PARACHAIN, GENERAL_INDEX]))), Some(PARACHAIN.into()) ); assert_eq!( - RelativeReserveProviderMigrationPhase::::reserve(&concrete_fungible(Location::new( - 0, - [PARACHAIN, GENERAL_INDEX] - ))), + RelativeReserveProvider::reserve(&concrete_fungible(Location::new(0, [PARACHAIN, GENERAL_INDEX]))), Some(PARACHAIN.into()) ); }); @@ -2041,14 +1996,14 @@ fn no_reserve_chain_for_absolute_self_for_relative() { ParaA::execute_with(|| { assert_eq!( - AbsoluteReserveProviderMigrationPhase::::reserve(&concrete_fungible(Location::new( + AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new( 0, [Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())] ))), None ); assert_eq!( - RelativeReserveProviderMigrationPhase::::reserve(&concrete_fungible(Location::new( + RelativeReserveProvider::reserve(&concrete_fungible(Location::new( 0, [Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())] ))), @@ -2059,24 +2014,24 @@ fn no_reserve_chain_for_absolute_self_for_relative() { #[test] fn non_chain_part_works() { - assert_eq!(ParaXTokens::non_chain_part(&Location::parent()), None); - assert_eq!(ParaXTokens::non_chain_part(&Location::new(1, [PARACHAIN])), None); - assert_eq!(ParaXTokens::non_chain_part(&Location::new(0, [PARACHAIN])), None); + assert_eq!(non_chain_part(&Location::parent()), None); + assert_eq!(non_chain_part(&Location::new(1, [PARACHAIN])), None); + assert_eq!(non_chain_part(&Location::new(0, [PARACHAIN])), None); assert_eq!( - ParaXTokens::non_chain_part(&Location::new(1, [GENERAL_INDEX])), + non_chain_part(&Location::new(1, [GENERAL_INDEX])), Some(GENERAL_INDEX.into()) ); assert_eq!( - ParaXTokens::non_chain_part(&Location::new(1, [GENERAL_INDEX, GENERAL_INDEX])), + non_chain_part(&Location::new(1, [GENERAL_INDEX, GENERAL_INDEX])), Some((GENERAL_INDEX, GENERAL_INDEX).into()) ); assert_eq!( - ParaXTokens::non_chain_part(&Location::new(1, [PARACHAIN, GENERAL_INDEX])), + non_chain_part(&Location::new(1, [PARACHAIN, GENERAL_INDEX])), Some(GENERAL_INDEX.into()) ); assert_eq!( - ParaXTokens::non_chain_part(&Location::new(0, [PARACHAIN, GENERAL_INDEX])), + non_chain_part(&Location::new(0, [PARACHAIN, GENERAL_INDEX])), Some(GENERAL_INDEX.into()) ); } @@ -2086,26 +2041,20 @@ fn multi_native_asset() { TestNet::reset(); ParaA::execute_with(|| { - assert!( - MultiNativeAsset::>::contains( - &Asset { - fun: Fungible(10), - id: AssetId(Location::parent()) - }, - &Parent.into() - ) - ); - assert!( - MultiNativeAsset::>::contains( - &Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100), - &Location::new(1, [Parachain(1)]), - ) - ); - assert!( - !MultiNativeAsset::>::contains( - &Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100), - &Location::parent(), - ) - ); + assert!(MultiNativeAsset::::contains( + &Asset { + fun: Fungible(10), + id: AssetId(Location::parent()) + }, + &Location::new(1, Parachain(ASSET_HUB_ID)) + )); + assert!(MultiNativeAsset::::contains( + &Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100), + &Location::new(1, [Parachain(1)]), + )); + assert!(!MultiNativeAsset::::contains( + &Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100), + &Location::parent(), + )); }); } From e35eba357733eafa9de63e8df4335c477337bd73 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Wed, 22 Oct 2025 11:42:28 +0800 Subject: [PATCH 2/2] fix --- asset-registry/src/mock/para.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/asset-registry/src/mock/para.rs b/asset-registry/src/mock/para.rs index 880043a38..618159439 100644 --- a/asset-registry/src/mock/para.rs +++ b/asset-registry/src/mock/para.rs @@ -12,7 +12,7 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSignedBy}; use orml_traits::{parameter_type_with_key, FixedConversionRateProvider, MultiCurrency}; use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset}; -use orml_xtokens::{AbsoluteReserveProviderMigrationPhase, RelativeReserveProviderMigrationPhase}; +use orml_xtokens::{AbsoluteReserveProvider, RelativeReserveProvider}; use pallet_xcm::XcmPassthrough; use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; use polkadot_parachain_primitives::primitives::Sibling; @@ -210,7 +210,7 @@ impl Config for XcmConfig { type XcmSender = XcmRouter; type AssetTransactor = LocalAssetTransactor; type OriginConverter = XcmOriginToCallOrigin; - type IsReserve = MultiNativeAsset>; + type IsReserve = MultiNativeAsset; type IsTeleporter = (); type UniversalLocation = UniversalLocation; type Barrier = Barrier; @@ -327,10 +327,9 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type UniversalLocation = UniversalLocation; type MaxAssetsForTransfer = MaxAssetsForTransfer; - type ReserveProvider = RelativeReserveProviderMigrationPhase; + type ReserveProvider = RelativeReserveProvider; type RateLimiter = (); type RateLimiterId = (); - type MigrationPhaseUpdateOrigin = EnsureRoot; } impl orml_xcm::Config for Runtime {