From d31223e54459aaa0b9440580dd4565c9f4456dfb Mon Sep 17 00:00:00 2001 From: Daanvdplas Date: Mon, 13 Jan 2025 17:29:56 +0200 Subject: [PATCH] test: xcm config reserves --- runtime/mainnet/src/config/xcm.rs | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/runtime/mainnet/src/config/xcm.rs b/runtime/mainnet/src/config/xcm.rs index f7cc1654..cd8974b6 100644 --- a/runtime/mainnet/src/config/xcm.rs +++ b/runtime/mainnet/src/config/xcm.rs @@ -228,3 +228,50 @@ impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; } + +#[cfg(test)] +mod tests { + use std::any::TypeId; + + use super::*; + + // Reserves accepted for native assets (except relay) and relay asset from Asset Hub. + #[test] + fn reserves() { + assert_eq!( + TypeId::of::<::IsReserve>(), + TypeId::of::<(NativeAssetExceptRelay, RelayAssetFromAssetHub,)>(), + ); + } + + #[test] + fn asset_hub_accepted_as_relay_asset_reserve() { + assert!(TrustedReserves::contains( + &Asset::from((AssetId::from(Parent), Fungibility::from(100u128))), + &AssetHub::get(), + )); + } + + #[test] + fn accept_native_assets_except_of_relay() { + let chain = Location::new(1, [Parachain(4242)]); + let native_asset = Asset::from((AssetId::from(chain.clone()), Fungibility::from(100u128))); + assert!(TrustedReserves::contains(&native_asset, &chain)); + + let relay_asset = Asset::from((AssetId::from(Parent), Fungibility::from(100u128))); + assert!(!TrustedReserves::contains(&relay_asset, &Parent.into())); + } + + #[test] + fn decline_non_native_assets() { + // Native asset X of chain Y example. + let chain_x = Location::new(1, [Parachain(4242)]); + let chain_y = Location::new(1, [Parachain(6969)]); + let chain_x_asset = Asset::from((AssetId::from(chain_x), Fungibility::from(100u128))); + assert!(!TrustedReserves::contains(&chain_x_asset, &chain_y)); + // `pallet-assets` example. + let usd = Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(1337)]); + let usd_asset = Asset::from((AssetId::from(usd), Fungibility::from(100u128))); + assert!(!TrustedReserves::contains(&usd_asset, &chain_y)); + } +}