Skip to content

Commit

Permalink
fix rust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzamontiel committed Jan 7, 2025
1 parent a75ef40 commit c365093
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 52 deletions.
8 changes: 4 additions & 4 deletions pallets/moonbeam-foreign-assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate as pallet_moonbeam_foreign_assets;

use frame_support::traits::Everything;
use frame_support::{construct_runtime, pallet_prelude::*, parameter_types};
use frame_system::EnsureRoot;
use frame_system::{EnsureRoot, EnsureSigned};
use pallet_evm::{FrameSystemAccountProvider, SubstrateBlockHashMapping};
use precompile_utils::testing::MockAccount;
use sp_core::{H256, U256};
Expand Down Expand Up @@ -178,14 +178,14 @@ impl sp_runtime::traits::Convert<AccountId, H160> for AccountIdToH160 {
}

parameter_types! {
pub const ForeignAssetCreationDeposit: u64 = 1;
pub const ForeignAssetCreationDeposit: u128 = 0;
}

impl crate::Config for Test {
type AccountIdToH160 = AccountIdToH160;
type AssetIdFilter = Everything;
type EvmRunner = pallet_evm::runner::stack::Runner<Self>;
type ForeignAssetCreatorOrigin = EnsureRoot<AccountId>;
type ForeignAssetCreatorOrigin = EnsureSigned<AccountId>;
type ForeignAssetFreezerOrigin = EnsureRoot<AccountId>;
type ForeignAssetModifierOrigin = EnsureRoot<AccountId>;
type ForeignAssetUnfreezerOrigin = EnsureRoot<AccountId>;
Expand All @@ -194,7 +194,7 @@ impl crate::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type XcmLocationToH160 = ();
type ForeignAssetCreationDeposit = ();
type ForeignAssetCreationDeposit = ForeignAssetCreationDeposit;
type Balance = Balance;

type Currency = Balances;
Expand Down
12 changes: 6 additions & 6 deletions pallets/moonbeam-foreign-assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn create_foreign_and_freeze_unfreeze() {
assert_eq!(
EvmForeignAssets::assets_creation_details(&1),
Some(AssetCreationDetails {
creator: Alice.into(),
deposit: 1
owner: AssetOwner::Account(Alice.into()),
deposit: Some(ForeignAssetCreationDeposit::get())
})
);

Expand All @@ -65,7 +65,7 @@ fn create_foreign_and_freeze_unfreeze() {
]),
asset_id: 1,
xcm_location: Location::parent(),
deposit: 1,
deposit: Some(ForeignAssetCreationDeposit::get()),
}]);

let (xcm_location, asset_id): (Location, u128) = get_asset_created_hook_invocation()
Expand All @@ -82,8 +82,8 @@ fn create_foreign_and_freeze_unfreeze() {
assert_eq!(
EvmForeignAssets::assets_creation_details(&1),
Some(AssetCreationDetails {
creator: Alice.into(),
deposit: 1
owner: AssetOwner::Account(Alice.into()),
deposit: Some(1)
})
);

Expand Down Expand Up @@ -212,7 +212,7 @@ fn test_root_can_change_foreign_asset_for_asset_id() {
]),
asset_id: 1,
xcm_location: Location::parent(),
deposit: 1,
deposit: Some(ForeignAssetCreationDeposit::get()),
},
crate::Event::ForeignAssetXcmLocationChanged {
asset_id: 1,
Expand Down
7 changes: 5 additions & 2 deletions pallets/moonbeam-lazy-migrations/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use super::*;
use crate as pallet_moonbeam_lazy_migrations;
use frame_support::traits::AsEnsureOriginWithArg;
use frame_support::traits::{AsEnsureOriginWithArg, ConstU128};
use frame_support::weights::constants::RocksDbWeight;
use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight};
use frame_system::{EnsureRoot, EnsureSigned};
Expand Down Expand Up @@ -292,7 +292,7 @@ impl pallet_moonbeam_foreign_assets::Config for Test {
type AccountIdToH160 = AccountIdToH160;
type AssetIdFilter = Everything;
type EvmRunner = pallet_evm::runner::stack::Runner<Self>;
type ForeignAssetCreatorOrigin = EnsureRoot<AccountId>;
type ForeignAssetCreatorOrigin = EnsureSigned<AccountId>;
type ForeignAssetFreezerOrigin = EnsureRoot<AccountId>;
type ForeignAssetModifierOrigin = EnsureRoot<AccountId>;
type ForeignAssetUnfreezerOrigin = EnsureRoot<AccountId>;
Expand All @@ -301,6 +301,9 @@ impl pallet_moonbeam_foreign_assets::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type XcmLocationToH160 = ();
type ForeignAssetCreationDeposit = ConstU128<1>;
type Balance = Balance;
type Currency = Balances;
}

impl Config for Test {
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl ExtBuilder {
for xcm_asset_initialization in xcm_assets {
let asset_id = xcm_asset_initialization.asset_id;
EvmForeignAssets::create_foreign_asset(
root_origin(),
moonbase_runtime::RuntimeOrigin::signed(AccountId::from(ALICE)),
asset_id,
xcm_asset_initialization.xcm_location,
xcm_asset_initialization.decimals,
Expand Down
84 changes: 45 additions & 39 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,48 +1266,54 @@ fn update_reward_address_via_precompile() {

#[test]
fn create_and_manipulate_foreign_asset() {
ExtBuilder::default().build().execute_with(|| {
let source_location = xcm::v4::Location::parent();
let alice = AccountId::from(ALICE);
ExtBuilder::default()
.with_balances(vec![
(alice, 1_000 * UNIT),
])
.build()
.execute_with(|| {
let source_location = xcm::v4::Location::parent();

// Create foreign asset
assert_ok!(EvmForeignAssets::create_foreign_asset(
moonbase_runtime::RuntimeOrigin::root(),
1,
source_location.clone(),
12,
bounded_vec![b'M', b'T'],
bounded_vec![b'M', b'y', b'T', b'o', b'k'],
));
assert_eq!(
EvmForeignAssets::assets_by_id(1),
Some(source_location.clone())
);
assert_eq!(
EvmForeignAssets::assets_by_location(&source_location),
Some((1, AssetStatus::Active))
);
// Create foreign asset
assert_ok!(EvmForeignAssets::create_foreign_asset(
moonbase_runtime::RuntimeOrigin::signed(alice),
1,
source_location.clone(),
12,
bounded_vec![b'M', b'T'],
bounded_vec![b'M', b'y', b'T', b'o', b'k'],
));
assert_eq!(
EvmForeignAssets::assets_by_id(1),
Some(source_location.clone())
);
assert_eq!(
EvmForeignAssets::assets_by_location(&source_location),
Some((1, AssetStatus::Active))
);

// Freeze foreign asset
assert_ok!(EvmForeignAssets::freeze_foreign_asset(
moonbase_runtime::RuntimeOrigin::root(),
1,
true
));
assert_eq!(
EvmForeignAssets::assets_by_location(&source_location),
Some((1, AssetStatus::FrozenXcmDepositAllowed))
);
// Freeze foreign asset
assert_ok!(EvmForeignAssets::freeze_foreign_asset(
root_origin(),
1,
true
));
assert_eq!(
EvmForeignAssets::assets_by_location(&source_location),
Some((1, AssetStatus::FrozenXcmDepositAllowed))
);

// Unfreeze foreign asset
assert_ok!(EvmForeignAssets::unfreeze_foreign_asset(
moonbase_runtime::RuntimeOrigin::root(),
1,
));
assert_eq!(
EvmForeignAssets::assets_by_location(&source_location),
Some((1, AssetStatus::Active))
);
});
// Unfreeze foreign asset
assert_ok!(EvmForeignAssets::unfreeze_foreign_asset(
root_origin(),
1,
));
assert_eq!(
EvmForeignAssets::assets_by_location(&source_location),
Some((1, AssetStatus::Active))
);
});
}

// The precoompile asset-erc20 is deprecated and not used anymore for new evm foreign assets
Expand Down

0 comments on commit c365093

Please sign in to comment.