mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Add Foreign Assets to Statemint (#2540)
* add foreign assets to statemint * make review changes * two dots --------- Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use asset_test_utils::{CollatorSessionKeys, ExtBuilder, RuntimeHelper};
|
||||
use codec::Decode;
|
||||
use codec::{Decode, Encode};
|
||||
use cumulus_primitives_utility::ChargeWeightInFungibles;
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok,
|
||||
@@ -11,17 +11,18 @@ use parachains_common::{
|
||||
};
|
||||
use statemint_runtime::xcm_config::{
|
||||
AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, DotLocation,
|
||||
TrustBackedAssetsPalletLocation,
|
||||
ForeignCreatorsSovereignAccountOf, TrustBackedAssetsPalletLocation, XcmConfig,
|
||||
};
|
||||
pub use statemint_runtime::{
|
||||
constants::fee::WeightToFee, xcm_config::XcmConfig, AssetDeposit, Assets, Balances,
|
||||
ExistentialDeposit, ParachainSystem, Runtime, RuntimeEvent, SessionKeys, System,
|
||||
TrustBackedAssetsInstance,
|
||||
constants::fee::WeightToFee, AssetDeposit, Assets, Balances, ExistentialDeposit, ForeignAssets,
|
||||
ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, Runtime,
|
||||
RuntimeCall, RuntimeEvent, SessionKeys, System, TrustBackedAssetsInstance,
|
||||
};
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_executor::traits::{Convert, WeightTrader};
|
||||
use xcm_executor::traits::{Convert, Identity, JustTry, WeightTrader};
|
||||
|
||||
const ALICE: [u8; 32] = [1u8; 32];
|
||||
const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
|
||||
|
||||
type AssetIdForTrustBackedAssetsConvert =
|
||||
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
|
||||
@@ -390,9 +391,15 @@ fn test_assets_balances_api_works() {
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let local_asset_id = 1;
|
||||
let foreign_asset_id_multilocation =
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1234), GeneralIndex(12345)) };
|
||||
|
||||
// check before
|
||||
assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0);
|
||||
assert_eq!(
|
||||
ForeignAssets::balance(foreign_asset_id_multilocation, AccountId::from(ALICE)),
|
||||
0
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0);
|
||||
assert!(Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
@@ -423,18 +430,40 @@ fn test_assets_balances_api_works() {
|
||||
minimum_asset_balance
|
||||
));
|
||||
|
||||
// create foreign asset
|
||||
let foreign_asset_minimum_asset_balance = 3333333_u128;
|
||||
assert_ok!(ForeignAssets::force_create(
|
||||
RuntimeHelper::<Runtime>::root_origin(),
|
||||
foreign_asset_id_multilocation,
|
||||
AccountId::from(SOME_ASSET_ADMIN).into(),
|
||||
false,
|
||||
foreign_asset_minimum_asset_balance
|
||||
));
|
||||
|
||||
// We first mint enough asset for the account to exist for assets
|
||||
assert_ok!(ForeignAssets::mint(
|
||||
RuntimeHelper::<Runtime>::origin_of(AccountId::from(SOME_ASSET_ADMIN)),
|
||||
foreign_asset_id_multilocation,
|
||||
AccountId::from(ALICE).into(),
|
||||
6 * foreign_asset_minimum_asset_balance
|
||||
));
|
||||
|
||||
// check after
|
||||
assert_eq!(
|
||||
Assets::balance(local_asset_id, AccountId::from(ALICE)),
|
||||
minimum_asset_balance
|
||||
);
|
||||
assert_eq!(
|
||||
ForeignAssets::balance(foreign_asset_id_multilocation, AccountId::from(ALICE)),
|
||||
6 * minimum_asset_balance
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency);
|
||||
|
||||
let result: MultiAssets = Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
assert_eq!(result.len(), 2);
|
||||
assert_eq!(result.len(), 3);
|
||||
|
||||
// check currency
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(
|
||||
@@ -449,6 +478,12 @@ fn test_assets_balances_api_works() {
|
||||
minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
// check foreign asset
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
Identity::reverse_ref(foreign_asset_id_multilocation).unwrap(),
|
||||
6 * foreign_asset_minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -475,6 +510,34 @@ asset_test_utils::include_teleports_for_native_asset_works!(
|
||||
1000
|
||||
);
|
||||
|
||||
asset_test_utils::include_teleports_for_foreign_assets_works!(
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
CheckingAccount,
|
||||
WeightToFee,
|
||||
ParachainSystem,
|
||||
ForeignCreatorsSovereignAccountOf,
|
||||
ForeignAssetsInstance,
|
||||
asset_test_utils::CollatorSessionKeys::new(
|
||||
AccountId::from(ALICE),
|
||||
AccountId::from(ALICE),
|
||||
SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }
|
||||
),
|
||||
ExistentialDeposit::get(),
|
||||
Box::new(|runtime_event_encoded: Vec<u8>| {
|
||||
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
||||
Ok(RuntimeEvent::PolkadotXcm(event)) => Some(event),
|
||||
_ => None,
|
||||
}
|
||||
}),
|
||||
Box::new(|runtime_event_encoded: Vec<u8>| {
|
||||
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
||||
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
asset_test_utils::include_asset_transactor_transfer_with_local_consensus_currency_works!(
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
@@ -482,14 +545,16 @@ asset_test_utils::include_asset_transactor_transfer_with_local_consensus_currenc
|
||||
ExistentialDeposit::get(),
|
||||
Box::new(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
}),
|
||||
Box::new(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
})
|
||||
);
|
||||
|
||||
asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_works!(
|
||||
asset_transactor_transfer_with_pallet_assets_instance_works,
|
||||
asset_transactor_transfer_with_trust_backed_assets_works,
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
TrustBackedAssetsInstance,
|
||||
@@ -498,6 +563,66 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
|
||||
collator_session_keys(),
|
||||
ExistentialDeposit::get(),
|
||||
12345,
|
||||
Box::new(|| {}),
|
||||
Box::new(|| {})
|
||||
Box::new(|| {
|
||||
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
}),
|
||||
Box::new(|| {
|
||||
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
})
|
||||
);
|
||||
|
||||
asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_works!(
|
||||
asset_transactor_transfer_with_foreign_assets_works,
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
ForeignAssetsInstance,
|
||||
MultiLocation,
|
||||
JustTry,
|
||||
asset_test_utils::CollatorSessionKeys::new(
|
||||
AccountId::from(ALICE),
|
||||
AccountId::from(ALICE),
|
||||
SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }
|
||||
),
|
||||
ExistentialDeposit::get(),
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1313), GeneralIndex(12345)) },
|
||||
Box::new(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
}),
|
||||
Box::new(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
})
|
||||
);
|
||||
|
||||
asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_parachain_assets_works!(
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
WeightToFee,
|
||||
ForeignCreatorsSovereignAccountOf,
|
||||
ForeignAssetsInstance,
|
||||
MultiLocation,
|
||||
JustTry,
|
||||
asset_test_utils::CollatorSessionKeys::new(
|
||||
AccountId::from(ALICE),
|
||||
AccountId::from(ALICE),
|
||||
SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }
|
||||
),
|
||||
ExistentialDeposit::get(),
|
||||
AssetDeposit::get(),
|
||||
MetadataDepositBase::get(),
|
||||
MetadataDepositPerByte::get(),
|
||||
Box::new(|pallet_asset_call| RuntimeCall::ForeignAssets(pallet_asset_call).encode()),
|
||||
Box::new(|runtime_event_encoded: Vec<u8>| {
|
||||
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
||||
Ok(RuntimeEvent::ForeignAssets(pallet_asset_event)) => Some(pallet_asset_event),
|
||||
_ => None,
|
||||
}
|
||||
}),
|
||||
Box::new(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
}),
|
||||
Box::new(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
assert_eq!(ForeignAssets::asset_ids().collect::<Vec<_>>().len(), 1);
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user