From f8699041179b53d210d493faebfe74ac54b7fb5c Mon Sep 17 00:00:00 2001 From: Gav Date: Mon, 5 Jun 2023 07:12:39 +0100 Subject: [PATCH] Fixups for new Convert APIs --- Cargo.lock | 1 + .../emulated/common/src/lib.rs | 2 +- .../assets/asset-hub-kusama/tests/tests.rs | 36 +++++++++++++---- .../assets/asset-hub-polkadot/tests/tests.rs | 36 +++++++++++++---- .../assets/asset-hub-westend/tests/tests.rs | 36 +++++++++++++---- parachains/runtimes/assets/common/Cargo.toml | 2 + .../assets/common/src/foreign_creators.rs | 10 ++--- .../assets/common/src/fungible_conversion.rs | 39 ++++++++++--------- parachains/runtimes/assets/common/src/lib.rs | 11 +++--- .../assets/test-utils/src/test_cases.rs | 24 ++++++------ xcm/xcm-emulator/src/lib.rs | 4 +- 11 files changed, 134 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 514c0015735..b271bfcc483 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -697,6 +697,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", + "sp-runtime", "sp-std", "substrate-wasm-builder", "xcm", diff --git a/parachains/integration-tests/emulated/common/src/lib.rs b/parachains/integration-tests/emulated/common/src/lib.rs index 39e4fbb453e..c793110a378 100644 --- a/parachains/integration-tests/emulated/common/src/lib.rs +++ b/parachains/integration-tests/emulated/common/src/lib.rs @@ -13,7 +13,7 @@ use xcm_emulator::{ decl_test_networks, decl_test_parachains, decl_test_relay_chains, Parachain, RelayChain, TestExt, }; -use xcm_executor::traits::Convert; +use xcm_executor::traits::ConvertLocation; decl_test_relay_chains! { #[api_version(5)] diff --git a/parachains/runtimes/assets/asset-hub-kusama/tests/tests.rs b/parachains/runtimes/assets/asset-hub-kusama/tests/tests.rs index 22d277c5d8c..21cec9bf56c 100644 --- a/parachains/runtimes/assets/asset-hub-kusama/tests/tests.rs +++ b/parachains/runtimes/assets/asset-hub-kusama/tests/tests.rs @@ -1,3 +1,22 @@ +// This file is part of Cumulus. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Tests for the Statemine (Kusama Assets Hub) chain. + use asset_hub_kusama_runtime::xcm_config::{ AssetFeeAsExistentialDepositMultiplierFeeCharger, KsmLocation, TrustBackedAssetsPalletLocation, }; @@ -17,8 +36,9 @@ use frame_support::{ weights::{Weight, WeightToFee as WeightToFeeT}, }; use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance}; +use sp_runtime::traits::MaybeEquivalence; use xcm::latest::prelude::*; -use xcm_executor::traits::{Convert, Identity, JustTry, WeightTrader}; +use xcm_executor::traits::{Identity, JustTry, WeightTrader}; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; @@ -66,7 +86,7 @@ fn test_asset_xcm_trader() { // get asset id as multilocation let asset_multilocation = - AssetIdForTrustBackedAssetsConvert::reverse_ref(local_asset_id).unwrap(); + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(); // Set Alice as block author, who will receive fees RuntimeHelper::::run_to_block(2, Some(AccountId::from(ALICE))); @@ -150,7 +170,7 @@ fn test_asset_xcm_trader_with_refund() { // We are going to buy 4e9 weight let bought = Weight::from_parts(4_000_000_000u64, 0); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); // lets calculate amount needed let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -220,7 +240,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { // We are going to buy small amount let bought = Weight::from_parts(500_000_000u64, 0); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -271,7 +291,7 @@ fn test_that_buying_ed_refund_does_not_refund() { // We are gonna buy ED let bought = Weight::from_parts(ExistentialDeposit::get().try_into().unwrap(), 0); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -346,7 +366,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { // lets calculate amount needed let asset_amount_needed = WeightToFee::weight_to_fee(&bought); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into(); @@ -461,13 +481,13 @@ fn test_assets_balances_api_works() { ))); // check trusted asset assert!(result.inner().iter().any(|asset| asset.eq(&( - AssetIdForTrustBackedAssetsConvert::reverse_ref(local_asset_id).unwrap(), + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(), minimum_asset_balance ) .into()))); // check foreign asset assert!(result.inner().iter().any(|asset| asset.eq(&( - Identity::reverse_ref(foreign_asset_id_multilocation).unwrap(), + Identity::convert_back(&foreign_asset_id_multilocation).unwrap(), 6 * foreign_asset_minimum_asset_balance ) .into()))); diff --git a/parachains/runtimes/assets/asset-hub-polkadot/tests/tests.rs b/parachains/runtimes/assets/asset-hub-polkadot/tests/tests.rs index f78f53c5e6b..cdd61f26796 100644 --- a/parachains/runtimes/assets/asset-hub-polkadot/tests/tests.rs +++ b/parachains/runtimes/assets/asset-hub-polkadot/tests/tests.rs @@ -1,3 +1,22 @@ +// This file is part of Cumulus. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Tests for the Statemint (Polkadot Assets Hub) chain. + use asset_hub_polkadot_runtime::xcm_config::{ AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, DotLocation, ForeignCreatorsSovereignAccountOf, TrustBackedAssetsPalletLocation, XcmConfig, @@ -18,8 +37,9 @@ use frame_support::{ use parachains_common::{ AccountId, AssetHubPolkadotAuraId as AuraId, AssetIdForTrustBackedAssets, Balance, }; +use sp_runtime::traits::MaybeEquivalence; use xcm::latest::prelude::*; -use xcm_executor::traits::{Convert, Identity, JustTry, WeightTrader}; +use xcm_executor::traits::{Identity, JustTry, WeightTrader}; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; @@ -67,7 +87,7 @@ fn test_asset_xcm_trader() { // get asset id as multilocation let asset_multilocation = - AssetIdForTrustBackedAssetsConvert::reverse_ref(local_asset_id).unwrap(); + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(); // Set Alice as block author, who will receive fees RuntimeHelper::::run_to_block(2, Some(AccountId::from(ALICE))); @@ -157,7 +177,7 @@ fn test_asset_xcm_trader_with_refund() { // bit more of weight let bought = Weight::from_parts(400_000_000_000u64, 0); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); // lets calculate amount needed let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -230,7 +250,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { // bit more of weight let bought = Weight::from_parts(50_000_000_000u64, 0); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -281,7 +301,7 @@ fn test_that_buying_ed_refund_does_not_refund() { // We are gonna buy ED let bought = Weight::from_parts(ExistentialDeposit::get().try_into().unwrap(), 0); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -359,7 +379,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { // lets calculate amount needed let asset_amount_needed = WeightToFee::weight_to_fee(&bought); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into(); @@ -474,13 +494,13 @@ fn test_assets_balances_api_works() { ))); // check trusted asset assert!(result.inner().iter().any(|asset| asset.eq(&( - AssetIdForTrustBackedAssetsConvert::reverse_ref(local_asset_id).unwrap(), + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(), minimum_asset_balance ) .into()))); // check foreign asset assert!(result.inner().iter().any(|asset| asset.eq(&( - Identity::reverse_ref(foreign_asset_id_multilocation).unwrap(), + Identity::convert_back(&foreign_asset_id_multilocation).unwrap(), 6 * foreign_asset_minimum_asset_balance ) .into()))); diff --git a/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index 87bfb4b699a..4cfed8fed08 100644 --- a/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -1,3 +1,22 @@ +// This file is part of Cumulus. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Tests for the Westmint (Westend Assets Hub) chain. + pub use asset_hub_westend_runtime::{ constants::fee::WeightToFee, xcm_config::{CheckingAccount, TrustBackedAssetsPalletLocation, XcmConfig}, @@ -20,10 +39,11 @@ use frame_support::{ weights::{Weight, WeightToFee as WeightToFeeT}, }; use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance}; +use sp_runtime::traits::MaybeEquivalence; use std::convert::Into; use xcm::{latest::prelude::*, VersionedXcm, MAX_XCM_DECODE_DEPTH}; use xcm_executor::{ - traits::{Convert, Identity, JustTry, WeightTrader}, + traits::{Identity, JustTry, WeightTrader}, XcmExecutor, }; @@ -73,7 +93,7 @@ fn test_asset_xcm_trader() { // get asset id as multilocation let asset_multilocation = - AssetIdForTrustBackedAssetsConvert::reverse_ref(local_asset_id).unwrap(); + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(); // Set Alice as block author, who will receive fees RuntimeHelper::::run_to_block(2, Some(AccountId::from(ALICE))); @@ -156,7 +176,7 @@ fn test_asset_xcm_trader_with_refund() { // We are going to buy 4e9 weight let bought = Weight::from_parts(4_000_000_000u64, 0); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); // lets calculate amount needed let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -226,7 +246,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() { // We are going to buy 5e9 weight let bought = Weight::from_parts(500_000_000u64, 0); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -276,7 +296,7 @@ fn test_that_buying_ed_refund_does_not_refund() { let bought = Weight::from_parts(500_000_000u64, 0); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let amount_bought = WeightToFee::weight_to_fee(&bought); @@ -351,7 +371,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() { // lets calculate amount needed let asset_amount_needed = WeightToFee::weight_to_fee(&bought); - let asset_multilocation = AssetIdForTrustBackedAssetsConvert::reverse_ref(1).unwrap(); + let asset_multilocation = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap(); let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into(); @@ -466,13 +486,13 @@ fn test_assets_balances_api_works() { ))); // check trusted asset assert!(result.inner().iter().any(|asset| asset.eq(&( - AssetIdForTrustBackedAssetsConvert::reverse_ref(local_asset_id).unwrap(), + AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(), minimum_asset_balance ) .into()))); // check foreign asset assert!(result.inner().iter().any(|asset| asset.eq(&( - Identity::reverse_ref(foreign_asset_id_multilocation).unwrap(), + Identity::convert_back(&foreign_asset_id_multilocation).unwrap(), 6 * foreign_asset_minimum_asset_balance ) .into()))); diff --git a/parachains/runtimes/assets/common/Cargo.toml b/parachains/runtimes/assets/common/Cargo.toml index f8c459a922d..97965b1e2c2 100644 --- a/parachains/runtimes/assets/common/Cargo.toml +++ b/parachains/runtimes/assets/common/Cargo.toml @@ -14,6 +14,7 @@ log = { version = "0.4.18", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } # Polkadot pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } @@ -38,6 +39,7 @@ std = [ "cumulus-primitives-core/std", "sp-api/std", "sp-std/std", + "sp-runtime/std", "pallet-xcm/std", "xcm/std", "xcm-builder/std", diff --git a/parachains/runtimes/assets/common/src/foreign_creators.rs b/parachains/runtimes/assets/common/src/foreign_creators.rs index dbdf4301d66..00f336f9c68 100644 --- a/parachains/runtimes/assets/common/src/foreign_creators.rs +++ b/parachains/runtimes/assets/common/src/foreign_creators.rs @@ -18,16 +18,16 @@ use frame_support::traits::{ }; use pallet_xcm::{EnsureXcm, Origin as XcmOrigin}; use xcm::latest::MultiLocation; -use xcm_executor::traits::Convert; +use xcm_executor::traits::ConvertLocation; -// `EnsureOriginWithArg` impl for `CreateOrigin` that allows only XCM origins that are locations -// containing the class location. +/// `EnsureOriginWithArg` impl for `CreateOrigin` that allows only XCM origins that are locations +/// containing the class location. pub struct ForeignCreators( sp_std::marker::PhantomData<(IsForeign, AccountOf, AccountId)>, ); impl< IsForeign: ContainsPair, - AccountOf: Convert, + AccountOf: ConvertLocation, AccountId: Clone, RuntimeOrigin: From + OriginTrait + Clone, > EnsureOriginWithArg @@ -46,7 +46,7 @@ where if !IsForeign::contains(asset_location, &origin_location) { return Err(origin) } - AccountOf::convert(origin_location).map_err(|_| origin) + AccountOf::convert_location(&origin_location).ok_or(origin) } #[cfg(feature = "runtime-benchmarks")] diff --git a/parachains/runtimes/assets/common/src/fungible_conversion.rs b/parachains/runtimes/assets/common/src/fungible_conversion.rs index 8ffb44b086b..00f0c40d611 100644 --- a/parachains/runtimes/assets/common/src/fungible_conversion.rs +++ b/parachains/runtimes/assets/common/src/fungible_conversion.rs @@ -17,10 +17,11 @@ use crate::runtime_api::FungiblesAccessError; use frame_support::traits::Contains; +use sp_runtime::traits::MaybeEquivalence; use sp_std::{borrow::Borrow, vec::Vec}; use xcm::latest::{MultiAsset, MultiLocation}; use xcm_builder::{ConvertedConcreteId, MatchedConvertedConcreteId}; -use xcm_executor::traits::{Convert, MatchesFungibles}; +use xcm_executor::traits::MatchesFungibles; /// Converting any [`(AssetId, Balance)`] to [`MultiAsset`] pub trait MultiAssetConverter: @@ -28,8 +29,8 @@ pub trait MultiAssetConverter: where AssetId: Clone, Balance: Clone, - ConvertAssetId: Convert, - ConvertBalance: Convert, + ConvertAssetId: MaybeEquivalence, + ConvertBalance: MaybeEquivalence, { fn convert_ref( value: impl Borrow<(AssetId, Balance)>, @@ -39,8 +40,8 @@ where impl< AssetId: Clone, Balance: Clone, - ConvertAssetId: Convert, - ConvertBalance: Convert, + ConvertAssetId: MaybeEquivalence, + ConvertBalance: MaybeEquivalence, > MultiAssetConverter for ConvertedConcreteId { @@ -48,12 +49,12 @@ impl< value: impl Borrow<(AssetId, Balance)>, ) -> Result { let (asset_id, balance) = value.borrow(); - match ConvertAssetId::reverse_ref(asset_id) { - Ok(asset_id_as_multilocation) => match ConvertBalance::reverse_ref(balance) { - Ok(amount) => Ok((asset_id_as_multilocation, amount).into()), - Err(_) => Err(FungiblesAccessError::AmountToBalanceConversionFailed), + match ConvertAssetId::convert_back(asset_id) { + Some(asset_id_as_multilocation) => match ConvertBalance::convert_back(balance) { + Some(amount) => Ok((asset_id_as_multilocation, amount).into()), + None => Err(FungiblesAccessError::AmountToBalanceConversionFailed), }, - Err(_) => Err(FungiblesAccessError::AssetIdConversionFailed), + None => Err(FungiblesAccessError::AssetIdConversionFailed), } } } @@ -62,8 +63,8 @@ impl< AssetId: Clone, Balance: Clone, MatchAssetId: Contains, - ConvertAssetId: Convert, - ConvertBalance: Convert, + ConvertAssetId: MaybeEquivalence, + ConvertBalance: MaybeEquivalence, > MultiAssetConverter for MatchedConvertedConcreteId { @@ -71,12 +72,12 @@ impl< value: impl Borrow<(AssetId, Balance)>, ) -> Result { let (asset_id, balance) = value.borrow(); - match ConvertAssetId::reverse_ref(asset_id) { - Ok(asset_id_as_multilocation) => match ConvertBalance::reverse_ref(balance) { - Ok(amount) => Ok((asset_id_as_multilocation, amount).into()), - Err(_) => Err(FungiblesAccessError::AmountToBalanceConversionFailed), + match ConvertAssetId::convert_back(asset_id) { + Some(asset_id_as_multilocation) => match ConvertBalance::convert_back(balance) { + Some(amount) => Ok((asset_id_as_multilocation, amount).into()), + None => Err(FungiblesAccessError::AmountToBalanceConversionFailed), }, - Err(_) => Err(FungiblesAccessError::AssetIdConversionFailed), + None => Err(FungiblesAccessError::AssetIdConversionFailed), } } } @@ -88,8 +89,8 @@ pub fn convert<'a, AssetId, Balance, ConvertAssetId, ConvertBalance, Converter>( where AssetId: Clone + 'a, Balance: Clone + 'a, - ConvertAssetId: Convert, - ConvertBalance: Convert, + ConvertAssetId: MaybeEquivalence, + ConvertBalance: MaybeEquivalence, Converter: MultiAssetConverter, { items.map(Converter::convert_ref).collect() diff --git a/parachains/runtimes/assets/common/src/lib.rs b/parachains/runtimes/assets/common/src/lib.rs index 8a321ad97aa..bdd127c9143 100644 --- a/parachains/runtimes/assets/common/src/lib.rs +++ b/parachains/runtimes/assets/common/src/lib.rs @@ -80,8 +80,9 @@ pub type ForeignAssetsConvertedConcreteId::reverse_ref( - local_asset_id + AssetIdForTrustBackedAssetsConvert::::convert_back( + &local_asset_id ) .unwrap(), expected_reverse_ref ); assert_eq!( - AssetIdForTrustBackedAssetsConvert::::convert_ref( - expected_reverse_ref + AssetIdForTrustBackedAssetsConvert::::convert( + &expected_reverse_ref ) .unwrap(), local_asset_id diff --git a/parachains/runtimes/assets/test-utils/src/test_cases.rs b/parachains/runtimes/assets/test-utils/src/test_cases.rs index 366c1922cda..162239a8d2a 100644 --- a/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -27,11 +27,11 @@ use parachains_runtimes_test_utils::{ RuntimeHelper, ValidatorIdOf, XcmReceivedFrom, }; use sp_runtime::{ - traits::{StaticLookup, Zero}, + traits::{MaybeEquivalence, StaticLookup, Zero}, DispatchError, Saturating, }; use xcm::latest::prelude::*; -use xcm_executor::{traits::Convert, XcmExecutor}; +use xcm_executor::{traits::ConvertLocation, XcmExecutor}; /// Test-case makes sure that `Runtime` can receive native asset from relay chain /// and can teleport it back and to the other parachains @@ -308,7 +308,7 @@ pub fn teleports_for_foreign_assets_works< >, WeightToFee: frame_support::weights::WeightToFee, ::Balance: From + Into, - SovereignAccountOf: Convert>, + SovereignAccountOf: ConvertLocation>, >::AssetId: From + Into, >::AssetIdParameter: @@ -330,7 +330,8 @@ pub fn teleports_for_foreign_assets_works< // foreign creator, which can be sibling parachain to match ForeignCreators let foreign_creator = MultiLocation { parents: 1, interior: X1(Parachain(foreign_para_id)) }; - let foreign_creator_as_account_id = SovereignAccountOf::convert(foreign_creator).expect(""); + let foreign_creator_as_account_id = + SovereignAccountOf::convert_location(&foreign_creator).expect(""); // we want to buy execution with local relay chain currency let buy_execution_fee_amount = @@ -744,7 +745,7 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works< From<::AccountId>, AssetsPalletInstance: 'static, AssetId: Clone + Copy, - AssetIdConverter: Convert, + AssetIdConverter: MaybeEquivalence, { ExtBuilder::::default() .with_collators(collator_session_keys.collators()) @@ -759,7 +760,7 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works< .execute_with(|| { // create some asset class let asset_minimum_asset_balance = 3333333_u128; - let asset_id_as_multilocation = AssetIdConverter::reverse_ref(asset_id).unwrap(); + let asset_id_as_multilocation = AssetIdConverter::convert_back(&asset_id).unwrap(); assert_ok!(>::force_create( RuntimeHelper::::root_origin(), asset_id.into(), @@ -1002,7 +1003,7 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor XcmConfig: xcm_executor::Config, WeightToFee: frame_support::weights::WeightToFee, ::Balance: From + Into, - SovereignAccountOf: Convert>, + SovereignAccountOf: ConvertLocation>, >::AssetId: From + Into, >::AssetIdParameter: @@ -1015,16 +1016,17 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor From<::AccountId>, ForeignAssetsPalletInstance: 'static, AssetId: Clone + Copy, - AssetIdConverter: Convert, + AssetIdConverter: MaybeEquivalence, { // foreign parachain with the same consenus currency as asset let foreign_asset_id_multilocation = MultiLocation { parents: 1, interior: X2(Parachain(2222), GeneralIndex(1234567)) }; - let asset_id = AssetIdConverter::convert(foreign_asset_id_multilocation).unwrap(); + let asset_id = AssetIdConverter::convert(&foreign_asset_id_multilocation).unwrap(); // foreign creator, which can be sibling parachain to match ForeignCreators let foreign_creator = MultiLocation { parents: 1, interior: X1(Parachain(2222)) }; - let foreign_creator_as_account_id = SovereignAccountOf::convert(foreign_creator).expect(""); + let foreign_creator_as_account_id = + SovereignAccountOf::convert_location(&foreign_creator).expect(""); // we want to buy execution with local relay chain currency let buy_execution_fee_amount = @@ -1204,7 +1206,7 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor // lets try create asset for different parachain(3333) (foreign_creator(2222) can create just his assets) let foreign_asset_id_multilocation = MultiLocation { parents: 1, interior: X2(Parachain(3333), GeneralIndex(1234567)) }; - let asset_id = AssetIdConverter::convert(foreign_asset_id_multilocation).unwrap(); + let asset_id = AssetIdConverter::convert(&foreign_asset_id_multilocation).unwrap(); // prepare data for xcm::Transact(create) let foreign_asset_create = runtime_call_encode(pallet_assets::Call::< diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 03838d29092..0a468e7fcaf 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -389,7 +389,7 @@ macro_rules! __impl_relay { } pub fn sovereign_account_id_of(location: $crate::MultiLocation) -> $crate::AccountId { - ::SovereignAccountOf::convert(location.into()).unwrap() + ::SovereignAccountOf::convert_location(&location).unwrap() } pub fn fund_accounts(accounts: Vec<(AccountId, Balance)>) { @@ -654,7 +654,7 @@ macro_rules! __impl_parachain { } pub fn sovereign_account_id_of(location: $crate::MultiLocation) -> $crate::AccountId { - ::LocationToAccountId::convert(location.into()).unwrap() + ::LocationToAccountId::convert_location(&location).unwrap() } pub fn fund_accounts(accounts: Vec<(AccountId, Balance)>) {