Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TarekkMA committed Jan 30, 2025
1 parent d74895b commit 2b2826d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
10 changes: 2 additions & 8 deletions runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -698,13 +699,6 @@ impl frame_support::traits::Contains<AssetId> 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<EnsureXcm<AllowSiblingsOnly>>,
MapSuccessToGovernance<
Expand Down Expand Up @@ -738,7 +732,7 @@ impl pallet_moonbeam_foreign_assets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = moonbase_weights::pallet_moonbeam_foreign_assets::WeightInfo<Runtime>;
type XcmLocationToH160 = LocationToH160;
type ForeignAssetCreationDeposit = ForeignAssetCreationDeposit;
type ForeignAssetCreationDeposit = dynamic_params::xcm_config::ForeignAssetCreationDeposit;
type Balance = Balance;
type Currency = Balances;
}
Expand Down
59 changes: 58 additions & 1 deletion runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(&para_location).expect("Cannot convert location");

let deposit = dynamic_params::xcm_config::ForeignAssetCreationDeposit::get();
Balances::make_free_balance_be(&para_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(&para_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.
/*
Expand Down

0 comments on commit 2b2826d

Please sign in to comment.