Skip to content

Commit

Permalink
chore: deduplicate test in asset hub westend and rococo
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoaguirre committed Nov 15, 2024
1 parent 430175b commit 06f9cc5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 3 additions & 23 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Runtime>::default().build().execute_with(|| {
let transfer_amount = 100u128;
let xcm_to_weigh = Xcm::<RuntimeCall>::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::<Runtime, RuntimeCall, Block>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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::<Runtime>::default().build().execute_with(|| {
let transfer_amount = 100u128;
let xcm_to_weigh = Xcm::<RuntimeCall>::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::<Runtime, RuntimeCall, Block>();
}
1 change: 1 addition & 0 deletions cumulus/parachains/runtimes/assets/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
40 changes: 39 additions & 1 deletion cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Runtime, RuntimeCall, Block: BlockT>()
where
Runtime: XcmPaymentApiV1<Block>
+ 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<Runtime>: From<AccountIdOf<Runtime>>,
{
use xcm::prelude::*;

ExtBuilder::<Runtime>::default().build().execute_with(|| {
let transfer_amount = 100u128;
let xcm_to_weigh = Xcm::<RuntimeCall>::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());
});
}

0 comments on commit 06f9cc5

Please sign in to comment.