mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Add Support for Foreign Assets (#2133)
* add foreign assets to westmint * add foreign assets to statemine * use updated api for ensure origin trait * Assets/ForeignAssets tests and fixes (#2167) * Test for create and transfer `TrustBackedAssets` with AssetTransactor * Test for transfer `local Currency` with AssetTransactor * Test for create foreign assets (covers foreign relaychain currency) * Added `ForeignFungiblesTransactor` and test for transfer `ForeignAssets` with AssetTransactor * Removed unused `pub const Local: MultiLocation` * Changed `ParaId -> Sibling` for `SiblingParachainConvertsVia` * Test for create foreign assets (covers local sibling parachain assets) * Reverted stuff for ForeignCreators from different global consensus (moved to transfer asset branch) * Refactor `weight_limit` for `execute_xcm` * Added test for `set_metadata` by ForeignCreator with `xcm::Transact(set_metadata)` * Renamed `receive_teleported_asset_works` -> `receive_teleported_asset_for_native_asset_works` * Allow `ForeignCreators` only for sibling parachains * Unify ReservedDmpWeight/ReservedXcmpWeight usage * Removed hack - replaced with `MatchedConvertedConcreteId` * Refactor `ForeignCreators` to assets-common * Add `ReceiveTeleportedAsset` test * Change test - `Utility::batch` -> Multiple `xcm::Transact` * Reusing the same deposits as for TrustBackedAssets * missing `try_successful_origin` ? * Finished `ForeignAssets` for westmint (converter, FungiblesApi, tests) * Refactoring tests - receive_teleported_asset_for_native_asset_works * ForeignAssets for statemine + refactored `receive_teleported_asset_from_foreign_creator_works` * Add `ForeignAssets` to statemine `FungiblesApi` * Add `asset_transactor_transfer_with_local_consensus_currency_works` to all runtimes * Added `asset_transactor_transfer_with_trust_backed_assets_works` test * Added `asset_transactor_transfer_with_foreign_assets_works` * Fix `missing `try_successful_origin` in implementation` * Added `create_and_manage_foreign_assets_for_local_consensus_parachain_assets_works` * Added `ExpectTransactStatus` check * Small rename * Extended `test_assets_balances_api_works` with ForeignAssets for `statemine` * PR fixes * Update parachains/runtimes/assets/test-utils/src/test_cases.rs --------- Co-authored-by: parity-processbot <> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Added `StartsWithExplicitGlobalConsensus` to ignores (#2338) * Update parachains/runtimes/assets/common/src/lib.rs Co-authored-by: Gavin Wood <gavin@parity.io> * include mint and burn in SafeCallFilter * include mint and burn in SafeCallFilter (statemine) * clarify doc * Fix compilation (moved trait `InspectMetadata`) * Fix test * Extended test for `teleport` from/to relaychain + `CheckingAccount` (Part I) * Extended test for `teleport` from/to foreign parachain + `CheckingAccount` (Part II) * Fixed TODO - `NonLocal` for `ForeignAssets` * Changed `NonLocal` to `NoChecking` * Fix weight in test --------- Co-authored-by: parity-processbot <> Co-authored-by: muharem <ismailov.m.h@gmail.com> Co-authored-by: Branislav Kontur <bkontur@gmail.com> Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
use asset_test_utils::{ExtBuilder, RuntimeHelper};
|
||||
use codec::Encode;
|
||||
use codec::Decode;
|
||||
use cumulus_primitives_utility::ChargeWeightInFungibles;
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, sp_io,
|
||||
assert_noop, assert_ok,
|
||||
traits::fungibles::InspectEnumerable,
|
||||
weights::{Weight, WeightToFee as WeightToFeeT},
|
||||
};
|
||||
use parachains_common::{AccountId, Balance, StatemintAuraId as AuraId};
|
||||
use parachains_common::{
|
||||
AccountId, AssetIdForTrustBackedAssets, Balance, StatemintAuraId as AuraId,
|
||||
};
|
||||
use statemint_runtime::xcm_config::{
|
||||
AssetFeeAsExistentialDepositMultiplierFeeCharger, DotLocation, TrustBackedAssetsPalletLocation,
|
||||
AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, DotLocation,
|
||||
TrustBackedAssetsPalletLocation,
|
||||
};
|
||||
pub use statemint_runtime::{
|
||||
constants::fee::WeightToFee, xcm_config::XcmConfig, Assets, Balances, ExistentialDeposit,
|
||||
ReservedDmpWeight, Runtime, SessionKeys, System,
|
||||
constants::fee::WeightToFee, xcm_config::XcmConfig, AssetDeposit, Assets, Balances,
|
||||
ExistentialDeposit, ParachainSystem, Runtime, RuntimeEvent, SessionKeys, System,
|
||||
TrustBackedAssetsInstance,
|
||||
};
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_executor::{
|
||||
traits::{Convert, WeightTrader},
|
||||
XcmExecutor,
|
||||
};
|
||||
use xcm_executor::traits::{Convert, WeightTrader};
|
||||
|
||||
pub const ALICE: [u8; 32] = [1u8; 32];
|
||||
const ALICE: [u8; 32] = [1u8; 32];
|
||||
|
||||
type AssetIdForTrustBackedAssetsConvert =
|
||||
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
|
||||
@@ -438,50 +440,63 @@ fn test_assets_balances_api_works() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn receive_teleported_asset_works() {
|
||||
ExtBuilder::<Runtime>::default()
|
||||
.with_collators(vec![AccountId::from(ALICE)])
|
||||
.with_session_keys(vec![(
|
||||
AccountId::from(ALICE),
|
||||
AccountId::from(ALICE),
|
||||
SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) },
|
||||
)])
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let xcm = Xcm(vec![
|
||||
ReceiveTeleportedAsset(MultiAssets::from(vec![MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 1, interior: Here }),
|
||||
fun: Fungible(10000000000000),
|
||||
}])),
|
||||
ClearOrigin,
|
||||
BuyExecution {
|
||||
fees: MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 1, interior: Here }),
|
||||
fun: Fungible(10000000000000),
|
||||
},
|
||||
weight_limit: Limited(Weight::from_parts(303531000, 65536)),
|
||||
},
|
||||
DepositAsset {
|
||||
assets: Wild(AllCounted(1)),
|
||||
beneficiary: MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 {
|
||||
network: None,
|
||||
id: [
|
||||
18, 153, 85, 112, 1, 245, 88, 21, 211, 252, 181, 60, 116, 70, 58,
|
||||
203, 12, 246, 209, 77, 70, 57, 179, 64, 152, 44, 96, 135, 127, 56,
|
||||
70, 9,
|
||||
],
|
||||
}),
|
||||
},
|
||||
},
|
||||
]);
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
asset_test_utils::include_teleports_for_native_asset_works!(
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
CheckingAccount,
|
||||
WeightToFee,
|
||||
ParachainSystem,
|
||||
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,
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
let weight_limit = ReservedDmpWeight::get();
|
||||
asset_test_utils::include_asset_transactor_transfer_with_local_consensus_currency_works!(
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
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(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
}),
|
||||
Box::new(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
})
|
||||
);
|
||||
|
||||
let outcome = XcmExecutor::<XcmConfig>::execute_xcm(Parent, xcm, hash, weight_limit);
|
||||
assert_eq!(outcome.ensure_complete(), Ok(()));
|
||||
})
|
||||
}
|
||||
asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_works!(
|
||||
asset_transactor_transfer_with_pallet_assets_instance_works,
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
TrustBackedAssetsInstance,
|
||||
AssetIdForTrustBackedAssets,
|
||||
AssetIdForTrustBackedAssetsConvert,
|
||||
asset_test_utils::CollatorSessionKeys::new(
|
||||
AccountId::from(ALICE),
|
||||
AccountId::from(ALICE),
|
||||
SessionKeys { aura: AuraId::from(sp_core::ed25519::Public::from_raw(ALICE)) }
|
||||
),
|
||||
ExistentialDeposit::get(),
|
||||
12345,
|
||||
Box::new(|| {}),
|
||||
Box::new(|| {})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user