From 2b2826d37f80385600127601e66dfa8bd40fe269 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 30 Jan 2025 12:52:13 +0200 Subject: [PATCH] test: add tests --- runtime/moonbase/src/xcm_config.rs | 10 +--- runtime/moonbase/tests/integration_test.rs | 59 +++++++++++++++++++++- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index 857b7ad6ea..31627fb34f 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -67,6 +67,7 @@ use xcm_primitives::{ }; use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; +use crate::runtime_params::dynamic_params; use pallet_moonbeam_foreign_assets::{MapSuccessToGovernance, MapSuccessToXcm}; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; @@ -698,13 +699,6 @@ impl frame_support::traits::Contains for EvmForeignAssetIdFilter { } } -parameter_types! { - /// Balance in the native currency that will be reserved from the user - /// to create a new foreign asset - pub ForeignAssetCreationDeposit: u128 = - runtime_params::dynamic_params::xcm_config::ForeignAssetCreationDeposit::get(); -} - pub type ForeignAssetManagerOrigin = EitherOf< MapSuccessToXcm>, MapSuccessToGovernance< @@ -738,7 +732,7 @@ impl pallet_moonbeam_foreign_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = moonbase_weights::pallet_moonbeam_foreign_assets::WeightInfo; type XcmLocationToH160 = LocationToH160; - type ForeignAssetCreationDeposit = ForeignAssetCreationDeposit; + type ForeignAssetCreationDeposit = dynamic_params::xcm_config::ForeignAssetCreationDeposit; type Balance = Balance; type Currency = Balances; } diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 24902e66e6..2bc9aae907 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -56,6 +56,7 @@ use xcm_executor::traits::ConvertLocation; use moonbase_runtime::currency::{GIGAWEI, WEI}; //use pallet_evm_precompileset_assets_erc20::{SELECTOR_LOG_APPROVAL, SELECTOR_LOG_TRANSFER}; use moonbase_runtime::runtime_params::dynamic_params; +use moonbase_runtime::xcm_config::LocationToAccountId; use moonbeam_xcm_benchmarks::weights::XcmWeight; use moonkit_xcm_primitives::AccountIdAssetIdConversion; use nimbus_primitives::NimbusId; @@ -1248,7 +1249,7 @@ fn update_reward_address_via_precompile() { } #[test] -fn create_and_manipulate_foreign_asset() { +fn create_and_manipulate_foreign_asset_using_root() { ExtBuilder::default().build().execute_with(|| { let source_location = xcm::v4::Location::parent(); @@ -1293,6 +1294,62 @@ fn create_and_manipulate_foreign_asset() { }); } +#[test] +fn create_and_manipulate_foreign_asset_using_sibling() { + ExtBuilder::default().build().execute_with(|| { + let asset_location: Location = (Parent, Parachain(1), PalletInstance(3)).into(); + let para_location = asset_location.chain_location(); + let para_account = + LocationToAccountId::convert_location(¶_location).expect("Cannot convert location"); + + let deposit = dynamic_params::xcm_config::ForeignAssetCreationDeposit::get(); + Balances::make_free_balance_be(¶_account, deposit * 2); + + // Create foreign asset + assert_ok!(EvmForeignAssets::create_foreign_asset( + pallet_xcm::Origin::Xcm(para_location.clone()).into(), + 1, + asset_location.clone(), + 12, + bounded_vec![b'M', b'T'], + bounded_vec![b'M', b'y', b'T', b'o', b'k'], + )); + + // deposit is taken from the account + assert_eq!(Balances::free_balance(¶_account), deposit); + + assert_eq!( + EvmForeignAssets::assets_by_id(1), + Some(asset_location.clone()) + ); + assert_eq!( + EvmForeignAssets::assets_by_location(&asset_location), + Some((1, AssetStatus::Active)) + ); + + // Freeze foreign asset + assert_ok!(EvmForeignAssets::freeze_foreign_asset( + pallet_xcm::Origin::Xcm(para_location.clone()).into(), + 1, + true + )); + assert_eq!( + EvmForeignAssets::assets_by_location(&asset_location), + Some((1, AssetStatus::FrozenXcmDepositAllowed)) + ); + + // Unfreeze foreign asset + assert_ok!(EvmForeignAssets::unfreeze_foreign_asset( + pallet_xcm::Origin::Xcm(para_location.clone()).into(), + 1, + )); + assert_eq!( + EvmForeignAssets::assets_by_location(&asset_location), + Some((1, AssetStatus::Active)) + ); + }); +} + // The precoompile asset-erc20 is deprecated and not used anymore for new evm foreign assets // We don't have testing tools in rust test to call real evm smart contract, so we rely on ts tests. /*