From 06f9cc59055ad5b1a063edfc4b6f527e775b7107 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 15 Nov 2024 12:18:24 -0300 Subject: [PATCH] chore: deduplicate test in asset hub westend and rococo --- Cargo.lock | 1 + .../assets/asset-hub-rococo/tests/tests.rs | 26 ++---------- .../assets/asset-hub-westend/tests/tests.rs | 26 ++---------- .../runtimes/assets/test-utils/Cargo.toml | 1 + .../assets/test-utils/src/test_cases.rs | 40 ++++++++++++++++++- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 775a7fe99e1e..baf99392cefb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1094,6 +1094,7 @@ dependencies = [ "staging-xcm-builder 7.0.0", "staging-xcm-executor 7.0.0", "substrate-wasm-builder 17.0.0", + "xcm-runtime-apis 0.1.0", ] [[package]] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index 968c96571624..94f37767cfea 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -27,7 +27,7 @@ use asset_hub_rococo_runtime::{ AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - SessionKeys, TrustBackedAssetsInstance, XcmpQueue, + SessionKeys, TrustBackedAssetsInstance, XcmpQueue, Block, }; use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, @@ -1473,26 +1473,6 @@ fn location_conversion_works() { } #[test] -fn calling_payment_api_with_a_lower_version_works() { - use xcm::prelude::*; - use xcm_runtime_apis::fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1; - - ExtBuilder::::default().build().execute_with(|| { - let transfer_amount = 100u128; - let xcm_to_weigh = Xcm::::builder_unsafe() - .withdraw_asset((Here, transfer_amount)) - .buy_execution((Here, transfer_amount), Unlimited) - .deposit_asset(AllCounted(1), [1u8; 32]) - .build(); - let versioned_xcm_to_weigh = VersionedXcm::from(xcm_to_weigh.clone().into()); - let lower_version_xcm_to_weigh = - versioned_xcm_to_weigh.into_version(XCM_VERSION - 1).unwrap(); - let xcm_weight = Runtime::query_xcm_weight(lower_version_xcm_to_weigh); - assert!(xcm_weight.is_ok()); - let native_token = VersionedAssetId::from(AssetId(Parent.into())); - let lower_version_native_token = native_token.into_version(XCM_VERSION - 1).unwrap(); - let execution_fees = - Runtime::query_weight_to_asset_fee(xcm_weight.unwrap(), lower_version_native_token); - assert!(execution_fees.is_ok()); - }); +fn xcm_payment_api_works() { + asset_test_utils::test_cases::xcm_payment_api_works::(); } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index eca2fc661e6c..cd4cdfff3069 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -27,7 +27,7 @@ use asset_hub_westend_runtime::{ AllPalletsWithoutSystem, Assets, Balances, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, - TrustBackedAssetsInstance, XcmpQueue, + TrustBackedAssetsInstance, XcmpQueue, Block, }; pub use asset_hub_westend_runtime::{AssetConversion, AssetDeposit, CollatorSelection, System}; use asset_test_utils::{ @@ -1448,26 +1448,6 @@ fn location_conversion_works() { } #[test] -fn calling_payment_api_with_a_lower_version_works() { - use xcm::prelude::*; - use xcm_runtime_apis::fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1; - - ExtBuilder::::default().build().execute_with(|| { - let transfer_amount = 100u128; - let xcm_to_weigh = Xcm::::builder_unsafe() - .withdraw_asset((Here, transfer_amount)) - .buy_execution((Here, transfer_amount), Unlimited) - .deposit_asset(AllCounted(1), [1u8; 32]) - .build(); - let versioned_xcm_to_weigh = VersionedXcm::from(xcm_to_weigh.clone().into()); - let lower_version_xcm_to_weigh = - versioned_xcm_to_weigh.into_version(XCM_VERSION - 1).unwrap(); - let xcm_weight = Runtime::query_xcm_weight(lower_version_xcm_to_weigh); - assert!(xcm_weight.is_ok()); - let native_token = VersionedAssetId::from(AssetId(Parent.into())); - let lower_version_native_token = native_token.into_version(XCM_VERSION - 1).unwrap(); - let execution_fees = - Runtime::query_weight_to_asset_fee(xcm_weight.unwrap(), lower_version_native_token); - assert!(execution_fees.is_ok()); - }); +fn xcm_payment_api_works() { + asset_test_utils::test_cases::xcm_payment_api_works::(); } diff --git a/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml b/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml index 529d6460fc4e..c1f29d2c3d9d 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/test-utils/Cargo.toml @@ -36,6 +36,7 @@ xcm = { workspace = true } xcm-builder = { workspace = true } xcm-executor = { workspace = true } pallet-xcm = { workspace = true } +xcm-runtime-apis = { workspace = true } # Bridges pallet-xcm-bridge-hub-router = { workspace = true } diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 8dc720e27753..5aa5c6ad9cb3 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -34,7 +34,7 @@ use parachains_runtimes_test_utils::{ CollatorSessionKeys, ExtBuilder, SlotDurations, ValidatorIdOf, XcmReceivedFrom, }; use sp_runtime::{ - traits::{MaybeEquivalence, StaticLookup, Zero}, + traits::{MaybeEquivalence, StaticLookup, Zero, Block as BlockT}, DispatchError, Saturating, }; use xcm::{latest::prelude::*, VersionedAssets}; @@ -1584,3 +1584,41 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works< ); }) } + +use xcm_runtime_apis::fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1; + +pub fn xcm_payment_api_works() +where + Runtime: XcmPaymentApiV1 + + frame_system::Config + + pallet_balances::Config + + pallet_session::Config + + pallet_xcm::Config + + parachain_info::Config + + pallet_collator_selection::Config + + cumulus_pallet_parachain_system::Config + + cumulus_pallet_xcmp_queue::Config + + pallet_timestamp::Config, + ValidatorIdOf: From>, +{ + use xcm::prelude::*; + + ExtBuilder::::default().build().execute_with(|| { + let transfer_amount = 100u128; + let xcm_to_weigh = Xcm::::builder_unsafe() + .withdraw_asset((Here, transfer_amount)) + .buy_execution((Here, transfer_amount), Unlimited) + .deposit_asset(AllCounted(1), [1u8; 32]) + .build(); + let versioned_xcm_to_weigh = VersionedXcm::from(xcm_to_weigh.clone().into()); + let lower_version_xcm_to_weigh = + versioned_xcm_to_weigh.into_version(XCM_VERSION - 1).unwrap(); + let xcm_weight = Runtime::query_xcm_weight(lower_version_xcm_to_weigh); + assert!(xcm_weight.is_ok()); + let native_token = VersionedAssetId::from(AssetId(Parent.into())); + let lower_version_native_token = native_token.into_version(XCM_VERSION - 1).unwrap(); + let execution_fees = + Runtime::query_weight_to_asset_fee(xcm_weight.unwrap(), lower_version_native_token); + assert!(execution_fees.is_ok()); + }); +}