From 5c21fd6959c83ade50225c9eb26c755231c54409 Mon Sep 17 00:00:00 2001 From: NachoPal Date: Thu, 15 Feb 2024 14:11:45 +0100 Subject: [PATCH 01/18] improve penpal + assethub local asset change --- Cargo.lock | 3 + .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../assets/asset-hub-westend/src/lib.rs | 2 +- .../parachains/testing/penpal/Cargo.toml | 3 + .../parachains/testing/penpal/src/genesis.rs | 17 +- .../parachains/testing/penpal/src/lib.rs | 9 +- .../emulated/common/src/impls.rs | 2 +- .../emulated/common/src/macros.rs | 27 +- .../tests/assets/asset-hub-rococo/Cargo.toml | 1 + .../tests/assets/asset-hub-rococo/src/lib.rs | 119 ++-- .../assets/asset-hub-rococo/src/tests/mod.rs | 8 - .../src/tests/reserve_transfer.rs | 628 +++++++++++++----- .../assets/asset-hub-rococo/src/tests/send.rs | 2 +- .../src/tests/set_xcm_versions.rs | 2 +- .../assets/asset-hub-rococo/src/tests/swap.rs | 6 +- .../asset-hub-rococo/src/tests/teleport.rs | 99 ++- .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../assets/asset-hub-rococo/src/xcm_config.rs | 17 +- .../assets/asset-hub-rococo/tests/tests.rs | 5 +- .../runtimes/assets/common/Cargo.toml | 1 + .../runtimes/assets/common/src/lib.rs | 12 +- .../runtimes/testing/penpal/src/xcm_config.rs | 40 +- polkadot/xcm/xcm-executor/src/lib.rs | 4 +- 23 files changed, 718 insertions(+), 293 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 952eaee499772..b1f1ea0eaab96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -833,6 +833,7 @@ dependencies = [ "pallet-xcm", "parachains-common", "parity-scale-codec", + "penpal-runtime", "rococo-runtime", "rococo-system-emulated-network", "sp-runtime", @@ -1079,6 +1080,7 @@ dependencies = [ "impl-trait-for-tuples", "log", "pallet-asset-conversion", + "pallet-assets", "pallet-xcm", "parachains-common", "parity-scale-codec", @@ -11558,6 +11560,7 @@ dependencies = [ "penpal-runtime", "rococo-emulated-chain", "sp-core", + "staging-xcm", "westend-emulated-chain", ] diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs index 00f4125642055..facab26996d8a 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs @@ -55,5 +55,5 @@ decl_test_parachains! { impl_accounts_helpers_for_parachain!(AssetHubRococo); impl_assert_events_helpers_for_parachain!(AssetHubRococo); impl_assets_helpers_for_parachain!(AssetHubRococo, Rococo); -impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, Rococo); +impl_foreign_assets_helpers_for_parachain!(AssetHubRococo); impl_xcm_helpers_for_parachain!(AssetHubRococo); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs index 25d7c1079b4dd..11945c8cb4a62 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs @@ -55,5 +55,5 @@ decl_test_parachains! { impl_accounts_helpers_for_parachain!(AssetHubWestend); impl_assert_events_helpers_for_parachain!(AssetHubWestend); impl_assets_helpers_for_parachain!(AssetHubWestend, Westend); -impl_foreign_assets_helpers_for_parachain!(AssetHubWestend, Westend); +impl_foreign_assets_helpers_for_parachain!(AssetHubWestend); impl_xcm_helpers_for_parachain!(AssetHubWestend); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml index a853825d8ef62..dbbe510d3ec37 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml @@ -16,6 +16,9 @@ workspace = true sp-core = { path = "../../../../../../../../substrate/primitives/core", default-features = false } frame-support = { path = "../../../../../../../../substrate/frame/support", default-features = false } +# Polkadot +xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false } + # Cumulus parachains-common = { path = "../../../../../../../parachains/common" } cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index 9ab32a977d711..938516cec9e11 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -20,13 +20,17 @@ use sp_core::{sr25519, storage::Storage}; use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION, }; -use parachains_common::Balance; - +use parachains_common::{Balance, AccountId}; +use penpal_runtime::xcm_config::{RelayLocationV3, SystemAssetHubLocationV3}; // Penpal pub const PARA_ID_A: u32 = 2000; pub const PARA_ID_B: u32 = 2001; pub const ED: Balance = penpal_runtime::EXISTENTIAL_DEPOSIT; +pub fn asset_owner() -> AccountId { + get_account_id_from_seed::("Alice") +} + pub fn genesis(para_id: u32) -> Storage { let genesis_config = penpal_runtime::RuntimeGenesisConfig { system: penpal_runtime::SystemConfig::default(), @@ -61,6 +65,15 @@ pub fn genesis(para_id: u32) -> Storage { sudo: penpal_runtime::SudoConfig { key: Some(get_account_id_from_seed::("Alice")), }, + foreign_assets: penpal_runtime::ForeignAssetsConfig { + assets: vec![ + // AssetHub Native asset representation + (SystemAssetHubLocationV3::get(), get_account_id_from_seed::("Alice"), true, ED), + // Relay Native asset representation + (RelayLocationV3::get(), get_account_id_from_seed::("Alice"), true, ED) + ], + ..Default::default() + }, ..Default::default() }; diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs index 8f586a46a75cb..eef2e1a6a4db1 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs @@ -14,17 +14,14 @@ // limitations under the License. mod genesis; -pub use genesis::{genesis, ED, PARA_ID_A, PARA_ID_B}; -pub use penpal_runtime::xcm_config::{ - LocalTeleportableToAssetHub, LocalTeleportableToAssetHubV3, XcmConfig, -}; +pub use genesis::{genesis, asset_owner, ED, PARA_ID_A, PARA_ID_B}; // Substrate use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ - impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, + impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, impl_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; use rococo_emulated_chain::Rococo; @@ -79,3 +76,5 @@ impl_assets_helpers_for_parachain!(PenpalA, Rococo); impl_assets_helpers_for_parachain!(PenpalB, Westend); impl_assert_events_helpers_for_parachain!(PenpalA); impl_assert_events_helpers_for_parachain!(PenpalB); +impl_foreign_assets_helpers_for_parachain!(PenpalA); +impl_foreign_assets_helpers_for_parachain!(PenpalB); diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 4bbb4701e4391..4245729156465 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -728,7 +728,7 @@ macro_rules! impl_assets_helpers_for_parachain { #[macro_export] macro_rules! impl_foreign_assets_helpers_for_parachain { - ( $chain:ident, $relay_chain:ident ) => { + ( $chain:ident) => { $crate::impls::paste::paste! { impl $chain { /// Create foreign assets using sudo `ForeignAssets::force_create()` diff --git a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs index 01a376e4dbf8c..fadfbf7016d53 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs @@ -19,14 +19,25 @@ pub use paste; pub use pallet_balances; pub use pallet_message_queue; pub use pallet_xcm; +pub use pallet_assets; +pub use frame_support::{pallet_prelude::Weight, weights::WeightToFee}; // Polkadot -pub use xcm::prelude::{AccountId32, WeightLimit}; +pub use xcm::{ + v3::Location as V3Location, + prelude::{ + OriginKind, AccountId32, WeightLimit, Asset, AssetId, Fungible, + Location, Here, VersionedXcm, Xcm, Unlimited, WithdrawAsset, BuyExecution, + Transact, ExpectTransactStatus, MaybeErrorCode, RefundSurplus, DepositAsset, + All + }, +}; // Cumulus pub use asset_test_utils; pub use cumulus_pallet_xcmp_queue; pub use xcm_emulator::Chain; +pub use parachains_common::AccountId; #[macro_export] macro_rules! test_parachain_is_trusted_teleporter { @@ -127,13 +138,19 @@ macro_rules! include_penpal_create_foreign_asset_on_asset_hub { $crate::impls::paste::paste! { pub fn penpal_create_foreign_asset_on_asset_hub( asset_id_on_penpal: u32, - foreign_asset_at_asset_hub: v3::Location, - ah_as_seen_by_penpal: Location, + foreign_asset_at_asset_hub: $crate::macros::V3Location, + ah_as_seen_by_penpal: $crate::macros::Location, is_sufficient: bool, - asset_owner: AccountId, + asset_owner: $crate::macros::AccountId, prefund_amount: u128, ) { - use frame_support::weights::WeightToFee; + use $crate::macros::{ + pallet_assets, pallet_xcm, Chain, Weight, OriginKind, Asset, AssetId, Fungible, + Location, Here, VersionedXcm, Xcm, Unlimited, WeightToFee, WithdrawAsset, BuyExecution, + Transact, ExpectTransactStatus, MaybeErrorCode, RefundSurplus, DepositAsset, + All + }; + let ah_check_account = $asset_hub::execute_with(|| { <$asset_hub as [<$asset_hub Pallet>]>::PolkadotXcm::check_account() }); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/Cargo.toml index 0a397c2617b4b..13eb7d8dfc49a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/Cargo.toml @@ -34,5 +34,6 @@ parachains-common = { path = "../../../../../../parachains/common" } cumulus-pallet-parachain-system = { path = "../../../../../../pallets/parachain-system", default-features = false } testnet-parachains-constants = { path = "../../../../../runtimes/constants", features = ["rococo"] } asset-hub-rococo-runtime = { path = "../../../../../runtimes/assets/asset-hub-rococo" } +penpal-runtime = { path = "../../../../../runtimes/testing/penpal" } emulated-integration-tests-common = { path = "../../../common", default-features = false } rococo-system-emulated-network = { path = "../../../networks/rococo-system" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs index 1cc25cb54a14b..7b44d5ee10512 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs @@ -13,59 +13,82 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub use codec::Encode; +#[cfg(test)] +mod imports { + pub use codec::Encode; + + // Substrate + pub use frame_support::{ + assert_err, assert_ok, + pallet_prelude::Weight, + sp_runtime::{DispatchError, DispatchResult, ModuleError}, + traits::fungibles::Inspect, + }; + + // Polkadot + pub use xcm::{ + prelude::{AccountId32 as AccountId32Junction, *}, + v3, + }; -// Substrate -pub use frame_support::{ - assert_err, assert_ok, - pallet_prelude::Weight, - sp_runtime::{AccountId32, DispatchError, DispatchResult}, - traits::fungibles::Inspect, -}; + // Cumulus + pub use asset_test_utils::xcm_helpers; + pub use emulated_integration_tests_common::{ + test_parachain_is_trusted_teleporter, + xcm_emulator::{ + assert_expected_events, bx, Chain, Parachain as Para, + RelayChain as Relay, Test, TestArgs, TestContext, TestExt, + }, + xcm_helpers::{xcm_transact_paid_execution, non_fee_asset}, + XCM_V3, + }; + pub use parachains_common::Balance; + pub use rococo_system_emulated_network::{ + asset_hub_rococo_emulated_chain::{ + genesis::{ED as ASSET_HUB_ROCOCO_ED, PARA_ID as ASSETHUB_PARA_ID}, AssetHubRococoParaPallet as AssetHubRococoPallet, + }, + penpal_emulated_chain::{PenpalAParaPallet as PenpalAPallet, PenpalBParaPallet as PenpalBPallet, asset_owner as penpal_asset_owner}, + rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, + AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, + AssetHubRococoParaSender as AssetHubRococoSender, BridgeHubRococoPara as BridgeHubRococo, + BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, PenpalAPara as PenpalA, + PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender, + PenpalBPara as PenpalB, PenpalBParaReceiver as PenpalBReceiver, RococoRelay as Rococo, + RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender, + }; -// Polkadot -pub use xcm::{ - prelude::{AccountId32 as AccountId32Junction, *}, - v3::{self, Error, NetworkId::Rococo as RococoId}, -}; + // Runtimes + pub use rococo_runtime::xcm_config::{XcmConfig as RococoXcmConfig, UniversalLocation as RococoUniversalLocation}; + pub use asset_hub_rococo_runtime::xcm_config::{ + XcmConfig as AssetHubRococoXcmConfig, UniversalLocation as AssetHubRococoUniversalLocation, + TokenLocationV3 as RelayLocationV3, + }; + pub use penpal_runtime::xcm_config::{ + LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3, + SystemAssetHubLocationV3, + UniversalLocation as PenpalUniversalLocation, XcmConfig as PenpalRococoXcmConfig + }; -// Cumulus -pub use asset_test_utils::xcm_helpers; -pub use emulated_integration_tests_common::{ - test_parachain_is_trusted_teleporter, - xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, - }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, -}; -pub use parachains_common::{AccountId, Balance}; -pub use rococo_system_emulated_network::{ - asset_hub_rococo_emulated_chain::{ - genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, - }, - penpal_emulated_chain::PenpalAParaPallet as PenpalAPallet, - rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, - AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, - AssetHubRococoParaSender as AssetHubRococoSender, BridgeHubRococoPara as BridgeHubRococo, - BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, PenpalAPara as PenpalA, - PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender, - PenpalBPara as PenpalB, PenpalBParaReceiver as PenpalBReceiver, RococoRelay as Rococo, - RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender, -}; + pub const ASSET_ID: u32 = 1; + pub const ASSET_MIN_BALANCE: u128 = 1000; + // `Assets` pallet index + pub const ASSETS_PALLET_ID: u8 = 50; -pub const ASSET_ID: u32 = 1; -pub const ASSET_MIN_BALANCE: u128 = 1000; -// `Assets` pallet index -pub const ASSETS_PALLET_ID: u8 = 50; + pub type RelayToSystemParaTest = Test; + pub type RelayToParaTest = Test; + pub type SystemParaToRelayTest = Test; + pub type SystemParaToParaTest = Test; + pub type ParaToSystemParaTest = Test; + pub type ParaToParaThroughRelayTest = Test; + pub type ParaToParaThroughSystemParaTest = Test; -pub type RelayToSystemParaTest = Test; -pub type RelayToParaTest = Test; -pub type SystemParaToRelayTest = Test; -pub type SystemParaToParaTest = Test; -pub type ParaToSystemParaTest = Test; -pub type ParaToParaTest = Test; + emulated_integration_tests_common::include_penpal_create_foreign_asset_on_asset_hub!( + PenpalA, + AssetHubRococo, + ROCOCO_ED, + testnet_parachains_constants::rococo::fee::WeightToFee + ); +} #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/mod.rs index 21bed234304e2..b3841af0e6c38 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/mod.rs @@ -18,11 +18,3 @@ mod send; mod set_xcm_versions; mod swap; mod teleport; - -use crate::*; -emulated_integration_tests_common::include_penpal_create_foreign_asset_on_asset_hub!( - PenpalA, - AssetHubRococo, - ROCOCO_ED, - testnet_parachains_constants::rococo::fee::WeightToFee -); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 50f47ab970bad..2b573e4584f68 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -13,14 +13,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; -use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; -use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; -use rococo_system_emulated_network::penpal_emulated_chain::XcmConfig as PenpalRococoXcmConfig; +use crate::imports::*; fn relay_to_para_sender_assertions(t: RelayToParaTest) { type RuntimeEvent = ::RuntimeEvent; + Rococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8_799))); + assert_expected_events!( Rococo, vec![ @@ -40,10 +39,12 @@ fn relay_to_para_sender_assertions(t: RelayToParaTest) { fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; + AssetHubRococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( 864_610_000, 8_799, ))); + assert_expected_events!( AssetHubRococo, vec![ @@ -57,19 +58,28 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { ), amount: *amount == t.args.amount, }, + // Transport fees are paid + RuntimeEvent::PolkadotXcm( + pallet_xcm::Event::FeesPaid { .. } + ) => {}, ] ); + AssetHubRococo::assert_xcm_pallet_sent(); } -fn para_receiver_assertions(_: Test) { +fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + + PenpalA::assert_xcmp_queue_success(None); + assert_expected_events!( PenpalA, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.receiver.account_id, + }, ] ); } @@ -81,11 +91,12 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { PenpalA, vec![ // Amount to reserve transfer is transferred to Parachain's Sovereign account - RuntimeEvent::Balances( - pallet_balances::Event::Withdraw { who, amount } + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - who: *who == t.sender.account_id, - amount: *amount == t.args.amount, + asset_id: *asset_id == SystemAssetHubLocationV3::get(), + owner: *owner == t.sender.account_id, + balance: *balance == t.args.amount, }, ] ); @@ -96,6 +107,9 @@ fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) { let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of( AssetHubRococo::sibling_location_of(PenpalA::para_id()), ); + + AssetHubRococo::assert_xcmp_queue_success(None); + assert_expected_events!( AssetHubRococo, vec![ @@ -107,9 +121,6 @@ fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) { amount: *amount == t.args.amount, }, RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, ] ); } @@ -134,17 +145,56 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { ), amount: *amount == t.args.amount, }, + // Native asset to pay for fees is transferred to Parachain's Sovereign account + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => { + who: *who == AssetHubRococo::sovereign_account_id_of( + t.args.dest.clone() + ), + }, + // Transport fees are paid + RuntimeEvent::PolkadotXcm( + pallet_xcm::Event::FeesPaid { .. } + ) => {}, ] ); } -fn system_para_to_para_assets_receiver_assertions(_: Test) { +fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; + let system_para_asset_location = xcm::v3::Location::new( + 1, [ + xcm::v3::Junction::Parachain(ASSETHUB_PARA_ID), + xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), + ] + ); + PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( PenpalA, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, - RuntimeEvent::Assets(pallet_assets::Event::Issued { .. }) => {}, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == SystemAssetHubLocationV3::get(), + owner: *owner == t.receiver.account_id, + }, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + asset_id: *asset_id == system_para_asset_location, + owner: *owner == t.receiver.account_id, + amount: *amount == t.args.amount, + }, + ] + ); +} + +fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PenpalA, + vec![ + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == RelayLocationV3::get(), + owner: *owner == t.receiver.account_id, + }, RuntimeEvent::MessageQueue( pallet_message_queue::Event::Processed { success: true, .. } ) => {}, @@ -152,33 +202,57 @@ fn system_para_to_para_assets_receiver_assertions(_: Test) { ); } -fn para_to_para_sender_assertions(t: ParaToParaTest) { +fn para_to_para_through_relay_sender_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; + + let relay_asset_location = RelayLocationV3::get(); + PenpalA::assert_xcm_pallet_attempted_complete(None); + // XCM sent to relay reserve + PenpalA::assert_parachain_system_ump_sent(); + assert_expected_events!( PenpalA, vec![ // Amount to reserve transfer is transferred to Parachain's Sovereign account - RuntimeEvent::Balances( - pallet_balances::Event::Withdraw { who, amount } + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, balance }, ) => { - who: *who == t.sender.account_id, - amount: *amount == t.args.amount, + asset_id: *asset_id == relay_asset_location, + owner: *owner == t.sender.account_id, + balance: *balance == t.args.amount, }, - // XCM sent to relay reserve - RuntimeEvent::ParachainSystem( - cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. } - ) => {}, ] ); } -fn para_to_para_relay_hop_assertions(t: ParaToParaTest) { +fn para_to_para_through_system_para_sender_assertions(t: ParaToParaThroughSystemParaTest) { + type RuntimeEvent = ::RuntimeEvent; + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + PenpalA::assert_xcm_pallet_attempted_complete(None); + + assert_expected_events!( + PenpalA, + vec![ + // Amount to reserve transfer is transferred to Parachain's Sovereign account + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, balance }, + ) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.sender.account_id, + balance: *balance == t.args.amount, + }, + ] + ); +} + +fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; let sov_penpal_a_on_rococo = Rococo::sovereign_account_id_of(Rococo::child_location_of(PenpalA::para_id())); let sov_penpal_b_on_rococo = Rococo::sovereign_account_id_of(Rococo::child_location_of(PenpalB::para_id())); + assert_expected_events!( Rococo, vec![ @@ -202,15 +276,65 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaTest) { ); } -fn para_to_para_receiver_assertions(_: ParaToParaTest) { +fn para_to_para_system_para_hop_assertions(t: ParaToParaThroughSystemParaTest) { + type RuntimeEvent = ::RuntimeEvent; + let sov_penpal_a_on_rococo = + Rococo::sovereign_account_id_of(Rococo::child_location_of(PenpalA::para_id())); + let sov_penpal_b_on_rococo = + Rococo::sovereign_account_id_of(Rococo::child_location_of(PenpalB::para_id())); + + AssetHubRococo::assert_xcmp_queue_success(None); + + assert_expected_events!( + AssetHubRococo, + vec![ + // Withdrawn from sender parachain SA + RuntimeEvent::Balances( + pallet_balances::Event::Withdraw { who, amount } + ) => { + who: *who == sov_penpal_a_on_rococo, + amount: *amount == t.args.amount, + }, + // Deposited to receiver parachain SA + RuntimeEvent::Balances( + pallet_balances::Event::Deposit { who, .. } + ) => { + who: *who == sov_penpal_b_on_rococo, + }, + ] + ); +} + +fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; + let relay_asset_location = RelayLocationV3::get(); + + PenpalB::assert_xcmp_queue_success(None); + assert_expected_events!( PenpalB, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == relay_asset_location, + owner: *owner == t.receiver.account_id, + }, + ] + ); +} + +fn para_to_para_through_system_para_receiver_assertions(t: ParaToParaThroughSystemParaTest) { + type RuntimeEvent = ::RuntimeEvent; + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + + PenpalB::assert_xcmp_queue_success(None); + + assert_expected_events!( + PenpalB, + vec![ + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.receiver.account_id, + }, ] ); } @@ -248,7 +372,18 @@ fn para_to_system_para_reserve_transfer_assets(t: ParaToSystemParaTest) -> Dispa ) } -fn para_to_para_limited_reserve_transfer_assets(t: ParaToParaTest) -> DispatchResult { +fn para_to_para_through_relay_limited_reserve_transfer_assets(t: ParaToParaThroughRelayTest) -> DispatchResult { + ::PolkadotXcm::limited_reserve_transfer_assets( + t.signed_origin, + bx!(t.args.dest.into()), + bx!(t.args.beneficiary.into()), + bx!(t.args.assets.into()), + t.args.fee_asset_item, + t.args.weight_limit, + ) +} + +fn para_to_para_through_system_para_limited_reserve_transfer_assets(t: ParaToParaThroughSystemParaTest) -> DispatchResult { ::PolkadotXcm::limited_reserve_transfer_assets( t.signed_origin, bx!(t.args.dest.into()), @@ -262,6 +397,7 @@ fn para_to_para_limited_reserve_transfer_assets(t: ParaToParaTest) -> DispatchRe /// Reserve Transfers of native asset from Relay Chain to the System Parachain shouldn't work #[test] fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { + // Init values for Relay Chain let signed_origin = ::RuntimeOrigin::signed(RococoSender::get().into()); let destination = Rococo::child_location_of(AssetHubRococo::para_id()); let beneficiary: Location = @@ -333,42 +469,58 @@ fn reserve_transfer_native_asset_from_system_para_to_relay_fails() { fn reserve_transfer_native_asset_from_relay_to_para() { // Init values for Relay let destination = Rococo::child_location_of(PenpalA::para_id()); - let beneficiary_id = PenpalAReceiver::get(); + let sender = RococoSender::get(); let amount_to_send: Balance = ROCOCO_ED * 1000; + let assets: Assets = (Here, amount_to_send).into(); + + // Init values fot Parachain + let relay_native_asset_location = RelayLocationV3::get(); + let receiver = PenpalAReceiver::get(); + // Init Test let test_args = TestContext { - sender: RococoSender::get(), - receiver: PenpalAReceiver::get(), - args: TestArgs::new_relay(destination, beneficiary_id, amount_to_send), + sender, + receiver: receiver.clone(), + args: TestArgs::new_relay(destination.clone(), receiver.clone(), amount_to_send), }; - let mut test = RelayToParaTest::new(test_args); + // Query initial balances let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; + let receiver_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.into(), &receiver) + }); + // Set assertions and dispatchables test.set_assertion::(relay_to_para_sender_assertions); - test.set_assertion::(para_receiver_assertions); + test.set_assertion::(relay_to_para_assets_receiver_assertions); test.set_dispatchable::(relay_to_para_reserve_transfer_assets); test.assert(); + // Calculate delivery fees let delivery_fees = Rococo::execute_with(|| { + let reanchored_assets = assets.reanchored( &destination, &RococoUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); + // Query final balances let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; + let receiver_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.into(), &receiver) + }); // Sender's balance is reduced assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); - // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); - // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; + // Receiver's asset balance is increased + assert!(receiver_assets_after > receiver_assets_before); + // Receiver's asset balance increased by `amount_to_send - delivery_fees - bought_execution`; // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but // should be non-zero - assert!(receiver_balance_after < receiver_balance_before + amount_to_send); + assert!(receiver_assets_after < receiver_assets_before + amount_to_send); } /// Reserve Transfers of native asset from System Parachain to Parachain should work @@ -376,87 +528,126 @@ fn reserve_transfer_native_asset_from_relay_to_para() { fn reserve_transfer_native_asset_from_system_para_to_para() { // Init values for System Parachain let destination = AssetHubRococo::sibling_location_of(PenpalA::para_id()); - let beneficiary_id = PenpalAReceiver::get(); - let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000; - let assets = (Parent, amount_to_send).into(); + let sender = AssetHubRococoSender::get(); + let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; + let assets: Assets = (Here, amount_to_send).into(); + + // Init values for Parachain + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let receiver = PenpalAReceiver::get(); + // Init Test let test_args = TestContext { - sender: AssetHubRococoSender::get(), - receiver: PenpalAReceiver::get(), - args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), + sender, + receiver: receiver.clone(), + args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), }; - let mut test = SystemParaToParaTest::new(test_args); + // Query initial balances let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; + let receiver_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.into(), &receiver) + }); + // Set assertions and dispatchables test.set_assertion::(system_para_to_para_sender_assertions); - test.set_assertion::(para_receiver_assertions); + // test.set_assertion::(system_para_to_para_native_assets_receiver_assertions); + test.set_assertion::(system_para_to_para_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - + // Calculate delivery fees let delivery_fees = AssetHubRococo::execute_with(|| { + let reanchored_assets = assets.reanchored( &destination, &AssetHubRococoUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + // Query final balances + let sender_balance_after = test.sender.balance; + let receiver_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &receiver) }); // Sender's balance is reduced assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); - // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); - // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; + // Receiver's assets is increased + assert!(receiver_assets_after > receiver_assets_before); + // Receiver's assets increased by `amount_to_send - delivery_fees - bought_execution`; // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but // should be non-zero - assert!(receiver_balance_after < receiver_balance_before + amount_to_send); + assert!(receiver_assets_after < receiver_assets_before + amount_to_send); } /// Reserve Transfers of native asset from Parachain to System Parachain should work #[test] fn reserve_transfer_native_asset_from_para_to_system_para() { - // Init values for Penpal Parachain + // Init values for Parachain let destination = PenpalA::sibling_location_of(AssetHubRococo::para_id()); - let beneficiary_id = AssetHubRococoReceiver::get(); + let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000; - let assets = (Parent, amount_to_send).into(); + let assets: Assets = ((Parent, Parachain(ASSETHUB_PARA_ID)), amount_to_send).into(); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let asset_owner = penpal_asset_owner(); + + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner), + system_para_native_asset_location, + sender.clone(), + amount_to_send + ); + + // Init values for System Parachain + let receiver = AssetHubRococoReceiver::get(); + let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id()); + let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr); + + // fund Parachain's SA on System Parachain with the native tokens held in reserve + AssetHubRococo::fund_accounts(vec![(sov_penpal_on_ahr.into(), amount_to_send * 2)]); + // Init Test let test_args = TestContext { - sender: PenpalASender::get(), - receiver: AssetHubRococoReceiver::get(), - args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), + sender: sender.clone(), + receiver: receiver.clone(), + args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), }; - let mut test = ParaToSystemParaTest::new(test_args); - let sender_balance_before = test.sender.balance; + // Query initial balances + let sender_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &sender) + }); let receiver_balance_before = test.receiver.balance; - let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id()); - let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr); - - // fund the Penpal's SA on AHR with the native tokens held in reserve - AssetHubRococo::fund_accounts(vec![(sov_penpal_on_ahr.into(), amount_to_send * 2)]); - + // Set assertions and dispatchables test.set_assertion::(para_to_system_para_sender_assertions); test.set_assertion::(para_to_system_para_receiver_assertions); test.set_dispatchable::(para_to_system_para_reserve_transfer_assets); test.assert(); - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - + // Calculate delivery fees let delivery_fees = PenpalA::execute_with(|| { + let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); + // Query final balances + let sender_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &sender) + }); + let receiver_balance_after = test.receiver.balance; + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + assert_eq!(sender_assets_before - amount_to_send - delivery_fees, sender_assets_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; @@ -469,149 +660,260 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { /// work #[test] fn reserve_transfer_assets_from_system_para_to_para() { - // Force create asset on AssetHubRococo and PenpalA from Relay Chain - AssetHubRococo::force_create_and_mint_asset( - ASSET_ID, - ASSET_MIN_BALANCE, - false, - AssetHubRococoSender::get(), - Some(Weight::from_parts(1_019_445_000, 200_000)), - ASSET_MIN_BALANCE * 1_000_000, - ); - PenpalA::force_create_and_mint_asset( - ASSET_ID, - ASSET_MIN_BALANCE, - false, - PenpalASender::get(), - None, - 0, - ); - // Init values for System Parachain let destination = AssetHubRococo::sibling_location_of(PenpalA::para_id()); - let beneficiary_id = PenpalAReceiver::get(); - let fee_amount_to_send = ASSET_HUB_ROCOCO_ED * 1000; - let asset_amount_to_send = ASSET_MIN_BALANCE * 1000; + let sender = AssetHubRococoSender::get(); + let fee_amount_to_send = ASSET_HUB_ROCOCO_ED * 10000; + let asset_amount_to_send = ASSET_MIN_BALANCE * 10000; + let asset_owner = penpal_asset_owner(); let assets: Assets = vec![ - (Parent, fee_amount_to_send).into(), + (Here, fee_amount_to_send).into(), ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], asset_amount_to_send) .into(), ] .into(); + let is_sufficient = false; + let min_balance = ASSET_MIN_BALANCE; let fee_asset_index = assets .inner() .iter() - .position(|r| r == &(Parent, fee_amount_to_send).into()) + .position(|r| r == &(Here, fee_amount_to_send).into()) .unwrap() as u32; + AssetHubRococo::force_create_and_mint_asset( + ASSET_ID, + min_balance, + is_sufficient, + asset_owner.clone(), + Some(Weight::from_parts(1_019_445_000, 200_000)), + min_balance * 1_000_000, + ); + + // Init values for Parachain + let receiver = PenpalAReceiver::get(); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_foreign_asset_location = xcm::v3::Location::new( + 1, [ + xcm::v3::Junction::Parachain(ASSETHUB_PARA_ID), + xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), + ] + ); + PenpalA::force_create_foreign_asset(system_para_foreign_asset_location.clone(), asset_owner.clone(), is_sufficient, min_balance, vec![]); + // Init Test let para_test_args = TestContext { - sender: AssetHubRococoSender::get(), - receiver: PenpalAReceiver::get(), + sender: sender.clone(), + receiver: receiver.clone(), args: TestArgs::new_para( destination, - beneficiary_id, + receiver.clone(), asset_amount_to_send, assets, None, fee_asset_index, ), }; - let mut test = SystemParaToParaTest::new(para_test_args); - // Create SA-of-Penpal-on-AHR with ED. - let penpal_location = AssetHubRococo::sibling_location_of(PenpalA::para_id()); - let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location); - AssetHubRococo::fund_accounts(vec![(sov_penpal_on_ahr.into(), ROCOCO_ED)]); - + // Query initial balances let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; - let sender_assets_before = AssetHubRococo::execute_with(|| { type Assets = ::Assets; - >::balance(ASSET_ID, &AssetHubRococoSender::get()) + >::balance(ASSET_ID, &sender) }); - let receiver_assets_before = PenpalA::execute_with(|| { - type Assets = ::Assets; - >::balance(ASSET_ID, &PenpalAReceiver::get()) + let receiver_system_native_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &receiver) + }); + let receiver_foreign_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_foreign_asset_location.clone(), &receiver) }); + // Set assertions and dispatchables test.set_assertion::(system_para_to_para_assets_sender_assertions); test.set_assertion::(system_para_to_para_assets_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); + // Query final balances let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - - // Sender's balance is reduced - assert!(sender_balance_after < sender_balance_before); - // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); - // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; - // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but - // should be non-zero - assert!(receiver_balance_after < receiver_balance_before + fee_amount_to_send); - let sender_assets_after = AssetHubRococo::execute_with(|| { type Assets = ::Assets; - >::balance(ASSET_ID, &AssetHubRococoSender::get()) + >::balance(ASSET_ID, &sender) }); - let receiver_assets_after = PenpalA::execute_with(|| { - type Assets = ::Assets; - >::balance(ASSET_ID, &PenpalAReceiver::get()) + let receiver_system_native_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &receiver) }); + let receiver_foreign_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_foreign_asset_location.clone(), &receiver) + }); + // Sender's balance is reduced + assert!(sender_balance_after < sender_balance_before); + // Receiver's foreign asset balance is increased + assert!(receiver_foreign_assets_after > receiver_foreign_assets_before); + // Receiver's system asset balance increased by `amount_to_send - delivery_fees - bought_execution`; + // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but + // should be non-zero + assert!(receiver_system_native_assets_after < receiver_system_native_assets_before + fee_amount_to_send); - // Sender's balance is reduced by exact amount + // Sender's asset balance is reduced by exact amount assert_eq!(sender_assets_before - asset_amount_to_send, sender_assets_after); - // Receiver's balance is increased by exact amount - assert_eq!(receiver_assets_after, receiver_assets_before + asset_amount_to_send); + // Receiver's foreign asset balance is increased by exact amount + assert_eq!(receiver_foreign_assets_after, receiver_foreign_assets_before + asset_amount_to_send); } /// Reserve Transfers of native asset from Parachain to Parachain (through Relay reserve) should /// work #[test] -fn reserve_transfer_native_asset_from_para_to_para() { - // Init values for Penpal Parachain +fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { + // Init values for Parachain Origin let destination = PenpalA::sibling_location_of(PenpalB::para_id()); - let beneficiary_id = PenpalBReceiver::get(); - let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; + let sender = PenpalASender::get(); + let amount_to_send: Balance = ROCOCO_ED * 10000; + let asset_owner = penpal_asset_owner(); let assets = (Parent, amount_to_send).into(); + let relay_native_asset_location = RelayLocationV3::get(); + let sender_as_seen_by_relay = Rococo::child_location_of(PenpalA::para_id()); + let sov_of_sender_on_relay = Rococo::sovereign_account_id_of(sender_as_seen_by_relay); + + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner), + relay_native_asset_location, + sender.clone(), + amount_to_send + ); + // fund the Parachain Origin's SA on Relay Chain with the native tokens held in reserve + Rococo::fund_accounts(vec![(sov_of_sender_on_relay.into(), amount_to_send * 2)]); + + // Init values for Parachain Desitnation + let receiver = PenpalBReceiver::get(); + + // Init Test let test_args = TestContext { - sender: PenpalASender::get(), - receiver: PenpalBReceiver::get(), - args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), + sender: sender.clone(), + receiver: receiver.clone(), + args: TestArgs::new_para(destination, receiver.clone(), amount_to_send, assets, None, 0), }; + let mut test = ParaToParaThroughRelayTest::new(test_args); - let mut test = ParaToParaTest::new(test_args); + // Query initial balances + let sender_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.clone(), &sender) + }); + let receiver_assets_before = PenpalB::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.clone(), &receiver) + }); - let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; + // Set assertions and dispatchables + test.set_assertion::(para_to_para_through_relay_sender_assertions); + test.set_assertion::(para_to_para_relay_hop_assertions); + test.set_assertion::(para_to_para_through_relay_receiver_assertions); + test.set_dispatchable::(para_to_para_through_relay_limited_reserve_transfer_assets); + test.assert(); - let sender_as_seen_by_relay = Rococo::child_location_of(PenpalA::para_id()); - let sov_of_sender_on_relay = Rococo::sovereign_account_id_of(sender_as_seen_by_relay); + // Calculate delivery fees + let delivery_fees = PenpalA::execute_with(|| { + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + // Query final balances + let sender_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.clone(), &sender) + }); + let receiver_assets_after = PenpalB::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.clone(), &receiver) + }); + + // Sender's balance is reduced + assert_eq!(sender_assets_before - amount_to_send - delivery_fees, sender_assets_after); + // Receiver's balance is increased + assert!(receiver_assets_after > receiver_assets_before); +} + +/// Reserve Transfers of native asset from Parachain to Parachain (through Relay reserve) should +/// work +#[test] +fn reserve_transfer_native_asset_from_para_to_para_through_system_para() { + // Init values for Parachain Origin + let destination = PenpalA::sibling_location_of(PenpalB::para_id()); + let sender = PenpalASender::get(); + let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; + let asset_owner = penpal_asset_owner(); + let assets: Assets = ((Parent, Parachain(ASSETHUB_PARA_ID)), amount_to_send).into(); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let sender_as_seen_by_system_para = AssetHubRococo::sibling_location_of(PenpalA::para_id()); + let sov_of_sender_on_system_para = AssetHubRococo::sovereign_account_id_of(sender_as_seen_by_system_para); // fund the PenpalA's SA on Rococo with the native tokens held in reserve - Rococo::fund_accounts(vec![(sov_of_sender_on_relay.into(), amount_to_send * 2)]); + AssetHubRococo::fund_accounts(vec![(sov_of_sender_on_system_para.into(), amount_to_send * 2)]); + + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner), + system_para_native_asset_location, + sender.clone(), + amount_to_send + ); - test.set_assertion::(para_to_para_sender_assertions); - test.set_assertion::(para_to_para_relay_hop_assertions); - test.set_assertion::(para_to_para_receiver_assertions); - test.set_dispatchable::(para_to_para_limited_reserve_transfer_assets); - test.assert(); + // Init values for Parachain Desitnation + let receiver = PenpalBReceiver::get(); - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; + // Init Test + let test_args = TestContext { + sender: sender.clone(), + receiver: receiver.clone(), + args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), + }; + let mut test = ParaToParaThroughSystemParaTest::new(test_args); + + // Query initial balances + let sender_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &sender) + }); + let receiver_assets_before = PenpalB::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &receiver) + }); + // Set assertions and dispatchables + test.set_assertion::(para_to_para_through_system_para_sender_assertions); + test.set_assertion::(para_to_para_system_para_hop_assertions); + test.set_assertion::(para_to_para_through_system_para_receiver_assertions); + test.set_dispatchable::(para_to_para_through_system_para_limited_reserve_transfer_assets); + test.assert(); + + // Calculate delivery fees let delivery_fees = PenpalA::execute_with(|| { + let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + // Query final balances + let sender_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &sender) + }); + let receiver_assets_after = PenpalB::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &receiver) }); // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + assert_eq!(sender_assets_before - amount_to_send - delivery_fees, sender_assets_after); // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); + assert!(receiver_assets_after > receiver_assets_before); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs index 3c9e76a34e36a..d1febbbe425c5 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; /// Relay Chain should be able to execute `Transact` instructions in System Parachain /// when `OriginKind::Superuser`. diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/set_xcm_versions.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/set_xcm_versions.rs index 7d630d368051d..5662a78ab67f5 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/set_xcm_versions.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/set_xcm_versions.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; #[test] fn relay_sets_system_para_xcm_supported_version() { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs index c6a10b252901c..10a56f499cca9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs @@ -13,9 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; -use rococo_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3; -use sp_runtime::ModuleError; +use crate::imports::*; #[test] fn swap_locally_on_chain_using_local_assets() { @@ -128,7 +126,7 @@ fn swap_locally_on_chain_using_foreign_assets() { .unwrap(); // 1. Create asset on penpal and, 2. Create foreign asset on asset_hub_rococo - super::penpal_create_foreign_asset_on_asset_hub( + penpal_create_foreign_asset_on_asset_hub( asset_id_on_penpal, foreign_asset_at_asset_hub_rococo, ah_as_seen_by_penpal, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 218234cc78eaa..766d24433653b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -13,11 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; -use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig; -use emulated_integration_tests_common::xcm_helpers::non_fee_asset; -use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; -use rococo_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3; +use crate::imports::*; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -114,18 +110,20 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - PenpalA::assert_xcm_pallet_attempted_complete(None); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); + + PenpalA::assert_xcm_pallet_attempted_complete(None); assert_expected_events!( PenpalA, vec![ - RuntimeEvent::Balances( - pallet_balances::Event::Withdraw { who, amount } + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, .. } ) => { - who: *who == t.sender.account_id, - amount: *amount == t.args.amount, + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.sender.account_id, }, RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { asset_id: *asset_id == expected_asset_id, @@ -144,6 +142,9 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); + + AssetHubRococo::assert_xcmp_queue_success(None); + assert_expected_events!( AssetHubRococo, vec![ @@ -163,9 +164,9 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { amount: *amount == expected_foreign_asset_amount, }, RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, + // RuntimeEvent::MessageQueue( + // pallet_message_queue::Event::Processed { success: true, .. } + // ) => {}, ] ); } @@ -205,6 +206,10 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let checking_account = ::PolkadotXcm::check_account(); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + + PenpalA::assert_xcmp_queue_success(None); + assert_expected_events!( PenpalA, vec![ @@ -221,12 +226,14 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { amount: *amount == expected_asset_amount, }, // native asset for fee is deposited to receiver - RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => { - who: *who == t.receiver.account_id, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.receiver.account_id, + amount: *amount == expected_asset_amount, }, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, + // RuntimeEvent::MessageQueue( + // pallet_message_queue::Event::Processed { success: true, .. } + // ) => {}, ] ); } @@ -558,40 +565,57 @@ fn teleport_to_other_system_parachains_works() { /// (using native reserve-based transfer for fees) #[test] fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { + // Init values for Parachain + let fee_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; + let asset_owner = penpal_asset_owner(); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let sender = PenpalASender::get(); + + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner.clone()), + system_para_native_asset_location, + sender.clone(), + fee_amount_to_send + ); + let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id()); let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); let asset_id_on_penpal = match asset_location_on_penpal.last() { Some(v3::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; - let asset_owner_on_penpal = PenpalASender::get(); + let foreign_asset_at_asset_hub_rococo = v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); - super::penpal_create_foreign_asset_on_asset_hub( + + penpal_create_foreign_asset_on_asset_hub( asset_id_on_penpal, foreign_asset_at_asset_hub_rococo, ah_as_seen_by_penpal.clone(), false, - asset_owner_on_penpal, + asset_owner, ASSET_MIN_BALANCE * 1_000_000, ); + + // Init values for System Parachain let penpal_to_ah_beneficiary_id = AssetHubRococoReceiver::get(); - let fee_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000; + // let fee_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000; let asset_amount_to_send = ASSET_MIN_BALANCE * 1000; let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); let penpal_assets: Assets = vec![ - (Parent, fee_amount_to_send).into(), + ((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into(), (asset_location_on_penpal_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = penpal_assets .inner() .iter() - .position(|r| r == &(Parent, fee_amount_to_send).into()) + .position(|r| r == &((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into()) .unwrap() as u32; // Penpal to AH test args @@ -609,7 +633,12 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { }; let mut penpal_to_ah = ParaToSystemParaTest::new(penpal_to_ah_test_args); - let penpal_sender_balance_before = penpal_to_ah.sender.balance; + // let penpal_sender_balance_before = penpal_to_ah.sender.balance; + let penpal_sender_balance_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &PenpalASender::get()) + }); + let ah_receiver_balance_before = penpal_to_ah.receiver.balance; let penpal_sender_assets_before = PenpalA::execute_with(|| { @@ -629,7 +658,11 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { penpal_to_ah.set_dispatchable::(para_to_system_para_transfer_assets); penpal_to_ah.assert(); - let penpal_sender_balance_after = penpal_to_ah.sender.balance; + let penpal_sender_balance_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &PenpalASender::get()) + }); + let ah_receiver_balance_after = penpal_to_ah.receiver.balance; let penpal_sender_assets_after = PenpalA::execute_with(|| { @@ -678,14 +711,14 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let ah_to_penpal_beneficiary_id = PenpalAReceiver::get(); let penpal_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let ah_assets: Assets = vec![ - (Parent, fee_amount_to_send).into(), + (Here, fee_amount_to_send).into(), (foreign_asset_at_asset_hub_rococo_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = ah_assets .inner() .iter() - .position(|r| r == &(Parent, fee_amount_to_send).into()) + .position(|r| r == &(Here, fee_amount_to_send).into()) .unwrap() as u32; // AH to Penpal test args @@ -704,7 +737,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let mut ah_to_penpal = SystemParaToParaTest::new(ah_to_penpal_test_args); let ah_sender_balance_before = ah_to_penpal.sender.balance; - let penpal_receiver_balance_before = ah_to_penpal.receiver.balance; + let penpal_receiver_balance_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &PenpalAReceiver::get()) + }); let ah_sender_assets_before = AssetHubRococo::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -724,7 +760,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { ah_to_penpal.assert(); let ah_sender_balance_after = ah_to_penpal.sender.balance; - let penpal_receiver_balance_after = ah_to_penpal.receiver.balance; + let penpal_receiver_balance_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &PenpalAReceiver::get()) + }); let ah_sender_assets_after = AssetHubRococo::execute_with(|| { type ForeignAssets = ::ForeignAssets; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 2c111c0efacee..073ca99eb01af 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -671,7 +671,7 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} parameter_types! { /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetId = AssetId(xcm_config::TokenLocation::get()); + pub FeeAssetId: AssetId = AssetId(xcm_config::TokenLocationAsNative::get()); /// The base fee for the message delivery fees. pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 693fd7c3fc78a..4227faa609ae8 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -23,6 +23,7 @@ use super::{ use assets_common::{ matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset}, TrustBackedAssetsAsLocation, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, }; use frame_support::{ parameter_types, @@ -67,7 +68,9 @@ use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; parameter_types! { pub const TokenLocation: Location = Location::parent(); + pub const TokenLocationAsNative: Location = Location::here(); pub const TokenLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); + pub const TokenLocationAsNativeV3: xcm::v3::Location = xcm::v3::Location::here(); pub const RelayNetwork: NetworkId = NetworkId::Rococo; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = @@ -119,7 +122,7 @@ pub type CurrencyTransactor = CurrencyAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, + (IsConcrete, IsConcrete), // Convert an XCM Location into a local account id: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -522,15 +525,6 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; -/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. -pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = - AssetFeeAsExistentialDepositMultiplier< - Runtime, - WeightToFee, - pallet_assets::BalanceToAssetBalance, - ForeignAssetsInstance, - >; - /// Locations that will not be charged fees in the executor, /// either execution or delivery. /// We only waive fees for system functions, which these locations represent. @@ -571,6 +565,7 @@ impl xcm_executor::Config for XcmConfig { MaxInstructions, >; type Trader = ( + UsingComponents>, UsingComponents>, cumulus_primitives_utility::SwapFirstAssetTrader< TokenLocationV3, @@ -601,7 +596,7 @@ impl xcm_executor::Config for XcmConfig { // `pallet_assets` instance - `ForeignAssets`. cumulus_primitives_utility::TakeFirstAssetTrader< AccountId, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignAssetsConvertedConcreteId, ForeignAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index cff2290222c35..ddb8a686f0188 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -21,7 +21,7 @@ use asset_hub_rococo_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf, + ForeignCreatorsSovereignAccountOf, LocationToAccountId, TokenLocation, TokenLocationV3, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, XcmConfig, }, @@ -30,6 +30,7 @@ use asset_hub_rococo_runtime::{ MetadataDepositPerByte, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, ToWestendXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue, }; +use assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger; use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder, SlotDurations, @@ -481,7 +482,7 @@ fn test_foreign_asset_xcm_take_first_trader() { // Lets calculate amount needed let asset_amount_needed = - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles( + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::::charge_weight_in_fungibles( foreign_location, bought, ) diff --git a/cumulus/parachains/runtimes/assets/common/Cargo.toml b/cumulus/parachains/runtimes/assets/common/Cargo.toml index 74e5e44ce1558..bc4e26b4afbb4 100644 --- a/cumulus/parachains/runtimes/assets/common/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/common/Cargo.toml @@ -21,6 +21,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-std = { path = "../../../../../substrate/primitives/std", default-features = false } sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false } pallet-asset-conversion = { path = "../../../../../substrate/frame/asset-conversion", default-features = false } +pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false } # Polkadot pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false } diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index a0c912b6f0fe3..30f1951e700e0 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -23,9 +23,10 @@ pub mod local_and_foreign_assets; pub mod matching; pub mod runtime_api; +use sp_runtime::traits::ConvertInto; use crate::matching::{LocalLocationPattern, ParentLocation}; use frame_support::traits::{Equals, EverythingBut}; -use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId}; +use parachains_common::{xcm_config::AssetFeeAsExistentialDepositMultiplier, AssetIdForTrustBackedAssets, CollectionId, ItemId}; use xcm_builder::{ AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, V4V3LocationConverter, }; @@ -125,6 +126,15 @@ pub type PoolAssetsConvertedConcreteId = JustTry, >; +/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. +pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = + AssetFeeAsExistentialDepositMultiplier< + Runtime, + WeightToFee, + pallet_assets::BalanceToAssetBalance, + ForeignAssetsInstance, + >; + #[cfg(test)] mod tests { use super::*; diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index 3fad47576fd6c..4eb47047183db 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -25,14 +25,14 @@ use super::{ AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Assets, Balance, Balances, ForeignAssets, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, - RuntimeOrigin, WeightToFee, XcmpQueue, + RuntimeOrigin, WeightToFee, XcmpQueue, ForeignAssetsInstance, Authorship, }; use core::marker::PhantomData; use frame_support::{ parameter_types, traits::{ fungibles::{self, Balanced, Credit}, - ConstU32, Contains, ContainsPair, Everything, Get, Nothing, + ConstU32, Contains, ContainsPair, Everything, Get, Nothing, EverythingBut }, weights::Weight, }; @@ -60,6 +60,7 @@ use xcm_executor::{traits::JustTry, XcmExecutor}; parameter_types! { pub const RelayLocation: Location = Location::parent(); + pub const NativeCurrency: Location = Location::here(); pub const RelayNetwork: Option = None; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = [Parachain(ParachainInfo::parachain_id().into())].into(); @@ -83,7 +84,7 @@ pub type CurrencyTransactor = CurrencyAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, + IsConcrete, // Do a simple punn to convert an AccountId32 Location into a native chain account ID: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -126,9 +127,17 @@ pub type FungiblesTransactor = FungiblesAdapter< CheckingAccount, >; -/// `AssetId/Balance` converter for `TrustBackedAssets` pub type ForeignAssetsConvertedConcreteId = - assets_common::ForeignAssetsConvertedConcreteId, Balance>; + assets_common::LocationConvertedConcreteId< + EverythingBut<( + // Here we rely on fact that something like this works: + // assert!(Location::new(1, + // [Parachain(100)]).starts_with(&Location::parent())); + // assert!([Parachain(100)].into().starts_with(&Here)); + StartsWith, + )>, + Balance, + >; /// Means for transacting foreign assets from different global consensus. pub type ForeignFungiblesTransactor = FungiblesAdapter< @@ -178,6 +187,7 @@ parameter_types! { pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; + pub XcmAssetFeesReceiver: Option = Authorship::author(); } pub struct ParentOrParentsExecutivePlurality; @@ -282,6 +292,8 @@ pub const TELEPORTABLE_ASSET_ID: u32 = 2; parameter_types! { /// The location that this chain recognizes as the Relay network's Asset Hub. pub SystemAssetHubLocation: Location = Location::new(1, [Parachain(1000)]); + pub SystemAssetHubLocationV3: xcm::v3::Location = xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(1000)]); + pub RelayLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); // ALWAYS ensure that the index in PalletInstance stays up-to-date with // the Relay Chain's Asset Hub's Assets pallet index pub SystemAssetHubAssetsPalletLocation: Location = @@ -334,8 +346,22 @@ impl xcm_executor::Config for XcmConfig { type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds; - type Trader = - UsingComponents>; + type Trader = ( + UsingComponents>, + // This trader allows to pay with `is_sufficient=true` "Foreign" assets from dedicated + // `pallet_assets` instance - `ForeignAssets`. + cumulus_primitives_utility::TakeFirstAssetTrader< + AccountId, + assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, + ForeignAssetsConvertedConcreteId, + ForeignAssets, + cumulus_primitives_utility::XcmFeesTo32ByteAccount< + ForeignFungiblesTransactor, + AccountId, + XcmAssetFeesReceiver, + >, + >, + ); type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index b26779f3ae9da..a305b19f28881 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -827,8 +827,10 @@ impl XcmExecutor { let to_weigh = self.holding.saturating_take(assets.clone()); self.holding.subsume_assets(to_weigh.clone()); + let to_weigh_reanchored = Self::reanchored(to_weigh, &dest, None); + let mut message_to_weigh = - vec![ReserveAssetDeposited(to_weigh.into()), ClearOrigin]; + vec![ReserveAssetDeposited(to_weigh_reanchored), ClearOrigin]; message_to_weigh.extend(xcm.0.clone().into_iter()); let (_, fee) = validate_send::(dest.clone(), Xcm(message_to_weigh))?; From 13d958ac6feac7579819d045777c9b078ac68520 Mon Sep 17 00:00:00 2001 From: NachoPal Date: Tue, 27 Feb 2024 11:00:49 +0100 Subject: [PATCH 02/18] apply changes to westend --- cumulus/pallets/parachain-system/src/lib.rs | 1754 ----------------- .../src/tests/reserve_transfer.rs | 154 -- .../tests/assets/asset-hub-westend/src/lib.rs | 122 +- .../src/tests/fellowship_treasury.rs | 2 +- .../assets/asset-hub-westend/src/tests/mod.rs | 8 - .../src/tests/reserve_transfer.rs | 547 +++-- .../asset-hub-westend/src/tests/send.rs | 2 +- .../src/tests/set_xcm_versions.rs | 2 +- .../asset-hub-westend/src/tests/swap.rs | 5 +- .../asset-hub-westend/src/tests/teleport.rs | 188 +- .../asset-hub-westend/src/tests/treasury.rs | 2 +- .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../assets/asset-hub-rococo/src/xcm_config.rs | 5 +- .../asset-hub-westend/src/xcm_config.rs | 13 +- .../assets/asset-hub-westend/tests/tests.rs | 5 +- 15 files changed, 535 insertions(+), 2276 deletions(-) delete mode 100644 cumulus/pallets/parachain-system/src/lib.rs diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs deleted file mode 100644 index 5a0fa57fb171c..0000000000000 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ /dev/null @@ -1,1754 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -#![cfg_attr(not(feature = "std"), no_std)] - -//! `cumulus-pallet-parachain-system` is a base pallet for Cumulus-based parachains. -//! -//! This pallet handles low-level details of being a parachain. Its responsibilities include: -//! -//! - ingestion of the parachain validation data; -//! - ingestion and dispatch of incoming downward and lateral messages; -//! - coordinating upgrades with the Relay Chain; and -//! - communication of parachain outputs, such as sent messages, signaling an upgrade, etc. -//! -//! Users must ensure that they register this pallet as an inherent provider. - -use codec::{Decode, Encode}; -use cumulus_primitives_core::{ - relay_chain, AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo, - GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, MessageSendError, - OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender, - XcmpMessageHandler, XcmpMessageSource, -}; -use cumulus_primitives_parachain_inherent::{MessageQueueChain, ParachainInherentData}; -use frame_support::{ - defensive, - dispatch::{DispatchResult, Pays, PostDispatchInfo}, - ensure, - inherent::{InherentData, InherentIdentifier, ProvideInherent}, - traits::{Get, HandleMessage}, - weights::Weight, -}; -use frame_system::{ensure_none, ensure_root, pallet_prelude::HeaderFor}; -use polkadot_parachain_primitives::primitives::RelayChainBlockNumber; -use polkadot_runtime_parachains::FeeTracker; -use scale_info::TypeInfo; -use sp_runtime::{ - traits::{Block as BlockT, BlockNumberProvider, Hash}, - transaction_validity::{ - InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction, - }, - BoundedSlice, FixedU128, RuntimeDebug, Saturating, -}; -use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*}; -use xcm::latest::XcmHash; - -mod benchmarking; -pub mod migration; -mod mock; -#[cfg(test)] -mod tests; -pub mod weights; - -pub use weights::WeightInfo; - -mod unincluded_segment; - -pub mod consensus_hook; -pub mod relay_state_snapshot; -#[macro_use] -pub mod validate_block; - -use unincluded_segment::{ - Ancestor, HrmpChannelUpdate, HrmpWatermarkUpdate, OutboundBandwidthLimits, SegmentTracker, - UsedBandwidth, -}; - -pub use consensus_hook::{ConsensusHook, ExpectParentIncluded}; -/// Register the `validate_block` function that is used by parachains to validate blocks on a -/// validator. -/// -/// Does *nothing* when `std` feature is enabled. -/// -/// Expects as parameters the runtime, a block executor and an inherent checker. -/// -/// # Example -/// -/// ``` -/// struct BlockExecutor; -/// struct Runtime; -/// struct CheckInherents; -/// -/// cumulus_pallet_parachain_system::register_validate_block! { -/// Runtime = Runtime, -/// BlockExecutor = Executive, -/// CheckInherents = CheckInherents, -/// } -/// -/// # fn main() {} -/// ``` -pub use cumulus_pallet_parachain_system_proc_macro::register_validate_block; -pub use relay_state_snapshot::{MessagingStateSnapshot, RelayChainStateProof}; - -pub use pallet::*; - -/// Something that can check the associated relay block number. -/// -/// Each Parachain block is built in the context of a relay chain block, this trait allows us -/// to validate the given relay chain block number. With async backing it is legal to build -/// multiple Parachain blocks per relay chain parent. With this trait it is possible for the -/// Parachain to ensure that still only one Parachain block is build per relay chain parent. -/// -/// By default [`RelayNumberStrictlyIncreases`] and [`AnyRelayNumber`] are provided. -pub trait CheckAssociatedRelayNumber { - /// Check the current relay number versus the previous relay number. - /// - /// The implementation should panic when there is something wrong. - fn check_associated_relay_number( - current: RelayChainBlockNumber, - previous: RelayChainBlockNumber, - ); -} - -/// Provides an implementation of [`CheckAssociatedRelayNumber`]. -/// -/// It will ensure that the associated relay block number strictly increases between Parachain -/// blocks. This should be used by production Parachains when in doubt. -pub struct RelayNumberStrictlyIncreases; - -impl CheckAssociatedRelayNumber for RelayNumberStrictlyIncreases { - fn check_associated_relay_number( - current: RelayChainBlockNumber, - previous: RelayChainBlockNumber, - ) { - if current <= previous { - panic!("Relay chain block number needs to strictly increase between Parachain blocks!") - } - } -} - -/// Provides an implementation of [`CheckAssociatedRelayNumber`]. -/// -/// This will accept any relay chain block number combination. This is mainly useful for -/// test parachains. -pub struct AnyRelayNumber; - -impl CheckAssociatedRelayNumber for AnyRelayNumber { - fn check_associated_relay_number(_: RelayChainBlockNumber, _: RelayChainBlockNumber) {} -} - -/// Provides an implementation of [`CheckAssociatedRelayNumber`]. -/// -/// It will ensure that the associated relay block number monotonically increases between Parachain -/// blocks. This should be used when asynchronous backing is enabled. -pub struct RelayNumberMonotonicallyIncreases; - -impl CheckAssociatedRelayNumber for RelayNumberMonotonicallyIncreases { - fn check_associated_relay_number( - current: RelayChainBlockNumber, - previous: RelayChainBlockNumber, - ) { - if current < previous { - panic!("Relay chain block number needs to monotonically increase between Parachain blocks!") - } - } -} - -/// The max length of a DMP message. -pub type MaxDmpMessageLenOf = <::DmpQueue as HandleMessage>::MaxMessageLen; - -pub mod ump_constants { - use super::FixedU128; - - /// `host_config.max_upward_queue_size / THRESHOLD_FACTOR` is the threshold after which delivery - /// starts getting exponentially more expensive. - /// `2` means the price starts to increase when queue is half full. - pub const THRESHOLD_FACTOR: u32 = 2; - /// The base number the delivery fee factor gets multiplied by every time it is increased. - /// Also the number it gets divided by when decreased. - pub const EXPONENTIAL_FEE_BASE: FixedU128 = FixedU128::from_rational(105, 100); // 1.05 - /// The base number message size in KB is multiplied by before increasing the fee factor. - pub const MESSAGE_SIZE_FEE_BASE: FixedU128 = FixedU128::from_rational(1, 1000); // 0.001 -} - -#[frame_support::pallet] -pub mod pallet { - use super::*; - use frame_support::pallet_prelude::*; - use frame_system::{pallet_prelude::*, WeightInfo as SystemWeightInfo}; - - #[pallet::pallet] - #[pallet::storage_version(migration::STORAGE_VERSION)] - #[pallet::without_storage_info] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config> { - /// The overarching event type. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// Something which can be notified when the validation data is set. - type OnSystemEvent: OnSystemEvent; - - /// Returns the parachain ID we are running with. - type SelfParaId: Get; - - /// The place where outbound XCMP messages come from. This is queried in `finalize_block`. - type OutboundXcmpMessageSource: XcmpMessageSource; - - /// Queues inbound downward messages for delayed processing. - /// - /// All inbound DMP messages from the relay are pushed into this. The handler is expected to - /// eventually process all the messages that are pushed to it. - type DmpQueue: HandleMessage; - - /// The weight we reserve at the beginning of the block for processing DMP messages. - type ReservedDmpWeight: Get; - - /// The message handler that will be invoked when messages are received via XCMP. - /// - /// This should normally link to the XCMP Queue pallet. - type XcmpMessageHandler: XcmpMessageHandler; - - /// The weight we reserve at the beginning of the block for processing XCMP messages. - type ReservedXcmpWeight: Get; - - /// Something that can check the associated relay parent block number. - type CheckAssociatedRelayNumber: CheckAssociatedRelayNumber; - - /// Weight info for functions and calls. - type WeightInfo: WeightInfo; - - /// An entry-point for higher-level logic to manage the backlog of unincluded parachain - /// blocks and authorship rights for those blocks. - /// - /// Typically, this should be a hook tailored to the collator-selection/consensus mechanism - /// that is used for this chain. - /// - /// However, to maintain the same behavior as prior to asynchronous backing, provide the - /// [`consensus_hook::ExpectParentIncluded`] here. This is only necessary in the case - /// that collators aren't expected to have node versions that supply the included block - /// in the relay-chain state proof. - /// - /// This config type is only available when the `parameterized-consensus-hook` crate feature - /// is activated. - #[cfg(feature = "parameterized-consensus-hook")] - type ConsensusHook: ConsensusHook; - } - - #[pallet::hooks] - impl Hooks> for Pallet { - /// Handles actually sending upward messages by moving them from `PendingUpwardMessages` to - /// `UpwardMessages`. Decreases the delivery fee factor if after sending messages, the queue - /// total size is less than the threshold (see [`ump_constants::THRESHOLD_FACTOR`]). - /// Also does the sending for HRMP messages it takes from `OutboundXcmpMessageSource`. - fn on_finalize(_: BlockNumberFor) { - >::kill(); - >::kill(); - let relay_upgrade_go_ahead = >::take(); - - let vfp = >::get() - .expect("set_validation_data inherent needs to be present in every block!"); - - LastRelayChainBlockNumber::::put(vfp.relay_parent_number); - - let host_config = match Self::host_configuration() { - Some(ok) => ok, - None => { - debug_assert!( - false, - "host configuration is promised to set until `on_finalize`; qed", - ); - return - }, - }; - - // Before updating the relevant messaging state, we need to extract - // the total bandwidth limits for the purpose of updating the unincluded - // segment. - let total_bandwidth_out = match Self::relevant_messaging_state() { - Some(s) => OutboundBandwidthLimits::from_relay_chain_state(&s), - None => { - debug_assert!( - false, - "relevant messaging state is promised to be set until `on_finalize`; \ - qed", - ); - return - }, - }; - - // After this point, the `RelevantMessagingState` in storage reflects the - // unincluded segment. - Self::adjust_egress_bandwidth_limits(); - - let (ump_msg_count, ump_total_bytes) = >::mutate(|up| { - let (available_capacity, available_size) = match Self::relevant_messaging_state() { - Some(limits) => ( - limits.relay_dispatch_queue_remaining_capacity.remaining_count, - limits.relay_dispatch_queue_remaining_capacity.remaining_size, - ), - None => { - debug_assert!( - false, - "relevant messaging state is promised to be set until `on_finalize`; \ - qed", - ); - return (0, 0) - }, - }; - - let available_capacity = - cmp::min(available_capacity, host_config.max_upward_message_num_per_candidate); - - // Count the number of messages we can possibly fit in the given constraints, i.e. - // available_capacity and available_size. - let (num, total_size) = up - .iter() - .scan((0u32, 0u32), |state, msg| { - let (cap_used, size_used) = *state; - let new_cap = cap_used.saturating_add(1); - let new_size = size_used.saturating_add(msg.len() as u32); - match available_capacity - .checked_sub(new_cap) - .and(available_size.checked_sub(new_size)) - { - Some(_) => { - *state = (new_cap, new_size); - Some(*state) - }, - _ => None, - } - }) - .last() - .unwrap_or_default(); - - // TODO: #274 Return back messages that do not longer fit into the queue. - - UpwardMessages::::put(&up[..num as usize]); - *up = up.split_off(num as usize); - - // If the total size of the pending messages is less than the threshold, - // we decrease the fee factor, since the queue is less congested. - // This makes delivery of new messages cheaper. - let threshold = host_config - .max_upward_queue_size - .saturating_div(ump_constants::THRESHOLD_FACTOR); - let remaining_total_size: usize = up.iter().map(UpwardMessage::len).sum(); - if remaining_total_size <= threshold as usize { - Self::decrease_fee_factor(()); - } - - (num, total_size) - }); - - // Sending HRMP messages is a little bit more involved. There are the following - // constraints: - // - // - a channel should exist (and it can be closed while a message is buffered), - // - at most one message can be sent in a channel, - // - the sent out messages should be ordered by ascension of recipient para id. - // - the capacity and total size of the channel is limited, - // - the maximum size of a message is limited (and can potentially be changed), - - let maximum_channels = host_config - .hrmp_max_message_num_per_candidate - .min(>::take()) as usize; - - // Note: this internally calls the `GetChannelInfo` implementation for this - // pallet, which draws on the `RelevantMessagingState`. That in turn has - // been adjusted above to reflect the correct limits in all channels. - let outbound_messages = - T::OutboundXcmpMessageSource::take_outbound_messages(maximum_channels) - .into_iter() - .map(|(recipient, data)| OutboundHrmpMessage { recipient, data }) - .collect::>(); - - // Update the unincluded segment length; capacity checks were done previously in - // `set_validation_data`, so this can be done unconditionally. - { - let hrmp_outgoing = outbound_messages - .iter() - .map(|msg| { - ( - msg.recipient, - HrmpChannelUpdate { msg_count: 1, total_bytes: msg.data.len() as u32 }, - ) - }) - .collect(); - let used_bandwidth = - UsedBandwidth { ump_msg_count, ump_total_bytes, hrmp_outgoing }; - - let mut aggregated_segment = - AggregatedUnincludedSegment::::get().unwrap_or_default(); - let consumed_go_ahead_signal = - if aggregated_segment.consumed_go_ahead_signal().is_some() { - // Some ancestor within the segment already processed this signal -- - // validated during inherent creation. - None - } else { - relay_upgrade_go_ahead - }; - // The bandwidth constructed was ensured to satisfy relay chain constraints. - let ancestor = Ancestor::new_unchecked(used_bandwidth, consumed_go_ahead_signal); - - let watermark = HrmpWatermark::::get(); - let watermark_update = HrmpWatermarkUpdate::new(watermark, vfp.relay_parent_number); - - aggregated_segment - .append(&ancestor, watermark_update, &total_bandwidth_out) - .expect("unincluded segment limits exceeded"); - AggregatedUnincludedSegment::::put(aggregated_segment); - // Check in `on_initialize` guarantees there's space for this block. - UnincludedSegment::::append(ancestor); - } - HrmpOutboundMessages::::put(outbound_messages); - } - - fn on_initialize(_n: BlockNumberFor) -> Weight { - let mut weight = Weight::zero(); - - // To prevent removing `NewValidationCode` that was set by another `on_initialize` - // like for example from scheduler, we only kill the storage entry if it was not yet - // updated in the current block. - if !>::get() { - NewValidationCode::::kill(); - weight += T::DbWeight::get().writes(1); - } - - // The parent hash was unknown during block finalization. Update it here. - { - >::mutate(|chain| { - if let Some(ancestor) = chain.last_mut() { - let parent = frame_system::Pallet::::parent_hash(); - // Ancestor is the latest finalized block, thus current parent is - // its output head. - ancestor.replace_para_head_hash(parent); - } - }); - weight += T::DbWeight::get().reads_writes(1, 1); - - // Weight used during finalization. - weight += T::DbWeight::get().reads_writes(3, 2); - } - - // Remove the validation from the old block. - ValidationData::::kill(); - ProcessedDownwardMessages::::kill(); - HrmpWatermark::::kill(); - UpwardMessages::::kill(); - HrmpOutboundMessages::::kill(); - CustomValidationHeadData::::kill(); - - weight += T::DbWeight::get().writes(6); - - // Here, in `on_initialize` we must report the weight for both `on_initialize` and - // `on_finalize`. - // - // One complication here, is that the `host_configuration` is updated by an inherent - // and those are processed after the block initialization phase. Therefore, we have to - // be content only with the configuration as per the previous block. That means that - // the configuration can be either stale (or be abscent altogether in case of the - // beginning of the chain). - // - // In order to mitigate this, we do the following. At the time, we are only concerned - // about `hrmp_max_message_num_per_candidate`. We reserve the amount of weight to - // process the number of HRMP messages according to the potentially stale - // configuration. In `on_finalize` we will process only the maximum between the - // announced number of messages and the actual received in the fresh configuration. - // - // In the common case, they will be the same. In the case the actual value is smaller - // than the announced, we would waste some of weight. In the case the actual value is - // greater than the announced, we will miss opportunity to send a couple of messages. - weight += T::DbWeight::get().reads_writes(1, 1); - let hrmp_max_message_num_per_candidate = Self::host_configuration() - .map(|cfg| cfg.hrmp_max_message_num_per_candidate) - .unwrap_or(0); - >::put(hrmp_max_message_num_per_candidate); - - // NOTE that the actual weight consumed by `on_finalize` may turn out lower. - weight += T::DbWeight::get().reads_writes( - 3 + hrmp_max_message_num_per_candidate as u64, - 4 + hrmp_max_message_num_per_candidate as u64, - ); - - // Weight for updating the last relay chain block number in `on_finalize`. - weight += T::DbWeight::get().reads_writes(1, 1); - - // Weight for adjusting the unincluded segment in `on_finalize`. - weight += T::DbWeight::get().reads_writes(6, 3); - - // Always try to read `UpgradeGoAhead` in `on_finalize`. - weight += T::DbWeight::get().reads(1); - - weight - } - } - - #[pallet::call] - impl Pallet { - /// Set the current validation data. - /// - /// This should be invoked exactly once per block. It will panic at the finalization - /// phase if the call was not invoked. - /// - /// The dispatch origin for this call must be `Inherent` - /// - /// As a side effect, this function upgrades the current validation function - /// if the appropriate time has come. - #[pallet::call_index(0)] - #[pallet::weight((0, DispatchClass::Mandatory))] - // TODO: This weight should be corrected. - pub fn set_validation_data( - origin: OriginFor, - data: ParachainInherentData, - ) -> DispatchResultWithPostInfo { - ensure_none(origin)?; - assert!( - !>::exists(), - "ValidationData must be updated only once in a block", - ); - - // TODO: This is more than zero, but will need benchmarking to figure out what. - let mut total_weight = Weight::zero(); - - // NOTE: the inherent data is expected to be unique, even if this block is built - // in the context of the same relay parent as the previous one. In particular, - // the inherent shouldn't contain messages that were already processed by any of the - // ancestors. - // - // This invariant should be upheld by the `ProvideInherent` implementation. - let ParachainInherentData { - validation_data: vfp, - relay_chain_state, - downward_messages, - horizontal_messages, - } = data; - - // Check that the associated relay chain block number is as expected. - T::CheckAssociatedRelayNumber::check_associated_relay_number( - vfp.relay_parent_number, - LastRelayChainBlockNumber::::get(), - ); - - let relay_state_proof = RelayChainStateProof::new( - T::SelfParaId::get(), - vfp.relay_parent_storage_root, - relay_chain_state.clone(), - ) - .expect("Invalid relay chain state proof"); - - // Update the desired maximum capacity according to the consensus hook. - #[cfg(feature = "parameterized-consensus-hook")] - let (consensus_hook_weight, capacity) = T::ConsensusHook::on_state_proof(&relay_state_proof); - #[cfg(not(feature = "parameterized-consensus-hook"))] - let (consensus_hook_weight, capacity) = ExpectParentIncluded::on_state_proof(&relay_state_proof); - total_weight += consensus_hook_weight; - total_weight += Self::maybe_drop_included_ancestors(&relay_state_proof, capacity); - // Deposit a log indicating the relay-parent storage root. - // TODO: remove this in favor of the relay-parent's hash after - // https://github.com/paritytech/cumulus/issues/303 - frame_system::Pallet::::deposit_log( - cumulus_primitives_core::rpsr_digest::relay_parent_storage_root_item( - vfp.relay_parent_storage_root, - vfp.relay_parent_number, - ), - ); - - // initialization logic: we know that this runs exactly once every block, - // which means we can put the initialization logic here to remove the - // sequencing problem. - let upgrade_go_ahead_signal = relay_state_proof - .read_upgrade_go_ahead_signal() - .expect("Invalid upgrade go ahead signal"); - - let upgrade_signal_in_segment = AggregatedUnincludedSegment::::get() - .as_ref() - .and_then(SegmentTracker::consumed_go_ahead_signal); - if let Some(signal_in_segment) = upgrade_signal_in_segment.as_ref() { - // Unincluded ancestor consuming upgrade signal is still within the segment, - // sanity check that it matches with the signal from relay chain. - assert_eq!(upgrade_go_ahead_signal, Some(*signal_in_segment)); - } - match upgrade_go_ahead_signal { - Some(_signal) if upgrade_signal_in_segment.is_some() => { - // Do nothing, processing logic was executed by unincluded ancestor. - }, - Some(relay_chain::UpgradeGoAhead::GoAhead) => { - assert!( - >::exists(), - "No new validation function found in storage, GoAhead signal is not expected", - ); - let validation_code = >::take(); - - frame_system::Pallet::::update_code_in_storage(&validation_code); - ::on_validation_code_applied(); - Self::deposit_event(Event::ValidationFunctionApplied { - relay_chain_block_num: vfp.relay_parent_number, - }); - }, - Some(relay_chain::UpgradeGoAhead::Abort) => { - >::kill(); - Self::deposit_event(Event::ValidationFunctionDiscarded); - }, - None => {}, - } - >::put( - relay_state_proof - .read_upgrade_restriction_signal() - .expect("Invalid upgrade restriction signal"), - ); - >::put(upgrade_go_ahead_signal); - - let host_config = relay_state_proof - .read_abridged_host_configuration() - .expect("Invalid host configuration in relay chain state proof"); - - let relevant_messaging_state = relay_state_proof - .read_messaging_state_snapshot(&host_config) - .expect("Invalid messaging state in relay chain state proof"); - - >::put(&vfp); - >::put(relay_chain_state); - >::put(relevant_messaging_state.clone()); - >::put(host_config); - - ::on_validation_data(&vfp); - - total_weight.saturating_accrue(Self::enqueue_inbound_downward_messages( - relevant_messaging_state.dmq_mqc_head, - downward_messages, - )); - total_weight.saturating_accrue(Self::enqueue_inbound_horizontal_messages( - &relevant_messaging_state.ingress_channels, - horizontal_messages, - vfp.relay_parent_number, - )); - - Ok(PostDispatchInfo { actual_weight: Some(total_weight), pays_fee: Pays::No }) - } - - #[pallet::call_index(1)] - #[pallet::weight((1_000, DispatchClass::Operational))] - pub fn sudo_send_upward_message( - origin: OriginFor, - message: UpwardMessage, - ) -> DispatchResult { - ensure_root(origin)?; - let _ = Self::send_upward_message(message); - Ok(()) - } - - /// Authorize an upgrade to a given `code_hash` for the runtime. The runtime can be supplied - /// later. - /// - /// The `check_version` parameter sets a boolean flag for whether or not the runtime's spec - /// version and name should be verified on upgrade. Since the authorization only has a hash, - /// it cannot actually perform the verification. - /// - /// This call requires Root origin. - #[pallet::call_index(2)] - #[pallet::weight(::SystemWeightInfo::authorize_upgrade())] - #[allow(deprecated)] - #[deprecated( - note = "To be removed after June 2024. Migrate to `frame_system::authorize_upgrade`." - )] - pub fn authorize_upgrade( - origin: OriginFor, - code_hash: T::Hash, - check_version: bool, - ) -> DispatchResult { - ensure_root(origin)?; - frame_system::Pallet::::do_authorize_upgrade(code_hash, check_version); - Ok(()) - } - - /// Provide the preimage (runtime binary) `code` for an upgrade that has been authorized. - /// - /// If the authorization required a version check, this call will ensure the spec name - /// remains unchanged and that the spec version has increased. - /// - /// Note that this function will not apply the new `code`, but only attempt to schedule the - /// upgrade with the Relay Chain. - /// - /// All origins are allowed. - #[pallet::call_index(3)] - #[pallet::weight(::SystemWeightInfo::apply_authorized_upgrade())] - #[allow(deprecated)] - #[deprecated( - note = "To be removed after June 2024. Migrate to `frame_system::apply_authorized_upgrade`." - )] - pub fn enact_authorized_upgrade( - _: OriginFor, - code: Vec, - ) -> DispatchResultWithPostInfo { - let post = frame_system::Pallet::::do_apply_authorize_upgrade(code)?; - Ok(post) - } - } - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// The validation function has been scheduled to apply. - ValidationFunctionStored, - /// The validation function was applied as of the contained relay chain block number. - ValidationFunctionApplied { relay_chain_block_num: RelayChainBlockNumber }, - /// The relay-chain aborted the upgrade process. - ValidationFunctionDiscarded, - /// Some downward messages have been received and will be processed. - DownwardMessagesReceived { count: u32 }, - /// Downward messages were processed using the given weight. - DownwardMessagesProcessed { weight_used: Weight, dmq_head: relay_chain::Hash }, - /// An upward message was sent to the relay chain. - UpwardMessageSent { message_hash: Option }, - } - - #[pallet::error] - pub enum Error { - /// Attempt to upgrade validation function while existing upgrade pending. - OverlappingUpgrades, - /// Polkadot currently prohibits this parachain from upgrading its validation function. - ProhibitedByPolkadot, - /// The supplied validation function has compiled into a blob larger than Polkadot is - /// willing to run. - TooBig, - /// The inherent which supplies the validation data did not run this block. - ValidationDataNotAvailable, - /// The inherent which supplies the host configuration did not run this block. - HostConfigurationNotAvailable, - /// No validation function upgrade is currently scheduled. - NotScheduled, - /// No code upgrade has been authorized. - NothingAuthorized, - /// The given code upgrade has not been authorized. - Unauthorized, - } - - /// Latest included block descendants the runtime accepted. In other words, these are - /// ancestors of the currently executing block which have not been included in the observed - /// relay-chain state. - /// - /// The segment length is limited by the capacity returned from the [`ConsensusHook`] configured - /// in the pallet. - #[pallet::storage] - pub(super) type UnincludedSegment = - StorageValue<_, Vec>, ValueQuery>; - - /// Storage field that keeps track of bandwidth used by the unincluded segment along with the - /// latest HRMP watermark. Used for limiting the acceptance of new blocks with - /// respect to relay chain constraints. - #[pallet::storage] - pub(super) type AggregatedUnincludedSegment = - StorageValue<_, SegmentTracker, OptionQuery>; - - /// In case of a scheduled upgrade, this storage field contains the validation code to be - /// applied. - /// - /// As soon as the relay chain gives us the go-ahead signal, we will overwrite the - /// [`:code`][sp_core::storage::well_known_keys::CODE] which will result the next block process - /// with the new validation code. This concludes the upgrade process. - #[pallet::storage] - #[pallet::getter(fn new_validation_function)] - pub(super) type PendingValidationCode = StorageValue<_, Vec, ValueQuery>; - - /// Validation code that is set by the parachain and is to be communicated to collator and - /// consequently the relay-chain. - /// - /// This will be cleared in `on_initialize` of each new block if no other pallet already set - /// the value. - #[pallet::storage] - pub(super) type NewValidationCode = StorageValue<_, Vec, OptionQuery>; - - /// The [`PersistedValidationData`] set for this block. - /// This value is expected to be set only once per block and it's never stored - /// in the trie. - #[pallet::storage] - #[pallet::getter(fn validation_data)] - pub(super) type ValidationData = StorageValue<_, PersistedValidationData>; - - /// Were the validation data set to notify the relay chain? - #[pallet::storage] - pub(super) type DidSetValidationCode = StorageValue<_, bool, ValueQuery>; - - /// The relay chain block number associated with the last parachain block. - /// - /// This is updated in `on_finalize`. - #[pallet::storage] - pub(super) type LastRelayChainBlockNumber = - StorageValue<_, RelayChainBlockNumber, ValueQuery>; - - /// An option which indicates if the relay-chain restricts signalling a validation code upgrade. - /// In other words, if this is `Some` and [`NewValidationCode`] is `Some` then the produced - /// candidate will be invalid. - /// - /// This storage item is a mirror of the corresponding value for the current parachain from the - /// relay-chain. This value is ephemeral which means it doesn't hit the storage. This value is - /// set after the inherent. - #[pallet::storage] - pub(super) type UpgradeRestrictionSignal = - StorageValue<_, Option, ValueQuery>; - - /// Optional upgrade go-ahead signal from the relay-chain. - /// - /// This storage item is a mirror of the corresponding value for the current parachain from the - /// relay-chain. This value is ephemeral which means it doesn't hit the storage. This value is - /// set after the inherent. - #[pallet::storage] - pub(super) type UpgradeGoAhead = - StorageValue<_, Option, ValueQuery>; - - /// The state proof for the last relay parent block. - /// - /// This field is meant to be updated each block with the validation data inherent. Therefore, - /// before processing of the inherent, e.g. in `on_initialize` this data may be stale. - /// - /// This data is also absent from the genesis. - #[pallet::storage] - #[pallet::getter(fn relay_state_proof)] - pub(super) type RelayStateProof = StorageValue<_, sp_trie::StorageProof>; - - /// The snapshot of some state related to messaging relevant to the current parachain as per - /// the relay parent. - /// - /// This field is meant to be updated each block with the validation data inherent. Therefore, - /// before processing of the inherent, e.g. in `on_initialize` this data may be stale. - /// - /// This data is also absent from the genesis. - #[pallet::storage] - #[pallet::getter(fn relevant_messaging_state)] - pub(super) type RelevantMessagingState = StorageValue<_, MessagingStateSnapshot>; - - /// The parachain host configuration that was obtained from the relay parent. - /// - /// This field is meant to be updated each block with the validation data inherent. Therefore, - /// before processing of the inherent, e.g. in `on_initialize` this data may be stale. - /// - /// This data is also absent from the genesis. - #[pallet::storage] - #[pallet::getter(fn host_configuration)] - pub(super) type HostConfiguration = StorageValue<_, AbridgedHostConfiguration>; - - /// The last downward message queue chain head we have observed. - /// - /// This value is loaded before and saved after processing inbound downward messages carried - /// by the system inherent. - #[pallet::storage] - pub(super) type LastDmqMqcHead = StorageValue<_, MessageQueueChain, ValueQuery>; - - /// The message queue chain heads we have observed per each channel incoming channel. - /// - /// This value is loaded before and saved after processing inbound downward messages carried - /// by the system inherent. - #[pallet::storage] - pub(super) type LastHrmpMqcHeads = - StorageValue<_, BTreeMap, ValueQuery>; - - /// Number of downward messages processed in a block. - /// - /// This will be cleared in `on_initialize` of each new block. - #[pallet::storage] - pub(super) type ProcessedDownwardMessages = StorageValue<_, u32, ValueQuery>; - - /// HRMP watermark that was set in a block. - /// - /// This will be cleared in `on_initialize` of each new block. - #[pallet::storage] - pub(super) type HrmpWatermark = - StorageValue<_, relay_chain::BlockNumber, ValueQuery>; - - /// HRMP messages that were sent in a block. - /// - /// This will be cleared in `on_initialize` of each new block. - #[pallet::storage] - pub(super) type HrmpOutboundMessages = - StorageValue<_, Vec, ValueQuery>; - - /// Upward messages that were sent in a block. - /// - /// This will be cleared in `on_initialize` of each new block. - #[pallet::storage] - pub(super) type UpwardMessages = StorageValue<_, Vec, ValueQuery>; - - /// Upward messages that are still pending and not yet send to the relay chain. - #[pallet::storage] - pub(super) type PendingUpwardMessages = - StorageValue<_, Vec, ValueQuery>; - - /// Initialization value for the delivery fee factor for UMP. - #[pallet::type_value] - pub fn UpwardInitialDeliveryFeeFactor() -> FixedU128 { - FixedU128::from_u32(1) - } - - /// The factor to multiply the base delivery fee by for UMP. - #[pallet::storage] - pub(super) type UpwardDeliveryFeeFactor = - StorageValue<_, FixedU128, ValueQuery, UpwardInitialDeliveryFeeFactor>; - - /// The number of HRMP messages we observed in `on_initialize` and thus used that number for - /// announcing the weight of `on_initialize` and `on_finalize`. - #[pallet::storage] - pub(super) type AnnouncedHrmpMessagesPerCandidate = StorageValue<_, u32, ValueQuery>; - - /// The weight we reserve at the beginning of the block for processing XCMP messages. This - /// overrides the amount set in the Config trait. - #[pallet::storage] - pub(super) type ReservedXcmpWeightOverride = StorageValue<_, Weight>; - - /// The weight we reserve at the beginning of the block for processing DMP messages. This - /// overrides the amount set in the Config trait. - #[pallet::storage] - pub(super) type ReservedDmpWeightOverride = StorageValue<_, Weight>; - - /// A custom head data that should be returned as result of `validate_block`. - /// - /// See `Pallet::set_custom_validation_head_data` for more information. - #[pallet::storage] - pub(super) type CustomValidationHeadData = StorageValue<_, Vec, OptionQuery>; - - #[pallet::inherent] - impl ProvideInherent for Pallet { - type Call = Call; - type Error = sp_inherents::MakeFatalError<()>; - const INHERENT_IDENTIFIER: InherentIdentifier = - cumulus_primitives_parachain_inherent::INHERENT_IDENTIFIER; - - fn create_inherent(data: &InherentData) -> Option { - let mut data: ParachainInherentData = - data.get_data(&Self::INHERENT_IDENTIFIER).ok().flatten().expect( - "validation function params are always injected into inherent data; qed", - ); - - Self::drop_processed_messages_from_inherent(&mut data); - - Some(Call::set_validation_data { data }) - } - - fn is_inherent(call: &Self::Call) -> bool { - matches!(call, Call::set_validation_data { .. }) - } - } - - #[pallet::genesis_config] - #[derive(frame_support::DefaultNoBound)] - pub struct GenesisConfig { - #[serde(skip)] - pub _config: sp_std::marker::PhantomData, - } - - #[pallet::genesis_build] - impl BuildGenesisConfig for GenesisConfig { - fn build(&self) { - // TODO: Remove after https://github.com/paritytech/cumulus/issues/479 - sp_io::storage::set(b":c", &[]); - } - } - - #[pallet::validate_unsigned] - impl sp_runtime::traits::ValidateUnsigned for Pallet { - type Call = Call; - - fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity { - if let Call::enact_authorized_upgrade { ref code } = call { - if let Ok(hash) = frame_system::Pallet::::validate_authorized_upgrade(&code[..]) - { - return Ok(ValidTransaction { - priority: 100, - requires: Vec::new(), - provides: vec![hash.as_ref().to_vec()], - longevity: TransactionLongevity::max_value(), - propagate: true, - }) - } - } - if let Call::set_validation_data { .. } = call { - return Ok(Default::default()) - } - Err(InvalidTransaction::Call.into()) - } - } -} - -impl Pallet { - /// Get the unincluded segment size after the given hash. - /// - /// If the unincluded segment doesn't contain the given hash, this returns the - /// length of the entire unincluded segment. - /// - /// This is intended to be used for determining how long the unincluded segment _would be_ - /// in runtime APIs related to authoring. - pub fn unincluded_segment_size_after(included_hash: T::Hash) -> u32 { - let segment = UnincludedSegment::::get(); - crate::unincluded_segment::size_after_included(included_hash, &segment) - } -} - -impl FeeTracker for Pallet { - type Id = (); - - fn get_fee_factor(_: Self::Id) -> FixedU128 { - UpwardDeliveryFeeFactor::::get() - } - - fn increase_fee_factor(_: Self::Id, message_size_factor: FixedU128) -> FixedU128 { - >::mutate(|f| { - *f = f.saturating_mul( - ump_constants::EXPONENTIAL_FEE_BASE.saturating_add(message_size_factor), - ); - *f - }) - } - - fn decrease_fee_factor(_: Self::Id) -> FixedU128 { - >::mutate(|f| { - *f = - UpwardInitialDeliveryFeeFactor::get().max(*f / ump_constants::EXPONENTIAL_FEE_BASE); - *f - }) - } -} - -impl GetChannelInfo for Pallet { - fn get_channel_status(id: ParaId) -> ChannelStatus { - // Note, that we are using `relevant_messaging_state` which may be from the previous - // block, in case this is called from `on_initialize`, i.e. before the inherent with - // fresh data is submitted. - // - // That shouldn't be a problem though because this is anticipated and already can - // happen. This is because sending implies that a message is buffered until there is - // space to send a message in the candidate. After a while waiting in a buffer, it may - // be discovered that the channel to which a message were addressed is now closed. - // Another possibility, is that the maximum message size was decreased so that a - // message in the buffer doesn't fit. Should any of that happen the sender should be - // notified about the message was discarded. - // - // Here it a similar case, with the difference that the realization that the channel is - // closed came the same block. - let channels = match Self::relevant_messaging_state() { - None => { - log::warn!("calling `get_channel_status` with no RelevantMessagingState?!"); - return ChannelStatus::Closed - }, - Some(d) => d.egress_channels, - }; - // ^^^ NOTE: This storage field should carry over from the previous block. So if it's - // None then it must be that this is an edge-case where a message is attempted to be - // sent at the first block. It should be safe to assume that there are no channels - // opened at all so early. At least, relying on this assumption seems to be a better - // trade-off, compared to introducing an error variant that the clients should be - // prepared to handle. - let index = match channels.binary_search_by_key(&id, |item| item.0) { - Err(_) => return ChannelStatus::Closed, - Ok(i) => i, - }; - let meta = &channels[index].1; - if meta.msg_count + 1 > meta.max_capacity { - // The channel is at its capacity. Skip it for now. - return ChannelStatus::Full - } - let max_size_now = meta.max_total_size - meta.total_size; - let max_size_ever = meta.max_message_size; - ChannelStatus::Ready(max_size_now as usize, max_size_ever as usize) - } - - fn get_channel_info(id: ParaId) -> Option { - let channels = Self::relevant_messaging_state()?.egress_channels; - let index = channels.binary_search_by_key(&id, |item| item.0).ok()?; - let info = ChannelInfo { - max_capacity: channels[index].1.max_capacity, - max_total_size: channels[index].1.max_total_size, - max_message_size: channels[index].1.max_message_size, - msg_count: channels[index].1.msg_count, - total_size: channels[index].1.total_size, - }; - Some(info) - } -} - -impl Pallet { - /// Updates inherent data to only contain messages that weren't already processed - /// by the runtime based on last relay chain block number. - /// - /// This method doesn't check for mqc heads mismatch. - fn drop_processed_messages_from_inherent(para_inherent: &mut ParachainInherentData) { - let ParachainInherentData { downward_messages, horizontal_messages, .. } = para_inherent; - - // Last relay chain block number. Any message with sent-at block number less - // than or equal to this value is assumed to be processed previously. - let last_relay_block_number = LastRelayChainBlockNumber::::get(); - - // DMQ. - let dmq_processed_num = downward_messages - .iter() - .take_while(|message| message.sent_at <= last_relay_block_number) - .count(); - downward_messages.drain(..dmq_processed_num); - - // HRMP. - for horizontal in horizontal_messages.values_mut() { - let horizontal_processed_num = horizontal - .iter() - .take_while(|message| message.sent_at <= last_relay_block_number) - .count(); - horizontal.drain(..horizontal_processed_num); - } - - // If MQC doesn't match after dropping messages, the runtime will panic when creating - // inherent. - } - - /// Enqueue all inbound downward messages relayed by the collator into the MQ pallet. - /// - /// Checks if the sequence of the messages is valid, dispatches them and communicates the - /// number of processed messages to the collator via a storage update. - /// - /// # Panics - /// - /// If it turns out that after processing all messages the Message Queue Chain - /// hash doesn't match the expected. - fn enqueue_inbound_downward_messages( - expected_dmq_mqc_head: relay_chain::Hash, - downward_messages: Vec, - ) -> Weight { - let dm_count = downward_messages.len() as u32; - let mut dmq_head = >::get(); - - let weight_used = T::WeightInfo::enqueue_inbound_downward_messages(dm_count); - if dm_count != 0 { - Self::deposit_event(Event::DownwardMessagesReceived { count: dm_count }); - - // Eagerly update the MQC head hash: - for m in &downward_messages { - dmq_head.extend_downward(m); - } - let bounded = downward_messages - .iter() - // Note: we are not using `.defensive()` here since that prints the whole value to - // console. In case that the message is too long, this clogs up the log quite badly. - .filter_map(|m| match BoundedSlice::try_from(&m.msg[..]) { - Ok(bounded) => Some(bounded), - Err(_) => { - defensive!("Inbound Downward message was too long; dropping"); - None - }, - }); - T::DmpQueue::handle_messages(bounded); - >::put(&dmq_head); - - Self::deposit_event(Event::DownwardMessagesProcessed { - weight_used, - dmq_head: dmq_head.head(), - }); - } - - // After hashing each message in the message queue chain submitted by the collator, we - // should arrive to the MQC head provided by the relay chain. - // - // A mismatch means that at least some of the submitted messages were altered, omitted or - // added improperly. - assert_eq!(dmq_head.head(), expected_dmq_mqc_head); - - ProcessedDownwardMessages::::put(dm_count); - - weight_used - } - - /// Process all inbound horizontal messages relayed by the collator. - /// - /// This is similar to [`enqueue_inbound_downward_messages`], but works with multiple inbound - /// channels. It immediately dispatches signals and queues all other XCMs. Blob messages are - /// ignored. - /// - /// **Panics** if either any of horizontal messages submitted by the collator was sent from - /// a para which has no open channel to this parachain or if after processing - /// messages across all inbound channels MQCs were obtained which do not - /// correspond to the ones found on the relay-chain. - fn enqueue_inbound_horizontal_messages( - ingress_channels: &[(ParaId, cumulus_primitives_core::AbridgedHrmpChannel)], - horizontal_messages: BTreeMap>, - relay_parent_number: relay_chain::BlockNumber, - ) -> Weight { - // First, check that all submitted messages are sent from channels that exist. The - // channel exists if its MQC head is present in `vfp.hrmp_mqc_heads`. - for sender in horizontal_messages.keys() { - // A violation of the assertion below indicates that one of the messages submitted - // by the collator was sent from a sender that doesn't have a channel opened to - // this parachain, according to the relay-parent state. - assert!(ingress_channels.binary_search_by_key(sender, |&(s, _)| s).is_ok(),); - } - - // Second, prepare horizontal messages for a more convenient processing: - // - // instead of a mapping from a para to a list of inbound HRMP messages, we will have a - // list of tuples `(sender, message)` first ordered by `sent_at` (the relay chain block - // number in which the message hit the relay-chain) and second ordered by para id - // ascending. - // - // The messages will be dispatched in this order. - let mut horizontal_messages = horizontal_messages - .into_iter() - .flat_map(|(sender, channel_contents)| { - channel_contents.into_iter().map(move |message| (sender, message)) - }) - .collect::>(); - horizontal_messages.sort_by(|a, b| { - // first sort by sent-at and then by the para id - match a.1.sent_at.cmp(&b.1.sent_at) { - cmp::Ordering::Equal => a.0.cmp(&b.0), - ord => ord, - } - }); - - let last_mqc_heads = >::get(); - let mut running_mqc_heads = BTreeMap::new(); - let mut hrmp_watermark = None; - - { - for (sender, ref horizontal_message) in &horizontal_messages { - if hrmp_watermark.map(|w| w < horizontal_message.sent_at).unwrap_or(true) { - hrmp_watermark = Some(horizontal_message.sent_at); - } - - running_mqc_heads - .entry(sender) - .or_insert_with(|| last_mqc_heads.get(sender).cloned().unwrap_or_default()) - .extend_hrmp(horizontal_message); - } - } - let message_iter = horizontal_messages - .iter() - .map(|&(sender, ref message)| (sender, message.sent_at, &message.data[..])); - - let max_weight = - >::get().unwrap_or_else(T::ReservedXcmpWeight::get); - let weight_used = T::XcmpMessageHandler::handle_xcmp_messages(message_iter, max_weight); - - // Check that the MQC heads for each channel provided by the relay chain match the MQC - // heads we have after processing all incoming messages. - // - // Along the way we also carry over the relevant entries from the `last_mqc_heads` to - // `running_mqc_heads`. Otherwise, in a block where no messages were sent in a channel - // it won't get into next block's `last_mqc_heads` and thus will be all zeros, which - // would corrupt the message queue chain. - for (sender, channel) in ingress_channels { - let cur_head = running_mqc_heads - .entry(sender) - .or_insert_with(|| last_mqc_heads.get(sender).cloned().unwrap_or_default()) - .head(); - let target_head = channel.mqc_head.unwrap_or_default(); - - assert!(cur_head == target_head); - } - - >::put(running_mqc_heads); - - // If we processed at least one message, then advance watermark to that location or if there - // were no messages, set it to the block number of the relay parent. - HrmpWatermark::::put(hrmp_watermark.unwrap_or(relay_parent_number)); - - weight_used - } - - /// Drop blocks from the unincluded segment with respect to the latest parachain head. - fn maybe_drop_included_ancestors( - relay_state_proof: &RelayChainStateProof, - capacity: consensus_hook::UnincludedSegmentCapacity, - ) -> Weight { - let mut weight_used = Weight::zero(); - // If the unincluded segment length is nonzero, then the parachain head must be present. - let para_head = - relay_state_proof.read_included_para_head().ok().map(|h| T::Hashing::hash(&h.0)); - - let unincluded_segment_len = >::decode_len().unwrap_or(0); - weight_used += T::DbWeight::get().reads(1); - - // Clean up unincluded segment if nonempty. - let included_head = match (para_head, capacity.is_expecting_included_parent()) { - (Some(h), true) => { - assert_eq!( - h, - frame_system::Pallet::::parent_hash(), - "expected parent to be included" - ); - - h - }, - (Some(h), false) => h, - (None, true) => { - // All this logic is essentially a workaround to support collators which - // might still not provide the included block with the state proof. - frame_system::Pallet::::parent_hash() - }, - (None, false) => panic!("included head not present in relay storage proof"), - }; - - let new_len = { - let para_head_hash = included_head; - let dropped: Vec> = >::mutate(|chain| { - // Drop everything up to (inclusive) the block with an included para head, if - // present. - let idx = chain - .iter() - .position(|block| { - let head_hash = block - .para_head_hash() - .expect("para head hash is updated during block initialization; qed"); - head_hash == ¶_head_hash - }) - .map_or(0, |idx| idx + 1); // inclusive. - - chain.drain(..idx).collect() - }); - weight_used += T::DbWeight::get().reads_writes(1, 1); - - let new_len = unincluded_segment_len - dropped.len(); - if !dropped.is_empty() { - >::mutate(|agg| { - let agg = agg.as_mut().expect( - "dropped part of the segment wasn't empty, hence value exists; qed", - ); - for block in dropped { - agg.subtract(&block); - } - }); - weight_used += T::DbWeight::get().reads_writes(1, 1); - } - - new_len as u32 - }; - - // Current block validity check: ensure there is space in the unincluded segment. - // - // If this fails, the parachain needs to wait for ancestors to be included before - // a new block is allowed. - assert!(new_len < capacity.get(), "no space left for the block in the unincluded segment"); - weight_used - } - - /// This adjusts the `RelevantMessagingState` according to the bandwidth limits in the - /// unincluded segment. - // - // Reads: 2 - // Writes: 1 - fn adjust_egress_bandwidth_limits() { - let unincluded_segment = match AggregatedUnincludedSegment::::get() { - None => return, - Some(s) => s, - }; - - >::mutate(|messaging_state| { - let messaging_state = match messaging_state { - None => return, - Some(s) => s, - }; - - let used_bandwidth = unincluded_segment.used_bandwidth(); - - let channels = &mut messaging_state.egress_channels; - for (para_id, used) in used_bandwidth.hrmp_outgoing.iter() { - let i = match channels.binary_search_by_key(para_id, |item| item.0) { - Ok(i) => i, - Err(_) => continue, // indicates channel closed. - }; - - let c = &mut channels[i].1; - - c.total_size = (c.total_size + used.total_bytes).min(c.max_total_size); - c.msg_count = (c.msg_count + used.msg_count).min(c.max_capacity); - } - - let upward_capacity = &mut messaging_state.relay_dispatch_queue_remaining_capacity; - upward_capacity.remaining_count = - upward_capacity.remaining_count.saturating_sub(used_bandwidth.ump_msg_count); - upward_capacity.remaining_size = - upward_capacity.remaining_size.saturating_sub(used_bandwidth.ump_total_bytes); - }); - } - - /// Put a new validation function into a particular location where polkadot - /// monitors for updates. Calling this function notifies polkadot that a new - /// upgrade has been scheduled. - fn notify_polkadot_of_pending_upgrade(code: &[u8]) { - NewValidationCode::::put(code); - >::put(true); - } - - /// The maximum code size permitted, in bytes. - /// - /// Returns `None` if the relay chain parachain host configuration hasn't been submitted yet. - pub fn max_code_size() -> Option { - >::get().map(|cfg| cfg.max_code_size) - } - - /// The implementation of the runtime upgrade functionality for parachains. - pub fn schedule_code_upgrade(validation_function: Vec) -> DispatchResult { - // Ensure that `ValidationData` exists. We do not care about the validation data per se, - // but we do care about the [`UpgradeRestrictionSignal`] which arrives with the same - // inherent. - ensure!(>::exists(), Error::::ValidationDataNotAvailable,); - ensure!(>::get().is_none(), Error::::ProhibitedByPolkadot); - - ensure!(!>::exists(), Error::::OverlappingUpgrades); - let cfg = Self::host_configuration().ok_or(Error::::HostConfigurationNotAvailable)?; - ensure!(validation_function.len() <= cfg.max_code_size as usize, Error::::TooBig); - - // When a code upgrade is scheduled, it has to be applied in two - // places, synchronized: both polkadot and the individual parachain - // have to upgrade on the same relay chain block. - // - // `notify_polkadot_of_pending_upgrade` notifies polkadot; the `PendingValidationCode` - // storage keeps track locally for the parachain upgrade, which will - // be applied later: when the relay-chain communicates go-ahead signal to us. - Self::notify_polkadot_of_pending_upgrade(&validation_function); - >::put(validation_function); - Self::deposit_event(Event::ValidationFunctionStored); - - Ok(()) - } - - /// Returns the [`CollationInfo`] of the current active block. - /// - /// The given `header` is the header of the built block we are collecting the collation info - /// for. - /// - /// This is expected to be used by the - /// [`CollectCollationInfo`](cumulus_primitives_core::CollectCollationInfo) runtime api. - pub fn collect_collation_info(header: &HeaderFor) -> CollationInfo { - CollationInfo { - hrmp_watermark: HrmpWatermark::::get(), - horizontal_messages: HrmpOutboundMessages::::get(), - upward_messages: UpwardMessages::::get(), - processed_downward_messages: ProcessedDownwardMessages::::get(), - new_validation_code: NewValidationCode::::get().map(Into::into), - // Check if there is a custom header that will also be returned by the validation phase. - // If so, we need to also return it here. - head_data: CustomValidationHeadData::::get() - .map_or_else(|| header.encode(), |v| v) - .into(), - } - } - - /// Set a custom head data that should be returned as result of `validate_block`. - /// - /// This will overwrite the head data that is returned as result of `validate_block` while - /// validating a `PoV` on the relay chain. Normally the head data that is being returned - /// by `validate_block` is the header of the block that is validated, thus it can be - /// enacted as the new best block. However, for features like forking it can be useful - /// to overwrite the head data with a custom header. - /// - /// # Attention - /// - /// This should only be used when you are sure what you are doing as this can brick - /// your Parachain. - pub fn set_custom_validation_head_data(head_data: Vec) { - CustomValidationHeadData::::put(head_data); - } - - /// Open HRMP channel for using it in benchmarks or tests. - /// - /// The caller assumes that the pallet will accept regular outbound message to the sibling - /// `target_parachain` after this call. No other assumptions are made. - #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] - pub fn open_outbound_hrmp_channel_for_benchmarks_or_tests(target_parachain: ParaId) { - RelevantMessagingState::::put(MessagingStateSnapshot { - dmq_mqc_head: Default::default(), - relay_dispatch_queue_remaining_capacity: Default::default(), - ingress_channels: Default::default(), - egress_channels: vec![( - target_parachain, - cumulus_primitives_core::AbridgedHrmpChannel { - max_capacity: 10, - max_total_size: 10_000_000_u32, - max_message_size: 10_000_000_u32, - msg_count: 5, - total_size: 5_000_000_u32, - mqc_head: None, - }, - )], - }) - } - - /// Open HRMP channel for using it in benchmarks or tests. - /// - /// The caller assumes that the pallet will accept regular outbound message to the sibling - /// `target_parachain` after this call. No other assumptions are made. - #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] - pub fn open_custom_outbound_hrmp_channel_for_benchmarks_or_tests( - target_parachain: ParaId, - channel: cumulus_primitives_core::AbridgedHrmpChannel, - ) { - RelevantMessagingState::::put(MessagingStateSnapshot { - dmq_mqc_head: Default::default(), - relay_dispatch_queue_remaining_capacity: Default::default(), - ingress_channels: Default::default(), - egress_channels: vec![(target_parachain, channel)], - }) - } - - /// Prepare/insert relevant data for `schedule_code_upgrade` for benchmarks. - #[cfg(feature = "runtime-benchmarks")] - pub fn initialize_for_set_code_benchmark(max_code_size: u32) { - // insert dummy ValidationData - let vfp = PersistedValidationData { - parent_head: polkadot_parachain_primitives::primitives::HeadData(Default::default()), - relay_parent_number: 1, - relay_parent_storage_root: Default::default(), - max_pov_size: 1_000, - }; - >::put(&vfp); - - // insert dummy HostConfiguration with - let host_config = AbridgedHostConfiguration { - max_code_size, - max_head_data_size: 32 * 1024, - max_upward_queue_count: 8, - max_upward_queue_size: 1024 * 1024, - max_upward_message_size: 4 * 1024, - max_upward_message_num_per_candidate: 2, - hrmp_max_message_num_per_candidate: 2, - validation_upgrade_cooldown: 2, - validation_upgrade_delay: 2, - async_backing_params: relay_chain::AsyncBackingParams { - allowed_ancestry_len: 0, - max_candidate_depth: 0, - }, - }; - >::put(host_config); - } -} - -/// Type that implements `SetCode`. -pub struct ParachainSetCode(sp_std::marker::PhantomData); -impl frame_system::SetCode for ParachainSetCode { - fn set_code(code: Vec) -> DispatchResult { - Pallet::::schedule_code_upgrade(code) - } -} - -impl Pallet { - /// Puts a message in the `PendingUpwardMessages` storage item. - /// The message will be later sent in `on_finalize`. - /// Checks host configuration to see if message is too big. - /// Increases the delivery fee factor if the queue is sufficiently (see - /// [`ump_constants::THRESHOLD_FACTOR`]) congested. - pub fn send_upward_message(message: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> { - let message_len = message.len(); - // Check if the message fits into the relay-chain constraints. - // - // Note, that we are using `host_configuration` here which may be from the previous - // block, in case this is called from `on_initialize`, i.e. before the inherent with fresh - // data is submitted. - // - // That shouldn't be a problem since this is a preliminary check and the actual check would - // be performed just before submitting the message from the candidate, and it already can - // happen that during the time the message is buffered for sending the relay-chain setting - // may change so that the message is no longer valid. - // - // However, changing this setting is expected to be rare. - if let Some(cfg) = Self::host_configuration() { - if message_len > cfg.max_upward_message_size as usize { - return Err(MessageSendError::TooBig) - } - let threshold = - cfg.max_upward_queue_size.saturating_div(ump_constants::THRESHOLD_FACTOR); - // We check the threshold against total size and not number of messages since messages - // could be big or small. - >::append(message.clone()); - let pending_messages = PendingUpwardMessages::::get(); - let total_size: usize = pending_messages.iter().map(UpwardMessage::len).sum(); - if total_size > threshold as usize { - // We increase the fee factor by a factor based on the new message's size in KB - let message_size_factor = FixedU128::from((message_len / 1024) as u128) - .saturating_mul(ump_constants::MESSAGE_SIZE_FEE_BASE); - Self::increase_fee_factor((), message_size_factor); - } - } else { - // This storage field should carry over from the previous block. So if it's None - // then it must be that this is an edge-case where a message is attempted to be - // sent at the first block. - // - // Let's pass this message through. I think it's not unreasonable to expect that - // the message is not huge and it comes through, but if it doesn't it can be - // returned back to the sender. - // - // Thus fall through here. - >::append(message.clone()); - }; - - // The relay ump does not use using_encoded - // We apply the same this to use the same hash - let hash = sp_io::hashing::blake2_256(&message); - Self::deposit_event(Event::UpwardMessageSent { message_hash: Some(hash) }); - Ok((0, hash)) - } - - /// Get the relay chain block number which was used as an anchor for the last block in this - /// chain. - pub fn last_relay_block_number() -> RelayChainBlockNumber { - LastRelayChainBlockNumber::::get() - } -} - -impl UpwardMessageSender for Pallet { - fn send_upward_message(message: UpwardMessage) -> Result<(u32, XcmHash), MessageSendError> { - Self::send_upward_message(message) - } -} - -/// Something that can check the inherents of a block. -#[cfg_attr( - feature = "parameterized-consensus-hook", - deprecated = "consider switching to `cumulus-pallet-parachain-system::ConsensusHook`" -)] -pub trait CheckInherents { - /// Check all inherents of the block. - /// - /// This function gets passed all the extrinsics of the block, so it is up to the callee to - /// identify the inherents. The `validation_data` can be used to access the - fn check_inherents( - block: &Block, - validation_data: &RelayChainStateProof, - ) -> frame_support::inherent::CheckInherentsResult; -} - -/// Struct that always returns `Ok` on inherents check, needed for backwards-compatibility. -#[doc(hidden)] -pub struct DummyCheckInherents(sp_std::marker::PhantomData); - -#[allow(deprecated)] -impl CheckInherents for DummyCheckInherents { - fn check_inherents( - _: &Block, - _: &RelayChainStateProof, - ) -> frame_support::inherent::CheckInherentsResult { - sp_inherents::CheckInherentsResult::new() - } -} - -/// Something that should be informed about system related events. -/// -/// This includes events like [`on_validation_data`](Self::on_validation_data) that is being -/// called when the parachain inherent is executed that contains the validation data. -/// Or like [`on_validation_code_applied`](Self::on_validation_code_applied) that is called -/// when the new validation is written to the state. This means that -/// from the next block the runtime is being using this new code. -#[impl_trait_for_tuples::impl_for_tuples(30)] -pub trait OnSystemEvent { - /// Called in each blocks once when the validation data is set by the inherent. - fn on_validation_data(data: &PersistedValidationData); - /// Called when the validation code is being applied, aka from the next block on this is the new - /// runtime. - fn on_validation_code_applied(); -} - -/// Holds the most recent relay-parent state root and block number of the current parachain block. -#[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo, Default, RuntimeDebug)] -pub struct RelayChainState { - /// Current relay chain height. - pub number: relay_chain::BlockNumber, - /// State root for current relay chain height. - pub state_root: relay_chain::Hash, -} - -/// This exposes the [`RelayChainState`] to other runtime modules. -/// -/// Enables parachains to read relay chain state via state proofs. -pub trait RelaychainStateProvider { - /// May be called by any runtime module to obtain the current state of the relay chain. - /// - /// **NOTE**: This is not guaranteed to return monotonically increasing relay parents. - fn current_relay_chain_state() -> RelayChainState; - - /// Utility function only to be used in benchmarking scenarios, to be implemented optionally, - /// else a noop. - /// - /// It allows for setting a custom RelayChainState. - #[cfg(feature = "runtime-benchmarks")] - fn set_current_relay_chain_state(_state: RelayChainState) {} -} - -/// Implements [`BlockNumberProvider`] that returns relay chain block number fetched from validation -/// data. -/// -/// When validation data is not available (e.g. within `on_initialize`), it will fallback to use -/// [`Pallet::last_relay_block_number()`]. -/// -/// **NOTE**: This has been deprecated, please use [`RelaychainDataProvider`] -#[deprecated = "Use `RelaychainDataProvider` instead"] -pub type RelaychainBlockNumberProvider = RelaychainDataProvider; - -/// Implements [`BlockNumberProvider`] and [`RelaychainStateProvider`] that returns relevant relay -/// data fetched from validation data. -/// -/// NOTE: When validation data is not available (e.g. within `on_initialize`): -/// -/// - [`current_relay_chain_state`](Self::current_relay_chain_state): Will return the default value -/// of [`RelayChainState`]. -/// - [`current_block_number`](Self::current_block_number): Will return -/// [`Pallet::last_relay_block_number()`]. -pub struct RelaychainDataProvider(sp_std::marker::PhantomData); - -impl BlockNumberProvider for RelaychainDataProvider { - type BlockNumber = relay_chain::BlockNumber; - - fn current_block_number() -> relay_chain::BlockNumber { - Pallet::::validation_data() - .map(|d| d.relay_parent_number) - .unwrap_or_else(|| Pallet::::last_relay_block_number()) - } - - #[cfg(feature = "runtime-benchmarks")] - fn set_block_number(block: Self::BlockNumber) { - let mut validation_data = Pallet::::validation_data().unwrap_or_else(|| - // PersistedValidationData does not impl default in non-std - PersistedValidationData { - parent_head: vec![].into(), - relay_parent_number: Default::default(), - max_pov_size: Default::default(), - relay_parent_storage_root: Default::default(), - }); - validation_data.relay_parent_number = block; - ValidationData::::put(validation_data) - } -} - -impl RelaychainStateProvider for RelaychainDataProvider { - fn current_relay_chain_state() -> RelayChainState { - Pallet::::validation_data() - .map(|d| RelayChainState { - number: d.relay_parent_number, - state_root: d.relay_parent_storage_root, - }) - .unwrap_or_default() - } - - #[cfg(feature = "runtime-benchmarks")] - fn set_current_relay_chain_state(state: RelayChainState) { - let mut validation_data = Pallet::::validation_data().unwrap_or_else(|| - // PersistedValidationData does not impl default in non-std - PersistedValidationData { - parent_head: vec![].into(), - relay_parent_number: Default::default(), - max_pov_size: Default::default(), - relay_parent_storage_root: Default::default(), - }); - validation_data.relay_parent_number = state.number; - validation_data.relay_parent_storage_root = state.state_root; - ValidationData::::put(validation_data) - } -} diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index fcf48632184c7..54f4dcd71fa06 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -229,26 +229,6 @@ fn para_to_para_through_relay_sender_assertions(t: ParaToParaThroughRelayTest) { ); } -fn para_to_para_through_system_para_sender_assertions(t: ParaToParaThroughSystemParaTest) { - type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); - PenpalA::assert_xcm_pallet_attempted_complete(None); - - assert_expected_events!( - PenpalA, - vec![ - // Amount to reserve transfer is transferred to Parachain's Sovereign account - RuntimeEvent::ForeignAssets( - pallet_assets::Event::Burned { asset_id, owner, balance }, - ) => { - asset_id: *asset_id == system_para_native_asset_location, - owner: *owner == t.sender.account_id, - balance: *balance == t.args.amount, - }, - ] - ); -} - fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; let sov_penpal_a_on_rococo = @@ -279,35 +259,6 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { ); } -fn para_to_para_system_para_hop_assertions(t: ParaToParaThroughSystemParaTest) { - type RuntimeEvent = ::RuntimeEvent; - let sov_penpal_a_on_rococo = - Rococo::sovereign_account_id_of(Rococo::child_location_of(PenpalA::para_id())); - let sov_penpal_b_on_rococo = - Rococo::sovereign_account_id_of(Rococo::child_location_of(PenpalB::para_id())); - - AssetHubRococo::assert_xcmp_queue_success(None); - - assert_expected_events!( - AssetHubRococo, - vec![ - // Withdrawn from sender parachain SA - RuntimeEvent::Balances( - pallet_balances::Event::Burned { who, amount } - ) => { - who: *who == sov_penpal_a_on_rococo, - amount: *amount == t.args.amount, - }, - // Deposited to receiver parachain SA - RuntimeEvent::Balances( - pallet_balances::Event::Minted { who, .. } - ) => { - who: *who == sov_penpal_b_on_rococo, - }, - ] - ); -} - fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; let relay_asset_location = RelayLocationV3::get(); @@ -325,23 +276,6 @@ fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) ); } -fn para_to_para_through_system_para_receiver_assertions(t: ParaToParaThroughSystemParaTest) { - type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); - - PenpalB::assert_xcmp_queue_success(None); - - assert_expected_events!( - PenpalB, - vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == system_para_native_asset_location, - owner: *owner == t.receiver.account_id, - }, - ] - ); -} - fn relay_to_para_reserve_transfer_assets(t: RelayToParaTest) -> DispatchResult { ::XcmPallet::limited_reserve_transfer_assets( t.signed_origin, @@ -386,17 +320,6 @@ fn para_to_para_through_relay_limited_reserve_transfer_assets(t: ParaToParaThrou ) } -fn para_to_para_through_system_para_limited_reserve_transfer_assets(t: ParaToParaThroughSystemParaTest) -> DispatchResult { - ::PolkadotXcm::limited_reserve_transfer_assets( - t.signed_origin, - bx!(t.args.dest.into()), - bx!(t.args.beneficiary.into()), - bx!(t.args.assets.into()), - t.args.fee_asset_item, - t.args.weight_limit, - ) -} - /// Reserve Transfers of native asset from Relay Chain to the System Parachain shouldn't work #[test] fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { @@ -843,80 +766,3 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { // Receiver's balance is increased assert!(receiver_assets_after > receiver_assets_before); } - -/// Reserve Transfers of native asset from Parachain to Parachain (through Relay reserve) should -/// work -#[test] -fn reserve_transfer_native_asset_from_para_to_para_through_system_para() { - // Init values for Parachain Origin - let destination = PenpalA::sibling_location_of(PenpalB::para_id()); - let sender = PenpalASender::get(); - let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; - let asset_owner = penpal_asset_owner(); - let assets: Assets = ((Parent, Parachain(ASSETHUB_PARA_ID)), amount_to_send).into(); - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); - let sender_as_seen_by_system_para = AssetHubRococo::sibling_location_of(PenpalA::para_id()); - let sov_of_sender_on_system_para = AssetHubRococo::sovereign_account_id_of(sender_as_seen_by_system_para); - - // fund the PenpalA's SA on Rococo with the native tokens held in reserve - AssetHubRococo::fund_accounts(vec![(sov_of_sender_on_system_para.into(), amount_to_send * 2)]); - - // fund Parachain's sender account - PenpalA::mint_foreign_asset( - ::RuntimeOrigin::signed(asset_owner), - system_para_native_asset_location, - sender.clone(), - amount_to_send - ); - - // Init values for Parachain Desitnation - let receiver = PenpalBReceiver::get(); - - // Init Test - let test_args = TestContext { - sender: sender.clone(), - receiver: receiver.clone(), - args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), - }; - let mut test = ParaToParaThroughSystemParaTest::new(test_args); - - // Query initial balances - let sender_assets_before = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) - }); - let receiver_assets_before = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) - }); - - // Set assertions and dispatchables - test.set_assertion::(para_to_para_through_system_para_sender_assertions); - test.set_assertion::(para_to_para_system_para_hop_assertions); - test.set_assertion::(para_to_para_through_system_para_receiver_assertions); - test.set_dispatchable::(para_to_para_through_system_para_limited_reserve_transfer_assets); - test.assert(); - - // Calculate delivery fees - let delivery_fees = PenpalA::execute_with(|| { - let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); - xcm_helpers::transfer_assets_delivery_fees::< - ::XcmSender, - >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) - }); - - // Query final balances - let sender_assets_after = PenpalA::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) - }); - let receiver_assets_after = PenpalB::execute_with(|| { - type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) - }); - - // Sender's balance is reduced - assert_eq!(sender_assets_before - amount_to_send - delivery_fees, sender_assets_after); - // Receiver's balance is increased - assert!(receiver_assets_after > receiver_assets_before); -} diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs index 409369df7bb06..4bdf1e9367969 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs @@ -13,67 +13,77 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub use codec::Encode; +#[cfg(test)] +mod imports { + pub use codec::Encode; + + // Substrate + pub use frame_support::{ + assert_err, assert_ok, + instances::Instance2, + pallet_prelude::Weight, + sp_runtime::{AccountId32, DispatchError, DispatchResult, ModuleError}, + traits::fungibles::Inspect, + BoundedVec, + }; -// Substrate -pub use frame_support::{ - assert_err, assert_ok, - instances::Instance2, - pallet_prelude::Weight, - sp_runtime::{AccountId32, DispatchError, DispatchResult, ModuleError}, - traits::fungibles::Inspect, - BoundedVec, -}; + // Polkadot + pub use xcm::{ + prelude::{AccountId32 as AccountId32Junction, *}, + v3::{self, Error, NetworkId::Westend as WestendId}, + }; -// Polkadot -pub use xcm::{ - prelude::{AccountId32 as AccountId32Junction, *}, - v3::{self, Error, NetworkId::Westend as WestendId}, -}; + // Cumulus + pub use asset_test_utils::xcm_helpers; + pub use emulated_integration_tests_common::{ + test_parachain_is_trusted_teleporter, + xcm_emulator::{ + assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, + RelayChain as Relay, Test, TestArgs, TestContext, TestExt, + }, + xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, + PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, + }; + pub use parachains_common::{AccountId, Balance}; + pub use westend_system_emulated_network::{ + asset_hub_westend_emulated_chain::{ + genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, + }, + collectives_westend_emulated_chain::{ + genesis::ED as COLLECTIVES_WESTEND_ED, + CollectivesWestendParaPallet as CollectivesWestendPallet, + }, + penpal_emulated_chain::PenpalBParaPallet as PenpalBPallet, + westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet}, + AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver, + AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubWestendPara as BridgeHubWestend, + BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, + CollectivesWestendPara as CollectivesWestend, PenpalAPara as PenpalA, + PenpalAParaReceiver as PenpalAReceiver, PenpalBPara as PenpalB, + PenpalBParaReceiver as PenpalBReceiver, PenpalBParaSender as PenpalBSender, + WestendRelay as Westend, WestendRelayReceiver as WestendReceiver, + WestendRelaySender as WestendSender, + }; -// Cumulus -pub use asset_test_utils::xcm_helpers; -pub use emulated_integration_tests_common::{ - test_parachain_is_trusted_teleporter, - xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, - }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, -}; -pub use parachains_common::{AccountId, Balance}; -pub use westend_system_emulated_network::{ - asset_hub_westend_emulated_chain::{ - genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, - }, - collectives_westend_emulated_chain::{ - genesis::ED as COLLECTIVES_WESTEND_ED, - CollectivesWestendParaPallet as CollectivesWestendPallet, - }, - penpal_emulated_chain::PenpalBParaPallet as PenpalBPallet, - westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet}, - AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver, - AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubWestendPara as BridgeHubWestend, - BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, - CollectivesWestendPara as CollectivesWestend, PenpalAPara as PenpalA, - PenpalAParaReceiver as PenpalAReceiver, PenpalBPara as PenpalB, - PenpalBParaReceiver as PenpalBReceiver, PenpalBParaSender as PenpalBSender, - WestendRelay as Westend, WestendRelayReceiver as WestendReceiver, - WestendRelaySender as WestendSender, -}; + pub const ASSET_ID: u32 = 1; + pub const ASSET_MIN_BALANCE: u128 = 1000; + // `Assets` pallet index + pub const ASSETS_PALLET_ID: u8 = 50; -pub const ASSET_ID: u32 = 1; -pub const ASSET_MIN_BALANCE: u128 = 1000; -// `Assets` pallet index -pub const ASSETS_PALLET_ID: u8 = 50; + pub type RelayToSystemParaTest = Test; + pub type RelayToParaTest = Test; + pub type SystemParaToRelayTest = Test; + pub type SystemParaToParaTest = Test; + pub type ParaToSystemParaTest = Test; + pub type ParaToParaTest = Test; -pub type RelayToSystemParaTest = Test; -pub type RelayToParaTest = Test; -pub type SystemParaToRelayTest = Test; -pub type SystemParaToParaTest = Test; -pub type ParaToSystemParaTest = Test; -pub type ParaToParaTest = Test; + emulated_integration_tests_common::include_penpal_create_foreign_asset_on_asset_hub!( + PenpalB, + AssetHubWestend, + WESTEND_ED, + testnet_parachains_constants::westend::fee::WeightToFee + ); +} #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/fellowship_treasury.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/fellowship_treasury.rs index 11e1e1762dbb4..2d02e90f47fb8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/fellowship_treasury.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/fellowship_treasury.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; use emulated_integration_tests_common::accounts::{ALICE, BOB}; use frame_support::traits::fungibles::{Create, Inspect, Mutate}; use polkadot_runtime_common::impls::VersionedLocatableAsset; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs index a56cde8f2a2cb..3cd7c9c46d69e 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs @@ -20,11 +20,3 @@ mod set_xcm_versions; mod swap; mod teleport; mod treasury; - -use crate::*; -emulated_integration_tests_common::include_penpal_create_foreign_asset_on_asset_hub!( - PenpalB, - AssetHubWestend, - WESTEND_ED, - testnet_parachains_constants::westend::fee::WeightToFee -); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index a29cd10ba8338..9e70cb9f8f649 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -13,10 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; -use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig; -use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; -use westend_system_emulated_network::penpal_emulated_chain::XcmConfig as PenpalWestendXcmConfig; +use crate::imports::*; fn relay_to_para_sender_assertions(t: RelayToParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -44,8 +41,8 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; AssetHubWestend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( - 676_119_000, - 6196, + 864_610_000, + 8_799, ))); assert_expected_events!( @@ -61,37 +58,45 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { ), amount: *amount == t.args.amount, }, + // Transport fees are paid + RuntimeEvent::PolkadotXcm( + pallet_xcm::Event::FeesPaid { .. } + ) => {}, ] ); + AssetHubWestend::assert_xcm_pallet_sent(); } -fn para_receiver_assertions(_: Test) { - type RuntimeEvent = ::RuntimeEvent; +fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { + type RuntimeEvent = ::RuntimeEvent; + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + + PenpalA::assert_xcmp_queue_success(None); + assert_expected_events!( - PenpalB, + PenpalA, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Minted { .. }) => {}, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.receiver.account_id, + }, ] ); } fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { - type RuntimeEvent = ::RuntimeEvent; - - PenpalB::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8_799))); - + type RuntimeEvent = ::RuntimeEvent; + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8_799))); assert_expected_events!( - PenpalB, + PenpalA, vec![ // Amount to reserve transfer is transferred to Parachain's Sovereign account - RuntimeEvent::Balances( - pallet_balances::Event::Burned { who, amount } + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - who: *who == t.sender.account_id, - amount: *amount == t.args.amount, + asset_id: *asset_id == SystemAssetHubLocationV3::get(), + owner: *owner == t.sender.account_id, + balance: *balance == t.args.amount, }, ] ); @@ -99,19 +104,20 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - - let sov_penpal_on_ahw = AssetHubWestend::sovereign_account_id_of( - AssetHubWestend::sibling_location_of(PenpalB::para_id()), + let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of( + AssetHubWestend::sibling_location_of(PenpalA::para_id()), ); + AssetHubWestend::assert_xcmp_queue_success(None); + assert_expected_events!( AssetHubWestend, vec![ - // Amount to reserve transfer is transferred to Parachain's Sovereign account + // Amount to reserve transfer is withdrawn from Parachain's Sovereign account RuntimeEvent::Balances( pallet_balances::Event::Burned { who, amount } ) => { - who: *who == sov_penpal_on_ahw.clone().into(), + who: *who == sov_penpal_on_ahr.clone().into(), amount: *amount == t.args.amount, }, RuntimeEvent::Balances(pallet_balances::Event::Minted { .. }) => {}, @@ -124,12 +130,10 @@ fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) { fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - AssetHubWestend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( - 676_119_000, - 6196, + 864_610_000, + 8799, ))); - assert_expected_events!( AssetHubWestend, vec![ @@ -144,17 +148,56 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { ), amount: *amount == t.args.amount, }, + // Native asset to pay for fees is transferred to Parachain's Sovereign account + RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { + who: *who == AssetHubWestend::sovereign_account_id_of( + t.args.dest.clone() + ), + }, + // Transport fees are paid + RuntimeEvent::PolkadotXcm( + pallet_xcm::Event::FeesPaid { .. } + ) => {}, ] ); } -fn system_para_to_para_assets_receiver_assertions(_: Test) { - type RuntimeEvent = ::RuntimeEvent; +fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { + type RuntimeEvent = ::RuntimeEvent; + let system_para_asset_location = xcm::v3::Location::new( + 1, [ + xcm::v3::Junction::Parachain(ASSETHUB_PARA_ID), + xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), + ] + ); + PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( - PenpalB, + PenpalA, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Minted { .. }) => {}, - RuntimeEvent::Assets(pallet_assets::Event::Issued { .. }) => {}, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == SystemAssetHubLocationV3::get(), + owner: *owner == t.receiver.account_id, + }, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + asset_id: *asset_id == system_para_asset_location, + owner: *owner == t.receiver.account_id, + amount: *amount == t.args.amount, + }, + ] + ); +} + +fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PenpalA, + vec![ + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == RelayLocationV3::get(), + owner: *owner == t.receiver.account_id, + }, RuntimeEvent::MessageQueue( pallet_message_queue::Event::Processed { success: true, .. } ) => {}, @@ -162,33 +205,37 @@ fn system_para_to_para_assets_receiver_assertions(_: Test) { ); } -fn para_to_para_sender_assertions(t: ParaToParaTest) { - type RuntimeEvent = ::RuntimeEvent; - PenpalB::assert_xcm_pallet_attempted_complete(None); +fn para_to_para_through_relay_sender_assertions(t: ParaToParaThroughRelayTest) { + type RuntimeEvent = ::RuntimeEvent; + + let relay_asset_location = RelayLocationV3::get(); + + PenpalA::assert_xcm_pallet_attempted_complete(None); + // XCM sent to relay reserve + PenpalA::assert_parachain_system_ump_sent(); + assert_expected_events!( - PenpalB, + PenpalA, vec![ // Amount to reserve transfer is transferred to Parachain's Sovereign account - RuntimeEvent::Balances( - pallet_balances::Event::Burned { who, amount } + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, balance }, ) => { - who: *who == t.sender.account_id, - amount: *amount == t.args.amount, + asset_id: *asset_id == relay_asset_location, + owner: *owner == t.sender.account_id, + balance: *balance == t.args.amount, }, - // XCM sent to relay reserve - RuntimeEvent::ParachainSystem( - cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. } - ) => {}, ] ); } -fn para_to_para_relay_hop_assertions(t: ParaToParaTest) { +fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let sov_penpal_b_on_westend = - Westend::sovereign_account_id_of(Westend::child_location_of(PenpalB::para_id())); let sov_penpal_a_on_westend = Westend::sovereign_account_id_of(Westend::child_location_of(PenpalA::para_id())); + let sov_penpal_b_on_westend = + Westend::sovereign_account_id_of(Westend::child_location_of(PenpalB::para_id())); + assert_expected_events!( Westend, vec![ @@ -196,14 +243,14 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaTest) { RuntimeEvent::Balances( pallet_balances::Event::Burned { who, amount } ) => { - who: *who == sov_penpal_b_on_westend, + who: *who == sov_penpal_a_on_westend, amount: *amount == t.args.amount, }, // Deposited to receiver parachain SA RuntimeEvent::Balances( pallet_balances::Event::Minted { who, .. } ) => { - who: *who == sov_penpal_a_on_westend, + who: *who == sov_penpal_b_on_westend, }, RuntimeEvent::MessageQueue( pallet_message_queue::Event::Processed { success: true, .. } @@ -212,15 +259,19 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaTest) { ); } -fn para_to_para_receiver_assertions(_: ParaToParaTest) { - type RuntimeEvent = ::RuntimeEvent; +fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) { + type RuntimeEvent = ::RuntimeEvent; + let relay_asset_location = RelayLocationV3::get(); + + PenpalB::assert_xcmp_queue_success(None); + assert_expected_events!( - PenpalA, + PenpalB, vec![ - RuntimeEvent::Balances(pallet_balances::Event::Minted { .. }) => {}, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == relay_asset_location, + owner: *owner == t.receiver.account_id, + }, ] ); } @@ -248,7 +299,7 @@ fn system_para_to_para_reserve_transfer_assets(t: SystemParaToParaTest) -> Dispa } fn para_to_system_para_reserve_transfer_assets(t: ParaToSystemParaTest) -> DispatchResult { - ::PolkadotXcm::limited_reserve_transfer_assets( + ::PolkadotXcm::limited_reserve_transfer_assets( t.signed_origin, bx!(t.args.dest.into()), bx!(t.args.beneficiary.into()), @@ -258,8 +309,8 @@ fn para_to_system_para_reserve_transfer_assets(t: ParaToSystemParaTest) -> Dispa ) } -fn para_to_para_limited_reserve_transfer_assets(t: ParaToParaTest) -> DispatchResult { - ::PolkadotXcm::limited_reserve_transfer_assets( +fn para_to_para_through_relay_limited_reserve_transfer_assets(t: ParaToParaThroughRelayTest) -> DispatchResult { + ::PolkadotXcm::limited_reserve_transfer_assets( t.signed_origin, bx!(t.args.dest.into()), bx!(t.args.beneficiary.into()), @@ -272,6 +323,7 @@ fn para_to_para_limited_reserve_transfer_assets(t: ParaToParaTest) -> DispatchRe /// Reserve Transfers of native asset from Relay Chain to the System Parachain shouldn't work #[test] fn reserve_transfer_native_asset_from_relay_to_system_para_fails() { + // Init values for Relay Chain let signed_origin = ::RuntimeOrigin::signed(WestendSender::get().into()); let destination = Westend::child_location_of(AssetHubWestend::para_id()); let beneficiary: Location = @@ -312,6 +364,7 @@ fn reserve_transfer_native_asset_from_system_para_to_relay_fails() { let beneficiary: Location = AccountId32Junction { network: None, id: beneficiary_id.into() }.into(); let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; + let assets: Assets = (Parent, amount_to_send).into(); let fee_asset_item = 0; @@ -341,132 +394,186 @@ fn reserve_transfer_native_asset_from_system_para_to_relay_fails() { #[test] fn reserve_transfer_native_asset_from_relay_to_para() { // Init values for Relay - let destination = Westend::child_location_of(PenpalB::para_id()); - let beneficiary_id = PenpalBReceiver::get(); + let destination = Westend::child_location_of(PenpalA::para_id()); + let sender = WestendSender::get(); let amount_to_send: Balance = WESTEND_ED * 1000; + let assets: Assets = (Here, amount_to_send).into(); + + // Init values fot Parachain + let relay_native_asset_location = RelayLocationV3::get(); + let receiver = PenpalAReceiver::get(); + // Init Test let test_args = TestContext { - sender: WestendSender::get(), - receiver: PenpalBReceiver::get(), - args: TestArgs::new_relay(destination, beneficiary_id, amount_to_send), + sender, + receiver: receiver.clone(), + args: TestArgs::new_relay(destination.clone(), receiver.clone(), amount_to_send), }; - let mut test = RelayToParaTest::new(test_args); + // Query initial balances let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; + let receiver_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.into(), &receiver) + }); + // Set assertions and dispatchables test.set_assertion::(relay_to_para_sender_assertions); - test.set_assertion::(para_receiver_assertions); + test.set_assertion::(relay_to_para_assets_receiver_assertions); test.set_dispatchable::(relay_to_para_reserve_transfer_assets); test.assert(); + // Calculate delivery fees let delivery_fees = Westend::execute_with(|| { + let reanchored_assets = assets.reanchored( &destination, &WestendUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); + // Query final balances let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; + let receiver_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.into(), &receiver) + }); // Sender's balance is reduced assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); - // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); - // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; + // Receiver's asset balance is increased + assert!(receiver_assets_after > receiver_assets_before); + // Receiver's asset balance increased by `amount_to_send - delivery_fees - bought_execution`; // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but // should be non-zero - assert!(receiver_balance_after < receiver_balance_before + amount_to_send); + assert!(receiver_assets_after < receiver_assets_before + amount_to_send); } /// Reserve Transfers of native asset from System Parachain to Parachain should work #[test] fn reserve_transfer_native_asset_from_system_para_to_para() { // Init values for System Parachain - let destination = AssetHubWestend::sibling_location_of(PenpalB::para_id()); - let beneficiary_id = PenpalBReceiver::get(); - let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; - let assets = (Parent, amount_to_send).into(); + let destination = AssetHubWestend::sibling_location_of(PenpalA::para_id()); + let sender = AssetHubWestendSender::get(); + let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 10000; + let assets: Assets = (Here, amount_to_send).into(); + + // Init values for Parachain + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let receiver = PenpalAReceiver::get(); + // Init Test let test_args = TestContext { - sender: AssetHubWestendSender::get(), - receiver: PenpalBReceiver::get(), - args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), + sender, + receiver: receiver.clone(), + args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), }; - let mut test = SystemParaToParaTest::new(test_args); + // Query initial balances let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; + let receiver_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.into(), &receiver) + }); + // Set assertions and dispatchables test.set_assertion::(system_para_to_para_sender_assertions); - test.set_assertion::(para_receiver_assertions); + // test.set_assertion::(system_para_to_para_native_assets_receiver_assertions); + test.set_assertion::(system_para_to_para_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - + // Calculate delivery fees let delivery_fees = AssetHubWestend::execute_with(|| { + let reanchored_assets = assets.reanchored( &destination, &AssetHubWestendUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + // Query final balances + let sender_balance_after = test.sender.balance; + let receiver_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &receiver) }); // Sender's balance is reduced assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); - // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); - // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; + // Receiver's assets is increased + assert!(receiver_assets_after > receiver_assets_before); + // Receiver's assets increased by `amount_to_send - delivery_fees - bought_execution`; // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but // should be non-zero - assert!(receiver_balance_after < receiver_balance_before + amount_to_send); + assert!(receiver_assets_after < receiver_assets_before + amount_to_send); } /// Reserve Transfers of native asset from Parachain to System Parachain should work #[test] fn reserve_transfer_native_asset_from_para_to_system_para() { - // Init values for Penpal Parachain - let destination = PenpalB::sibling_location_of(AssetHubWestend::para_id()); - let beneficiary_id = AssetHubWestendReceiver::get(); + // Init values for Parachain + let destination = PenpalA::sibling_location_of(AssetHubWestend::para_id()); + let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; - let assets = (Parent, amount_to_send).into(); + let assets: Assets = ((Parent, Parachain(ASSETHUB_PARA_ID)), amount_to_send).into(); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let asset_owner = penpal_asset_owner(); + + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner), + system_para_native_asset_location, + sender.clone(), + amount_to_send + ); + + // Init values for System Parachain + let receiver = AssetHubWestendReceiver::get(); + let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id()); + let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); + + // fund Parachain's SA on System Parachain with the native tokens held in reserve + AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ahr.into(), amount_to_send * 2)]); + // Init Test let test_args = TestContext { - sender: PenpalBSender::get(), - receiver: AssetHubWestendReceiver::get(), - args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), + sender: sender.clone(), + receiver: receiver.clone(), + args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), }; - let mut test = ParaToSystemParaTest::new(test_args); - let sender_balance_before = test.sender.balance; + // Query initial balances + let sender_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &sender) + }); let receiver_balance_before = test.receiver.balance; - let penpal_location_as_seen_by_ahw = AssetHubWestend::sibling_location_of(PenpalB::para_id()); - let sov_penpal_on_ahw = - AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahw); - - // fund the Penpal's SA on AHW with the native tokens held in reserve - AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ahw.into(), amount_to_send * 2)]); - - test.set_assertion::(para_to_system_para_sender_assertions); + // Set assertions and dispatchables + test.set_assertion::(para_to_system_para_sender_assertions); test.set_assertion::(para_to_system_para_receiver_assertions); - test.set_dispatchable::(para_to_system_para_reserve_transfer_assets); + test.set_dispatchable::(para_to_system_para_reserve_transfer_assets); test.assert(); - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - - let delivery_fees = PenpalB::execute_with(|| { + // Calculate delivery fees + let delivery_fees = PenpalA::execute_with(|| { + let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, - >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); + // Query final balances + let sender_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &sender) + }); + let receiver_balance_after = test.receiver.balance; + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + assert_eq!(sender_assets_before - amount_to_send - delivery_fees, sender_assets_after); // Receiver's balance is increased assert!(receiver_balance_after > receiver_balance_before); // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; @@ -479,149 +586,183 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { /// work #[test] fn reserve_transfer_assets_from_system_para_to_para() { - // Force create asset on AssetHubWestend and PenpalB from Relay Chain - AssetHubWestend::force_create_and_mint_asset( - ASSET_ID, - ASSET_MIN_BALANCE, - true, - AssetHubWestendSender::get(), - Some(Weight::from_parts(1_019_445_000, 200_000)), - ASSET_MIN_BALANCE * 1_000_000, - ); - PenpalB::force_create_and_mint_asset( - ASSET_ID, - ASSET_MIN_BALANCE, - false, - PenpalBSender::get(), - None, - 0, - ); - // Init values for System Parachain - let destination = AssetHubWestend::sibling_location_of(PenpalB::para_id()); - let beneficiary_id = PenpalBReceiver::get(); - let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 1000; - let asset_amount_to_send = ASSET_MIN_BALANCE * 1000; + let destination = AssetHubWestend::sibling_location_of(PenpalA::para_id()); + let sender = AssetHubWestendSender::get(); + let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 10000; + let asset_amount_to_send = ASSET_MIN_BALANCE * 10000; + let asset_owner = penpal_asset_owner(); let assets: Assets = vec![ - (Parent, fee_amount_to_send).into(), + (Here, fee_amount_to_send).into(), ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], asset_amount_to_send) .into(), ] .into(); + let is_sufficient = false; + let min_balance = ASSET_MIN_BALANCE; let fee_asset_index = assets .inner() .iter() - .position(|r| r == &(Parent, fee_amount_to_send).into()) + .position(|r| r == &(Here, fee_amount_to_send).into()) .unwrap() as u32; + AssetHubWestend::force_create_and_mint_asset( + ASSET_ID, + min_balance, + is_sufficient, + asset_owner.clone(), + Some(Weight::from_parts(1_019_445_000, 200_000)), + min_balance * 1_000_000, + ); + + // Init values for Parachain + let receiver = PenpalAReceiver::get(); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_foreign_asset_location = xcm::v3::Location::new( + 1, [ + xcm::v3::Junction::Parachain(ASSETHUB_PARA_ID), + xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), + ] + ); + PenpalA::force_create_foreign_asset(system_para_foreign_asset_location.clone(), asset_owner.clone(), is_sufficient, min_balance, vec![]); + // Init Test let para_test_args = TestContext { - sender: AssetHubWestendSender::get(), - receiver: PenpalBReceiver::get(), + sender: sender.clone(), + receiver: receiver.clone(), args: TestArgs::new_para( destination, - beneficiary_id, + receiver.clone(), asset_amount_to_send, assets, None, fee_asset_index, ), }; - let mut test = SystemParaToParaTest::new(para_test_args); - // Create SA-of-Penpal-on-AHW with ED. - let penpal_location = AssetHubWestend::sibling_location_of(PenpalB::para_id()); - let sov_penpal_on_ahw = AssetHubWestend::sovereign_account_id_of(penpal_location); - AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ahw.into(), WESTEND_ED)]); - + // Query initial balances let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; - let sender_assets_before = AssetHubWestend::execute_with(|| { type Assets = ::Assets; - >::balance(ASSET_ID, &AssetHubWestendSender::get()) + >::balance(ASSET_ID, &sender) }); - let receiver_assets_before = PenpalB::execute_with(|| { - type Assets = ::Assets; - >::balance(ASSET_ID, &PenpalBReceiver::get()) + let receiver_system_native_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &receiver) + }); + let receiver_foreign_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_foreign_asset_location.clone(), &receiver) }); + // Set assertions and dispatchables test.set_assertion::(system_para_to_para_assets_sender_assertions); - test.set_assertion::(system_para_to_para_assets_receiver_assertions); + test.set_assertion::(system_para_to_para_assets_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); + // Query final balances let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - - // Sender's balance is reduced - assert!(sender_balance_after < sender_balance_before); - // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); - // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; - // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but - // should be non-zero - assert!(receiver_balance_after < receiver_balance_before + fee_amount_to_send); - let sender_assets_after = AssetHubWestend::execute_with(|| { type Assets = ::Assets; - >::balance(ASSET_ID, &AssetHubWestendSender::get()) + >::balance(ASSET_ID, &sender) }); - let receiver_assets_after = PenpalB::execute_with(|| { - type Assets = ::Assets; - >::balance(ASSET_ID, &PenpalBReceiver::get()) + let receiver_system_native_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &receiver) }); + let receiver_foreign_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_foreign_asset_location.clone(), &receiver) + }); + // Sender's balance is reduced + assert!(sender_balance_after < sender_balance_before); + // Receiver's foreign asset balance is increased + assert!(receiver_foreign_assets_after > receiver_foreign_assets_before); + // Receiver's system asset balance increased by `amount_to_send - delivery_fees - bought_execution`; + // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but + // should be non-zero + assert!(receiver_system_native_assets_after < receiver_system_native_assets_before + fee_amount_to_send); - // Sender's balance is reduced by exact amount + // Sender's asset balance is reduced by exact amount assert_eq!(sender_assets_before - asset_amount_to_send, sender_assets_after); - // Receiver's balance is increased by exact amount - assert_eq!(receiver_assets_after, receiver_assets_before + asset_amount_to_send); + // Receiver's foreign asset balance is increased by exact amount + assert_eq!(receiver_foreign_assets_after, receiver_foreign_assets_before + asset_amount_to_send); } /// Reserve Transfers of native asset from Parachain to Parachain (through Relay reserve) should /// work #[test] -fn reserve_transfer_native_asset_from_para_to_para() { - // Init values for Penpal Parachain - let destination = PenpalB::sibling_location_of(PenpalA::para_id()); - let beneficiary_id = PenpalAReceiver::get(); - let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; +fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { + // Init values for Parachain Origin + let destination = PenpalA::sibling_location_of(PenpalB::para_id()); + let sender = PenpalASender::get(); + let amount_to_send: Balance = WESTEND_ED * 10000; + let asset_owner = penpal_asset_owner(); let assets = (Parent, amount_to_send).into(); + let relay_native_asset_location = RelayLocationV3::get(); + let sender_as_seen_by_relay = Westend::child_location_of(PenpalA::para_id()); + let sov_of_sender_on_relay = Westend::sovereign_account_id_of(sender_as_seen_by_relay); - let test_args = TestContext { - sender: PenpalBSender::get(), - receiver: PenpalAReceiver::get(), - args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0), - }; + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner), + relay_native_asset_location, + sender.clone(), + amount_to_send + ); - let mut test = ParaToParaTest::new(test_args); + // fund the Parachain Origin's SA on Relay Chain with the native tokens held in reserve + Westend::fund_accounts(vec![(sov_of_sender_on_relay.into(), amount_to_send * 2)]); - let sender_balance_before = test.sender.balance; - let receiver_balance_before = test.receiver.balance; + // Init values for Parachain Desitnation + let receiver = PenpalBReceiver::get(); - let sender_as_seen_by_relay = Westend::child_location_of(PenpalB::para_id()); - let sov_of_sender_on_relay = Westend::sovereign_account_id_of(sender_as_seen_by_relay); + // Init Test + let test_args = TestContext { + sender: sender.clone(), + receiver: receiver.clone(), + args: TestArgs::new_para(destination, receiver.clone(), amount_to_send, assets, None, 0), + }; + let mut test = ParaToParaThroughRelayTest::new(test_args); - // fund the PenpalB's SA on Westend with the native tokens held in reserve - Westend::fund_accounts(vec![(sov_of_sender_on_relay.into(), amount_to_send * 2)]); + // Query initial balances + let sender_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.clone(), &sender) + }); + let receiver_assets_before = PenpalB::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.clone(), &receiver) + }); - test.set_assertion::(para_to_para_sender_assertions); + // Set assertions and dispatchables + test.set_assertion::(para_to_para_through_relay_sender_assertions); test.set_assertion::(para_to_para_relay_hop_assertions); - test.set_assertion::(para_to_para_receiver_assertions); - test.set_dispatchable::(para_to_para_limited_reserve_transfer_assets); + test.set_assertion::(para_to_para_through_relay_receiver_assertions); + test.set_dispatchable::(para_to_para_through_relay_limited_reserve_transfer_assets); test.assert(); - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - - let delivery_fees = PenpalB::execute_with(|| { + // Calculate delivery fees + let delivery_fees = PenpalA::execute_with(|| { xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); + // Query final balances + let sender_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.clone(), &sender) + }); + let receiver_assets_after = PenpalB::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.clone(), &receiver) + }); + // Sender's balance is reduced - assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); + assert_eq!(sender_assets_before - amount_to_send - delivery_fees, sender_assets_after); // Receiver's balance is increased - assert!(receiver_balance_after > receiver_balance_before); + assert!(receiver_assets_after > receiver_assets_before); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs index a3cd5c5803eef..84e93841ad7bd 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; /// Relay Chain should be able to execute `Transact` instructions in System Parachain /// when `OriginKind::Superuser`. diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/set_xcm_versions.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/set_xcm_versions.rs index 130454551d2ca..474e9a86ccc22 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/set_xcm_versions.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/set_xcm_versions.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; #[test] fn relay_sets_system_para_xcm_supported_version() { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index b39cc2159de8d..b75eafeec50a8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -13,8 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; -use westend_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3; +use crate::imports::*; #[test] fn swap_locally_on_chain_using_local_assets() { @@ -126,7 +125,7 @@ fn swap_locally_on_chain_using_foreign_assets() { .unwrap(); // 1. Create asset on penpal and, 2. Create foreign asset on asset_hub_westend - super::penpal_create_foreign_asset_on_asset_hub( + penpal_create_foreign_asset_on_asset_hub( asset_id_on_penpal, foreign_asset_at_asset_hub_westend, ah_as_seen_by_penpal, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 0dd1a1533b559..0827baa09ab28 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -13,16 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; -use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig; -use emulated_integration_tests_common::xcm_helpers::non_fee_asset; -use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; -use westend_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3; +use crate::imports::*; fn relay_origin_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - Westend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(632_207_000, 7_186))); + Westend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(631_531_000, 7_186))); assert_expected_events!( Westend, @@ -47,7 +43,7 @@ fn relay_dest_assertions(t: SystemParaToRelayTest) { Westend::assert_ump_queue_processed( true, Some(AssetHubWestend::para_id()), - Some(Weight::from_parts(308_222_000, 7_186)), + Some(Weight::from_parts(307_225_000, 7_186)), ); assert_expected_events!( @@ -70,7 +66,7 @@ fn relay_dest_assertions_fail(_t: SystemParaToRelayTest) { Westend::assert_ump_queue_processed( false, Some(AssetHubWestend::para_id()), - Some(Weight::from_parts(148_705_000, 3_593)), + Some(Weight::from_parts(157_718_000, 3_593)), ); } @@ -78,8 +74,8 @@ fn para_origin_assertions(t: SystemParaToRelayTest) { type RuntimeEvent = ::RuntimeEvent; AssetHubWestend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( - 533_910_000, - 7167, + 720_053_000, + 7_203, ))); AssetHubWestend::assert_parachain_system_ump_sent(); @@ -99,7 +95,7 @@ fn para_origin_assertions(t: SystemParaToRelayTest) { fn para_dest_assertions(t: RelayToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - AssetHubWestend::assert_dmp_queue_complete(Some(Weight::from_parts(164_793_000, 3593))); + AssetHubWestend::assert_dmp_queue_complete(Some(Weight::from_parts(157_718_000, 3593))); assert_expected_events!( AssetHubWestend, @@ -113,19 +109,21 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { } fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { - type RuntimeEvent = ::RuntimeEvent; - PenpalB::assert_xcm_pallet_attempted_complete(None); + type RuntimeEvent = ::RuntimeEvent; + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); + + PenpalA::assert_xcm_pallet_attempted_complete(None); assert_expected_events!( - PenpalB, + PenpalA, vec![ - RuntimeEvent::Balances( - pallet_balances::Event::Burned { who, amount } + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, .. } ) => { - who: *who == t.sender.account_id, - amount: *amount == t.args.amount, + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.sender.account_id, }, RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { asset_id: *asset_id == expected_asset_id, @@ -139,11 +137,14 @@ fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of( - AssetHubWestend::sibling_location_of(PenpalB::para_id()), + AssetHubWestend::sibling_location_of(PenpalA::para_id()), ); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); + + AssetHubWestend::assert_xcmp_queue_success(None); + assert_expected_events!( AssetHubWestend, vec![ @@ -163,9 +164,9 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { amount: *amount == expected_foreign_asset_amount, }, RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, + // RuntimeEvent::MessageQueue( + // pallet_message_queue::Event::Processed { success: true, .. } + // ) => {}, ] ); } @@ -200,13 +201,17 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { } fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { - type RuntimeEvent = ::RuntimeEvent; + type RuntimeEvent = ::RuntimeEvent; let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); - let checking_account = ::PolkadotXcm::check_account(); + let checking_account = ::PolkadotXcm::check_account(); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + + PenpalA::assert_xcmp_queue_success(None); + assert_expected_events!( - PenpalB, + PenpalA, vec![ // checking account burns local asset as part of incoming teleport RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { @@ -221,12 +226,11 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { amount: *amount == expected_asset_amount, }, // native asset for fee is deposited to receiver - RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { - who: *who == t.receiver.account_id, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.receiver.account_id, + amount: *amount == expected_asset_amount, }, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, ] ); } @@ -273,8 +277,8 @@ fn system_para_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult { ) } -fn system_para_to_para_transfer_assets(t: SystemParaToParaTest) -> DispatchResult { - ::PolkadotXcm::transfer_assets( +fn para_to_system_para_transfer_assets(t: ParaToSystemParaTest) -> DispatchResult { + ::PolkadotXcm::transfer_assets( t.signed_origin, bx!(t.args.dest.into()), bx!(t.args.beneficiary.into()), @@ -284,8 +288,8 @@ fn system_para_to_para_transfer_assets(t: SystemParaToParaTest) -> DispatchResul ) } -fn para_to_system_para_transfer_assets(t: ParaToSystemParaTest) -> DispatchResult { - ::PolkadotXcm::transfer_assets( +fn system_para_to_para_transfer_assets(t: SystemParaToParaTest) -> DispatchResult { + ::PolkadotXcm::transfer_assets( t.signed_origin, bx!(t.args.dest.into()), bx!(t.args.beneficiary.into()), @@ -301,11 +305,11 @@ fn limited_teleport_native_assets_from_relay_to_system_para_works() { // Init values for Relay Chain let amount_to_send: Balance = WESTEND_ED * 1000; let dest = Westend::child_location_of(AssetHubWestend::para_id()); - let beneficiary = AssetHubWestendReceiver::get(); + let beneficiary_id = AssetHubWestendReceiver::get(); let test_args = TestContext { sender: WestendSender::get(), - receiver: beneficiary.clone(), - args: TestArgs::new_relay(dest, beneficiary, amount_to_send), + receiver: AssetHubWestendReceiver::get(), + args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send), }; let mut test = RelayToSystemParaTest::new(test_args); @@ -424,11 +428,11 @@ fn teleport_native_assets_from_relay_to_system_para_works() { // Init values for Relay Chain let amount_to_send: Balance = WESTEND_ED * 1000; let dest = Westend::child_location_of(AssetHubWestend::para_id()); - let beneficiary = AssetHubWestendReceiver::get(); + let beneficiary_id = AssetHubWestendReceiver::get(); let test_args = TestContext { sender: WestendSender::get(), - receiver: beneficiary.clone(), - args: TestArgs::new_relay(dest, beneficiary, amount_to_send), + receiver: AssetHubWestendReceiver::get(), + args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send), }; let mut test = RelayToSystemParaTest::new(test_args); @@ -485,15 +489,15 @@ fn teleport_native_assets_back_from_system_para_to_relay_works() { test.set_dispatchable::(system_para_teleport_assets); test.assert(); + let sender_balance_after = test.sender.balance; + let receiver_balance_after = test.receiver.balance; + let delivery_fees = AssetHubWestend::execute_with(|| { xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) }); - let sender_balance_after = test.sender.balance; - let receiver_balance_after = test.receiver.balance; - // Sender's balance is reduced assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after); // Receiver's balance is increased @@ -558,45 +562,62 @@ fn teleport_to_other_system_parachains_works() { /// (using native reserve-based transfer for fees) #[test] fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { - let ah_as_seen_by_penpal = PenpalB::sibling_location_of(AssetHubWestend::para_id()); + // Init values for Parachain + let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 10000; + let asset_owner = penpal_asset_owner(); + let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let sender = PenpalASender::get(); + + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner.clone()), + system_para_native_asset_location, + sender.clone(), + fee_amount_to_send + ); + + let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubWestend::para_id()); let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); let asset_id_on_penpal = match asset_location_on_penpal.last() { Some(v3::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; - let asset_owner_on_penpal = PenpalBSender::get(); + let foreign_asset_at_asset_hub_westend = - v3::Location::new(1, [v3::Junction::Parachain(PenpalB::para_id().into())]) + v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); - super::penpal_create_foreign_asset_on_asset_hub( + + penpal_create_foreign_asset_on_asset_hub( asset_id_on_penpal, foreign_asset_at_asset_hub_westend, ah_as_seen_by_penpal.clone(), false, - asset_owner_on_penpal, + asset_owner, ASSET_MIN_BALANCE * 1_000_000, ); + + // Init values for System Parachain let penpal_to_ah_beneficiary_id = AssetHubWestendReceiver::get(); - let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 1000; + // let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000; let asset_amount_to_send = ASSET_MIN_BALANCE * 1000; let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); let penpal_assets: Assets = vec![ - (Parent, fee_amount_to_send).into(), + ((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into(), (asset_location_on_penpal_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = penpal_assets .inner() .iter() - .position(|r| r == &(Parent, fee_amount_to_send).into()) + .position(|r| r == &((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into()) .unwrap() as u32; // Penpal to AH test args let penpal_to_ah_test_args = TestContext { - sender: PenpalBSender::get(), + sender: PenpalASender::get(), receiver: AssetHubWestendReceiver::get(), args: TestArgs::new_para( ah_as_seen_by_penpal, @@ -609,12 +630,17 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { }; let mut penpal_to_ah = ParaToSystemParaTest::new(penpal_to_ah_test_args); - let penpal_sender_balance_before = penpal_to_ah.sender.balance; + // let penpal_sender_balance_before = penpal_to_ah.sender.balance; + let penpal_sender_balance_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &PenpalASender::get()) + }); + let ah_receiver_balance_before = penpal_to_ah.receiver.balance; - let penpal_sender_assets_before = PenpalB::execute_with(|| { - type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalBSender::get()) + let penpal_sender_assets_before = PenpalA::execute_with(|| { + type Assets = ::Assets; + >::balance(asset_id_on_penpal, &PenpalASender::get()) }); let ah_receiver_assets_before = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; @@ -624,17 +650,21 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { ) }); - penpal_to_ah.set_assertion::(penpal_to_ah_foreign_assets_sender_assertions); + penpal_to_ah.set_assertion::(penpal_to_ah_foreign_assets_sender_assertions); penpal_to_ah.set_assertion::(penpal_to_ah_foreign_assets_receiver_assertions); - penpal_to_ah.set_dispatchable::(para_to_system_para_transfer_assets); + penpal_to_ah.set_dispatchable::(para_to_system_para_transfer_assets); penpal_to_ah.assert(); - let penpal_sender_balance_after = penpal_to_ah.sender.balance; + let penpal_sender_balance_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &PenpalASender::get()) + }); + let ah_receiver_balance_after = penpal_to_ah.receiver.balance; - let penpal_sender_assets_after = PenpalB::execute_with(|| { - type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalBSender::get()) + let penpal_sender_assets_after = PenpalA::execute_with(|| { + type Assets = ::Assets; + >::balance(asset_id_on_penpal, &PenpalASender::get()) }); let ah_receiver_assets_after = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; @@ -675,23 +705,23 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let foreign_asset_at_asset_hub_westend_latest: Location = foreign_asset_at_asset_hub_westend.try_into().unwrap(); - let ah_to_penpal_beneficiary_id = PenpalBReceiver::get(); - let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalB::para_id()); + let ah_to_penpal_beneficiary_id = PenpalAReceiver::get(); + let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let ah_assets: Assets = vec![ - (Parent, fee_amount_to_send).into(), + (Here, fee_amount_to_send).into(), (foreign_asset_at_asset_hub_westend_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = ah_assets .inner() .iter() - .position(|r| r == &(Parent, fee_amount_to_send).into()) + .position(|r| r == &(Here, fee_amount_to_send).into()) .unwrap() as u32; // AH to Penpal test args let ah_to_penpal_test_args = TestContext { sender: AssetHubWestendSender::get(), - receiver: PenpalBReceiver::get(), + receiver: PenpalAReceiver::get(), args: TestArgs::new_para( penpal_as_seen_by_ah, ah_to_penpal_beneficiary_id, @@ -704,7 +734,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let mut ah_to_penpal = SystemParaToParaTest::new(ah_to_penpal_test_args); let ah_sender_balance_before = ah_to_penpal.sender.balance; - let penpal_receiver_balance_before = ah_to_penpal.receiver.balance; + let penpal_receiver_balance_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &PenpalAReceiver::get()) + }); let ah_sender_assets_before = AssetHubWestend::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -713,18 +746,21 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { &AssetHubWestendSender::get(), ) }); - let penpal_receiver_assets_before = PenpalB::execute_with(|| { - type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalBReceiver::get()) + let penpal_receiver_assets_before = PenpalA::execute_with(|| { + type Assets = ::Assets; + >::balance(asset_id_on_penpal, &PenpalAReceiver::get()) }); ah_to_penpal.set_assertion::(ah_to_penpal_foreign_assets_sender_assertions); - ah_to_penpal.set_assertion::(ah_to_penpal_foreign_assets_receiver_assertions); + ah_to_penpal.set_assertion::(ah_to_penpal_foreign_assets_receiver_assertions); ah_to_penpal.set_dispatchable::(system_para_to_para_transfer_assets); ah_to_penpal.assert(); let ah_sender_balance_after = ah_to_penpal.sender.balance; - let penpal_receiver_balance_after = ah_to_penpal.receiver.balance; + let penpal_receiver_balance_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location, &PenpalAReceiver::get()) + }); let ah_sender_assets_after = AssetHubWestend::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -733,9 +769,9 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { &AssetHubWestendSender::get(), ) }); - let penpal_receiver_assets_after = PenpalB::execute_with(|| { - type Assets = ::Assets; - >::balance(asset_id_on_penpal, &PenpalBReceiver::get()) + let penpal_receiver_assets_after = PenpalA::execute_with(|| { + type Assets = ::Assets; + >::balance(asset_id_on_penpal, &PenpalAReceiver::get()) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury.rs index 8e82059a32d17..6d8c0f5e5de6a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; use emulated_integration_tests_common::accounts::{ALICE, BOB}; use frame_support::traits::fungibles::{Create, Inspect, Mutate}; use polkadot_runtime_common::impls::VersionedLocatableAsset; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index c4335d2dcaae5..ed893091533a2 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -671,7 +671,7 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} parameter_types! { /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetId = AssetId(xcm_config::TokenLocationAsNative::get()); + pub FeeAssetId: AssetId = AssetId(xcm_config::TokenLocation::get()); /// The base fee for the message delivery fees. pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 95c4fcbc618f1..09434df38ee75 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -67,9 +67,7 @@ use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; parameter_types! { pub const TokenLocation: Location = Location::parent(); - pub const TokenLocationAsNative: Location = Location::here(); pub const TokenLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); - pub const TokenLocationAsNativeV3: xcm::v3::Location = xcm::v3::Location::here(); pub const RelayNetwork: NetworkId = NetworkId::Rococo; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = @@ -120,7 +118,7 @@ pub type FungibleTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - (IsConcrete, IsConcrete), + IsConcrete, // Convert an XCM Location into a local account id: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -563,7 +561,6 @@ impl xcm_executor::Config for XcmConfig { MaxInstructions, >; type Trader = ( - UsingComponents>, UsingComponents>, cumulus_primitives_utility::SwapFirstAssetTrader< TokenLocationV3, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 50865c0006117..3d72724e6b8bf 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -22,7 +22,7 @@ use super::{ }; use assets_common::{ matching::{FromSiblingParachain, IsForeignConcreteAsset}, - TrustBackedAssetsAsLocation, + TrustBackedAssetsAsLocation, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, }; use frame_support::{ parameter_types, @@ -543,15 +543,6 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; -/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. -pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = - AssetFeeAsExistentialDepositMultiplier< - Runtime, - WeightToFee, - pallet_assets::BalanceToAssetBalance, - ForeignAssetsInstance, - >; - /// Locations that will not be charged fees in the executor, /// either execution or delivery. /// We only waive fees for system functions, which these locations represent. @@ -621,7 +612,7 @@ impl xcm_executor::Config for XcmConfig { // `pallet_assets` instance - `ForeignAssets`. cumulus_primitives_utility::TakeFirstAssetTrader< AccountId, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger ForeignAssetsConvertedConcreteId, ForeignAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index 5f6e4c007cd98..c3bc002a8087f 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -21,7 +21,7 @@ use asset_hub_westend_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf, + ForeignCreatorsSovereignAccountOf, LocationToAccountId, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, WestendLocation, WestendLocationV3, XcmConfig, }, @@ -30,6 +30,7 @@ use asset_hub_westend_runtime::{ PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, ToRococoXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue, }; +use assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger; pub use asset_hub_westend_runtime::{AssetConversion, AssetDeposit, CollatorSelection, System}; use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, @@ -482,7 +483,7 @@ fn test_foreign_asset_xcm_take_first_trader() { // Lets calculate amount needed let asset_amount_needed = - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles( + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::::charge_weight_in_fungibles( foreign_location, bought, ) From 1e845b8a4082a79dc8ef1e8c2ec0551a8ccde3ef Mon Sep 17 00:00:00 2001 From: NachoPal Date: Thu, 29 Feb 2024 18:07:09 +0100 Subject: [PATCH 03/18] asset-hub-rococo&westend test working --- Cargo.lock | 4 +- .../assets/asset-hub-rococo/src/genesis.rs | 24 +- .../assets/asset-hub-rococo/src/lib.rs | 6 +- .../assets/asset-hub-westend/src/genesis.rs | 24 +- .../assets/asset-hub-westend/src/lib.rs | 6 +- .../parachains/testing/penpal/Cargo.toml | 2 - .../parachains/testing/penpal/src/genesis.rs | 25 ++- .../parachains/testing/penpal/src/lib.rs | 14 +- .../emulated/common/Cargo.toml | 1 + .../emulated/common/src/impls.rs | 138 +++++++++--- .../emulated/common/src/lib.rs | 23 +- .../emulated/common/src/macros.rs | 208 +++++++++--------- .../tests/assets/asset-hub-rococo/src/lib.rs | 23 +- .../src/tests/reserve_transfer.rs | 204 +++++++++++++---- .../assets/asset-hub-rococo/src/tests/swap.rs | 49 ++--- .../asset-hub-rococo/src/tests/teleport.rs | 84 +++---- .../tests/assets/asset-hub-westend/Cargo.toml | 1 + .../tests/assets/asset-hub-westend/src/lib.rs | 62 +++--- .../src/tests/reserve_transfer.rs | 208 ++++++++++++++---- .../asset-hub-westend/src/tests/send.rs | 14 +- .../asset-hub-westend/src/tests/swap.rs | 99 ++++----- .../asset-hub-westend/src/tests/teleport.rs | 86 ++++---- .../asset-hub-westend/src/xcm_config.rs | 2 +- .../runtimes/testing/penpal/src/xcm_config.rs | 36 +-- 24 files changed, 851 insertions(+), 492 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc020851483bb..09c1685528037 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -955,6 +955,7 @@ dependencies = [ "pallet-xcm", "parachains-common", "parity-scale-codec", + "penpal-runtime", "polkadot-runtime-common", "sp-runtime", "staging-xcm", @@ -4927,6 +4928,7 @@ dependencies = [ "parachains-common", "parity-scale-codec", "paste", + "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-runtime-parachains", "sc-consensus-grandpa", @@ -11675,10 +11677,8 @@ dependencies = [ "frame-support", "parachains-common", "penpal-runtime", - "rococo-emulated-chain", "sp-core", "staging-xcm", - "westend-emulated-chain", ] [[package]] diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs index 80db56444696a..9b0ee2bf8bd80 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs @@ -14,17 +14,24 @@ // limitations under the License. // Substrate -use sp_core::storage::Storage; +use sp_core::{sr25519, storage::Storage}; +use frame_support::parameter_types; // Cumulus use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, SAFE_XCM_VERSION, + RESERVABLE_ASSET_ID, PenpalSiblingSovereigAccount, PenpalTeleportableAssetLocation, + get_account_id_from_seed }; -use parachains_common::Balance; +use parachains_common::{AccountId, Balance}; pub const PARA_ID: u32 = 1000; pub const ED: Balance = testnet_parachains_constants::rococo::currency::EXISTENTIAL_DEPOSIT; +parameter_types! { + pub AssetHubRococoAssetOwner: AccountId = get_account_id_from_seed::("Alice"); +} + pub fn genesis() -> Storage { let genesis_config = asset_hub_rococo_runtime::RuntimeGenesisConfig { system: asset_hub_rococo_runtime::SystemConfig::default(), @@ -60,6 +67,19 @@ pub fn genesis() -> Storage { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, + assets: asset_hub_rococo_runtime::AssetsConfig { + assets: vec![ + (RESERVABLE_ASSET_ID, AssetHubRococoAssetOwner::get(), true, ED), + ], + .. Default::default() + }, + foreign_assets: asset_hub_rococo_runtime::ForeignAssetsConfig { + assets: vec![ + // Penpal's teleportable asset representation + (PenpalTeleportableAssetLocation::get(), PenpalSiblingSovereigAccount::get(), true, ED), + ], + ..Default::default() + }, ..Default::default() }; diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs index facab26996d8a..01d156f00bbad 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs @@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, + impl_assets_helpers_for_system_parachain, impl_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; use rococo_emulated_chain::Rococo; @@ -54,6 +54,6 @@ decl_test_parachains! { // AssetHubRococo implementation impl_accounts_helpers_for_parachain!(AssetHubRococo); impl_assert_events_helpers_for_parachain!(AssetHubRococo); -impl_assets_helpers_for_parachain!(AssetHubRococo, Rococo); -impl_foreign_assets_helpers_for_parachain!(AssetHubRococo); +impl_assets_helpers_for_system_parachain!(AssetHubRococo, Rococo); +impl_assets_helpers_for_parachain!(AssetHubRococo); impl_xcm_helpers_for_parachain!(AssetHubRococo); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs index b2e4645ee0768..743e1eedc3f97 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs @@ -14,17 +14,24 @@ // limitations under the License. // Substrate -use sp_core::storage::Storage; +use sp_core::{sr25519, storage::Storage}; +use frame_support::parameter_types; // Cumulus use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, SAFE_XCM_VERSION, + RESERVABLE_ASSET_ID, PenpalSiblingSovereigAccount, PenpalTeleportableAssetLocation, + get_account_id_from_seed }; -use parachains_common::Balance; +use parachains_common::{AccountId, Balance}; pub const PARA_ID: u32 = 1000; pub const ED: Balance = testnet_parachains_constants::westend::currency::EXISTENTIAL_DEPOSIT; +parameter_types! { + pub AssetHubWestendAssetOwner: AccountId = get_account_id_from_seed::("Alice"); +} + pub fn genesis() -> Storage { let genesis_config = asset_hub_westend_runtime::RuntimeGenesisConfig { system: asset_hub_westend_runtime::SystemConfig::default(), @@ -56,6 +63,19 @@ pub fn genesis() -> Storage { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, + assets: asset_hub_westend_runtime::AssetsConfig { + assets: vec![ + (RESERVABLE_ASSET_ID, AssetHubWestendAssetOwner::get(), true, ED), + ], + .. Default::default() + }, + foreign_assets: asset_hub_westend_runtime::ForeignAssetsConfig { + assets: vec![ + // Penpal's teleportable asset representation + (PenpalTeleportableAssetLocation::get(), PenpalSiblingSovereigAccount::get(), true, ED), + ], + ..Default::default() + }, ..Default::default() }; diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs index 11945c8cb4a62..5e140b6ae961e 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs @@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, + impl_assets_helpers_for_system_parachain, impl_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; use westend_emulated_chain::Westend; @@ -54,6 +54,6 @@ decl_test_parachains! { // AssetHubWestend implementation impl_accounts_helpers_for_parachain!(AssetHubWestend); impl_assert_events_helpers_for_parachain!(AssetHubWestend); -impl_assets_helpers_for_parachain!(AssetHubWestend, Westend); -impl_foreign_assets_helpers_for_parachain!(AssetHubWestend); +impl_assets_helpers_for_system_parachain!(AssetHubWestend, Westend); +impl_assets_helpers_for_parachain!(AssetHubWestend); impl_xcm_helpers_for_parachain!(AssetHubWestend); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml index dbbe510d3ec37..f47350b00eb18 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml @@ -24,5 +24,3 @@ parachains-common = { path = "../../../../../../../parachains/common" } cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false } emulated-integration-tests-common = { path = "../../../../common", default-features = false } penpal-runtime = { path = "../../../../../../runtimes/testing/penpal" } -rococo-emulated-chain = { path = "../../../relays/rococo" } -westend-emulated-chain = { path = "../../../relays/westend" } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index 938516cec9e11..6f46ec3fda996 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -13,22 +13,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Substrate +// SubstratePenpal use sp_core::{sr25519, storage::Storage}; - +use frame_support::parameter_types; // Cumulus use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{Balance, AccountId}; -use penpal_runtime::xcm_config::{RelayLocationV3, SystemAssetHubLocationV3}; +use penpal_runtime::xcm_config::{RelayLocationV3, SystemAssetHubLocationV3, LocalReservableFromAssetHubV3}; // Penpal pub const PARA_ID_A: u32 = 2000; pub const PARA_ID_B: u32 = 2001; pub const ED: Balance = penpal_runtime::EXISTENTIAL_DEPOSIT; -pub fn asset_owner() -> AccountId { - get_account_id_from_seed::("Alice") +parameter_types! { + pub PenpalSudoAcccount: AccountId = get_account_id_from_seed::("Alice"); + pub PenpalAssetOwner: AccountId = PenpalSudoAcccount::get(); } pub fn genesis(para_id: u32) -> Storage { @@ -63,14 +64,20 @@ pub fn genesis(para_id: u32) -> Storage { ..Default::default() }, sudo: penpal_runtime::SudoConfig { - key: Some(get_account_id_from_seed::("Alice")), + key: Some(PenpalSudoAcccount::get()), + }, + assets: penpal_runtime::AssetsConfig { + assets: vec![ + (penpal_runtime::xcm_config::TELEPORTABLE_ASSET_ID, PenpalAssetOwner::get(), false, ED), + ], + .. Default::default() }, foreign_assets: penpal_runtime::ForeignAssetsConfig { assets: vec![ - // AssetHub Native asset representation - (SystemAssetHubLocationV3::get(), get_account_id_from_seed::("Alice"), true, ED), // Relay Native asset representation - (RelayLocationV3::get(), get_account_id_from_seed::("Alice"), true, ED) + (RelayLocationV3::get(), PenpalAssetOwner::get(), true, ED), + // Sufficient AssetHub asset representation + (LocalReservableFromAssetHubV3::get(), PenpalAssetOwner::get(), true, ED), ], ..Default::default() }, diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs index eef2e1a6a4db1..192c68fa16746 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs @@ -14,18 +14,16 @@ // limitations under the License. mod genesis; -pub use genesis::{genesis, asset_owner, ED, PARA_ID_A, PARA_ID_B}; +pub use genesis::{genesis, ED, PARA_ID_A, PARA_ID_B, PenpalSudoAcccount, PenpalAssetOwner}; // Substrate use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ - impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, - impl_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, + impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_assets_helpers_for_parachain, + impls::Parachain, xcm_emulator::decl_test_parachains, }; -use rococo_emulated_chain::Rococo; -use westend_emulated_chain::Westend; // Penpal Parachain declaration decl_test_parachains! { @@ -72,9 +70,7 @@ decl_test_parachains! { // Penpal implementation impl_accounts_helpers_for_parachain!(PenpalA); impl_accounts_helpers_for_parachain!(PenpalB); -impl_assets_helpers_for_parachain!(PenpalA, Rococo); -impl_assets_helpers_for_parachain!(PenpalB, Westend); impl_assert_events_helpers_for_parachain!(PenpalA); impl_assert_events_helpers_for_parachain!(PenpalB); -impl_foreign_assets_helpers_for_parachain!(PenpalA); -impl_foreign_assets_helpers_for_parachain!(PenpalB); +impl_assets_helpers_for_parachain!(PenpalA); +impl_assets_helpers_for_parachain!(PenpalB); diff --git a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml index 721c58fd86481..8c44cce7d922d 100644 --- a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml @@ -27,6 +27,7 @@ pallet-message-queue = { path = "../../../../../substrate/frame/message-queue" } # Polkadot polkadot-primitives = { path = "../../../../../polkadot/primitives" } +polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain" } polkadot-runtime-parachains = { path = "../../../../../polkadot/runtime/parachains" } xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm" } pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm" } diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 4245729156465..0363178edce9d 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -592,7 +592,7 @@ macro_rules! impl_assert_events_helpers_for_parachain { } #[macro_export] -macro_rules! impl_assets_helpers_for_parachain { +macro_rules! impl_assets_helpers_for_system_parachain { ( $chain:ident, $relay_chain:ident ) => { $crate::impls::paste::paste! { impl $chain { @@ -630,37 +630,37 @@ macro_rules! impl_assets_helpers_for_parachain { $crate::impls::xcm_transact_unpaid_execution(call, origin_kind) } - /// Mint assets making use of the assets pallet - pub fn mint_asset( - signed_origin: ::RuntimeOrigin, - id: u32, - beneficiary: $crate::impls::AccountId, - amount_to_mint: u128, - ) { - ::execute_with(|| { - $crate::impls::assert_ok!(]>::Assets::mint( - signed_origin, - id.clone().into(), - beneficiary.clone().into(), - amount_to_mint - )); - - type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; - - $crate::impls::assert_expected_events!( - Self, - vec![ - RuntimeEvent::::Assets( - $crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount } - ) => { - asset_id: *asset_id == id, - owner: *owner == beneficiary.clone().into(), - amount: *amount == amount_to_mint, - }, - ] - ); - }); - } + // /// Mint assets making use of the assets pallet + // pub fn mint_asset( + // signed_origin: ::RuntimeOrigin, + // id: u32, + // beneficiary: $crate::impls::AccountId, + // amount_to_mint: u128, + // ) { + // ::execute_with(|| { + // $crate::impls::assert_ok!(]>::Assets::mint( + // signed_origin, + // id.clone().into(), + // beneficiary.clone().into(), + // amount_to_mint + // )); + + // type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; + + // $crate::impls::assert_expected_events!( + // Self, + // vec![ + // RuntimeEvent::::Assets( + // $crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount } + // ) => { + // asset_id: *asset_id == id, + // owner: *owner == beneficiary.clone().into(), + // amount: *amount == amount_to_mint, + // }, + // ] + // ); + // }); + // } /// Force create and mint assets making use of the assets pallet pub fn force_create_and_mint_asset( @@ -727,7 +727,7 @@ macro_rules! impl_assets_helpers_for_parachain { } #[macro_export] -macro_rules! impl_foreign_assets_helpers_for_parachain { +macro_rules! impl_assets_helpers_for_parachain { ( $chain:ident) => { $crate::impls::paste::paste! { impl $chain { @@ -803,6 +803,78 @@ macro_rules! impl_foreign_assets_helpers_for_parachain { ); }); } + /// Create assets using sudo `Assets::force_create()` + pub fn force_create_asset( + id: u32, + owner: $crate::impls::AccountId, + is_sufficient: bool, + min_balance: u128, + prefund_accounts: Vec<($crate::impls::AccountId, u128)>, + ) { + use $crate::impls::Inspect; + let sudo_origin = <$chain as $crate::impls::Chain>::RuntimeOrigin::root(); + ::execute_with(|| { + $crate::impls::assert_ok!( + ]>::Assets::force_create( + sudo_origin, + id.clone().into(), + owner.clone().into(), + is_sufficient, + min_balance, + ) + ); + assert!(]>::Assets::asset_exists(id.clone())); + type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; + $crate::impls::assert_expected_events!( + Self, + vec![ + RuntimeEvent::::Assets( + $crate::impls::pallet_assets::Event::ForceCreated { + asset_id, + .. + } + ) => { asset_id: *asset_id == id, }, + ] + ); + }); + for (beneficiary, amount) in prefund_accounts.into_iter() { + let signed_origin = + <$chain as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone()); + Self::mint_asset(signed_origin, id.clone(), beneficiary, amount); + } + } + + /// Mint assets making use of the assets pallet + pub fn mint_asset( + signed_origin: ::RuntimeOrigin, + id: u32, + beneficiary: $crate::impls::AccountId, + amount_to_mint: u128, + ) { + ::execute_with(|| { + $crate::impls::assert_ok!(]>::Assets::mint( + signed_origin, + id.clone().into(), + beneficiary.clone().into(), + amount_to_mint + )); + + type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; + + $crate::impls::assert_expected_events!( + Self, + vec![ + RuntimeEvent::::Assets( + $crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount } + ) => { + asset_id: *asset_id == id, + owner: *owner == beneficiary.clone().into(), + amount: *amount == amount_to_mint, + }, + ] + ); + }); + } } } }; diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 1a5cc1f6fea6d..023d8ac078fed 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -26,13 +26,15 @@ use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_core::{sr25519, storage::Storage, Pair, Public}; use sp_runtime::{ - traits::{IdentifyAccount, Verify}, + traits::{IdentifyAccount, Verify, AccountIdConversion}, BuildStorage, MultiSignature, }; +use frame_support::parameter_types; // Polakdot use parachains_common::BlockNumber; use polkadot_runtime_parachains::configuration::HostConfiguration; +use polkadot_parachain_primitives::primitives::Sibling; // Cumulus use parachains_common::{AccountId, AuraId}; @@ -49,6 +51,25 @@ pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; type AccountPublic = ::Signer; +// This asset is added to AH as Asset and reserved transfer between Parachain and AH +pub const RESERVABLE_ASSET_ID: u32 = 1; +// This asset is added to AH as ForeignAsset and teleported between Penpal and AH +pub const TELEPORTABLE_ASSET_ID: u32 = 2; + +pub const PENPAL_ID: u32 = 2000; +pub const ASSETS_PALLET_ID: u8 = 50; + +parameter_types! { + pub PenpalTeleportableAssetLocation: xcm::v3::Location + = xcm::v3::Location::new(1, [ + xcm::v3::Junction::Parachain(PENPAL_ID), + xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v3::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()), + ] + ); + pub PenpalSiblingSovereigAccount: AccountId = Sibling::from(PENPAL_ID).into_account_truncating(); +} + /// Helper function to generate a crypto pair from seed pub fn get_from_seed(seed: &str) -> ::Public { TPublic::Pair::from_string(&format!("//{}", seed), None) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs index 0ab83cf3c9248..7a4f1bc480072 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs @@ -132,107 +132,107 @@ macro_rules! test_parachain_is_trusted_teleporter { }; } -#[macro_export] -macro_rules! include_penpal_create_foreign_asset_on_asset_hub { - ( $penpal:ident, $asset_hub:ident, $relay_ed:expr, $weight_to_fee:expr) => { - $crate::impls::paste::paste! { - pub fn penpal_create_foreign_asset_on_asset_hub( - asset_id_on_penpal: u32, - foreign_asset_at_asset_hub: $crate::macros::V3Location, - ah_as_seen_by_penpal: $crate::macros::Location, - is_sufficient: bool, - asset_owner: $crate::macros::AccountId, - prefund_amount: u128, - ) { - use $crate::macros::{ - pallet_assets, pallet_xcm, Chain, Weight, OriginKind, Asset, AssetId, Fungible, - Location, Here, VersionedXcm, Xcm, Unlimited, WeightToFee, WithdrawAsset, BuyExecution, - Transact, ExpectTransactStatus, MaybeErrorCode, RefundSurplus, DepositAsset, - All - }; - - let ah_check_account = $asset_hub::execute_with(|| { - <$asset_hub as [<$asset_hub Pallet>]>::PolkadotXcm::check_account() - }); - let penpal_check_account = - $penpal::execute_with(|| <$penpal as [<$penpal Pallet>]>::PolkadotXcm::check_account()); - let penpal_as_seen_by_ah = $asset_hub::sibling_location_of($penpal::para_id()); - - // prefund SA of Penpal on AssetHub with enough native tokens to pay for creating - // new foreign asset, also prefund CheckingAccount with ED, because teleported asset - // itself might not be sufficient and CheckingAccount cannot be created otherwise - let sov_penpal_on_ah = $asset_hub::sovereign_account_id_of(penpal_as_seen_by_ah.clone()); - $asset_hub::fund_accounts(vec![ - (sov_penpal_on_ah.clone().into(), $relay_ed * 100_000_000_000), - (ah_check_account.clone().into(), $relay_ed * 1000), - ]); - - // prefund SA of AssetHub on Penpal with native asset - let sov_ah_on_penpal = $penpal::sovereign_account_id_of(ah_as_seen_by_penpal.clone()); - $penpal::fund_accounts(vec![ - (sov_ah_on_penpal.into(), $relay_ed * 1_000_000_000), - (penpal_check_account.clone().into(), $relay_ed * 1000), - ]); - - // Force create asset on $penpal and prefund [<$penpal Sender>] - $penpal::force_create_and_mint_asset( - asset_id_on_penpal, - ASSET_MIN_BALANCE, - is_sufficient, - asset_owner, - None, - prefund_amount, - ); - - let require_weight_at_most = Weight::from_parts(1_100_000_000_000, 30_000); - // `OriginKind::Xcm` required by ForeignCreators pallet-assets origin filter - let origin_kind = OriginKind::Xcm; - let call_create_foreign_assets = - <$asset_hub as Chain>::RuntimeCall::ForeignAssets(pallet_assets::Call::< - <$asset_hub as Chain>::Runtime, - pallet_assets::Instance2, - >::create { - id: foreign_asset_at_asset_hub, - min_balance: ASSET_MIN_BALANCE, - admin: sov_penpal_on_ah.into(), - }) - .encode(); - let buy_execution_fee_amount = $weight_to_fee::weight_to_fee( - &Weight::from_parts(10_100_000_000_000, 300_000), - ); - let buy_execution_fee = Asset { - id: AssetId(Location { parents: 1, interior: Here }), - fun: Fungible(buy_execution_fee_amount), - }; - let xcm = VersionedXcm::from(Xcm(vec![ - WithdrawAsset { 0: vec![buy_execution_fee.clone()].into() }, - BuyExecution { fees: buy_execution_fee.clone(), weight_limit: Unlimited }, - Transact { require_weight_at_most, origin_kind, call: call_create_foreign_assets.into() }, - ExpectTransactStatus(MaybeErrorCode::Success), - RefundSurplus, - DepositAsset { assets: All.into(), beneficiary: penpal_as_seen_by_ah }, - ])); - // Send XCM message from penpal => asset_hub - let sudo_penpal_origin = <$penpal as Chain>::RuntimeOrigin::root(); - $penpal::execute_with(|| { - assert_ok!(<$penpal as [<$penpal Pallet>]>::PolkadotXcm::send( - sudo_penpal_origin.clone(), - bx!(ah_as_seen_by_penpal.into()), - bx!(xcm), - )); - type RuntimeEvent = <$penpal as Chain>::RuntimeEvent; - assert_expected_events!( - $penpal, - vec![ - RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - $asset_hub::execute_with(|| { - type ForeignAssets = <$asset_hub as [<$asset_hub Pallet>]>::ForeignAssets; - assert!(ForeignAssets::asset_exists(foreign_asset_at_asset_hub)); - }); - } - } - }; -} +// #[macro_export] +// macro_rules! include_penpal_create_foreign_asset_on_asset_hub { +// ( $penpal:ident, $asset_hub:ident, $relay_ed:expr, $weight_to_fee:expr) => { +// $crate::impls::paste::paste! { +// pub fn penpal_create_foreign_asset_on_asset_hub( +// asset_id_on_penpal: u32, +// foreign_asset_at_asset_hub: $crate::macros::V3Location, +// ah_as_seen_by_penpal: $crate::macros::Location, +// is_sufficient: bool, +// asset_owner: $crate::macros::AccountId, +// prefund_amount: u128, +// ) { +// use $crate::macros::{ +// pallet_assets, pallet_xcm, Chain, Weight, OriginKind, Asset, AssetId, Fungible, +// Location, Here, VersionedXcm, Xcm, Unlimited, WeightToFee, WithdrawAsset, BuyExecution, +// Transact, ExpectTransactStatus, MaybeErrorCode, RefundSurplus, DepositAsset, +// All +// }; + +// let ah_check_account = $asset_hub::execute_with(|| { +// <$asset_hub as [<$asset_hub Pallet>]>::PolkadotXcm::check_account() +// }); +// let penpal_check_account = +// $penpal::execute_with(|| <$penpal as [<$penpal Pallet>]>::PolkadotXcm::check_account()); +// let penpal_as_seen_by_ah = $asset_hub::sibling_location_of($penpal::para_id()); + +// // prefund SA of Penpal on AssetHub with enough native tokens to pay for creating +// // new foreign asset, also prefund CheckingAccount with ED, because teleported asset +// // itself might not be sufficient and CheckingAccount cannot be created otherwise +// let sov_penpal_on_ah = $asset_hub::sovereign_account_id_of(penpal_as_seen_by_ah.clone()); +// $asset_hub::fund_accounts(vec![ +// (sov_penpal_on_ah.clone().into(), $relay_ed * 100_000_000_000), +// (ah_check_account.clone().into(), $relay_ed * 1000), +// ]); + +// // prefund SA of AssetHub on Penpal with native asset +// let sov_ah_on_penpal = $penpal::sovereign_account_id_of(ah_as_seen_by_penpal.clone()); +// $penpal::fund_accounts(vec![ +// (sov_ah_on_penpal.into(), $relay_ed * 1_000_000_000), +// (penpal_check_account.clone().into(), $relay_ed * 1000), +// ]); + +// // Force create asset on $penpal and prefund [<$penpal Sender>] +// $penpal::force_create_and_mint_asset( +// asset_id_on_penpal, +// ASSET_MIN_BALANCE, +// is_sufficient, +// asset_owner, +// None, +// prefund_amount, +// ); + +// let require_weight_at_most = Weight::from_parts(1_100_000_000_000, 30_000); +// // `OriginKind::Xcm` required by ForeignCreators pallet-assets origin filter +// let origin_kind = OriginKind::Xcm; +// let call_create_foreign_assets = +// <$asset_hub as Chain>::RuntimeCall::ForeignAssets(pallet_assets::Call::< +// <$asset_hub as Chain>::Runtime, +// pallet_assets::Instance2, +// >::create { +// id: foreign_asset_at_asset_hub, +// min_balance: ASSET_MIN_BALANCE, +// admin: sov_penpal_on_ah.into(), +// }) +// .encode(); +// let buy_execution_fee_amount = $weight_to_fee::weight_to_fee( +// &Weight::from_parts(10_100_000_000_000, 300_000), +// ); +// let buy_execution_fee = Asset { +// id: AssetId(Location { parents: 1, interior: Here }), +// fun: Fungible(buy_execution_fee_amount), +// }; +// let xcm = VersionedXcm::from(Xcm(vec![ +// WithdrawAsset { 0: vec![buy_execution_fee.clone()].into() }, +// BuyExecution { fees: buy_execution_fee.clone(), weight_limit: Unlimited }, +// Transact { require_weight_at_most, origin_kind, call: call_create_foreign_assets.into() }, +// ExpectTransactStatus(MaybeErrorCode::Success), +// RefundSurplus, +// DepositAsset { assets: All.into(), beneficiary: penpal_as_seen_by_ah }, +// ])); +// // Send XCM message from penpal => asset_hub +// let sudo_penpal_origin = <$penpal as Chain>::RuntimeOrigin::root(); +// $penpal::execute_with(|| { +// assert_ok!(<$penpal as [<$penpal Pallet>]>::PolkadotXcm::send( +// sudo_penpal_origin.clone(), +// bx!(ah_as_seen_by_penpal.into()), +// bx!(xcm), +// )); +// type RuntimeEvent = <$penpal as Chain>::RuntimeEvent; +// assert_expected_events!( +// $penpal, +// vec![ +// RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {}, +// ] +// ); +// }); +// $asset_hub::execute_with(|| { +// type ForeignAssets = <$asset_hub as [<$asset_hub Pallet>]>::ForeignAssets; +// assert!(ForeignAssets::asset_exists(foreign_asset_at_asset_hub)); +// }); +// } +// } +// }; +// } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs index 7b44d5ee10512..5e20d38dccb70 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs @@ -40,14 +40,14 @@ mod imports { RelayChain as Relay, Test, TestArgs, TestContext, TestExt, }, xcm_helpers::{xcm_transact_paid_execution, non_fee_asset}, - XCM_V3, + XCM_V3, RESERVABLE_ASSET_ID, ASSETS_PALLET_ID }; pub use parachains_common::Balance; pub use rococo_system_emulated_network::{ asset_hub_rococo_emulated_chain::{ - genesis::{ED as ASSET_HUB_ROCOCO_ED, PARA_ID as ASSETHUB_PARA_ID}, AssetHubRococoParaPallet as AssetHubRococoPallet, + genesis::{ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoAssetOwner}, AssetHubRococoParaPallet as AssetHubRococoPallet, }, - penpal_emulated_chain::{PenpalAParaPallet as PenpalAPallet, PenpalBParaPallet as PenpalBPallet, asset_owner as penpal_asset_owner}, + penpal_emulated_chain::{ED as PENPAL_ED, PenpalAParaPallet as PenpalAPallet, PenpalBParaPallet as PenpalBPallet, PenpalAssetOwner}, rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, AssetHubRococoParaSender as AssetHubRococoSender, BridgeHubRococoPara as BridgeHubRococo, @@ -65,29 +65,20 @@ mod imports { }; pub use penpal_runtime::xcm_config::{ LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3, - SystemAssetHubLocationV3, - UniversalLocation as PenpalUniversalLocation, XcmConfig as PenpalRococoXcmConfig + UniversalLocation as PenpalUniversalLocation, XcmConfig as PenpalRococoXcmConfig, + LocalReservableFromAssetHubV3 as PenpalLocalReservableFromAssetHubV3, }; - pub const ASSET_ID: u32 = 1; + pub const ASSET_ID: u32 = 3; pub const ASSET_MIN_BALANCE: u128 = 1000; - // `Assets` pallet index - pub const ASSETS_PALLET_ID: u8 = 50; pub type RelayToSystemParaTest = Test; pub type RelayToParaTest = Test; + pub type ParaToRelayTest = Test; pub type SystemParaToRelayTest = Test; pub type SystemParaToParaTest = Test; pub type ParaToSystemParaTest = Test; pub type ParaToParaThroughRelayTest = Test; - pub type ParaToParaThroughSystemParaTest = Test; - - emulated_integration_tests_common::include_penpal_create_foreign_asset_on_asset_hub!( - PenpalA, - AssetHubRococo, - ROCOCO_ED, - testnet_parachains_constants::rococo::fee::WeightToFee - ); } #[cfg(test)] diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 54f4dcd71fa06..2ac9a4cf73de5 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -37,6 +37,24 @@ fn relay_to_para_sender_assertions(t: RelayToParaTest) { ); } +fn para_to_relay_sender_assertions(t: ParaToRelayTest) { + type RuntimeEvent = ::RuntimeEvent; + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8_799))); + assert_expected_events!( + PenpalA, + vec![ + // Amount to reserve transfer is transferred to Parachain's Sovereign account + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, balance, .. } + ) => { + asset_id: *asset_id == RelayLocationV3::get(), + owner: *owner == t.sender.account_id, + balance: *balance == t.args.amount, + }, + ] + ); +} + fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -69,7 +87,7 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_native_asset_location = RelayLocationV3::get(); PenpalA::assert_xcmp_queue_success(None); @@ -94,7 +112,7 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == SystemAssetHubLocationV3::get(), + asset_id: *asset_id == RelayLocationV3::get(), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -102,6 +120,36 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { ); } +fn para_to_relay_receiver_assertions(t: ParaToRelayTest) { + type RuntimeEvent = ::RuntimeEvent; + let sov_penpal_on_relay = Rococo::sovereign_account_id_of( + Rococo::child_location_of(PenpalA::para_id()), + ); + + Rococo::assert_ump_queue_processed( + true, + Some(PenpalA::para_id()), + Some(Weight::from_parts(306305000, 7_186)), + ); + + assert_expected_events!( + Rococo, + vec![ + // Amount to reserve transfer is withdrawn from Parachain's Sovereign account + RuntimeEvent::Balances( + pallet_balances::Event::Burned { who, amount } + ) => { + who: *who == sov_penpal_on_relay.clone().into(), + amount: *amount == t.args.amount, + }, + RuntimeEvent::Balances(pallet_balances::Event::Minted { .. }) => {}, + RuntimeEvent::MessageQueue( + pallet_message_queue::Event::Processed { success: true, .. } + ) => {}, + ] + ); +} + fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of( @@ -141,7 +189,7 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { RuntimeEvent::Assets( pallet_assets::Event::Transferred { asset_id, from, to, amount } ) => { - asset_id: *asset_id == ASSET_ID, + asset_id: *asset_id == RESERVABLE_ASSET_ID, from: *from == t.sender.account_id, to: *to == AssetHubRococo::sovereign_account_id_of( t.args.dest.clone() @@ -164,19 +212,13 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_asset_location = xcm::v3::Location::new( - 1, [ - xcm::v3::Junction::Parachain(ASSETHUB_PARA_ID), - xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), - ] - ); + let system_para_asset_location = PenpalLocalReservableFromAssetHubV3::get(); PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == SystemAssetHubLocationV3::get(), + asset_id: *asset_id == RelayLocationV3::get(), owner: *owner == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { @@ -287,6 +329,17 @@ fn relay_to_para_reserve_transfer_assets(t: RelayToParaTest) -> DispatchResult { ) } +fn para_to_relay_reserve_transfer_assets(t: ParaToRelayTest) -> DispatchResult { + ::PolkadotXcm::limited_reserve_transfer_assets( + t.signed_origin, + bx!(t.args.dest.into()), + bx!(t.args.beneficiary.into()), + bx!(t.args.assets.into()), + t.args.fee_asset_item, + t.args.weight_limit, + ) +} + fn system_para_to_para_reserve_transfer_assets(t: SystemParaToParaTest) -> DispatchResult { ::PolkadotXcm::limited_reserve_transfer_assets( t.signed_origin, @@ -449,6 +502,79 @@ fn reserve_transfer_native_asset_from_relay_to_para() { assert!(receiver_assets_after < receiver_assets_before + amount_to_send); } +/// Reserve Transfers of native asset from Parachain to Relay should work +#[test] +fn reserve_transfer_native_asset_from_para_to_relay() { + // Init values for Parachain + let destination = PenpalA::parent_location(); + let sender = PenpalASender::get(); + let amount_to_send: Balance = ROCOCO_ED * 1000; + let assets: Assets = (Parent, amount_to_send).into(); + let asset_owner = PenpalAssetOwner::get(); + let relay_native_asset_location = RelayLocationV3::get(); + + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner), + relay_native_asset_location, + sender.clone(), + amount_to_send + ); + + // Init values for Relay + let receiver = RococoReceiver::get(); + let penpal_location_as_seen_by_relay = Rococo::child_location_of(PenpalA::para_id()); + let sov_penpal_on_relay = Rococo::sovereign_account_id_of(penpal_location_as_seen_by_relay); + + // fund Parachain's SA on Relay with the native tokens held in reserve + Rococo::fund_accounts(vec![(sov_penpal_on_relay.into(), amount_to_send * 2)]); + + // Init Test + let test_args = TestContext { + sender: sender.clone(), + receiver: receiver.clone(), + args: TestArgs::new_para(destination.clone(), receiver, amount_to_send, assets.clone(), None, 0), + }; + let mut test = ParaToRelayTest::new(test_args); + + // Query initial balances + let sender_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.into(), &sender) + }); + let receiver_balance_before = test.receiver.balance; + + // Set assertions and dispatchables + test.set_assertion::(para_to_relay_sender_assertions); + test.set_assertion::(para_to_relay_receiver_assertions); + test.set_dispatchable::(para_to_relay_reserve_transfer_assets); + test.assert(); + + // Calculate delivery fees + let delivery_fees = PenpalA::execute_with(|| { + let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + // Query final balances + let sender_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.into(), &sender) + }); + let receiver_balance_after = test.receiver.balance; + + // Sender's balance is reduced + assert_eq!(sender_assets_before - amount_to_send - delivery_fees, sender_assets_after); + // Receiver's asset balance is increased + assert!(receiver_balance_after > receiver_balance_before); + // Receiver's asset balance increased by `amount_to_send - delivery_fees - bought_execution`; + // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but + // should be non-zero + assert!(receiver_balance_after < receiver_balance_before + amount_to_send); +} + /// Reserve Transfers of native asset from System Parachain to Parachain should work #[test] fn reserve_transfer_native_asset_from_system_para_to_para() { @@ -456,10 +582,10 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let destination = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sender = AssetHubRococoSender::get(); let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; - let assets: Assets = (Here, amount_to_send).into(); + let assets: Assets = (Parent, amount_to_send).into(); // Init values for Parachain - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_native_asset_location = RelayLocationV3::get(); let receiver = PenpalAReceiver::get(); // Init Test @@ -516,9 +642,9 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let destination = PenpalA::sibling_location_of(AssetHubRococo::para_id()); let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000; - let assets: Assets = ((Parent, Parachain(ASSETHUB_PARA_ID)), amount_to_send).into(); - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); - let asset_owner = penpal_asset_owner(); + let assets: Assets = (Parent, amount_to_send).into(); + let system_para_native_asset_location = RelayLocationV3::get(); + let asset_owner = PenpalAssetOwner::get(); // fund Parachain's sender account PenpalA::mint_foreign_asset( @@ -588,43 +714,37 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { fn reserve_transfer_assets_from_system_para_to_para() { // Init values for System Parachain let destination = AssetHubRococo::sibling_location_of(PenpalA::para_id()); + let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(destination.clone()); let sender = AssetHubRococoSender::get(); let fee_amount_to_send = ASSET_HUB_ROCOCO_ED * 10000; - let asset_amount_to_send = ASSET_MIN_BALANCE * 10000; - let asset_owner = penpal_asset_owner(); + let asset_amount_to_send = PENPAL_ED * 10000; + let asset_owner = AssetHubRococoAssetOwner::get(); + let asset_owner_signer = ::RuntimeOrigin::signed(asset_owner.clone()); let assets: Assets = vec![ - (Here, fee_amount_to_send).into(), - ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], asset_amount_to_send) + (Parent, fee_amount_to_send).into(), + ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())], asset_amount_to_send) .into(), ] .into(); - let is_sufficient = false; - let min_balance = ASSET_MIN_BALANCE; let fee_asset_index = assets .inner() .iter() - .position(|r| r == &(Here, fee_amount_to_send).into()) + .position(|r| r == &(Parent, fee_amount_to_send).into()) .unwrap() as u32; - AssetHubRococo::force_create_and_mint_asset( - ASSET_ID, - min_balance, - is_sufficient, - asset_owner.clone(), - Some(Weight::from_parts(1_019_445_000, 200_000)), - min_balance * 1_000_000, + AssetHubRococo::mint_asset( + asset_owner_signer, + RESERVABLE_ASSET_ID, + asset_owner, + asset_amount_to_send * 2, ); + // Create SA-of-Penpal-on-AHR with ED. + AssetHubRococo::fund_accounts(vec![(sov_penpal_on_ahr.into(), ASSET_HUB_ROCOCO_ED)]); + // Init values for Parachain let receiver = PenpalAReceiver::get(); - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); - let system_para_foreign_asset_location = xcm::v3::Location::new( - 1, [ - xcm::v3::Junction::Parachain(ASSETHUB_PARA_ID), - xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), - ] - ); - PenpalA::force_create_foreign_asset(system_para_foreign_asset_location.clone(), asset_owner.clone(), is_sufficient, min_balance, vec![]); + let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHubV3::get(); // Init Test let para_test_args = TestContext { @@ -645,7 +765,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { let sender_balance_before = test.sender.balance; let sender_assets_before = AssetHubRococo::execute_with(|| { type Assets = ::Assets; - >::balance(ASSET_ID, &sender) + >::balance(RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -666,7 +786,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let sender_assets_after = AssetHubRococo::execute_with(|| { type Assets = ::Assets; - >::balance(ASSET_ID, &sender) + >::balance(RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -699,7 +819,7 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { let destination = PenpalA::sibling_location_of(PenpalB::para_id()); let sender = PenpalASender::get(); let amount_to_send: Balance = ROCOCO_ED * 10000; - let asset_owner = penpal_asset_owner(); + let asset_owner = PenpalAssetOwner::get(); let assets = (Parent, amount_to_send).into(); let relay_native_asset_location = RelayLocationV3::get(); let sender_as_seen_by_relay = Rococo::child_location_of(PenpalA::para_id()); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs index 10a56f499cca9..0bde356f20b6c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs @@ -112,49 +112,36 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new(asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get()); - let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id()); + let asset_native = Box::new(RelayLocationV3::get()); let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); - let asset_id_on_penpal = match asset_location_on_penpal.last() { - Some(v3::Junction::GeneralIndex(id)) => *id as u32, - _ => unreachable!(), - }; - let asset_owner_on_penpal = PenpalASender::get(); let foreign_asset_at_asset_hub_rococo = v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); - // 1. Create asset on penpal and, 2. Create foreign asset on asset_hub_rococo - penpal_create_foreign_asset_on_asset_hub( - asset_id_on_penpal, - foreign_asset_at_asset_hub_rococo, - ah_as_seen_by_penpal, - true, - asset_owner_on_penpal, - ASSET_MIN_BALANCE * 1_000_000, - ); - let penpal_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_as_seen_by_ah); AssetHubRococo::fund_accounts(vec![ - (AssetHubRococoSender::get().into(), 5_000_000 * ROCOCO_ED), /* An account to swap dot - * for something else. */ + // An account to swap dot for something else. + (AssetHubRococoSender::get().into(), 5_000_000 * ASSET_HUB_ROCOCO_ED), + // Penpal's sovereign account in AH should have some balance + (sov_penpal_on_ahr.clone().into(), 100_000_000 * ASSET_HUB_ROCOCO_ED), ]); AssetHubRococo::execute_with(|| { - // 3: Mint foreign asset on asset_hub_rococo: + // 1: Mint foreign asset on asset_hub_rococo: // // (While it might be nice to use batch, // currently that's disabled due to safe call filters.) type RuntimeEvent = ::RuntimeEvent; - // 3. Mint foreign asset (in reality this should be a teleport or some such) + // 1. Mint foreign asset (in reality this should be a teleport or some such) assert_ok!(::ForeignAssets::mint( ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone().into()), foreign_asset_at_asset_hub_rococo, sov_penpal_on_ahr.clone().into(), - 3_000_000_000_000, + // 3_000_000_000_000, + ASSET_HUB_ROCOCO_ED * 3_000_000_000_000, )); assert_expected_events!( @@ -164,7 +151,7 @@ fn swap_locally_on_chain_using_foreign_assets() { ] ); - // 4. Create pool: + // 2. Create pool: assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubRococoSender::get()), asset_native.clone(), @@ -178,7 +165,7 @@ fn swap_locally_on_chain_using_foreign_assets() { ] ); - // 5. Add liquidity: + // 3. Add liquidity: assert_ok!(::AssetConversion::add_liquidity( ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone()), asset_native.clone(), @@ -199,15 +186,15 @@ fn swap_locally_on_chain_using_foreign_assets() { ] ); - // 6. Swap! + // 4. Swap! let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_rococo)]; assert_ok!( ::AssetConversion::swap_exact_tokens_for_tokens( ::RuntimeOrigin::signed(AssetHubRococoSender::get()), path, - 100000, - 1000, + 100000 * ASSET_HUB_ROCOCO_ED, + 1000 * ASSET_HUB_ROCOCO_ED, AssetHubRococoSender::get().into(), true ) @@ -217,18 +204,18 @@ fn swap_locally_on_chain_using_foreign_assets() { AssetHubRococo, vec![ RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::SwapExecuted { amount_in, amount_out, .. },) => { - amount_in: *amount_in == 100000, - amount_out: *amount_out == 199399, + amount_in: *amount_in == 333333300000, + amount_out: *amount_out == 498874118173, }, ] ); - // 7. Remove liquidity + // 5. Remove liquidity assert_ok!(::AssetConversion::remove_liquidity( ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone()), asset_native.clone(), Box::new(foreign_asset_at_asset_hub_rococo), - 1414213562273 - 2_000_000_000, // all but the 2 EDs can't be retrieved. + 1414213562273 - ASSET_HUB_ROCOCO_ED * 2, // all but the 2 EDs can't be retrieved. 0, 0, sov_penpal_on_ahr.clone().into(), diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 4af554eb9199e..4c466e5750e2f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -110,7 +110,7 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_native_asset_location = RelayLocationV3::get(); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); @@ -206,7 +206,7 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let checking_account = ::PolkadotXcm::check_account(); - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_native_asset_location = RelayLocationV3::get(); PenpalA::assert_xcmp_queue_success(None); @@ -564,57 +564,61 @@ fn teleport_to_other_system_parachains_works() { fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { // Init values for Parachain let fee_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; - let asset_owner = penpal_asset_owner(); - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); - let sender = PenpalASender::get(); - - // fund Parachain's sender account - PenpalA::mint_foreign_asset( - ::RuntimeOrigin::signed(asset_owner.clone()), - system_para_native_asset_location, - sender.clone(), - fee_amount_to_send - ); - - let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id()); let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); let asset_id_on_penpal = match asset_location_on_penpal.last() { Some(v3::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; - - let foreign_asset_at_asset_hub_rococo = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) - .appended_with(asset_location_on_penpal) - .unwrap(); - - penpal_create_foreign_asset_on_asset_hub( - asset_id_on_penpal, - foreign_asset_at_asset_hub_rococo, - ah_as_seen_by_penpal.clone(), - false, - asset_owner, - ASSET_MIN_BALANCE * 1_000_000, - ); - - // Init values for System Parachain - let penpal_to_ah_beneficiary_id = AssetHubRococoReceiver::get(); - - // let fee_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000; - let asset_amount_to_send = ASSET_MIN_BALANCE * 1000; - + let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 1000; + let asset_owner = PenpalAssetOwner::get(); + let system_para_native_asset_location = RelayLocationV3::get(); + let sender = PenpalASender::get(); + let penpal_check_account = + ::PolkadotXcm::check_account(); + let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id()); let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); let penpal_assets: Assets = vec![ - ((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into(), + (Parent, fee_amount_to_send).into(), (asset_location_on_penpal_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = penpal_assets .inner() .iter() - .position(|r| r == &((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into()) + // .position(|r| r == &((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into()) + .position(|r| r == &(Parent, fee_amount_to_send).into()) .unwrap() as u32; + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner.clone()), + system_para_native_asset_location, + sender.clone(), + fee_amount_to_send + ); + PenpalA::mint_asset( + ::RuntimeOrigin::signed(asset_owner.clone()), + asset_id_on_penpal, + sender.clone(), + asset_amount_to_send + ); + // fund Parachain's check account to be able to teleport + PenpalA::fund_accounts(vec![((penpal_check_account.clone().into(), ASSET_HUB_ROCOCO_ED * 1000))]); + + // prefund SA of Penpal on AssetHub with enough native tokens to pay for fees + let penpal_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id()); + let sov_penpal_on_ah = AssetHubRococo::sovereign_account_id_of(penpal_as_seen_by_ah); + AssetHubRococo::fund_accounts(vec![ + (sov_penpal_on_ah.clone().into(), ASSET_HUB_ROCOCO_ED * 100_000_000_000), + ]); + + // Init values for System Parachain + let foreign_asset_at_asset_hub_rococo = + v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + .appended_with(asset_location_on_penpal) + .unwrap(); + let penpal_to_ah_beneficiary_id = AssetHubRococoReceiver::get(); + // Penpal to AH test args let penpal_to_ah_test_args = TestContext { sender: PenpalASender::get(), @@ -708,14 +712,14 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let ah_to_penpal_beneficiary_id = PenpalAReceiver::get(); let penpal_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let ah_assets: Assets = vec![ - (Here, fee_amount_to_send).into(), + (Parent, fee_amount_to_send).into(), (foreign_asset_at_asset_hub_rococo_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = ah_assets .inner() .iter() - .position(|r| r == &(Here, fee_amount_to_send).into()) + .position(|r| r == &(Parent, fee_amount_to_send).into()) .unwrap() as u32; // AH to Penpal test args diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml index 0c920730d0fe6..8ac8efb5218fb 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml @@ -33,6 +33,7 @@ westend-runtime = { path = "../../../../../../../polkadot/runtime/westend" } # Cumulus parachains-common = { path = "../../../../../../parachains/common" } testnet-parachains-constants = { path = "../../../../../runtimes/constants", features = ["westend"] } +penpal-runtime = { path = "../../../../../runtimes/testing/penpal" } asset-hub-westend-runtime = { path = "../../../../../runtimes/assets/asset-hub-westend" } asset-test-utils = { path = "../../../../../runtimes/assets/test-utils" } cumulus-pallet-xcmp-queue = { default-features = false, path = "../../../../../../pallets/xcmp-queue" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs index 4bdf1e9367969..be7cd9974ef0c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs @@ -20,17 +20,15 @@ mod imports { // Substrate pub use frame_support::{ assert_err, assert_ok, - instances::Instance2, pallet_prelude::Weight, - sp_runtime::{AccountId32, DispatchError, DispatchResult, ModuleError}, + sp_runtime::{DispatchError, DispatchResult, ModuleError}, traits::fungibles::Inspect, - BoundedVec, }; // Polkadot pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, - v3::{self, Error, NetworkId::Westend as WestendId}, + v3, }; // Cumulus @@ -38,51 +36,53 @@ mod imports { pub use emulated_integration_tests_common::{ test_parachain_is_trusted_teleporter, xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, + assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, Test, TestArgs, TestContext, TestExt, }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, + xcm_helpers::{xcm_transact_paid_execution, non_fee_asset}, + XCM_V3, RESERVABLE_ASSET_ID, ASSETS_PALLET_ID }; - pub use parachains_common::{AccountId, Balance}; + pub use parachains_common::{Balance, AccountId}; pub use westend_system_emulated_network::{ asset_hub_westend_emulated_chain::{ - genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, + genesis::{ED as ASSET_HUB_WESTEND_ED, AssetHubWestendAssetOwner}, AssetHubWestendParaPallet as AssetHubWestendPallet, }, collectives_westend_emulated_chain::{ - genesis::ED as COLLECTIVES_WESTEND_ED, CollectivesWestendParaPallet as CollectivesWestendPallet, }, - penpal_emulated_chain::PenpalBParaPallet as PenpalBPallet, + penpal_emulated_chain::{PenpalAParaPallet as PenpalAPallet, PenpalBParaPallet as PenpalBPallet, PenpalAssetOwner}, westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet}, AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver, AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubWestendPara as BridgeHubWestend, - BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, - CollectivesWestendPara as CollectivesWestend, PenpalAPara as PenpalA, - PenpalAParaReceiver as PenpalAReceiver, PenpalBPara as PenpalB, - PenpalBParaReceiver as PenpalBReceiver, PenpalBParaSender as PenpalBSender, - WestendRelay as Westend, WestendRelayReceiver as WestendReceiver, - WestendRelaySender as WestendSender, + BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, PenpalAPara as PenpalA, + CollectivesWestendPara as CollectivesWestend, + PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender, + PenpalBPara as PenpalB, PenpalBParaReceiver as PenpalBReceiver, WestendRelay as Westend, + WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender, }; - pub const ASSET_ID: u32 = 1; + // Runtimes + pub use westend_runtime::xcm_config::{XcmConfig as WestendXcmConfig, UniversalLocation as WestendUniversalLocation}; + pub use asset_hub_westend_runtime::xcm_config::{ + XcmConfig as AssetHubWestendXcmConfig, UniversalLocation as AssetHubWestendUniversalLocation, + WestendLocationV3 as RelayLocationV3, + }; + pub use penpal_runtime::xcm_config::{ + LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3, + UniversalLocation as PenpalUniversalLocation, XcmConfig as PenpalWestendXcmConfig, + LocalReservableFromAssetHubV3 as PenpalLocalReservableFromAssetHubV3, + }; + + pub const ASSET_ID: u32 = 3; pub const ASSET_MIN_BALANCE: u128 = 1000; - // `Assets` pallet index - pub const ASSETS_PALLET_ID: u8 = 50; pub type RelayToSystemParaTest = Test; - pub type RelayToParaTest = Test; + pub type RelayToParaTest = Test; + pub type ParaToRelayTest = Test; pub type SystemParaToRelayTest = Test; - pub type SystemParaToParaTest = Test; - pub type ParaToSystemParaTest = Test; - pub type ParaToParaTest = Test; - - emulated_integration_tests_common::include_penpal_create_foreign_asset_on_asset_hub!( - PenpalB, - AssetHubWestend, - WESTEND_ED, - testnet_parachains_constants::westend::fee::WeightToFee - ); + pub type SystemParaToParaTest = Test; + pub type ParaToSystemParaTest = Test; + pub type ParaToParaThroughRelayTest = Test; } #[cfg(test)] diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 9e70cb9f8f649..00a362ca0bcf5 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -37,6 +37,24 @@ fn relay_to_para_sender_assertions(t: RelayToParaTest) { ); } +fn para_to_relay_sender_assertions(t: ParaToRelayTest) { + type RuntimeEvent = ::RuntimeEvent; + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8_799))); + assert_expected_events!( + PenpalA, + vec![ + // Amount to reserve transfer is transferred to Parachain's Sovereign account + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, balance, .. } + ) => { + asset_id: *asset_id == RelayLocationV3::get(), + owner: *owner == t.sender.account_id, + balance: *balance == t.args.amount, + }, + ] + ); +} + fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -69,7 +87,7 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_native_asset_location = RelayLocationV3::get(); PenpalA::assert_xcmp_queue_success(None); @@ -94,7 +112,7 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == SystemAssetHubLocationV3::get(), + asset_id: *asset_id == RelayLocationV3::get(), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -102,6 +120,36 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { ); } +fn para_to_relay_receiver_assertions(t: ParaToRelayTest) { + type RuntimeEvent = ::RuntimeEvent; + let sov_penpal_on_relay = Westend::sovereign_account_id_of( + Westend::child_location_of(PenpalA::para_id()), + ); + + Westend::assert_ump_queue_processed( + true, + Some(PenpalA::para_id()), + Some(Weight::from_parts(306305000, 7_186)), + ); + + assert_expected_events!( + Westend, + vec![ + // Amount to reserve transfer is withdrawn from Parachain's Sovereign account + RuntimeEvent::Balances( + pallet_balances::Event::Burned { who, amount } + ) => { + who: *who == sov_penpal_on_relay.clone().into(), + amount: *amount == t.args.amount, + }, + RuntimeEvent::Balances(pallet_balances::Event::Minted { .. }) => {}, + RuntimeEvent::MessageQueue( + pallet_message_queue::Event::Processed { success: true, .. } + ) => {}, + ] + ); +} + fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of( @@ -141,7 +189,7 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { RuntimeEvent::Assets( pallet_assets::Event::Transferred { asset_id, from, to, amount } ) => { - asset_id: *asset_id == ASSET_ID, + asset_id: *asset_id == RESERVABLE_ASSET_ID, from: *from == t.sender.account_id, to: *to == AssetHubWestend::sovereign_account_id_of( t.args.dest.clone() @@ -164,19 +212,13 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_asset_location = xcm::v3::Location::new( - 1, [ - xcm::v3::Junction::Parachain(ASSETHUB_PARA_ID), - xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), - ] - ); + let system_para_asset_location = PenpalLocalReservableFromAssetHubV3::get(); PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == SystemAssetHubLocationV3::get(), + asset_id: *asset_id == RelayLocationV3::get(), owner: *owner == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { @@ -287,6 +329,17 @@ fn relay_to_para_reserve_transfer_assets(t: RelayToParaTest) -> DispatchResult { ) } +fn para_to_relay_reserve_transfer_assets(t: ParaToRelayTest) -> DispatchResult { + ::PolkadotXcm::limited_reserve_transfer_assets( + t.signed_origin, + bx!(t.args.dest.into()), + bx!(t.args.beneficiary.into()), + bx!(t.args.assets.into()), + t.args.fee_asset_item, + t.args.weight_limit, + ) +} + fn system_para_to_para_reserve_transfer_assets(t: SystemParaToParaTest) -> DispatchResult { ::PolkadotXcm::limited_reserve_transfer_assets( t.signed_origin, @@ -449,17 +502,90 @@ fn reserve_transfer_native_asset_from_relay_to_para() { assert!(receiver_assets_after < receiver_assets_before + amount_to_send); } +/// Reserve Transfers of native asset from Parachain to Relay should work +#[test] +fn reserve_transfer_native_asset_from_para_to_relay() { + // Init values for Parachain + let destination = PenpalA::parent_location(); + let sender = PenpalASender::get(); + let amount_to_send: Balance = WESTEND_ED * 1000; + let assets: Assets = (Parent, amount_to_send).into(); + let asset_owner = PenpalAssetOwner::get(); + let relay_native_asset_location = RelayLocationV3::get(); + + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner), + relay_native_asset_location, + sender.clone(), + amount_to_send + ); + + // Init values for Relay + let receiver = WestendReceiver::get(); + let penpal_location_as_seen_by_relay = Westend::child_location_of(PenpalA::para_id()); + let sov_penpal_on_relay = Westend::sovereign_account_id_of(penpal_location_as_seen_by_relay); + + // fund Parachain's SA on Relay with the native tokens held in reserve + Westend::fund_accounts(vec![(sov_penpal_on_relay.into(), amount_to_send * 2)]); + + // Init Test + let test_args = TestContext { + sender: sender.clone(), + receiver: receiver.clone(), + args: TestArgs::new_para(destination.clone(), receiver, amount_to_send, assets.clone(), None, 0), + }; + let mut test = ParaToRelayTest::new(test_args); + + // Query initial balances + let sender_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.into(), &sender) + }); + let receiver_balance_before = test.receiver.balance; + + // Set assertions and dispatchables + test.set_assertion::(para_to_relay_sender_assertions); + test.set_assertion::(para_to_relay_receiver_assertions); + test.set_dispatchable::(para_to_relay_reserve_transfer_assets); + test.assert(); + + // Calculate delivery fees + let delivery_fees = PenpalA::execute_with(|| { + let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); + xcm_helpers::transfer_assets_delivery_fees::< + ::XcmSender, + >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) + }); + + // Query final balances + let sender_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(relay_native_asset_location.into(), &sender) + }); + let receiver_balance_after = test.receiver.balance; + + // Sender's balance is reduced + assert_eq!(sender_assets_before - amount_to_send - delivery_fees, sender_assets_after); + // Receiver's asset balance is increased + assert!(receiver_balance_after > receiver_balance_before); + // Receiver's asset balance increased by `amount_to_send - delivery_fees - bought_execution`; + // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but + // should be non-zero + assert!(receiver_balance_after < receiver_balance_before + amount_to_send); +} + /// Reserve Transfers of native asset from System Parachain to Parachain should work #[test] fn reserve_transfer_native_asset_from_system_para_to_para() { // Init values for System Parachain let destination = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let sender = AssetHubWestendSender::get(); - let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 10000; - let assets: Assets = (Here, amount_to_send).into(); + let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 2000; + let assets: Assets = (Parent, amount_to_send).into(); // Init values for Parachain - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_native_asset_location = RelayLocationV3::get(); let receiver = PenpalAReceiver::get(); // Init Test @@ -516,9 +642,9 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let destination = PenpalA::sibling_location_of(AssetHubWestend::para_id()); let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; - let assets: Assets = ((Parent, Parachain(ASSETHUB_PARA_ID)), amount_to_send).into(); - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); - let asset_owner = penpal_asset_owner(); + let assets: Assets = (Parent, amount_to_send).into(); + let system_para_native_asset_location = RelayLocationV3::get(); + let asset_owner = PenpalAssetOwner::get(); // fund Parachain's sender account PenpalA::mint_foreign_asset( @@ -588,43 +714,37 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { fn reserve_transfer_assets_from_system_para_to_para() { // Init values for System Parachain let destination = AssetHubWestend::sibling_location_of(PenpalA::para_id()); + let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(destination.clone()); let sender = AssetHubWestendSender::get(); - let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 10000; - let asset_amount_to_send = ASSET_MIN_BALANCE * 10000; - let asset_owner = penpal_asset_owner(); + let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 100; + let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; + let asset_owner = AssetHubWestendAssetOwner::get(); + let asset_owner_signer = ::RuntimeOrigin::signed(asset_owner.clone()); let assets: Assets = vec![ - (Here, fee_amount_to_send).into(), - ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], asset_amount_to_send) + (Parent, fee_amount_to_send).into(), + ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())], asset_amount_to_send) .into(), ] .into(); - let is_sufficient = false; - let min_balance = ASSET_MIN_BALANCE; let fee_asset_index = assets .inner() .iter() - .position(|r| r == &(Here, fee_amount_to_send).into()) + .position(|r| r == &(Parent, fee_amount_to_send).into()) .unwrap() as u32; - AssetHubWestend::force_create_and_mint_asset( - ASSET_ID, - min_balance, - is_sufficient, - asset_owner.clone(), - Some(Weight::from_parts(1_019_445_000, 200_000)), - min_balance * 1_000_000, + AssetHubWestend::mint_asset( + asset_owner_signer, + RESERVABLE_ASSET_ID, + asset_owner, + asset_amount_to_send * 2, ); + // Create SA-of-Penpal-on-AHR with ED. + AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ahr.into(), ASSET_HUB_WESTEND_ED)]); + // Init values for Parachain let receiver = PenpalAReceiver::get(); - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); - let system_para_foreign_asset_location = xcm::v3::Location::new( - 1, [ - xcm::v3::Junction::Parachain(ASSETHUB_PARA_ID), - xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), - ] - ); - PenpalA::force_create_foreign_asset(system_para_foreign_asset_location.clone(), asset_owner.clone(), is_sufficient, min_balance, vec![]); + let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHubV3::get(); // Init Test let para_test_args = TestContext { @@ -645,7 +765,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { let sender_balance_before = test.sender.balance; let sender_assets_before = AssetHubWestend::execute_with(|| { type Assets = ::Assets; - >::balance(ASSET_ID, &sender) + >::balance(RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -666,7 +786,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { let sender_balance_after = test.sender.balance; let sender_assets_after = AssetHubWestend::execute_with(|| { type Assets = ::Assets; - >::balance(ASSET_ID, &sender) + >::balance(RESERVABLE_ASSET_ID, &sender) }); let receiver_system_native_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; @@ -699,7 +819,7 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { let destination = PenpalA::sibling_location_of(PenpalB::para_id()); let sender = PenpalASender::get(); let amount_to_send: Balance = WESTEND_ED * 10000; - let asset_owner = penpal_asset_owner(); + let asset_owner = PenpalAssetOwner::get(); let assets = (Parent, amount_to_send).into(); let relay_native_asset_location = RelayLocationV3::get(); let sender_as_seen_by_relay = Westend::child_location_of(PenpalA::para_id()); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs index 84e93841ad7bd..f90f9d3b17573 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs @@ -33,7 +33,7 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() { #[test] fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { let para_sovereign_account = AssetHubWestend::sovereign_account_id_of( - AssetHubWestend::sibling_location_of(PenpalB::para_id()), + AssetHubWestend::sibling_location_of(PenpalA::para_id()), ); // Force create and mint assets for Parachain's sovereign account @@ -60,8 +60,8 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { let native_asset = ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); - let root_origin = ::RuntimeOrigin::root(); - let system_para_destination = PenpalB::sibling_location_of(AssetHubWestend::para_id()).into(); + let root_origin = ::RuntimeOrigin::root(); + let system_para_destination = PenpalA::sibling_location_of(AssetHubWestend::para_id()).into(); let xcm = xcm_transact_paid_execution( call, origin_kind, @@ -69,21 +69,21 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { para_sovereign_account.clone(), ); - PenpalB::execute_with(|| { - assert_ok!(::PolkadotXcm::send( + PenpalA::execute_with(|| { + assert_ok!(::PolkadotXcm::send( root_origin, bx!(system_para_destination), bx!(xcm), )); - PenpalB::assert_xcm_pallet_sent(); + PenpalA::assert_xcm_pallet_sent(); }); AssetHubWestend::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; AssetHubWestend::assert_xcmp_queue_success(Some(Weight::from_parts( - 16_290_336_000, + 15_594_564_000, 562_893, ))); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index b75eafeec50a8..03ee89d4442d9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -111,49 +111,36 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocationV3::get()); - let ah_as_seen_by_penpal = PenpalB::sibling_location_of(AssetHubWestend::para_id()); + let asset_native = Box::new(RelayLocationV3::get()); let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); - let asset_id_on_penpal = match asset_location_on_penpal.last() { - Some(v3::Junction::GeneralIndex(id)) => *id as u32, - _ => unreachable!(), - }; - let asset_owner_on_penpal = PenpalBSender::get(); let foreign_asset_at_asset_hub_westend = - v3::Location::new(1, [v3::Junction::Parachain(PenpalB::para_id().into())]) + v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); - // 1. Create asset on penpal and, 2. Create foreign asset on asset_hub_westend - penpal_create_foreign_asset_on_asset_hub( - asset_id_on_penpal, - foreign_asset_at_asset_hub_westend, - ah_as_seen_by_penpal, - true, - asset_owner_on_penpal, - ASSET_MIN_BALANCE * 1_000_000, - ); - - let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalB::para_id()); - let sov_penpal_on_ahw = AssetHubWestend::sovereign_account_id_of(penpal_as_seen_by_ah); + let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); + let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_as_seen_by_ah); AssetHubWestend::fund_accounts(vec![ - (AssetHubWestendSender::get().into(), 5_000_000 * WESTEND_ED), /* An account to swap dot - * for something else. */ + // An account to swap dot for something else. + (AssetHubWestendSender::get().into(), 5_000_000 * ASSET_HUB_WESTEND_ED), + // Penpal's sovereign account in AH should have some balance + (sov_penpal_on_ahr.clone().into(), 100_000_000 * ASSET_HUB_WESTEND_ED), ]); AssetHubWestend::execute_with(|| { - // 3: Mint foreign asset on asset_hub_westend: + // 1: Mint foreign asset on asset_hub_westend: // // (While it might be nice to use batch, // currently that's disabled due to safe call filters.) type RuntimeEvent = ::RuntimeEvent; - // 3. Mint foreign asset (in reality this should be a teleport or some such) + // 1. Mint foreign asset (in reality this should be a teleport or some such) assert_ok!(::ForeignAssets::mint( - ::RuntimeOrigin::signed(sov_penpal_on_ahw.clone().into()), + ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone().into()), foreign_asset_at_asset_hub_westend, - sov_penpal_on_ahw.clone().into(), - 3_000_000_000_000, + sov_penpal_on_ahr.clone().into(), + // 3_000_000_000_000, + ASSET_HUB_WESTEND_ED * 3_000_000_000_000, )); assert_expected_events!( @@ -163,7 +150,7 @@ fn swap_locally_on_chain_using_foreign_assets() { ] ); - // 4. Create pool: + // 2. Create pool: assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubWestendSender::get()), asset_native.clone(), @@ -177,58 +164,60 @@ fn swap_locally_on_chain_using_foreign_assets() { ] ); - // 5. Add liquidity: + // 3. Add liquidity: assert_ok!(::AssetConversion::add_liquidity( - ::RuntimeOrigin::signed(sov_penpal_on_ahw.clone()), + ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone()), asset_native.clone(), Box::new(foreign_asset_at_asset_hub_westend), - 1_000_000_000_000, - 2_000_000_000_000, + 1_000_000_000_000_000, + 2_000_000_000_000_000, 0, 0, - sov_penpal_on_ahw.clone().into() + sov_penpal_on_ahr.clone().into() )); assert_expected_events!( AssetHubWestend, vec![ RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::LiquidityAdded {lp_token_minted, .. }) => { - lp_token_minted: *lp_token_minted == 1414213562273, + lp_token_minted: *lp_token_minted == 1414213562372995, }, ] ); - // 6. Swap! + // 4. Swap! let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_westend)]; - assert_ok!(::AssetConversion::swap_exact_tokens_for_tokens( - ::RuntimeOrigin::signed(AssetHubWestendSender::get()), - path, - 100000, - 1000, - AssetHubWestendSender::get().into(), - true - )); + assert_ok!( + ::AssetConversion::swap_exact_tokens_for_tokens( + ::RuntimeOrigin::signed(AssetHubWestendSender::get()), + path, + 100000 * ASSET_HUB_WESTEND_ED, + 1000 * ASSET_HUB_WESTEND_ED, + AssetHubWestendSender::get().into(), + true + ) + ); assert_expected_events!( AssetHubWestend, vec![ RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::SwapExecuted { amount_in, amount_out, .. },) => { - amount_in: *amount_in == 100000, - amount_out: *amount_out == 199399, + amount_in: *amount_in == 100000000000000, + amount_out: *amount_out == 181322178776029, }, ] ); - // 7. Remove liquidity + // 5. Remove liquidity assert_ok!(::AssetConversion::remove_liquidity( - ::RuntimeOrigin::signed(sov_penpal_on_ahw.clone()), + ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone()), asset_native.clone(), Box::new(foreign_asset_at_asset_hub_westend), - 1414213562273 - 2_000_000_000, // all but the 2 EDs can't be retrieved. + 1414213562372995 - ASSET_HUB_WESTEND_ED * 2, // all but the 2 EDs can't be retrieved. 0, 0, - sov_penpal_on_ahw.into(), + sov_penpal_on_ahr.clone().into(), )); }); } @@ -282,7 +271,7 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { .into(), }; let penpal = AssetHubWestend::sovereign_account_id_of(AssetHubWestend::sibling_location_of( - PenpalB::para_id(), + PenpalA::para_id(), )); AssetHubWestend::execute_with(|| { @@ -355,7 +344,7 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { )); }); - PenpalB::execute_with(|| { + PenpalA::execute_with(|| { // send xcm transact from `penpal` account which as only `ASSET_ID` tokens on // `AssetHubWestend` let call = AssetHubWestend::force_create_asset_call( @@ -365,11 +354,11 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { ASSET_MIN_BALANCE, ); - let penpal_root = ::RuntimeOrigin::root(); + let penpal_root = ::RuntimeOrigin::root(); let fee_amount = 4_000_000_000_000u128; let asset_one = ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); - let asset_hub_location = PenpalB::sibling_location_of(AssetHubWestend::para_id()).into(); + let asset_hub_location = PenpalA::sibling_location_of(AssetHubWestend::para_id()).into(); let xcm = xcm_transact_paid_execution( call, OriginKind::SovereignAccount, @@ -377,13 +366,13 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { penpal.clone(), ); - assert_ok!(::PolkadotXcm::send( + assert_ok!(::PolkadotXcm::send( penpal_root, bx!(asset_hub_location), bx!(xcm), )); - PenpalB::assert_xcm_pallet_sent(); + PenpalA::assert_xcm_pallet_sent(); }); AssetHubWestend::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 0827baa09ab28..95a9dc50063d8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -110,7 +110,7 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_native_asset_location = RelayLocationV3::get(); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); @@ -206,7 +206,7 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let checking_account = ::PolkadotXcm::check_account(); - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); + let system_para_native_asset_location = RelayLocationV3::get(); PenpalA::assert_xcmp_queue_success(None); @@ -563,58 +563,62 @@ fn teleport_to_other_system_parachains_works() { #[test] fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { // Init values for Parachain - let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 10000; - let asset_owner = penpal_asset_owner(); - let system_para_native_asset_location = SystemAssetHubLocationV3::get(); - let sender = PenpalASender::get(); - - // fund Parachain's sender account - PenpalA::mint_foreign_asset( - ::RuntimeOrigin::signed(asset_owner.clone()), - system_para_native_asset_location, - sender.clone(), - fee_amount_to_send - ); - - let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubWestend::para_id()); + let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 100; let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); let asset_id_on_penpal = match asset_location_on_penpal.last() { Some(v3::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; - - let foreign_asset_at_asset_hub_westend = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) - .appended_with(asset_location_on_penpal) - .unwrap(); - - penpal_create_foreign_asset_on_asset_hub( - asset_id_on_penpal, - foreign_asset_at_asset_hub_westend, - ah_as_seen_by_penpal.clone(), - false, - asset_owner, - ASSET_MIN_BALANCE * 1_000_000, - ); - - // Init values for System Parachain - let penpal_to_ah_beneficiary_id = AssetHubWestendReceiver::get(); - - // let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000; - let asset_amount_to_send = ASSET_MIN_BALANCE * 1000; - + let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; + let asset_owner = PenpalAssetOwner::get(); + let system_para_native_asset_location = RelayLocationV3::get(); + let sender = PenpalASender::get(); + let penpal_check_account = + ::PolkadotXcm::check_account(); + let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubWestend::para_id()); let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); let penpal_assets: Assets = vec![ - ((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into(), + (Parent, fee_amount_to_send).into(), (asset_location_on_penpal_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = penpal_assets .inner() .iter() - .position(|r| r == &((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into()) + // .position(|r| r == &((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into()) + .position(|r| r == &(Parent, fee_amount_to_send).into()) .unwrap() as u32; + // fund Parachain's sender account + PenpalA::mint_foreign_asset( + ::RuntimeOrigin::signed(asset_owner.clone()), + system_para_native_asset_location, + sender.clone(), + fee_amount_to_send + ); + PenpalA::mint_asset( + ::RuntimeOrigin::signed(asset_owner.clone()), + asset_id_on_penpal, + sender.clone(), + asset_amount_to_send + ); + // fund Parachain's check account to be able to teleport + PenpalA::fund_accounts(vec![((penpal_check_account.clone().into(), ASSET_HUB_WESTEND_ED * 1000))]); + + // prefund SA of Penpal on AssetHub with enough native tokens to pay for fees + let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); + let sov_penpal_on_ah = AssetHubWestend::sovereign_account_id_of(penpal_as_seen_by_ah); + AssetHubWestend::fund_accounts(vec![ + (sov_penpal_on_ah.clone().into(), ASSET_HUB_WESTEND_ED * 100_000_000_000), + ]); + + // Init values for System Parachain + let foreign_asset_at_asset_hub_westend = + v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + .appended_with(asset_location_on_penpal) + .unwrap(); + let penpal_to_ah_beneficiary_id = AssetHubWestendReceiver::get(); + // Penpal to AH test args let penpal_to_ah_test_args = TestContext { sender: PenpalASender::get(), @@ -708,14 +712,14 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let ah_to_penpal_beneficiary_id = PenpalAReceiver::get(); let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let ah_assets: Assets = vec![ - (Here, fee_amount_to_send).into(), + (Parent, fee_amount_to_send).into(), (foreign_asset_at_asset_hub_westend_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = ah_assets .inner() .iter() - .position(|r| r == &(Here, fee_amount_to_send).into()) + .position(|r| r == &(Parent, fee_amount_to_send).into()) .unwrap() as u32; // AH to Penpal test args diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 3d72724e6b8bf..689d69c3a38d1 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -612,7 +612,7 @@ impl xcm_executor::Config for XcmConfig { // `pallet_assets` instance - `ForeignAssets`. cumulus_primitives_utility::TakeFirstAssetTrader< AccountId, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignAssetsConvertedConcreteId, ForeignAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index 34be746132ac4..8bd01dc98eace 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -46,7 +46,7 @@ use sp_runtime::traits::Zero; use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AsPrefixedGeneralIndex, ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsConcrete, LocalMint, NativeAsset, NoChecking, @@ -198,7 +198,7 @@ impl Contains for ParentOrParentsExecutivePlurality { pub struct CommonGoodAssetsParachain; impl Contains for CommonGoodAssetsParachain { fn contains(location: &Location) -> bool { - matches!(location.unpack(), (1, [Parachain(1000)])) + matches!(location.unpack(), (1, [Parachain(ASSET_HUB_ID)])) } } @@ -212,12 +212,6 @@ pub type Barrier = TrailingSetTopicAsId<( // If the message is one that immediately attempts to pay for execution, then // allow it. AllowTopLevelPaidExecutionFrom, - // System Assets parachain, parent and its exec plurality get free - // execution - AllowExplicitUnpaidExecutionFrom<( - CommonGoodAssetsParachain, - ParentOrParentsExecutivePlurality, - )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, ), @@ -285,27 +279,41 @@ where } } +// This asset can be added to AH as Asset and reserved transfer between Penpal and AH +pub const RESERVABLE_ASSET_ID: u32 = 1; // This asset can be added to AH as ForeignAsset and teleported between Penpal and AH pub const TELEPORTABLE_ASSET_ID: u32 = 2; + +pub const ASSETS_PALLET_ID: u8 = 50; +pub const ASSET_HUB_ID: u32 = 1000; + parameter_types! { /// The location that this chain recognizes as the Relay network's Asset Hub. - pub SystemAssetHubLocation: Location = Location::new(1, [Parachain(1000)]); - pub SystemAssetHubLocationV3: xcm::v3::Location = xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(1000)]); + pub SystemAssetHubLocation: Location = Location::new(1, [Parachain(ASSET_HUB_ID)]); + pub SystemAssetHubLocationV3: xcm::v3::Location = xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(ASSET_HUB_ID)]); pub RelayLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); // ALWAYS ensure that the index in PalletInstance stays up-to-date with // the Relay Chain's Asset Hub's Assets pallet index pub SystemAssetHubAssetsPalletLocation: Location = - Location::new(1, [Parachain(1000), PalletInstance(50)]); + Location::new(1, [Parachain(ASSET_HUB_ID), PalletInstance(ASSETS_PALLET_ID)]); pub AssetsPalletLocation: Location = - Location::new(0, [PalletInstance(50)]); + Location::new(0, [PalletInstance(ASSETS_PALLET_ID)]); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); pub LocalTeleportableToAssetHub: Location = Location::new( 0, - [PalletInstance(50), GeneralIndex(TELEPORTABLE_ASSET_ID.into())] + [PalletInstance(ASSETS_PALLET_ID), GeneralIndex(TELEPORTABLE_ASSET_ID.into())] ); pub LocalTeleportableToAssetHubV3: xcm::v3::Location = xcm::v3::Location::new( 0, - [xcm::v3::Junction::PalletInstance(50), xcm::v3::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into())] + [xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), xcm::v3::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into())] + ); + pub LocalReservableFromAssetHub: Location = Location::new( + 1, + [Parachain(ASSET_HUB_ID), PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())] + ); + pub LocalReservableFromAssetHubV3: xcm::v3::Location = xcm::v3::Location::new( + 1, + [xcm::v3::Junction::Parachain(ASSET_HUB_ID), xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), xcm::v3::Junction::GeneralIndex(RESERVABLE_ASSET_ID.into())] ); pub EthereumLocation: Location = Location::new(2, [GlobalConsensus(EthereumNetwork::get())]); } From 01e483c89d4924e002fbaf05b3cc42e118fe9f5a Mon Sep 17 00:00:00 2001 From: NachoPal Date: Thu, 29 Feb 2024 19:52:19 +0100 Subject: [PATCH 04/18] fix imports --- .../parachains/testing/penpal/src/genesis.rs | 2 +- .../bridges/bridge-hub-rococo/src/lib.rs | 100 ++++++++---------- .../bridge-hub-rococo/src/tests/mod.rs | 2 +- .../bridge-hub-rococo/src/tests/snowbridge.rs | 2 +- .../bridge-hub-rococo/src/tests/teleport.rs | 2 +- .../bridges/bridge-hub-westend/src/lib.rs | 93 ++++++++-------- .../bridge-hub-westend/src/tests/mod.rs | 2 +- .../bridge-hub-westend/src/tests/teleport.rs | 2 +- .../tests/people/people-rococo/src/lib.rs | 75 ++++++------- .../people-rococo/src/tests/reap_identity.rs | 2 +- .../people-rococo/src/tests/teleport.rs | 2 +- .../tests/people/people-westend/src/lib.rs | 76 ++++++------- .../people-westend/src/tests/reap_identity.rs | 2 +- .../people-westend/src/tests/teleport.rs | 2 +- 14 files changed, 166 insertions(+), 198 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index 6f46ec3fda996..93bf50683db3f 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -21,7 +21,7 @@ use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{Balance, AccountId}; -use penpal_runtime::xcm_config::{RelayLocationV3, SystemAssetHubLocationV3, LocalReservableFromAssetHubV3}; +use penpal_runtime::xcm_config::{RelayLocationV3, LocalReservableFromAssetHubV3}; // Penpal pub const PARA_ID_A: u32 = 2000; pub const PARA_ID_B: u32 = 2001; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs index 9ce981b074c5b..d97886d4a34d9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs @@ -13,62 +13,56 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Substrate -pub use frame_support::{assert_err, assert_ok, pallet_prelude::DispatchResult}; -pub use sp_runtime::DispatchError; - -// Polkadot -pub use xcm::{ - latest::ParentThen, - prelude::{AccountId32 as AccountId32Junction, *}, - v3::{ - self, Error, - NetworkId::{Rococo as RococoId, Westend as WestendId}, - }, -}; +#[cfg(test)] +mod imports { + // Substrate + pub use frame_support::{assert_err, assert_ok, pallet_prelude::DispatchResult}; + pub use sp_runtime::DispatchError; -// Bridges -pub use bp_messages::LaneId; + // Polkadot + pub use xcm::{ + latest::ParentThen, + prelude::{AccountId32 as AccountId32Junction, *}, + v3::{ + self, + NetworkId::Westend as WestendId, + }, + }; -// Cumulus -pub use emulated_integration_tests_common::{ - accounts::ALICE, - impls::Inspect, - test_parachain_is_trusted_teleporter, - xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, - }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, -}; -pub use parachains_common::{AccountId, Balance}; -pub use rococo_westend_system_emulated_network::{ - asset_hub_rococo_emulated_chain::{ - genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, - }, - asset_hub_westend_emulated_chain::{ - genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, - }, - bridge_hub_rococo_emulated_chain::{ - genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubRococoParaPallet as BridgeHubRococoPallet, - }, - penpal_emulated_chain::PenpalAParaPallet as PenpalAPallet, - rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, - AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, - AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, - AssetHubWestendParaReceiver as AssetHubWestendReceiver, - AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, - BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, - BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWestendPara as BridgeHubWestend, - PenpalAPara as PenpalA, PenpalAParaReceiver as PenpalAReceiver, - PenpalAParaSender as PenpalASender, RococoRelay as Rococo, - RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender, -}; + // Cumulus + pub use emulated_integration_tests_common::{ + accounts::ALICE, + impls::Inspect, + test_parachain_is_trusted_teleporter, + xcm_emulator::{ + assert_expected_events, bx, Chain, Parachain as Para, + RelayChain as Relay, TestExt, + }, + }; + pub use parachains_common::AccountId; + pub use rococo_westend_system_emulated_network::{ + asset_hub_rococo_emulated_chain::{ + genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, + }, + asset_hub_westend_emulated_chain::{ + genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, + }, + bridge_hub_rococo_emulated_chain::{ + genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubRococoParaPallet as BridgeHubRococoPallet, + }, + penpal_emulated_chain::PenpalAParaPallet as PenpalAPallet, + rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, + AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, + AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, + AssetHubWestendParaReceiver as AssetHubWestendReceiver, + AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, + BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWestendPara as BridgeHubWestend, + PenpalAPara as PenpalA, PenpalAParaReceiver as PenpalAReceiver, + PenpalAParaSender as PenpalASender, RococoRelay as Rococo, + }; -pub const ASSET_ID: u32 = 1; -pub const ASSET_MIN_BALANCE: u128 = 1000; -pub const ASSETS_PALLET_ID: u8 = 50; + pub const ASSET_MIN_BALANCE: u128 = 1000; +} #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs index 6d7b53c8fdfdb..88dad06434b0d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; mod asset_transfers; mod send_xcm; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index a5957ee339306..a3f7eed1865b0 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -12,7 +12,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; use bridge_hub_rococo_runtime::{EthereumBeaconClient, EthereumInboundQueue, RuntimeOrigin}; use codec::{Decode, Encode}; use emulated_integration_tests_common::xcm_emulator::ConvertLocation; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs index 43f8af9244f56..8f51f5b180004 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::tests::*; use bridge_hub_rococo_runtime::xcm_config::XcmConfig; #[test] diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs index 223979cc9c9d3..a394c3af64184 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs @@ -13,59 +13,52 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Substrate -pub use frame_support::{assert_err, assert_ok, pallet_prelude::DispatchResult}; -pub use sp_runtime::DispatchError; - -// Polkadot -pub use xcm::{ - latest::ParentThen, - prelude::{AccountId32 as AccountId32Junction, *}, - v3, - v4::{ - Error, - NetworkId::{Rococo as RococoId, Westend as WestendId}, - }, -}; +#[cfg(test)] +mod imports { + // Substrate + pub use frame_support::{assert_err, assert_ok, pallet_prelude::DispatchResult}; + pub use sp_runtime::DispatchError; -// Bridges -pub use bp_messages::LaneId; + // Polkadot + pub use xcm::{ + latest::ParentThen, + prelude::{AccountId32 as AccountId32Junction, *}, + v3, + v4::NetworkId::Rococo as RococoId, + }; -// Cumulus -pub use emulated_integration_tests_common::{ - accounts::ALICE, - impls::Inspect, - test_parachain_is_trusted_teleporter, - xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, - }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, -}; -pub use parachains_common::{AccountId, Balance}; -pub use rococo_westend_system_emulated_network::{ - asset_hub_rococo_emulated_chain::{ - genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, - }, - asset_hub_westend_emulated_chain::{ - genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, - }, - bridge_hub_westend_emulated_chain::{ - genesis::ED as BRIDGE_HUB_WESTEND_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, - }, - westend_emulated_chain::WestendRelayPallet as WestendPallet, - AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, - AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, - AssetHubWestendParaReceiver as AssetHubWestendReceiver, - AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, - BridgeHubWestendPara as BridgeHubWestend, BridgeHubWestendParaSender as BridgeHubWestendSender, - WestendRelay as Westend, -}; + // Cumulus + pub use emulated_integration_tests_common::{ + accounts::ALICE, + impls::Inspect, + test_parachain_is_trusted_teleporter, + xcm_emulator::{ + assert_expected_events, bx, Chain, Parachain as Para, + RelayChain as Relay, TestExt + }, + }; + pub use parachains_common::AccountId; + pub use rococo_westend_system_emulated_network::{ + asset_hub_rococo_emulated_chain::{ + genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, + }, + asset_hub_westend_emulated_chain::{ + genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, + }, + bridge_hub_westend_emulated_chain::{ + genesis::ED as BRIDGE_HUB_WESTEND_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, + }, + westend_emulated_chain::WestendRelayPallet as WestendPallet, + AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, + AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, + AssetHubWestendParaReceiver as AssetHubWestendReceiver, + AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, + BridgeHubWestendPara as BridgeHubWestend, BridgeHubWestendParaSender as BridgeHubWestendSender, + WestendRelay as Westend, + }; -pub const ASSET_ID: u32 = 1; -pub const ASSET_MIN_BALANCE: u128 = 1000; -pub const ASSETS_PALLET_ID: u8 = 50; + pub const ASSET_MIN_BALANCE: u128 = 1000; +} #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs index 3074435e8e4e0..b781d6e987ca1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; mod asset_transfers; mod send_xcm; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs index edffaf165960c..c960233c08b73 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::tests::*; use bridge_hub_westend_runtime::xcm_config::XcmConfig; #[test] diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs index 6f2f1409135df..b343d272f5460 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -13,52 +13,43 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub use codec::Encode; +#[cfg(test)] +mod imports { + pub use codec::Encode; -// Substrate -pub use frame_support::{ - assert_err, assert_ok, - pallet_prelude::Weight, - sp_runtime::{AccountId32, DispatchError, DispatchResult}, - traits::fungibles::Inspect, -}; + // Substrate + pub use frame_support::{ + assert_ok, + pallet_prelude::Weight, + sp_runtime::{AccountId32, DispatchResult}, + traits::fungibles::Inspect, + }; -// Polkadot -pub use xcm::{ - prelude::{AccountId32 as AccountId32Junction, *}, - v3::{Error, NetworkId::Rococo as RococoId}, -}; + // Polkadot + pub use xcm::prelude::*; -// Cumulus -pub use asset_test_utils::xcm_helpers; -pub use emulated_integration_tests_common::{ - test_parachain_is_trusted_teleporter, - xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, - }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, -}; -pub use parachains_common::{AccountId, Balance}; -pub use rococo_system_emulated_network::{ - people_rococo_emulated_chain::{ - genesis::ED as PEOPLE_ROCOCO_ED, PeopleRococoParaPallet as PeopleRococoPallet, - }, - rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, - PenpalAPara as PenpalA, PeopleRococoPara as PeopleRococo, - PeopleRococoParaReceiver as PeopleRococoReceiver, PeopleRococoParaSender as PeopleRococoSender, - RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, - RococoRelaySender as RococoSender, -}; + // Cumulus + pub use asset_test_utils::xcm_helpers; + pub use emulated_integration_tests_common:: + xcm_emulator::{ + assert_expected_events, bx, Chain, Parachain as Para, + RelayChain as Relay, Test, TestArgs, TestContext, TestExt, + }; + pub use parachains_common::Balance; + pub use rococo_system_emulated_network::{ + people_rococo_emulated_chain::{ + genesis::ED as PEOPLE_ROCOCO_ED, PeopleRococoParaPallet as PeopleRococoPallet, + }, + rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, + PeopleRococoPara as PeopleRococo, + PeopleRococoParaReceiver as PeopleRococoReceiver, PeopleRococoParaSender as PeopleRococoSender, + RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, + RococoRelaySender as RococoSender, + }; -// pub const ASSET_ID: u32 = 1; -// pub const ASSET_MIN_BALANCE: u128 = 1000; -pub type RelayToSystemParaTest = Test; -pub type RelayToParaTest = Test; -pub type SystemParaToRelayTest = Test; -pub type SystemParaToParaTest = Test; -pub type ParaToSystemParaTest = Test; + pub type RelayToSystemParaTest = Test; + pub type SystemParaToRelayTest = Test; +} #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs index 87adb363e022b..3f1f8638d6fa1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/reap_identity.rs @@ -38,7 +38,7 @@ //! - The freed deposit from the Relay Chain is sufficient for the parachain deposit; and //! - The account will exist on the parachain. -use crate::*; +use crate::imports::*; use frame_support::BoundedVec; use pallet_balances::Event as BalancesEvent; use pallet_identity::{legacy::IdentityInfo, Data, Event as IdentityEvent}; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs index 0a12277395d73..3abe5c6cf66a3 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/tests/teleport.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; use people_rococo_runtime::xcm_config::XcmConfig as PeopleRococoXcmConfig; use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/lib.rs index 59cec36030b23..d3d6baefeaf5b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/lib.rs @@ -13,52 +13,42 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub use codec::Encode; - -// Substrate -pub use frame_support::{ - assert_err, assert_ok, - pallet_prelude::Weight, - sp_runtime::{AccountId32, DispatchError, DispatchResult}, - traits::fungibles::Inspect, -}; +#[cfg(test)] +mod imports { + pub use codec::Encode; + // Substrate + pub use frame_support::{ + assert_ok, + pallet_prelude::Weight, + sp_runtime::{AccountId32, DispatchResult}, + traits::fungibles::Inspect, + }; -// Polkadot -pub use xcm::{ - prelude::{AccountId32 as AccountId32Junction, *}, - v3::{Error, NetworkId::Westend as WestendId}, -}; + // Polkadot + pub use xcm::prelude::*; -// Cumulus -pub use asset_test_utils::xcm_helpers; -pub use emulated_integration_tests_common::{ - test_parachain_is_trusted_teleporter, - xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, - }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, -}; -pub use parachains_common::{AccountId, Balance}; -pub use westend_system_emulated_network::{ - people_westend_emulated_chain::{ - genesis::ED as PEOPLE_WESTEND_ED, PeopleWestendParaPallet as PeopleWestendPallet, - }, - westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet}, - PenpalAPara as PenpalA, PeopleWestendPara as PeopleWestend, - PeopleWestendParaReceiver as PeopleWestendReceiver, - PeopleWestendParaSender as PeopleWestendSender, WestendRelay as Westend, - WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender, -}; + // Cumulus + pub use asset_test_utils::xcm_helpers; + pub use emulated_integration_tests_common:: + xcm_emulator::{ + assert_expected_events, bx, Chain, Parachain as Para, + RelayChain as Relay, Test, TestArgs, TestContext, TestExt, + }; + pub use parachains_common::Balance; + pub use westend_system_emulated_network::{ + people_westend_emulated_chain::{ + genesis::ED as PEOPLE_WESTEND_ED, PeopleWestendParaPallet as PeopleWestendPallet, + }, + westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet}, + PeopleWestendPara as PeopleWestend, + PeopleWestendParaReceiver as PeopleWestendReceiver, + PeopleWestendParaSender as PeopleWestendSender, WestendRelay as Westend, + WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender, + }; -// pub const ASSET_ID: u32 = 1; -// pub const ASSET_MIN_BALANCE: u128 = 1000; -pub type RelayToSystemParaTest = Test; -pub type RelayToParaTest = Test; -pub type SystemParaToRelayTest = Test; -pub type SystemParaToParaTest = Test; -pub type ParaToSystemParaTest = Test; + pub type RelayToSystemParaTest = Test; + pub type SystemParaToRelayTest = Test; +} #[cfg(test)] mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/reap_identity.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/reap_identity.rs index 8d63c8ceff6ef..3ed8592918d65 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/reap_identity.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/reap_identity.rs @@ -38,7 +38,7 @@ //! - The freed deposit from the Relay Chain is sufficient for the parachain deposit; and //! - The account will exist on the parachain. -use crate::*; +use crate::imports::*; use frame_support::BoundedVec; use pallet_balances::Event as BalancesEvent; use pallet_identity::{legacy::IdentityInfo, Data, Event as IdentityEvent}; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs index 345663be99baa..eef35a99a8331 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/teleport.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::imports::*; use people_westend_runtime::xcm_config::XcmConfig as PeopleWestendXcmConfig; use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig; From 4e569791a394ea27b334576ff56463a4f8908581 Mon Sep 17 00:00:00 2001 From: NachoPal Date: Fri, 1 Mar 2024 13:22:17 +0100 Subject: [PATCH 05/18] add para to ah test --- .../emulated/common/src/impls.rs | 32 --- .../emulated/common/src/macros.rs | 105 --------- .../src/tests/reserve_transfer.rs | 204 +++++++++++++++++- .../src/tests/reserve_transfer.rs | 204 +++++++++++++++++- .../assets/asset-hub-rococo/tests/tests.rs | 2 +- .../assets/asset-hub-westend/tests/tests.rs | 2 +- 6 files changed, 408 insertions(+), 141 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 0363178edce9d..5732a4cf50281 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -630,38 +630,6 @@ macro_rules! impl_assets_helpers_for_system_parachain { $crate::impls::xcm_transact_unpaid_execution(call, origin_kind) } - // /// Mint assets making use of the assets pallet - // pub fn mint_asset( - // signed_origin: ::RuntimeOrigin, - // id: u32, - // beneficiary: $crate::impls::AccountId, - // amount_to_mint: u128, - // ) { - // ::execute_with(|| { - // $crate::impls::assert_ok!(]>::Assets::mint( - // signed_origin, - // id.clone().into(), - // beneficiary.clone().into(), - // amount_to_mint - // )); - - // type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; - - // $crate::impls::assert_expected_events!( - // Self, - // vec![ - // RuntimeEvent::::Assets( - // $crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount } - // ) => { - // asset_id: *asset_id == id, - // owner: *owner == beneficiary.clone().into(), - // amount: *amount == amount_to_mint, - // }, - // ] - // ); - // }); - // } - /// Force create and mint assets making use of the assets pallet pub fn force_create_and_mint_asset( id: u32, diff --git a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs index 7a4f1bc480072..edd9d318b1328 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs @@ -131,108 +131,3 @@ macro_rules! test_parachain_is_trusted_teleporter { } }; } - -// #[macro_export] -// macro_rules! include_penpal_create_foreign_asset_on_asset_hub { -// ( $penpal:ident, $asset_hub:ident, $relay_ed:expr, $weight_to_fee:expr) => { -// $crate::impls::paste::paste! { -// pub fn penpal_create_foreign_asset_on_asset_hub( -// asset_id_on_penpal: u32, -// foreign_asset_at_asset_hub: $crate::macros::V3Location, -// ah_as_seen_by_penpal: $crate::macros::Location, -// is_sufficient: bool, -// asset_owner: $crate::macros::AccountId, -// prefund_amount: u128, -// ) { -// use $crate::macros::{ -// pallet_assets, pallet_xcm, Chain, Weight, OriginKind, Asset, AssetId, Fungible, -// Location, Here, VersionedXcm, Xcm, Unlimited, WeightToFee, WithdrawAsset, BuyExecution, -// Transact, ExpectTransactStatus, MaybeErrorCode, RefundSurplus, DepositAsset, -// All -// }; - -// let ah_check_account = $asset_hub::execute_with(|| { -// <$asset_hub as [<$asset_hub Pallet>]>::PolkadotXcm::check_account() -// }); -// let penpal_check_account = -// $penpal::execute_with(|| <$penpal as [<$penpal Pallet>]>::PolkadotXcm::check_account()); -// let penpal_as_seen_by_ah = $asset_hub::sibling_location_of($penpal::para_id()); - -// // prefund SA of Penpal on AssetHub with enough native tokens to pay for creating -// // new foreign asset, also prefund CheckingAccount with ED, because teleported asset -// // itself might not be sufficient and CheckingAccount cannot be created otherwise -// let sov_penpal_on_ah = $asset_hub::sovereign_account_id_of(penpal_as_seen_by_ah.clone()); -// $asset_hub::fund_accounts(vec![ -// (sov_penpal_on_ah.clone().into(), $relay_ed * 100_000_000_000), -// (ah_check_account.clone().into(), $relay_ed * 1000), -// ]); - -// // prefund SA of AssetHub on Penpal with native asset -// let sov_ah_on_penpal = $penpal::sovereign_account_id_of(ah_as_seen_by_penpal.clone()); -// $penpal::fund_accounts(vec![ -// (sov_ah_on_penpal.into(), $relay_ed * 1_000_000_000), -// (penpal_check_account.clone().into(), $relay_ed * 1000), -// ]); - -// // Force create asset on $penpal and prefund [<$penpal Sender>] -// $penpal::force_create_and_mint_asset( -// asset_id_on_penpal, -// ASSET_MIN_BALANCE, -// is_sufficient, -// asset_owner, -// None, -// prefund_amount, -// ); - -// let require_weight_at_most = Weight::from_parts(1_100_000_000_000, 30_000); -// // `OriginKind::Xcm` required by ForeignCreators pallet-assets origin filter -// let origin_kind = OriginKind::Xcm; -// let call_create_foreign_assets = -// <$asset_hub as Chain>::RuntimeCall::ForeignAssets(pallet_assets::Call::< -// <$asset_hub as Chain>::Runtime, -// pallet_assets::Instance2, -// >::create { -// id: foreign_asset_at_asset_hub, -// min_balance: ASSET_MIN_BALANCE, -// admin: sov_penpal_on_ah.into(), -// }) -// .encode(); -// let buy_execution_fee_amount = $weight_to_fee::weight_to_fee( -// &Weight::from_parts(10_100_000_000_000, 300_000), -// ); -// let buy_execution_fee = Asset { -// id: AssetId(Location { parents: 1, interior: Here }), -// fun: Fungible(buy_execution_fee_amount), -// }; -// let xcm = VersionedXcm::from(Xcm(vec![ -// WithdrawAsset { 0: vec![buy_execution_fee.clone()].into() }, -// BuyExecution { fees: buy_execution_fee.clone(), weight_limit: Unlimited }, -// Transact { require_weight_at_most, origin_kind, call: call_create_foreign_assets.into() }, -// ExpectTransactStatus(MaybeErrorCode::Success), -// RefundSurplus, -// DepositAsset { assets: All.into(), beneficiary: penpal_as_seen_by_ah }, -// ])); -// // Send XCM message from penpal => asset_hub -// let sudo_penpal_origin = <$penpal as Chain>::RuntimeOrigin::root(); -// $penpal::execute_with(|| { -// assert_ok!(<$penpal as [<$penpal Pallet>]>::PolkadotXcm::send( -// sudo_penpal_origin.clone(), -// bx!(ah_as_seen_by_penpal.into()), -// bx!(xcm), -// )); -// type RuntimeEvent = <$penpal as Chain>::RuntimeEvent; -// assert_expected_events!( -// $penpal, -// vec![ -// RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {}, -// ] -// ); -// }); -// $asset_hub::execute_with(|| { -// type ForeignAssets = <$asset_hub as [<$asset_hub Pallet>]>::ForeignAssets; -// assert!(ForeignAssets::asset_exists(foreign_asset_at_asset_hub)); -// }); -// } -// } -// }; -// } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 2ac9a4cf73de5..67d45442b8f76 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -210,6 +210,40 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { ); } +fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { + type RuntimeEvent = ::RuntimeEvent; + let system_para_native_asset_location = RelayLocationV3::get(); + let reservable_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( + 864_610_000, + 8799, + ))); + assert_expected_events!( + PenpalA, + vec![ + // Fees amount to reserve transfer is burned from Parachains's sender account + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, .. } + ) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.sender.account_id, + }, + // Amount to reserve transfer is burned from Parachains's sender account + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, balance } + ) => { + asset_id: *asset_id == reservable_asset_location, + owner: *owner == t.sender.account_id, + balance: *balance == t.args.amount, + }, + // Transport fees are paid + RuntimeEvent::PolkadotXcm( + pallet_xcm::Event::FeesPaid { .. } + ) => {}, + ] + ); +} + fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; let system_para_asset_location = PenpalLocalReservableFromAssetHubV3::get(); @@ -230,6 +264,39 @@ fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { ); } +fn para_to_system_para_assets_receiver_assertions(t: ParaToSystemParaTest) { + type RuntimeEvent = ::RuntimeEvent; + let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of( + AssetHubRococo::sibling_location_of(PenpalA::para_id()), + ); + AssetHubRococo::assert_xcmp_queue_success(None); + assert_expected_events!( + AssetHubRococo, + vec![ + // Amount to reserve transfer is burned from Parachain's Sovereign account + RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { + asset_id: *asset_id == RESERVABLE_ASSET_ID, + owner: *owner == sov_penpal_on_ahr, + balance: *balance == t.args.amount, + }, + // Fee amount is burned from Parachain's Sovereign account + RuntimeEvent::Balances(pallet_balances::Event::Burned { who, .. }) => { + who: *who == sov_penpal_on_ahr, + }, + // Amount to reserve transfer is issued for beneficiary + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + asset_id: *asset_id == RESERVABLE_ASSET_ID, + owner: *owner == t.receiver.account_id, + amount: *amount == t.args.amount, + }, + // Remaining fee amount is minted for for beneficiary + RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { + who: *who == t.receiver.account_id, + }, + ] + ); +} + fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -443,6 +510,9 @@ fn reserve_transfer_native_asset_from_system_para_to_relay_fails() { }); } +// ========================================================================= +// ========= Reserve Transfers - Native Asset - Relay<>Parachain =========== +// ========================================================================= /// Reserve Transfers of native asset from Relay to Parachain should work #[test] fn reserve_transfer_native_asset_from_relay_to_para() { @@ -575,6 +645,9 @@ fn reserve_transfer_native_asset_from_para_to_relay() { assert!(receiver_balance_after < receiver_balance_before + amount_to_send); } +// ========================================================================= +// ======= Reserve Transfers - Native Asset - AssetHub<>Parachain ========== +// ========================================================================= /// Reserve Transfers of native asset from System Parachain to Parachain should work #[test] fn reserve_transfer_native_asset_from_system_para_to_para() { @@ -605,7 +678,6 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { // Set assertions and dispatchables test.set_assertion::(system_para_to_para_sender_assertions); - // test.set_assertion::(system_para_to_para_native_assets_receiver_assertions); test.set_assertion::(system_para_to_para_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); @@ -708,6 +780,9 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { assert!(receiver_balance_after < receiver_balance_before + amount_to_send); } +// ========================================================================= +// ======= Reserve Transfers - Non-system Asset - AssetHub<>Parachain ====== +// ========================================================================= /// Reserve Transfers of a local asset and native asset from System Parachain to Parachain should /// work #[test] @@ -811,6 +886,133 @@ fn reserve_transfer_assets_from_system_para_to_para() { assert_eq!(receiver_foreign_assets_after, receiver_foreign_assets_before + asset_amount_to_send); } +/// Reserve Transfers of a foreign asset and native asset from Parachain to System Para should +/// work +#[test] +fn reserve_transfer_assets_from_para_to_system_para() { + // Init values for Parachain + let destination = PenpalA::sibling_location_of(AssetHubRococo::para_id()); + let sender = PenpalASender::get(); + let fee_amount_to_send = ASSET_HUB_ROCOCO_ED * 10000; + let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 10000; + let penpal_asset_owner = PenpalAssetOwner::get(); + let penpal_asset_owner_signer = ::RuntimeOrigin::signed(penpal_asset_owner); + let asset_location_on_penpal = PenpalLocalReservableFromAssetHubV3::get(); + let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); + let system_asset_location_on_penpal = RelayLocationV3::get(); + let assets: Assets = vec![ + (Parent, fee_amount_to_send).into(), + (asset_location_on_penpal_latest, asset_amount_to_send) + .into(), + ] + .into(); + let fee_asset_index = assets + .inner() + .iter() + .position(|r| r == &(Parent, fee_amount_to_send).into()) + .unwrap() as u32; + // Fund Parachain's sender account with some foreign assets + PenpalA::mint_foreign_asset( + penpal_asset_owner_signer.clone(), + asset_location_on_penpal, + sender.clone(), + asset_amount_to_send * 2, + ); + // Fund Parachain's sender account with some system assets + PenpalA::mint_foreign_asset( + penpal_asset_owner_signer, + system_asset_location_on_penpal, + sender.clone(), + fee_amount_to_send * 2, + ); + + // Init values for System Parachain + let receiver = AssetHubRococoReceiver::get(); + let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id()); + let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr); + let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let ah_asset_owner = AssetHubRococoAssetOwner::get(); + let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); + + // Fund SA-of-Penpal-on-AHR to be able to pay for the fees. + AssetHubRococo::fund_accounts(vec![(sov_penpal_on_ahr.clone().into(), ASSET_HUB_ROCOCO_ED * 10000000)]); + // Fund SA-of-Penpal-on-AHR to be able to pay for the sent amount. + AssetHubRococo::mint_asset( + ah_asset_owner_signer, + RESERVABLE_ASSET_ID, + sov_penpal_on_ahr, + asset_amount_to_send * 2, + ); + + // Init Test + let para_test_args = TestContext { + sender: sender.clone(), + receiver: receiver.clone(), + args: TestArgs::new_para( + destination, + receiver.clone(), + asset_amount_to_send, + assets, + None, + fee_asset_index, + ), + }; + let mut test = ParaToSystemParaTest::new(para_test_args); + + // Query initial balances + let sender_system_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &sender) + }); + let sender_foreign_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_foreign_asset_location.clone(), &sender) + }); + let receiver_balance_before = test.receiver.balance; + let receiver_assets_before = AssetHubRococo::execute_with(|| { + type Assets = ::Assets; + >::balance(RESERVABLE_ASSET_ID, &receiver) + }); + + // Set assertions and dispatchables + test.set_assertion::(para_to_system_para_assets_sender_assertions); + test.set_assertion::(para_to_system_para_assets_receiver_assertions); + test.set_dispatchable::(para_to_system_para_reserve_transfer_assets); + test.assert(); + + // Query final balances + let sender_system_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &sender) + }); + let sender_foreign_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_foreign_asset_location.clone(), &sender) + }); + let receiver_balance_after = test.receiver.balance; + let receiver_assets_after = AssetHubRococo::execute_with(|| { + type Assets = ::Assets; + >::balance(RESERVABLE_ASSET_ID, &receiver) + }); + // Sender's system asset balance is reduced + assert!(sender_system_assets_after < sender_system_assets_before); + // Receiver's balance is increased + assert!(receiver_balance_after > receiver_balance_before); + // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; + // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but + // should be non-zero + assert!(receiver_balance_after < receiver_balance_before + fee_amount_to_send); + + // Sender's asset balance is reduced by exact amount + assert_eq!(sender_foreign_assets_before - asset_amount_to_send, sender_foreign_assets_after); + // Receiver's foreign asset balance is increased by exact amount + assert_eq!(receiver_assets_after, receiver_assets_before + asset_amount_to_send); +} + +// ========================================================================= +// ===== Reserve Transfers - Native Asset - Parachain<>Relay<>Parachain ==== +// ========================================================================= /// Reserve Transfers of native asset from Parachain to Parachain (through Relay reserve) should /// work #[test] diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 00a362ca0bcf5..6dac5a07260d6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -210,6 +210,40 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { ); } +fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { + type RuntimeEvent = ::RuntimeEvent; + let system_para_native_asset_location = RelayLocationV3::get(); + let reservable_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( + 864_610_000, + 8799, + ))); + assert_expected_events!( + PenpalA, + vec![ + // Fees amount to reserve transfer is burned from Parachains's sender account + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, .. } + ) => { + asset_id: *asset_id == system_para_native_asset_location, + owner: *owner == t.sender.account_id, + }, + // Amount to reserve transfer is burned from Parachains's sender account + RuntimeEvent::ForeignAssets( + pallet_assets::Event::Burned { asset_id, owner, balance } + ) => { + asset_id: *asset_id == reservable_asset_location, + owner: *owner == t.sender.account_id, + balance: *balance == t.args.amount, + }, + // Transport fees are paid + RuntimeEvent::PolkadotXcm( + pallet_xcm::Event::FeesPaid { .. } + ) => {}, + ] + ); +} + fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; let system_para_asset_location = PenpalLocalReservableFromAssetHubV3::get(); @@ -230,6 +264,39 @@ fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { ); } +fn para_to_system_para_assets_receiver_assertions(t: ParaToSystemParaTest) { + type RuntimeEvent = ::RuntimeEvent; + let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of( + AssetHubWestend::sibling_location_of(PenpalA::para_id()), + ); + AssetHubWestend::assert_xcmp_queue_success(None); + assert_expected_events!( + AssetHubWestend, + vec![ + // Amount to reserve transfer is burned from Parachain's Sovereign account + RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { + asset_id: *asset_id == RESERVABLE_ASSET_ID, + owner: *owner == sov_penpal_on_ahr, + balance: *balance == t.args.amount, + }, + // Fee amount is burned from Parachain's Sovereign account + RuntimeEvent::Balances(pallet_balances::Event::Burned { who, .. }) => { + who: *who == sov_penpal_on_ahr, + }, + // Amount to reserve transfer is issued for beneficiary + RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + asset_id: *asset_id == RESERVABLE_ASSET_ID, + owner: *owner == t.receiver.account_id, + amount: *amount == t.args.amount, + }, + // Remaining fee amount is minted for for beneficiary + RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { + who: *who == t.receiver.account_id, + }, + ] + ); +} + fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -443,6 +510,9 @@ fn reserve_transfer_native_asset_from_system_para_to_relay_fails() { }); } +// ========================================================================= +// ========= Reserve Transfers - Native Asset - Relay<>Parachain =========== +// ========================================================================= /// Reserve Transfers of native asset from Relay to Parachain should work #[test] fn reserve_transfer_native_asset_from_relay_to_para() { @@ -575,6 +645,9 @@ fn reserve_transfer_native_asset_from_para_to_relay() { assert!(receiver_balance_after < receiver_balance_before + amount_to_send); } +// ========================================================================= +// ======= Reserve Transfers - Native Asset - AssetHub<>Parachain ========== +// ========================================================================= /// Reserve Transfers of native asset from System Parachain to Parachain should work #[test] fn reserve_transfer_native_asset_from_system_para_to_para() { @@ -605,7 +678,6 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { // Set assertions and dispatchables test.set_assertion::(system_para_to_para_sender_assertions); - // test.set_assertion::(system_para_to_para_native_assets_receiver_assertions); test.set_assertion::(system_para_to_para_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); @@ -708,6 +780,9 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { assert!(receiver_balance_after < receiver_balance_before + amount_to_send); } +// ========================================================================= +// ======= Reserve Transfers - Non-system Asset - AssetHub<>Parachain ====== +// ========================================================================= /// Reserve Transfers of a local asset and native asset from System Parachain to Parachain should /// work #[test] @@ -811,6 +886,133 @@ fn reserve_transfer_assets_from_system_para_to_para() { assert_eq!(receiver_foreign_assets_after, receiver_foreign_assets_before + asset_amount_to_send); } +/// Reserve Transfers of a foreign asset and native asset from Parachain to System Para should +/// work +#[test] +fn reserve_transfer_assets_from_para_to_system_para() { + // Init values for Parachain + let destination = PenpalA::sibling_location_of(AssetHubWestend::para_id()); + let sender = PenpalASender::get(); + let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 100; + let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; + let penpal_asset_owner = PenpalAssetOwner::get(); + let penpal_asset_owner_signer = ::RuntimeOrigin::signed(penpal_asset_owner); + let asset_location_on_penpal = PenpalLocalReservableFromAssetHubV3::get(); + let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); + let system_asset_location_on_penpal = RelayLocationV3::get(); + let assets: Assets = vec![ + (Parent, fee_amount_to_send).into(), + (asset_location_on_penpal_latest, asset_amount_to_send) + .into(), + ] + .into(); + let fee_asset_index = assets + .inner() + .iter() + .position(|r| r == &(Parent, fee_amount_to_send).into()) + .unwrap() as u32; + // Fund Parachain's sender account with some foreign assets + PenpalA::mint_foreign_asset( + penpal_asset_owner_signer.clone(), + asset_location_on_penpal, + sender.clone(), + asset_amount_to_send * 2, + ); + // Fund Parachain's sender account with some system assets + PenpalA::mint_foreign_asset( + penpal_asset_owner_signer, + system_asset_location_on_penpal, + sender.clone(), + fee_amount_to_send * 2, + ); + + // Init values for System Parachain + let receiver = AssetHubWestendReceiver::get(); + let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id()); + let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); + let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let ah_asset_owner = AssetHubWestendAssetOwner::get(); + let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); + + // Fund SA-of-Penpal-on-AHR to be able to pay for the fees. + AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ahr.clone().into(), ASSET_HUB_WESTEND_ED * 1000)]); + // Fund SA-of-Penpal-on-AHR to be able to pay for the sent amount. + AssetHubWestend::mint_asset( + ah_asset_owner_signer, + RESERVABLE_ASSET_ID, + sov_penpal_on_ahr, + asset_amount_to_send * 2, + ); + + // Init Test + let para_test_args = TestContext { + sender: sender.clone(), + receiver: receiver.clone(), + args: TestArgs::new_para( + destination, + receiver.clone(), + asset_amount_to_send, + assets, + None, + fee_asset_index, + ), + }; + let mut test = ParaToSystemParaTest::new(para_test_args); + + // Query initial balances + let sender_system_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &sender) + }); + let sender_foreign_assets_before = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_foreign_asset_location.clone(), &sender) + }); + let receiver_balance_before = test.receiver.balance; + let receiver_assets_before = AssetHubWestend::execute_with(|| { + type Assets = ::Assets; + >::balance(RESERVABLE_ASSET_ID, &receiver) + }); + + // Set assertions and dispatchables + test.set_assertion::(para_to_system_para_assets_sender_assertions); + test.set_assertion::(para_to_system_para_assets_receiver_assertions); + test.set_dispatchable::(para_to_system_para_reserve_transfer_assets); + test.assert(); + + // Query final balances + let sender_system_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_native_asset_location.clone(), &sender) + }); + let sender_foreign_assets_after = PenpalA::execute_with(|| { + type ForeignAssets = ::ForeignAssets; + >::balance(system_para_foreign_asset_location.clone(), &sender) + }); + let receiver_balance_after = test.receiver.balance; + let receiver_assets_after = AssetHubWestend::execute_with(|| { + type Assets = ::Assets; + >::balance(RESERVABLE_ASSET_ID, &receiver) + }); + // Sender's system asset balance is reduced + assert!(sender_system_assets_after < sender_system_assets_before); + // Receiver's balance is increased + assert!(receiver_balance_after > receiver_balance_before); + // Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`; + // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but + // should be non-zero + assert!(receiver_balance_after < receiver_balance_before + fee_amount_to_send); + + // Sender's asset balance is reduced by exact amount + assert_eq!(sender_foreign_assets_before - asset_amount_to_send, sender_foreign_assets_after); + // Receiver's foreign asset balance is increased by exact amount + assert_eq!(receiver_assets_after, receiver_assets_before + asset_amount_to_send); +} + +// ========================================================================= +// ===== Reserve Transfers - Native Asset - Parachain<>Relay<>Parachain ==== +// ========================================================================= /// Reserve Transfers of native asset from Parachain to Parachain (through Relay reserve) should /// work #[test] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index 65b9d6a12d5b8..f172b8d2be93a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -21,7 +21,7 @@ use asset_hub_rococo_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignCreatorsSovereignAccountOf, + ForeignCreatorsSovereignAccountOf, StakingPot, LocationToAccountId, TokenLocation, TokenLocationV3, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, XcmConfig, }, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index 19960753b64c1..0fec28ecbfdf9 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -21,7 +21,7 @@ use asset_hub_westend_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignCreatorsSovereignAccountOf, + ForeignCreatorsSovereignAccountOf, StakingPot, LocationToAccountId, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, WestendLocation, WestendLocationV3, XcmConfig, }, From 991fc0e5f1ec48d4bce3e37e0810862bb95b16e6 Mon Sep 17 00:00:00 2001 From: NachoPal Date: Fri, 1 Mar 2024 13:43:28 +0100 Subject: [PATCH 06/18] cleanup --- Cargo.lock | 1 - .../emulated/chains/parachains/testing/penpal/Cargo.toml | 3 --- .../chains/parachains/testing/penpal/src/genesis.rs | 2 +- .../tests/assets/asset-hub-rococo/src/tests/swap.rs | 1 - .../tests/assets/asset-hub-rococo/src/tests/teleport.rs | 6 ------ .../tests/assets/asset-hub-westend/src/tests/swap.rs | 1 - .../tests/assets/asset-hub-westend/src/tests/teleport.rs | 6 ------ 7 files changed, 1 insertion(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09c1685528037..361d88ef1be12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11678,7 +11678,6 @@ dependencies = [ "parachains-common", "penpal-runtime", "sp-core", - "staging-xcm", ] [[package]] diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml index f47350b00eb18..ba6996107c98f 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml @@ -16,9 +16,6 @@ workspace = true sp-core = { path = "../../../../../../../../substrate/primitives/core", default-features = false } frame-support = { path = "../../../../../../../../substrate/frame/support", default-features = false } -# Polkadot -xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false } - # Cumulus parachains-common = { path = "../../../../../../../parachains/common" } cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index 93bf50683db3f..44196cc4b8ef9 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// SubstratePenpal +// Substrate use sp_core::{sr25519, storage::Storage}; use frame_support::parameter_types; // Cumulus diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs index 0bde356f20b6c..8eeac93072943 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs @@ -140,7 +140,6 @@ fn swap_locally_on_chain_using_foreign_assets() { ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone().into()), foreign_asset_at_asset_hub_rococo, sov_penpal_on_ahr.clone().into(), - // 3_000_000_000_000, ASSET_HUB_ROCOCO_ED * 3_000_000_000_000, )); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 4c466e5750e2f..619c6abdf068b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -164,9 +164,6 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { amount: *amount == expected_foreign_asset_amount, }, RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, - // RuntimeEvent::MessageQueue( - // pallet_message_queue::Event::Processed { success: true, .. } - // ) => {}, ] ); } @@ -585,7 +582,6 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let fee_asset_index = penpal_assets .inner() .iter() - // .position(|r| r == &((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into()) .position(|r| r == &(Parent, fee_amount_to_send).into()) .unwrap() as u32; @@ -633,8 +629,6 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { ), }; let mut penpal_to_ah = ParaToSystemParaTest::new(penpal_to_ah_test_args); - - // let penpal_sender_balance_before = penpal_to_ah.sender.balance; let penpal_sender_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance(system_para_native_asset_location, &PenpalASender::get()) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index 03ee89d4442d9..db93b47531e8c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -139,7 +139,6 @@ fn swap_locally_on_chain_using_foreign_assets() { ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone().into()), foreign_asset_at_asset_hub_westend, sov_penpal_on_ahr.clone().into(), - // 3_000_000_000_000, ASSET_HUB_WESTEND_ED * 3_000_000_000_000, )); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 95a9dc50063d8..a03244d63e2a0 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -164,9 +164,6 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { amount: *amount == expected_foreign_asset_amount, }, RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {}, - // RuntimeEvent::MessageQueue( - // pallet_message_queue::Event::Processed { success: true, .. } - // ) => {}, ] ); } @@ -585,7 +582,6 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let fee_asset_index = penpal_assets .inner() .iter() - // .position(|r| r == &((Parent, Parachain(ASSETHUB_PARA_ID)), fee_amount_to_send).into()) .position(|r| r == &(Parent, fee_amount_to_send).into()) .unwrap() as u32; @@ -633,8 +629,6 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { ), }; let mut penpal_to_ah = ParaToSystemParaTest::new(penpal_to_ah_test_args); - - // let penpal_sender_balance_before = penpal_to_ah.sender.balance; let penpal_sender_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance(system_para_native_asset_location, &PenpalASender::get()) From 62b9e88b13a4bec9ee125b2e84ac39a4ff5555ef Mon Sep 17 00:00:00 2001 From: NachoPal Date: Fri, 1 Mar 2024 13:44:24 +0100 Subject: [PATCH 07/18] fmt --- .../assets/asset-hub-rococo/src/genesis.rs | 25 ++-- .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../assets/asset-hub-westend/src/genesis.rs | 25 ++-- .../assets/asset-hub-westend/src/lib.rs | 2 +- .../parachains/testing/penpal/src/genesis.rs | 31 ++--- .../parachains/testing/penpal/src/lib.rs | 6 +- .../emulated/common/src/lib.rs | 6 +- .../emulated/common/src/macros.rs | 17 ++- .../tests/assets/asset-hub-rococo/src/lib.rs | 26 ++-- .../src/tests/reserve_transfer.rs | 107 ++++++++++++----- .../asset-hub-rococo/src/tests/teleport.rs | 44 ++++--- .../tests/assets/asset-hub-westend/src/lib.rs | 40 ++++--- .../src/tests/reserve_transfer.rs | 113 ++++++++++++------ .../asset-hub-westend/src/tests/teleport.rs | 44 ++++--- .../bridges/bridge-hub-rococo/src/lib.rs | 15 +-- .../bridges/bridge-hub-westend/src/lib.rs | 10 +- .../tests/people/people-rococo/src/lib.rs | 16 ++- .../tests/people/people-westend/src/lib.rs | 12 +- .../assets/asset-hub-rococo/src/xcm_config.rs | 10 +- .../assets/asset-hub-rococo/tests/tests.rs | 21 ++-- .../asset-hub-westend/src/xcm_config.rs | 9 +- .../assets/asset-hub-westend/tests/tests.rs | 21 ++-- .../runtimes/assets/common/src/lib.rs | 25 ++-- .../runtimes/testing/penpal/src/xcm_config.rs | 51 ++++---- 24 files changed, 411 insertions(+), 267 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs index 9b0ee2bf8bd80..2acccb9649b89 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs @@ -14,14 +14,14 @@ // limitations under the License. // Substrate -use sp_core::{sr25519, storage::Storage}; use frame_support::parameter_types; +use sp_core::{sr25519, storage::Storage}; // Cumulus use emulated_integration_tests_common::{ - accounts, build_genesis_storage, collators, SAFE_XCM_VERSION, - RESERVABLE_ASSET_ID, PenpalSiblingSovereigAccount, PenpalTeleportableAssetLocation, - get_account_id_from_seed + accounts, build_genesis_storage, collators, get_account_id_from_seed, + PenpalSiblingSovereigAccount, PenpalTeleportableAssetLocation, RESERVABLE_ASSET_ID, + SAFE_XCM_VERSION, }; use parachains_common::{AccountId, Balance}; @@ -68,16 +68,19 @@ pub fn genesis() -> Storage { ..Default::default() }, assets: asset_hub_rococo_runtime::AssetsConfig { - assets: vec![ - (RESERVABLE_ASSET_ID, AssetHubRococoAssetOwner::get(), true, ED), - ], - .. Default::default() + assets: vec![(RESERVABLE_ASSET_ID, AssetHubRococoAssetOwner::get(), true, ED)], + ..Default::default() }, foreign_assets: asset_hub_rococo_runtime::ForeignAssetsConfig { assets: vec![ - // Penpal's teleportable asset representation - (PenpalTeleportableAssetLocation::get(), PenpalSiblingSovereigAccount::get(), true, ED), - ], + // Penpal's teleportable asset representation + ( + PenpalTeleportableAssetLocation::get(), + PenpalSiblingSovereigAccount::get(), + true, + ED, + ), + ], ..Default::default() }, ..Default::default() diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs index 01d156f00bbad..f1e972e869dc9 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs @@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_system_parachain, impl_assets_helpers_for_parachain, + impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain, impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; use rococo_emulated_chain::Rococo; diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs index 743e1eedc3f97..e30529aff42ca 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs @@ -14,14 +14,14 @@ // limitations under the License. // Substrate -use sp_core::{sr25519, storage::Storage}; use frame_support::parameter_types; +use sp_core::{sr25519, storage::Storage}; // Cumulus use emulated_integration_tests_common::{ - accounts, build_genesis_storage, collators, SAFE_XCM_VERSION, - RESERVABLE_ASSET_ID, PenpalSiblingSovereigAccount, PenpalTeleportableAssetLocation, - get_account_id_from_seed + accounts, build_genesis_storage, collators, get_account_id_from_seed, + PenpalSiblingSovereigAccount, PenpalTeleportableAssetLocation, RESERVABLE_ASSET_ID, + SAFE_XCM_VERSION, }; use parachains_common::{AccountId, Balance}; @@ -64,16 +64,19 @@ pub fn genesis() -> Storage { ..Default::default() }, assets: asset_hub_westend_runtime::AssetsConfig { - assets: vec![ - (RESERVABLE_ASSET_ID, AssetHubWestendAssetOwner::get(), true, ED), - ], - .. Default::default() + assets: vec![(RESERVABLE_ASSET_ID, AssetHubWestendAssetOwner::get(), true, ED)], + ..Default::default() }, foreign_assets: asset_hub_westend_runtime::ForeignAssetsConfig { assets: vec![ - // Penpal's teleportable asset representation - (PenpalTeleportableAssetLocation::get(), PenpalSiblingSovereigAccount::get(), true, ED), - ], + // Penpal's teleportable asset representation + ( + PenpalTeleportableAssetLocation::get(), + PenpalSiblingSovereigAccount::get(), + true, + ED, + ), + ], ..Default::default() }, ..Default::default() diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs index 5e140b6ae961e..7f05eefb4c208 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs @@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_system_parachain, impl_assets_helpers_for_parachain, + impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain, impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; use westend_emulated_chain::Westend; diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index 44196cc4b8ef9..1d4a92a6a9d04 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -14,14 +14,14 @@ // limitations under the License. // Substrate -use sp_core::{sr25519, storage::Storage}; use frame_support::parameter_types; +use sp_core::{sr25519, storage::Storage}; // Cumulus use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION, }; -use parachains_common::{Balance, AccountId}; -use penpal_runtime::xcm_config::{RelayLocationV3, LocalReservableFromAssetHubV3}; +use parachains_common::{AccountId, Balance}; +use penpal_runtime::xcm_config::{LocalReservableFromAssetHubV3, RelayLocationV3}; // Penpal pub const PARA_ID_A: u32 = 2000; pub const PARA_ID_B: u32 = 2001; @@ -63,22 +63,23 @@ pub fn genesis(para_id: u32) -> Storage { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, - sudo: penpal_runtime::SudoConfig { - key: Some(PenpalSudoAcccount::get()), - }, + sudo: penpal_runtime::SudoConfig { key: Some(PenpalSudoAcccount::get()) }, assets: penpal_runtime::AssetsConfig { - assets: vec![ - (penpal_runtime::xcm_config::TELEPORTABLE_ASSET_ID, PenpalAssetOwner::get(), false, ED), - ], - .. Default::default() + assets: vec![( + penpal_runtime::xcm_config::TELEPORTABLE_ASSET_ID, + PenpalAssetOwner::get(), + false, + ED, + )], + ..Default::default() }, foreign_assets: penpal_runtime::ForeignAssetsConfig { assets: vec![ - // Relay Native asset representation - (RelayLocationV3::get(), PenpalAssetOwner::get(), true, ED), - // Sufficient AssetHub asset representation - (LocalReservableFromAssetHubV3::get(), PenpalAssetOwner::get(), true, ED), - ], + // Relay Native asset representation + (RelayLocationV3::get(), PenpalAssetOwner::get(), true, ED), + // Sufficient AssetHub asset representation + (LocalReservableFromAssetHubV3::get(), PenpalAssetOwner::get(), true, ED), + ], ..Default::default() }, ..Default::default() diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs index 192c68fa16746..dad2c4ac0cb54 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs @@ -14,15 +14,15 @@ // limitations under the License. mod genesis; -pub use genesis::{genesis, ED, PARA_ID_A, PARA_ID_B, PenpalSudoAcccount, PenpalAssetOwner}; +pub use genesis::{genesis, PenpalAssetOwner, PenpalSudoAcccount, ED, PARA_ID_A, PARA_ID_B}; // Substrate use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ - impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_assets_helpers_for_parachain, - impls::Parachain, xcm_emulator::decl_test_parachains, + impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, + impl_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; // Penpal Parachain declaration diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 023d8ac078fed..40204ca297a0a 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -21,20 +21,20 @@ pub use xcm_emulator; // Substrate use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; +use frame_support::parameter_types; use grandpa::AuthorityId as GrandpaId; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_core::{sr25519, storage::Storage, Pair, Public}; use sp_runtime::{ - traits::{IdentifyAccount, Verify, AccountIdConversion}, + traits::{AccountIdConversion, IdentifyAccount, Verify}, BuildStorage, MultiSignature, }; -use frame_support::parameter_types; // Polakdot use parachains_common::BlockNumber; -use polkadot_runtime_parachains::configuration::HostConfiguration; use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_parachains::configuration::HostConfiguration; // Cumulus use parachains_common::{AccountId, AuraId}; diff --git a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs index edd9d318b1328..6951de6faa728 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs @@ -16,28 +16,27 @@ pub use paste; // Substrate +pub use frame_support::{pallet_prelude::Weight, weights::WeightToFee}; +pub use pallet_assets; pub use pallet_balances; pub use pallet_message_queue; pub use pallet_xcm; -pub use pallet_assets; -pub use frame_support::{pallet_prelude::Weight, weights::WeightToFee}; // Polkadot pub use xcm::{ - v3::Location as V3Location, - prelude::{ - OriginKind, AccountId32, WeightLimit, Asset, AssetId, Fungible, - Location, Here, VersionedXcm, Xcm, Unlimited, WithdrawAsset, BuyExecution, - Transact, ExpectTransactStatus, MaybeErrorCode, RefundSurplus, DepositAsset, - All + prelude::{ + AccountId32, All, Asset, AssetId, BuyExecution, DepositAsset, ExpectTransactStatus, + Fungible, Here, Location, MaybeErrorCode, OriginKind, RefundSurplus, Transact, Unlimited, + VersionedXcm, WeightLimit, WithdrawAsset, Xcm, }, + v3::Location as V3Location, }; // Cumulus pub use asset_test_utils; pub use cumulus_pallet_xcmp_queue; -pub use xcm_emulator::Chain; pub use parachains_common::AccountId; +pub use xcm_emulator::Chain; #[macro_export] macro_rules! test_parachain_is_trusted_teleporter { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs index 5e20d38dccb70..d307cc5faf02d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs @@ -36,18 +36,22 @@ mod imports { pub use emulated_integration_tests_common::{ test_parachain_is_trusted_teleporter, xcm_emulator::{ - assert_expected_events, bx, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, + assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, Test, + TestArgs, TestContext, TestExt, }, - xcm_helpers::{xcm_transact_paid_execution, non_fee_asset}, - XCM_V3, RESERVABLE_ASSET_ID, ASSETS_PALLET_ID + xcm_helpers::{non_fee_asset, xcm_transact_paid_execution}, + ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, XCM_V3, }; pub use parachains_common::Balance; pub use rococo_system_emulated_network::{ asset_hub_rococo_emulated_chain::{ - genesis::{ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoAssetOwner}, AssetHubRococoParaPallet as AssetHubRococoPallet, + genesis::{AssetHubRococoAssetOwner, ED as ASSET_HUB_ROCOCO_ED}, + AssetHubRococoParaPallet as AssetHubRococoPallet, + }, + penpal_emulated_chain::{ + PenpalAParaPallet as PenpalAPallet, PenpalAssetOwner, + PenpalBParaPallet as PenpalBPallet, ED as PENPAL_ED, }, - penpal_emulated_chain::{ED as PENPAL_ED, PenpalAParaPallet as PenpalAPallet, PenpalBParaPallet as PenpalBPallet, PenpalAssetOwner}, rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, AssetHubRococoParaSender as AssetHubRococoSender, BridgeHubRococoPara as BridgeHubRococo, @@ -58,15 +62,17 @@ mod imports { }; // Runtimes - pub use rococo_runtime::xcm_config::{XcmConfig as RococoXcmConfig, UniversalLocation as RococoUniversalLocation}; pub use asset_hub_rococo_runtime::xcm_config::{ - XcmConfig as AssetHubRococoXcmConfig, UniversalLocation as AssetHubRococoUniversalLocation, - TokenLocationV3 as RelayLocationV3, + TokenLocationV3 as RelayLocationV3, UniversalLocation as AssetHubRococoUniversalLocation, + XcmConfig as AssetHubRococoXcmConfig, }; pub use penpal_runtime::xcm_config::{ + LocalReservableFromAssetHubV3 as PenpalLocalReservableFromAssetHubV3, LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3, UniversalLocation as PenpalUniversalLocation, XcmConfig as PenpalRococoXcmConfig, - LocalReservableFromAssetHubV3 as PenpalLocalReservableFromAssetHubV3, + }; + pub use rococo_runtime::xcm_config::{ + UniversalLocation as RococoUniversalLocation, XcmConfig as RococoXcmConfig, }; pub const ASSET_ID: u32 = 3; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 67d45442b8f76..7f3f7f22c91f5 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -122,9 +122,8 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { fn para_to_relay_receiver_assertions(t: ParaToRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let sov_penpal_on_relay = Rococo::sovereign_account_id_of( - Rococo::child_location_of(PenpalA::para_id()), - ); + let sov_penpal_on_relay = + Rococo::sovereign_account_id_of(Rococo::child_location_of(PenpalA::para_id())); Rococo::assert_ump_queue_processed( true, @@ -214,10 +213,7 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; let system_para_native_asset_location = RelayLocationV3::get(); let reservable_asset_location = PenpalLocalReservableFromAssetHubV3::get(); - PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( - 864_610_000, - 8799, - ))); + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); assert_expected_events!( PenpalA, vec![ @@ -429,7 +425,9 @@ fn para_to_system_para_reserve_transfer_assets(t: ParaToSystemParaTest) -> Dispa ) } -fn para_to_para_through_relay_limited_reserve_transfer_assets(t: ParaToParaThroughRelayTest) -> DispatchResult { +fn para_to_para_through_relay_limited_reserve_transfer_assets( + t: ParaToParaThroughRelayTest, +) -> DispatchResult { ::PolkadotXcm::limited_reserve_transfer_assets( t.signed_origin, bx!(t.args.dest.into()), @@ -549,7 +547,8 @@ fn reserve_transfer_native_asset_from_relay_to_para() { // Calculate delivery fees let delivery_fees = Rococo::execute_with(|| { - let reanchored_assets = assets.reanchored( &destination, &RococoUniversalLocation::get()).unwrap(); + let reanchored_assets = + assets.reanchored(&destination, &RococoUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) @@ -588,7 +587,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { ::RuntimeOrigin::signed(asset_owner), relay_native_asset_location, sender.clone(), - amount_to_send + amount_to_send, ); // Init values for Relay @@ -603,7 +602,14 @@ fn reserve_transfer_native_asset_from_para_to_relay() { let test_args = TestContext { sender: sender.clone(), receiver: receiver.clone(), - args: TestArgs::new_para(destination.clone(), receiver, amount_to_send, assets.clone(), None, 0), + args: TestArgs::new_para( + destination.clone(), + receiver, + amount_to_send, + assets.clone(), + None, + 0, + ), }; let mut test = ParaToRelayTest::new(test_args); @@ -622,7 +628,8 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Calculate delivery fees let delivery_fees = PenpalA::execute_with(|| { - let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); + let reanchored_assets = + assets.reanchored(&destination, &PenpalUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) @@ -665,7 +672,14 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let test_args = TestContext { sender, receiver: receiver.clone(), - args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), + args: TestArgs::new_para( + destination.clone(), + receiver.clone(), + amount_to_send, + assets.clone(), + None, + 0, + ), }; let mut test = SystemParaToParaTest::new(test_args); @@ -676,15 +690,17 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { >::balance(system_para_native_asset_location.into(), &receiver) }); - // Set assertions and dispatchables + // Set assertions and dispatchables test.set_assertion::(system_para_to_para_sender_assertions); test.set_assertion::(system_para_to_para_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); - // Calculate delivery fees + // Calculate delivery fees let delivery_fees = AssetHubRococo::execute_with(|| { - let reanchored_assets = assets.reanchored( &destination, &AssetHubRococoUniversalLocation::get()).unwrap(); + let reanchored_assets = assets + .reanchored(&destination, &AssetHubRococoUniversalLocation::get()) + .unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) @@ -723,10 +739,10 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { ::RuntimeOrigin::signed(asset_owner), system_para_native_asset_location, sender.clone(), - amount_to_send + amount_to_send, ); - // Init values for System Parachain + // Init values for System Parachain let receiver = AssetHubRococoReceiver::get(); let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr); @@ -738,7 +754,14 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let test_args = TestContext { sender: sender.clone(), receiver: receiver.clone(), - args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), + args: TestArgs::new_para( + destination.clone(), + receiver.clone(), + amount_to_send, + assets.clone(), + None, + 0, + ), }; let mut test = ParaToSystemParaTest::new(test_args); @@ -755,9 +778,10 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { test.set_dispatchable::(para_to_system_para_reserve_transfer_assets); test.assert(); - // Calculate delivery fees + // Calculate delivery fees let delivery_fees = PenpalA::execute_with(|| { - let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); + let reanchored_assets = + assets.reanchored(&destination, &PenpalUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) @@ -797,7 +821,10 @@ fn reserve_transfer_assets_from_system_para_to_para() { let asset_owner_signer = ::RuntimeOrigin::signed(asset_owner.clone()); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), - ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())], asset_amount_to_send) + ( + [PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())], + asset_amount_to_send, + ) .into(), ] .into(); @@ -848,7 +875,10 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &receiver) + >::balance( + system_para_foreign_asset_location.clone(), + &receiver, + ) }); // Set assertions and dispatchables @@ -869,21 +899,30 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &receiver) + >::balance( + system_para_foreign_asset_location.clone(), + &receiver, + ) }); // Sender's balance is reduced assert!(sender_balance_after < sender_balance_before); // Receiver's foreign asset balance is increased assert!(receiver_foreign_assets_after > receiver_foreign_assets_before); - // Receiver's system asset balance increased by `amount_to_send - delivery_fees - bought_execution`; - // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but - // should be non-zero - assert!(receiver_system_native_assets_after < receiver_system_native_assets_before + fee_amount_to_send); + // Receiver's system asset balance increased by `amount_to_send - delivery_fees - + // bought_execution`; `delivery_fees` might be paid from transfer or JIT, also + // `bought_execution` is unknown but should be non-zero + assert!( + receiver_system_native_assets_after < + receiver_system_native_assets_before + fee_amount_to_send + ); // Sender's asset balance is reduced by exact amount assert_eq!(sender_assets_before - asset_amount_to_send, sender_assets_after); // Receiver's foreign asset balance is increased by exact amount - assert_eq!(receiver_foreign_assets_after, receiver_foreign_assets_before + asset_amount_to_send); + assert_eq!( + receiver_foreign_assets_after, + receiver_foreign_assets_before + asset_amount_to_send + ); } /// Reserve Transfers of a foreign asset and native asset from Parachain to System Para should @@ -902,8 +941,7 @@ fn reserve_transfer_assets_from_para_to_system_para() { let system_asset_location_on_penpal = RelayLocationV3::get(); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), - (asset_location_on_penpal_latest, asset_amount_to_send) - .into(), + (asset_location_on_penpal_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = assets @@ -936,7 +974,10 @@ fn reserve_transfer_assets_from_para_to_system_para() { let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); // Fund SA-of-Penpal-on-AHR to be able to pay for the fees. - AssetHubRococo::fund_accounts(vec![(sov_penpal_on_ahr.clone().into(), ASSET_HUB_ROCOCO_ED * 10000000)]); + AssetHubRococo::fund_accounts(vec![( + sov_penpal_on_ahr.clone().into(), + ASSET_HUB_ROCOCO_ED * 10000000, + )]); // Fund SA-of-Penpal-on-AHR to be able to pay for the sent amount. AssetHubRococo::mint_asset( ah_asset_owner_signer, @@ -1032,7 +1073,7 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { ::RuntimeOrigin::signed(asset_owner), relay_native_asset_location, sender.clone(), - amount_to_send + amount_to_send, ); // fund the Parachain Origin's SA on Relay Chain with the native tokens held in reserve diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 619c6abdf068b..e8fe394647016 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -570,8 +570,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let asset_owner = PenpalAssetOwner::get(); let system_para_native_asset_location = RelayLocationV3::get(); let sender = PenpalASender::get(); - let penpal_check_account = - ::PolkadotXcm::check_account(); + let penpal_check_account = ::PolkadotXcm::check_account(); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id()); let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); let penpal_assets: Assets = vec![ @@ -590,29 +589,32 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { ::RuntimeOrigin::signed(asset_owner.clone()), system_para_native_asset_location, sender.clone(), - fee_amount_to_send + fee_amount_to_send, ); PenpalA::mint_asset( ::RuntimeOrigin::signed(asset_owner.clone()), asset_id_on_penpal, sender.clone(), - asset_amount_to_send + asset_amount_to_send, ); // fund Parachain's check account to be able to teleport - PenpalA::fund_accounts(vec![((penpal_check_account.clone().into(), ASSET_HUB_ROCOCO_ED * 1000))]); + PenpalA::fund_accounts(vec![ + ((penpal_check_account.clone().into(), ASSET_HUB_ROCOCO_ED * 1000)), + ]); // prefund SA of Penpal on AssetHub with enough native tokens to pay for fees let penpal_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ah = AssetHubRococo::sovereign_account_id_of(penpal_as_seen_by_ah); - AssetHubRococo::fund_accounts(vec![ - (sov_penpal_on_ah.clone().into(), ASSET_HUB_ROCOCO_ED * 100_000_000_000), - ]); + AssetHubRococo::fund_accounts(vec![( + sov_penpal_on_ah.clone().into(), + ASSET_HUB_ROCOCO_ED * 100_000_000_000, + )]); // Init values for System Parachain let foreign_asset_at_asset_hub_rococo = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) - .appended_with(asset_location_on_penpal) - .unwrap(); + v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + .appended_with(asset_location_on_penpal) + .unwrap(); let penpal_to_ah_beneficiary_id = AssetHubRococoReceiver::get(); // Penpal to AH test args @@ -631,7 +633,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let mut penpal_to_ah = ParaToSystemParaTest::new(penpal_to_ah_test_args); let penpal_sender_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &PenpalASender::get()) + >::balance( + system_para_native_asset_location, + &PenpalASender::get(), + ) }); let ah_receiver_balance_before = penpal_to_ah.receiver.balance; @@ -655,7 +660,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let penpal_sender_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &PenpalASender::get()) + >::balance( + system_para_native_asset_location, + &PenpalASender::get(), + ) }); let ah_receiver_balance_after = penpal_to_ah.receiver.balance; @@ -734,7 +742,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let ah_sender_balance_before = ah_to_penpal.sender.balance; let penpal_receiver_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &PenpalAReceiver::get()) + >::balance( + system_para_native_asset_location, + &PenpalAReceiver::get(), + ) }); let ah_sender_assets_before = AssetHubRococo::execute_with(|| { @@ -757,7 +768,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let ah_sender_balance_after = ah_to_penpal.sender.balance; let penpal_receiver_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &PenpalAReceiver::get()) + >::balance( + system_para_native_asset_location, + &PenpalAReceiver::get(), + ) }); let ah_sender_assets_after = AssetHubRococo::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs index be7cd9974ef0c..5d53edc1a86b4 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs @@ -36,41 +36,47 @@ mod imports { pub use emulated_integration_tests_common::{ test_parachain_is_trusted_teleporter, xcm_emulator::{ - assert_expected_events, bx, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, + assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, Test, + TestArgs, TestContext, TestExt, }, - xcm_helpers::{xcm_transact_paid_execution, non_fee_asset}, - XCM_V3, RESERVABLE_ASSET_ID, ASSETS_PALLET_ID + xcm_helpers::{non_fee_asset, xcm_transact_paid_execution}, + ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, XCM_V3, }; - pub use parachains_common::{Balance, AccountId}; + pub use parachains_common::{AccountId, Balance}; pub use westend_system_emulated_network::{ asset_hub_westend_emulated_chain::{ - genesis::{ED as ASSET_HUB_WESTEND_ED, AssetHubWestendAssetOwner}, AssetHubWestendParaPallet as AssetHubWestendPallet, + genesis::{AssetHubWestendAssetOwner, ED as ASSET_HUB_WESTEND_ED}, + AssetHubWestendParaPallet as AssetHubWestendPallet, }, - collectives_westend_emulated_chain::{ - CollectivesWestendParaPallet as CollectivesWestendPallet, + collectives_westend_emulated_chain::CollectivesWestendParaPallet as CollectivesWestendPallet, + penpal_emulated_chain::{ + PenpalAParaPallet as PenpalAPallet, PenpalAssetOwner, + PenpalBParaPallet as PenpalBPallet, }, - penpal_emulated_chain::{PenpalAParaPallet as PenpalAPallet, PenpalBParaPallet as PenpalBPallet, PenpalAssetOwner}, westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet}, - AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver, - AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubWestendPara as BridgeHubWestend, - BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, PenpalAPara as PenpalA, - CollectivesWestendPara as CollectivesWestend, + AssetHubWestendPara as AssetHubWestend, + AssetHubWestendParaReceiver as AssetHubWestendReceiver, + AssetHubWestendParaSender as AssetHubWestendSender, + BridgeHubWestendPara as BridgeHubWestend, + BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, + CollectivesWestendPara as CollectivesWestend, PenpalAPara as PenpalA, PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender, PenpalBPara as PenpalB, PenpalBParaReceiver as PenpalBReceiver, WestendRelay as Westend, WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender, }; // Runtimes - pub use westend_runtime::xcm_config::{XcmConfig as WestendXcmConfig, UniversalLocation as WestendUniversalLocation}; pub use asset_hub_westend_runtime::xcm_config::{ - XcmConfig as AssetHubWestendXcmConfig, UniversalLocation as AssetHubWestendUniversalLocation, - WestendLocationV3 as RelayLocationV3, + UniversalLocation as AssetHubWestendUniversalLocation, + WestendLocationV3 as RelayLocationV3, XcmConfig as AssetHubWestendXcmConfig, }; pub use penpal_runtime::xcm_config::{ + LocalReservableFromAssetHubV3 as PenpalLocalReservableFromAssetHubV3, LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3, UniversalLocation as PenpalUniversalLocation, XcmConfig as PenpalWestendXcmConfig, - LocalReservableFromAssetHubV3 as PenpalLocalReservableFromAssetHubV3, + }; + pub use westend_runtime::xcm_config::{ + UniversalLocation as WestendUniversalLocation, XcmConfig as WestendXcmConfig, }; pub const ASSET_ID: u32 = 3; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 6dac5a07260d6..bc7969d7e376e 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -122,9 +122,8 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { fn para_to_relay_receiver_assertions(t: ParaToRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let sov_penpal_on_relay = Westend::sovereign_account_id_of( - Westend::child_location_of(PenpalA::para_id()), - ); + let sov_penpal_on_relay = + Westend::sovereign_account_id_of(Westend::child_location_of(PenpalA::para_id())); Westend::assert_ump_queue_processed( true, @@ -214,10 +213,7 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; let system_para_native_asset_location = RelayLocationV3::get(); let reservable_asset_location = PenpalLocalReservableFromAssetHubV3::get(); - PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( - 864_610_000, - 8799, - ))); + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); assert_expected_events!( PenpalA, vec![ @@ -429,7 +425,9 @@ fn para_to_system_para_reserve_transfer_assets(t: ParaToSystemParaTest) -> Dispa ) } -fn para_to_para_through_relay_limited_reserve_transfer_assets(t: ParaToParaThroughRelayTest) -> DispatchResult { +fn para_to_para_through_relay_limited_reserve_transfer_assets( + t: ParaToParaThroughRelayTest, +) -> DispatchResult { ::PolkadotXcm::limited_reserve_transfer_assets( t.signed_origin, bx!(t.args.dest.into()), @@ -549,7 +547,8 @@ fn reserve_transfer_native_asset_from_relay_to_para() { // Calculate delivery fees let delivery_fees = Westend::execute_with(|| { - let reanchored_assets = assets.reanchored( &destination, &WestendUniversalLocation::get()).unwrap(); + let reanchored_assets = + assets.reanchored(&destination, &WestendUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) @@ -588,7 +587,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { ::RuntimeOrigin::signed(asset_owner), relay_native_asset_location, sender.clone(), - amount_to_send + amount_to_send, ); // Init values for Relay @@ -603,7 +602,14 @@ fn reserve_transfer_native_asset_from_para_to_relay() { let test_args = TestContext { sender: sender.clone(), receiver: receiver.clone(), - args: TestArgs::new_para(destination.clone(), receiver, amount_to_send, assets.clone(), None, 0), + args: TestArgs::new_para( + destination.clone(), + receiver, + amount_to_send, + assets.clone(), + None, + 0, + ), }; let mut test = ParaToRelayTest::new(test_args); @@ -622,7 +628,8 @@ fn reserve_transfer_native_asset_from_para_to_relay() { // Calculate delivery fees let delivery_fees = PenpalA::execute_with(|| { - let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); + let reanchored_assets = + assets.reanchored(&destination, &PenpalUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) @@ -665,7 +672,14 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let test_args = TestContext { sender, receiver: receiver.clone(), - args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), + args: TestArgs::new_para( + destination.clone(), + receiver.clone(), + amount_to_send, + assets.clone(), + None, + 0, + ), }; let mut test = SystemParaToParaTest::new(test_args); @@ -676,15 +690,17 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { >::balance(system_para_native_asset_location.into(), &receiver) }); - // Set assertions and dispatchables + // Set assertions and dispatchables test.set_assertion::(system_para_to_para_sender_assertions); test.set_assertion::(system_para_to_para_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); - // Calculate delivery fees + // Calculate delivery fees let delivery_fees = AssetHubWestend::execute_with(|| { - let reanchored_assets = assets.reanchored( &destination, &AssetHubWestendUniversalLocation::get()).unwrap(); + let reanchored_assets = assets + .reanchored(&destination, &AssetHubWestendUniversalLocation::get()) + .unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) @@ -723,13 +739,14 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { ::RuntimeOrigin::signed(asset_owner), system_para_native_asset_location, sender.clone(), - amount_to_send + amount_to_send, ); - // Init values for System Parachain + // Init values for System Parachain let receiver = AssetHubWestendReceiver::get(); let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id()); - let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); + let sov_penpal_on_ahr = + AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); // fund Parachain's SA on System Parachain with the native tokens held in reserve AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ahr.into(), amount_to_send * 2)]); @@ -738,7 +755,14 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let test_args = TestContext { sender: sender.clone(), receiver: receiver.clone(), - args: TestArgs::new_para(destination.clone(), receiver.clone(), amount_to_send, assets.clone(), None, 0), + args: TestArgs::new_para( + destination.clone(), + receiver.clone(), + amount_to_send, + assets.clone(), + None, + 0, + ), }; let mut test = ParaToSystemParaTest::new(test_args); @@ -755,9 +779,10 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { test.set_dispatchable::(para_to_system_para_reserve_transfer_assets); test.assert(); - // Calculate delivery fees + // Calculate delivery fees let delivery_fees = PenpalA::execute_with(|| { - let reanchored_assets = assets.reanchored( &destination, &PenpalUniversalLocation::get()).unwrap(); + let reanchored_assets = + assets.reanchored(&destination, &PenpalUniversalLocation::get()).unwrap(); xcm_helpers::transfer_assets_delivery_fees::< ::XcmSender, >(reanchored_assets, 0, test.args.weight_limit, test.args.beneficiary, test.args.dest) @@ -797,7 +822,10 @@ fn reserve_transfer_assets_from_system_para_to_para() { let asset_owner_signer = ::RuntimeOrigin::signed(asset_owner.clone()); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), - ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())], asset_amount_to_send) + ( + [PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())], + asset_amount_to_send, + ) .into(), ] .into(); @@ -848,7 +876,10 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &receiver) + >::balance( + system_para_foreign_asset_location.clone(), + &receiver, + ) }); // Set assertions and dispatchables @@ -869,21 +900,30 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &receiver) + >::balance( + system_para_foreign_asset_location.clone(), + &receiver, + ) }); // Sender's balance is reduced assert!(sender_balance_after < sender_balance_before); // Receiver's foreign asset balance is increased assert!(receiver_foreign_assets_after > receiver_foreign_assets_before); - // Receiver's system asset balance increased by `amount_to_send - delivery_fees - bought_execution`; - // `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but - // should be non-zero - assert!(receiver_system_native_assets_after < receiver_system_native_assets_before + fee_amount_to_send); + // Receiver's system asset balance increased by `amount_to_send - delivery_fees - + // bought_execution`; `delivery_fees` might be paid from transfer or JIT, also + // `bought_execution` is unknown but should be non-zero + assert!( + receiver_system_native_assets_after < + receiver_system_native_assets_before + fee_amount_to_send + ); // Sender's asset balance is reduced by exact amount assert_eq!(sender_assets_before - asset_amount_to_send, sender_assets_after); // Receiver's foreign asset balance is increased by exact amount - assert_eq!(receiver_foreign_assets_after, receiver_foreign_assets_before + asset_amount_to_send); + assert_eq!( + receiver_foreign_assets_after, + receiver_foreign_assets_before + asset_amount_to_send + ); } /// Reserve Transfers of a foreign asset and native asset from Parachain to System Para should @@ -902,8 +942,7 @@ fn reserve_transfer_assets_from_para_to_system_para() { let system_asset_location_on_penpal = RelayLocationV3::get(); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), - (asset_location_on_penpal_latest, asset_amount_to_send) - .into(), + (asset_location_on_penpal_latest, asset_amount_to_send).into(), ] .into(); let fee_asset_index = assets @@ -929,14 +968,18 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Init values for System Parachain let receiver = AssetHubWestendReceiver::get(); let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id()); - let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); + let sov_penpal_on_ahr = + AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); let system_para_native_asset_location = RelayLocationV3::get(); let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHubV3::get(); let ah_asset_owner = AssetHubWestendAssetOwner::get(); let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); // Fund SA-of-Penpal-on-AHR to be able to pay for the fees. - AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ahr.clone().into(), ASSET_HUB_WESTEND_ED * 1000)]); + AssetHubWestend::fund_accounts(vec![( + sov_penpal_on_ahr.clone().into(), + ASSET_HUB_WESTEND_ED * 1000, + )]); // Fund SA-of-Penpal-on-AHR to be able to pay for the sent amount. AssetHubWestend::mint_asset( ah_asset_owner_signer, @@ -1032,7 +1075,7 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { ::RuntimeOrigin::signed(asset_owner), relay_native_asset_location, sender.clone(), - amount_to_send + amount_to_send, ); // fund the Parachain Origin's SA on Relay Chain with the native tokens held in reserve diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index a03244d63e2a0..7b868c4948ccf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -570,8 +570,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let asset_owner = PenpalAssetOwner::get(); let system_para_native_asset_location = RelayLocationV3::get(); let sender = PenpalASender::get(); - let penpal_check_account = - ::PolkadotXcm::check_account(); + let penpal_check_account = ::PolkadotXcm::check_account(); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubWestend::para_id()); let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); let penpal_assets: Assets = vec![ @@ -590,29 +589,32 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { ::RuntimeOrigin::signed(asset_owner.clone()), system_para_native_asset_location, sender.clone(), - fee_amount_to_send + fee_amount_to_send, ); PenpalA::mint_asset( ::RuntimeOrigin::signed(asset_owner.clone()), asset_id_on_penpal, sender.clone(), - asset_amount_to_send + asset_amount_to_send, ); // fund Parachain's check account to be able to teleport - PenpalA::fund_accounts(vec![((penpal_check_account.clone().into(), ASSET_HUB_WESTEND_ED * 1000))]); + PenpalA::fund_accounts(vec![ + ((penpal_check_account.clone().into(), ASSET_HUB_WESTEND_ED * 1000)), + ]); // prefund SA of Penpal on AssetHub with enough native tokens to pay for fees let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ah = AssetHubWestend::sovereign_account_id_of(penpal_as_seen_by_ah); - AssetHubWestend::fund_accounts(vec![ - (sov_penpal_on_ah.clone().into(), ASSET_HUB_WESTEND_ED * 100_000_000_000), - ]); + AssetHubWestend::fund_accounts(vec![( + sov_penpal_on_ah.clone().into(), + ASSET_HUB_WESTEND_ED * 100_000_000_000, + )]); // Init values for System Parachain let foreign_asset_at_asset_hub_westend = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) - .appended_with(asset_location_on_penpal) - .unwrap(); + v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + .appended_with(asset_location_on_penpal) + .unwrap(); let penpal_to_ah_beneficiary_id = AssetHubWestendReceiver::get(); // Penpal to AH test args @@ -631,7 +633,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let mut penpal_to_ah = ParaToSystemParaTest::new(penpal_to_ah_test_args); let penpal_sender_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &PenpalASender::get()) + >::balance( + system_para_native_asset_location, + &PenpalASender::get(), + ) }); let ah_receiver_balance_before = penpal_to_ah.receiver.balance; @@ -655,7 +660,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let penpal_sender_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &PenpalASender::get()) + >::balance( + system_para_native_asset_location, + &PenpalASender::get(), + ) }); let ah_receiver_balance_after = penpal_to_ah.receiver.balance; @@ -734,7 +742,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let ah_sender_balance_before = ah_to_penpal.sender.balance; let penpal_receiver_balance_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &PenpalAReceiver::get()) + >::balance( + system_para_native_asset_location, + &PenpalAReceiver::get(), + ) }); let ah_sender_assets_before = AssetHubWestend::execute_with(|| { @@ -757,7 +768,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { let ah_sender_balance_after = ah_to_penpal.sender.balance; let penpal_receiver_balance_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location, &PenpalAReceiver::get()) + >::balance( + system_para_native_asset_location, + &PenpalAReceiver::get(), + ) }); let ah_sender_assets_after = AssetHubWestend::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs index d97886d4a34d9..b5e19cf3fa3a2 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs @@ -23,10 +23,7 @@ mod imports { pub use xcm::{ latest::ParentThen, prelude::{AccountId32 as AccountId32Junction, *}, - v3::{ - self, - NetworkId::Westend as WestendId, - }, + v3::{self, NetworkId::Westend as WestendId}, }; // Cumulus @@ -35,8 +32,7 @@ mod imports { impls::Inspect, test_parachain_is_trusted_teleporter, xcm_emulator::{ - assert_expected_events, bx, Chain, Parachain as Para, - RelayChain as Relay, TestExt, + assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, TestExt, }, }; pub use parachains_common::AccountId; @@ -56,9 +52,10 @@ mod imports { AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver, AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, - BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWestendPara as BridgeHubWestend, - PenpalAPara as PenpalA, PenpalAParaReceiver as PenpalAReceiver, - PenpalAParaSender as PenpalASender, RococoRelay as Rococo, + BridgeHubRococoParaSender as BridgeHubRococoSender, + BridgeHubWestendPara as BridgeHubWestend, PenpalAPara as PenpalA, + PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender, + RococoRelay as Rococo, }; pub const ASSET_MIN_BALANCE: u128 = 1000; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs index a394c3af64184..60c31ce5a4aef 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs @@ -33,8 +33,7 @@ mod imports { impls::Inspect, test_parachain_is_trusted_teleporter, xcm_emulator::{ - assert_expected_events, bx, Chain, Parachain as Para, - RelayChain as Relay, TestExt + assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, TestExt, }, }; pub use parachains_common::AccountId; @@ -46,15 +45,16 @@ mod imports { genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, }, bridge_hub_westend_emulated_chain::{ - genesis::ED as BRIDGE_HUB_WESTEND_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, + genesis::ED as BRIDGE_HUB_WESTEND_ED, + BridgeHubWestendParaPallet as BridgeHubWestendPallet, }, westend_emulated_chain::WestendRelayPallet as WestendPallet, AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver, AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, - BridgeHubWestendPara as BridgeHubWestend, BridgeHubWestendParaSender as BridgeHubWestendSender, - WestendRelay as Westend, + BridgeHubWestendPara as BridgeHubWestend, + BridgeHubWestendParaSender as BridgeHubWestendSender, WestendRelay as Westend, }; pub const ASSET_MIN_BALANCE: u128 = 1000; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs index b343d272f5460..38ff08b486d47 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-rococo/src/lib.rs @@ -30,21 +30,19 @@ mod imports { // Cumulus pub use asset_test_utils::xcm_helpers; - pub use emulated_integration_tests_common:: - xcm_emulator::{ - assert_expected_events, bx, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, - }; + pub use emulated_integration_tests_common::xcm_emulator::{ + assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, Test, TestArgs, + TestContext, TestExt, + }; pub use parachains_common::Balance; pub use rococo_system_emulated_network::{ people_rococo_emulated_chain::{ genesis::ED as PEOPLE_ROCOCO_ED, PeopleRococoParaPallet as PeopleRococoPallet, }, rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, - PeopleRococoPara as PeopleRococo, - PeopleRococoParaReceiver as PeopleRococoReceiver, PeopleRococoParaSender as PeopleRococoSender, - RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, - RococoRelaySender as RococoSender, + PeopleRococoPara as PeopleRococo, PeopleRococoParaReceiver as PeopleRococoReceiver, + PeopleRococoParaSender as PeopleRococoSender, RococoRelay as Rococo, + RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender, }; pub type RelayToSystemParaTest = Test; diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/lib.rs index d3d6baefeaf5b..77ac7cfc78c78 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/lib.rs @@ -29,19 +29,17 @@ mod imports { // Cumulus pub use asset_test_utils::xcm_helpers; - pub use emulated_integration_tests_common:: - xcm_emulator::{ - assert_expected_events, bx, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, - }; + pub use emulated_integration_tests_common::xcm_emulator::{ + assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, Test, TestArgs, + TestContext, TestExt, + }; pub use parachains_common::Balance; pub use westend_system_emulated_network::{ people_westend_emulated_chain::{ genesis::ED as PEOPLE_WESTEND_ED, PeopleWestendParaPallet as PeopleWestendPallet, }, westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet}, - PeopleWestendPara as PeopleWestend, - PeopleWestendParaReceiver as PeopleWestendReceiver, + PeopleWestendPara as PeopleWestend, PeopleWestendParaReceiver as PeopleWestendReceiver, PeopleWestendParaSender as PeopleWestendSender, WestendRelay as Westend, WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender, }; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 09434df38ee75..177880a51f237 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -22,8 +22,7 @@ use super::{ }; use assets_common::{ matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset}, - TrustBackedAssetsAsLocation, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, TrustBackedAssetsAsLocation, }; use frame_support::{ parameter_types, @@ -591,7 +590,12 @@ impl xcm_executor::Config for XcmConfig { // `pallet_assets` instance - `ForeignAssets`. cumulus_primitives_utility::TakeFirstAssetTrader< AccountId, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger< + Runtime, + WeightToFee, + Balances, + ForeignAssetsInstance, + >, ForeignAssetsConvertedConcreteId, ForeignAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index f172b8d2be93a..eeba95df1dcdc 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -21,20 +21,20 @@ use asset_hub_rococo_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignCreatorsSovereignAccountOf, StakingPot, - LocationToAccountId, TokenLocation, TokenLocationV3, TrustBackedAssetsPalletLocation, - TrustBackedAssetsPalletLocationV3, XcmConfig, + ForeignCreatorsSovereignAccountOf, LocationToAccountId, StakingPot, TokenLocation, + TokenLocationV3, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, + XcmConfig, }, AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, ToWestendXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue, }; -use assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger; use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder, SlotDurations, }; +use assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger; use codec::{Decode, Encode}; use cumulus_primitives_utility::ChargeWeightInFungibles; use frame_support::{ @@ -528,12 +528,13 @@ fn test_foreign_asset_xcm_take_first_trader() { let bought = Weight::from_parts(4_000_000_000u64, 0); // Lets calculate amount needed - let asset_amount_needed = - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::::charge_weight_in_fungibles( - foreign_location, - bought, - ) - .expect("failed to compute"); + let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::< + Runtime, + WeightToFee, + Balances, + ForeignAssetsInstance, + >::charge_weight_in_fungibles(foreign_location, bought) + .expect("failed to compute"); // Lets pay with: asset_amount_needed + asset_amount_extra let asset_amount_extra = 100_u128; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 689d69c3a38d1..7d64598f3de40 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -22,7 +22,7 @@ use super::{ }; use assets_common::{ matching::{FromSiblingParachain, IsForeignConcreteAsset}, - TrustBackedAssetsAsLocation, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, TrustBackedAssetsAsLocation, }; use frame_support::{ parameter_types, @@ -612,7 +612,12 @@ impl xcm_executor::Config for XcmConfig { // `pallet_assets` instance - `ForeignAssets`. cumulus_primitives_utility::TakeFirstAssetTrader< AccountId, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger< + Runtime, + WeightToFee, + Balances, + ForeignAssetsInstance, + >, ForeignAssetsConvertedConcreteId, ForeignAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index 0fec28ecbfdf9..3a3ff3d2b6652 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -21,21 +21,21 @@ use asset_hub_westend_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignCreatorsSovereignAccountOf, StakingPot, - LocationToAccountId, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, - WestendLocation, WestendLocationV3, XcmConfig, + ForeignCreatorsSovereignAccountOf, LocationToAccountId, StakingPot, + TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, WestendLocation, + WestendLocationV3, XcmConfig, }, AllPalletsWithoutSystem, Assets, Balances, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, ToRococoXcmRouterInstance, TrustBackedAssetsInstance, XcmpQueue, }; -use assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger; pub use asset_hub_westend_runtime::{AssetConversion, AssetDeposit, CollatorSelection, System}; use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder, SlotDurations, }; +use assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger; use codec::{Decode, Encode}; use cumulus_primitives_utility::ChargeWeightInFungibles; use frame_support::{ @@ -528,12 +528,13 @@ fn test_foreign_asset_xcm_take_first_trader() { let bought = Weight::from_parts(4_000_000_000u64, 0); // Lets calculate amount needed - let asset_amount_needed = - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::::charge_weight_in_fungibles( - foreign_location, - bought, - ) - .expect("failed to compute"); + let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::< + Runtime, + WeightToFee, + Balances, + ForeignAssetsInstance, + >::charge_weight_in_fungibles(foreign_location, bought) + .expect("failed to compute"); // Lets pay with: asset_amount_needed + asset_amount_extra let asset_amount_extra = 100_u128; diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index b9476adcc0cc4..c3fa5656a7074 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -23,10 +23,13 @@ pub mod local_and_foreign_assets; pub mod matching; pub mod runtime_api; -use sp_runtime::traits::ConvertInto; use crate::matching::{LocalLocationPattern, ParentLocation}; use frame_support::traits::{Equals, EverythingBut}; -use parachains_common::{xcm_config::AssetFeeAsExistentialDepositMultiplier, AssetIdForTrustBackedAssets, CollectionId, ItemId}; +use parachains_common::{ + xcm_config::AssetFeeAsExistentialDepositMultiplier, AssetIdForTrustBackedAssets, CollectionId, + ItemId, +}; +use sp_runtime::traits::ConvertInto; use xcm_builder::{ AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, V4V3LocationConverter, }; @@ -127,13 +130,17 @@ pub type PoolAssetsConvertedConcreteId = >; /// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. -pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = - AssetFeeAsExistentialDepositMultiplier< - Runtime, - WeightToFee, - pallet_assets::BalanceToAssetBalance, - ForeignAssetsInstance, - >; +pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger< + Runtime, + WeightToFee, + Balances, + ForeignAssetsInstance, +> = AssetFeeAsExistentialDepositMultiplier< + Runtime, + WeightToFee, + pallet_assets::BalanceToAssetBalance, + ForeignAssetsInstance, +>; #[cfg(test)] mod tests { diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index 8bd01dc98eace..f14bd5fdb2c2d 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -23,16 +23,16 @@ //! `ReserveAssetTransferDeposited` message but that will but the intension will be to support this //! soon. use super::{ - AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Assets, Balance, Balances, - ForeignAssets, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, - RuntimeOrigin, WeightToFee, XcmpQueue, ForeignAssetsInstance, Authorship, + AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Assets, Authorship, Balance, + Balances, ForeignAssets, ForeignAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }; use core::marker::PhantomData; use frame_support::{ parameter_types, traits::{ fungibles::{self, Balanced, Credit}, - ConstU32, Contains, ContainsPair, Everything, Get, Nothing, EverythingBut + ConstU32, Contains, ContainsPair, Everything, EverythingBut, Get, Nothing, }, weights::Weight, }; @@ -46,14 +46,13 @@ use sp_runtime::traits::Zero; use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, - AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AsPrefixedGeneralIndex, - ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, - FungibleAdapter, FungiblesAdapter, IsConcrete, LocalMint, NativeAsset, NoChecking, - ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, StartsWith, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WithComputedOrigin, WithUniqueTopic, + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, AsPrefixedGeneralIndex, ConvertedConcreteId, EnsureXcmOrigin, + FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsConcrete, + LocalMint, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, StartsWith, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::{traits::JustTry, XcmExecutor}; @@ -125,17 +124,16 @@ pub type FungiblesTransactor = FungiblesAdapter< CheckingAccount, >; -pub type ForeignAssetsConvertedConcreteId = - assets_common::LocationConvertedConcreteId< - EverythingBut<( - // Here we rely on fact that something like this works: - // assert!(Location::new(1, - // [Parachain(100)]).starts_with(&Location::parent())); - // assert!([Parachain(100)].into().starts_with(&Here)); - StartsWith, - )>, - Balance, - >; +pub type ForeignAssetsConvertedConcreteId = assets_common::LocationConvertedConcreteId< + EverythingBut<( + // Here we rely on fact that something like this works: + // assert!(Location::new(1, + // [Parachain(100)]).starts_with(&Location::parent())); + // assert!([Parachain(100)].into().starts_with(&Here)); + StartsWith, + )>, + Balance, +>; /// Means for transacting foreign assets from different global consensus. pub type ForeignFungiblesTransactor = FungiblesAdapter< @@ -358,7 +356,12 @@ impl xcm_executor::Config for XcmConfig { // `pallet_assets` instance - `ForeignAssets`. cumulus_primitives_utility::TakeFirstAssetTrader< AccountId, - assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, + assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger< + Runtime, + WeightToFee, + Balances, + ForeignAssetsInstance, + >, ForeignAssetsConvertedConcreteId, ForeignAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< From 777df2a7a9e1a7d38c203a49af322bebc8b215d0 Mon Sep 17 00:00:00 2001 From: NachoPal Date: Fri, 1 Mar 2024 14:33:09 +0100 Subject: [PATCH 08/18] fix feature propagation --- cumulus/parachains/runtimes/assets/common/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/common/Cargo.toml b/cumulus/parachains/runtimes/assets/common/Cargo.toml index a558ff61f3ed7..8f6d28b82d91f 100644 --- a/cumulus/parachains/runtimes/assets/common/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/common/Cargo.toml @@ -44,6 +44,7 @@ std = [ "frame-support/std", "log/std", "pallet-asset-conversion/std", + "pallet-assets/std", "pallet-xcm/std", "parachains-common/std", "scale-info/std", @@ -59,6 +60,7 @@ runtime-benchmarks = [ "cumulus-primitives-core/runtime-benchmarks", "frame-support/runtime-benchmarks", "pallet-asset-conversion/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", From ba01023f006360e8bd911fb303d04e3e829a82e9 Mon Sep 17 00:00:00 2001 From: NachoPal Date: Fri, 1 Mar 2024 14:50:50 +0100 Subject: [PATCH 09/18] make clippy happy --- .../src/tests/reserve_transfer.rs | 16 ++++++------- .../asset-hub-rococo/src/tests/teleport.rs | 2 +- .../src/tests/reserve_transfer.rs | 24 +++++++++---------- .../asset-hub-westend/src/tests/teleport.rs | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 7f3f7f22c91f5..d90001396bf78 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -871,12 +871,12 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_system_native_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) + >::balance(system_para_native_asset_location, &receiver) }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_foreign_asset_location.clone(), + system_para_foreign_asset_location, &receiver, ) }); @@ -895,12 +895,12 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_system_native_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) + >::balance(system_para_native_asset_location, &receiver) }); let receiver_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_foreign_asset_location.clone(), + system_para_foreign_asset_location, &receiver, ) }); @@ -1004,11 +1004,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query initial balances let sender_system_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) + >::balance(system_para_native_asset_location, &sender) }); let sender_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &sender) + >::balance(system_para_foreign_asset_location, &sender) }); let receiver_balance_before = test.receiver.balance; let receiver_assets_before = AssetHubRococo::execute_with(|| { @@ -1025,11 +1025,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query final balances let sender_system_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) + >::balance(system_para_native_asset_location, &sender) }); let sender_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &sender) + >::balance(system_para_foreign_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; let receiver_assets_after = AssetHubRococo::execute_with(|| { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index e8fe394647016..de815d16c09e9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -599,7 +599,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { ); // fund Parachain's check account to be able to teleport PenpalA::fund_accounts(vec![ - ((penpal_check_account.clone().into(), ASSET_HUB_ROCOCO_ED * 1000)), + (penpal_check_account.clone().into(), ASSET_HUB_ROCOCO_ED * 1000), ]); // prefund SA of Penpal on AssetHub with enough native tokens to pay for fees diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index bc7969d7e376e..e4a979c510a34 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -872,12 +872,12 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_system_native_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) + >::balance(system_para_native_asset_location, &receiver) }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_foreign_asset_location.clone(), + system_para_foreign_asset_location, &receiver, ) }); @@ -896,12 +896,12 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_system_native_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &receiver) + >::balance(system_para_native_asset_location, &receiver) }); let receiver_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; >::balance( - system_para_foreign_asset_location.clone(), + system_para_foreign_asset_location, &receiver, ) }); @@ -1006,11 +1006,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query initial balances let sender_system_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) + >::balance(system_para_native_asset_location, &sender) }); let sender_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &sender) + >::balance(system_para_foreign_asset_location, &sender) }); let receiver_balance_before = test.receiver.balance; let receiver_assets_before = AssetHubWestend::execute_with(|| { @@ -1027,11 +1027,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { // Query final balances let sender_system_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_native_asset_location.clone(), &sender) + >::balance(system_para_native_asset_location, &sender) }); let sender_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(system_para_foreign_asset_location.clone(), &sender) + >::balance(system_para_foreign_asset_location, &sender) }); let receiver_balance_after = test.receiver.balance; let receiver_assets_after = AssetHubWestend::execute_with(|| { @@ -1095,11 +1095,11 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(relay_native_asset_location, &sender) }); let receiver_assets_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(relay_native_asset_location, &receiver) }); // Set assertions and dispatchables @@ -1119,11 +1119,11 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(relay_native_asset_location, &sender) }); let receiver_assets_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(relay_native_asset_location, &receiver) }); // Sender's balance is reduced diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 7b868c4948ccf..f88ce3c7ea5cc 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -599,7 +599,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { ); // fund Parachain's check account to be able to teleport PenpalA::fund_accounts(vec![ - ((penpal_check_account.clone().into(), ASSET_HUB_WESTEND_ED * 1000)), + (penpal_check_account.clone().into(), ASSET_HUB_WESTEND_ED * 1000), ]); // prefund SA of Penpal on AssetHub with enough native tokens to pay for fees From 158e12f9fcdb1838206b94e24bd2e2429324fcaa Mon Sep 17 00:00:00 2001 From: NachoPal Date: Fri, 1 Mar 2024 14:59:39 +0100 Subject: [PATCH 10/18] make clippy happy 2 --- .../assets/asset-hub-rococo/src/tests/reserve_transfer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index d90001396bf78..7bf11a7a9b25c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -1093,11 +1093,11 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { // Query initial balances let sender_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(relay_native_asset_location, &sender) }); let receiver_assets_before = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(relay_native_asset_location, &receiver) }); // Set assertions and dispatchables @@ -1117,11 +1117,11 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { // Query final balances let sender_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &sender) + >::balance(relay_native_asset_location, &sender) }); let receiver_assets_after = PenpalB::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance(relay_native_asset_location.clone(), &receiver) + >::balance(relay_native_asset_location, &receiver) }); // Sender's balance is reduced From 750e22c3c23b34d73d2445e6645df32ee4b9fdcd Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 1 Mar 2024 14:01:40 +0000 Subject: [PATCH 11/18] ".git/.scripts/commands/fmt/fmt.sh" --- .../asset-hub-rococo/src/tests/reserve_transfer.rs | 10 ++-------- .../assets/asset-hub-rococo/src/tests/teleport.rs | 4 +--- .../asset-hub-westend/src/tests/reserve_transfer.rs | 10 ++-------- .../assets/asset-hub-westend/src/tests/teleport.rs | 7 ++++--- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 7bf11a7a9b25c..3b6f242bbec16 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -875,10 +875,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - system_para_foreign_asset_location, - &receiver, - ) + >::balance(system_para_foreign_asset_location, &receiver) }); // Set assertions and dispatchables @@ -899,10 +896,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - system_para_foreign_asset_location, - &receiver, - ) + >::balance(system_para_foreign_asset_location, &receiver) }); // Sender's balance is reduced assert!(sender_balance_after < sender_balance_before); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index de815d16c09e9..131c7a196624e 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -598,9 +598,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { asset_amount_to_send, ); // fund Parachain's check account to be able to teleport - PenpalA::fund_accounts(vec![ - (penpal_check_account.clone().into(), ASSET_HUB_ROCOCO_ED * 1000), - ]); + PenpalA::fund_accounts(vec![(penpal_check_account.clone().into(), ASSET_HUB_ROCOCO_ED * 1000)]); // prefund SA of Penpal on AssetHub with enough native tokens to pay for fees let penpal_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id()); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index e4a979c510a34..4116bacd99740 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -876,10 +876,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_foreign_assets_before = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - system_para_foreign_asset_location, - &receiver, - ) + >::balance(system_para_foreign_asset_location, &receiver) }); // Set assertions and dispatchables @@ -900,10 +897,7 @@ fn reserve_transfer_assets_from_system_para_to_para() { }); let receiver_foreign_assets_after = PenpalA::execute_with(|| { type ForeignAssets = ::ForeignAssets; - >::balance( - system_para_foreign_asset_location, - &receiver, - ) + >::balance(system_para_foreign_asset_location, &receiver) }); // Sender's balance is reduced assert!(sender_balance_after < sender_balance_before); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index f88ce3c7ea5cc..ed66132437912 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -598,9 +598,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { asset_amount_to_send, ); // fund Parachain's check account to be able to teleport - PenpalA::fund_accounts(vec![ - (penpal_check_account.clone().into(), ASSET_HUB_WESTEND_ED * 1000), - ]); + PenpalA::fund_accounts(vec![( + penpal_check_account.clone().into(), + ASSET_HUB_WESTEND_ED * 1000, + )]); // prefund SA of Penpal on AssetHub with enough native tokens to pay for fees let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id()); From c6dbbb91b2b691e241ee3ffe01d270033d377cde Mon Sep 17 00:00:00 2001 From: NachoPal Date: Mon, 4 Mar 2024 14:00:24 +0100 Subject: [PATCH 12/18] address comments --- .../emulated/common/src/impls.rs | 40 ++++++ .../assets/asset-hub-rococo/src/tests/send.rs | 116 ++++++++++++++++-- .../assets/asset-hub-rococo/src/tests/swap.rs | 2 + .../asset-hub-rococo/src/tests/teleport.rs | 1 + .../asset-hub-westend/src/tests/send.rs | 116 ++++++++++++++++-- .../asset-hub-westend/src/tests/swap.rs | 2 + .../asset-hub-westend/src/tests/teleport.rs | 1 + 7 files changed, 254 insertions(+), 24 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 5732a4cf50281..b1b903830887f 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -843,6 +843,46 @@ macro_rules! impl_assets_helpers_for_parachain { ); }); } + + /// Returns the encoded call for `create` from the assets pallet + pub fn create_asset_call( + asset_id: u32, + min_balance: $crate::impls::Balance, + admin: $crate::impls::AccountId, + ) -> $crate::impls::DoubleEncoded<()> { + use $crate::impls::{Chain, Encode}; + + ::RuntimeCall::Assets($crate::impls::pallet_assets::Call::< + ::Runtime, + $crate::impls::pallet_assets::Instance1, + >::create { + id: asset_id.into(), + min_balance, + admin: admin.into(), + }) + .encode() + .into() + } + + /// Returns the encoded call for `create` from the foreign assets pallet + pub fn create_foreign_asset_call( + asset_id: $crate::impls::v3::Location, + min_balance: $crate::impls::Balance, + admin: $crate::impls::AccountId, + ) -> $crate::impls::DoubleEncoded<()> { + use $crate::impls::{Chain, Encode}; + + ::RuntimeCall::ForeignAssets($crate::impls::pallet_assets::Call::< + ::Runtime, + $crate::impls::pallet_assets::Instance2, + >::create { + id: asset_id.into(), + min_balance, + admin: admin.into(), + }) + .encode() + .into() + } } } }; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs index d1febbbe425c5..65a6153f1b992 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs @@ -28,8 +28,92 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() { ) } -/// Parachain should be able to send XCM paying its fee with sufficient asset -/// in the System Parachain +/// We tests two things here: +/// - Parachain should be able to send XCM paying its fee with system asset +/// in the System Parachain +/// - Parachain should be able to create a new Foreign Asset in the System Parachain +#[test] +fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { + let para_sovereign_account = AssetHubRococo::sovereign_account_id_of( + AssetHubRococo::sibling_location_of(PenpalA::para_id()), + ); + let asset_location_on_penpal = v3::Location::new( + 0, + [v3::Junction::PalletInstance(ASSETS_PALLET_ID), v3::Junction::GeneralIndex(ASSET_ID.into())] + ); + let foreign_asset_at_asset_hub = + v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + .appended_with(asset_location_on_penpal) + .unwrap(); + + // Encoded `create_asset` call to be executed in AssetHub + let call = AssetHubRococo::create_foreign_asset_call( + foreign_asset_at_asset_hub, + ASSET_MIN_BALANCE, + para_sovereign_account.clone(), + ); + + let origin_kind = OriginKind::Xcm; + let fee_amount = ASSET_HUB_ROCOCO_ED * 1000000; + let system_asset = + (Parent, fee_amount).into(); + + let root_origin = ::RuntimeOrigin::root(); + let system_para_destination = PenpalA::sibling_location_of(AssetHubRococo::para_id()).into(); + let xcm = xcm_transact_paid_execution( + call, + origin_kind, + system_asset, + para_sovereign_account.clone(), + ); + + // SA-of-Penpal-on-AHR needs to have balance to pay for fees and asset creation deposit + AssetHubRococo::fund_accounts(vec![(para_sovereign_account.clone().into(), ASSET_HUB_ROCOCO_ED * 10000000000)]); + + PenpalA::execute_with(|| { + assert_ok!(::PolkadotXcm::send( + root_origin, + bx!(system_para_destination), + bx!(xcm), + )); + + PenpalA::assert_xcm_pallet_sent(); + }); + + AssetHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + AssetHubRococo::assert_xcmp_queue_success(Some(Weight::from_parts( + 15_594_564_000, + 562_893, + ))); + + assert_expected_events!( + AssetHubRococo, + vec![ + // Burned the fee + RuntimeEvent::Balances(pallet_balances::Event::Burned { who, amount }) => { + who: *who == para_sovereign_account, + amount: *amount == fee_amount, + }, + // Foreign Asset created + RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { asset_id, creator, owner }) => { + asset_id: *asset_id == foreign_asset_at_asset_hub.clone(), + creator: *creator == para_sovereign_account.clone(), + owner: *owner == para_sovereign_account, + }, + ] + ); + + type ForeignAssets = ::ForeignAssets; + assert!(ForeignAssets::asset_exists(foreign_asset_at_asset_hub)); + }); +} + +/// We tests two things here: +/// - Parachain should be able to send XCM paying its fee with system assets +/// in the System Parachain +/// - Parachain should be able to create a new Asset in the System Parachain #[test] fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { let para_sovereign_account = AssetHubRococo::sovereign_account_id_of( @@ -46,18 +130,19 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { ASSET_MIN_BALANCE * 1000000000, ); - // We just need a call that can pass the `SafeCallFilter` - // Call values are not relevant - let call = AssetHubRococo::force_create_asset_call( - ASSET_ID, - para_sovereign_account.clone(), - true, + // Just a different `asset_id`` that does not exist yet + let new_asset_id = ASSET_ID + 1; + + // Encoded `create_asset` call to be executed in AssetHub + let call = AssetHubRococo::create_asset_call( + new_asset_id, ASSET_MIN_BALANCE, + para_sovereign_account.clone(), ); let origin_kind = OriginKind::SovereignAccount; let fee_amount = ASSET_MIN_BALANCE * 1000000; - let native_asset = + let asset = ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); let root_origin = ::RuntimeOrigin::root(); @@ -65,10 +150,13 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { let xcm = xcm_transact_paid_execution( call, origin_kind, - native_asset, + asset, para_sovereign_account.clone(), ); + // SA-of-Penpal-on-AHR needs to have balance to pay for asset creation deposit + AssetHubRococo::fund_accounts(vec![(para_sovereign_account.clone().into(), ASSET_HUB_ROCOCO_ED * 10000000000)]); + PenpalA::execute_with(|| { assert_ok!(::PolkadotXcm::send( root_origin, @@ -90,13 +178,17 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { assert_expected_events!( AssetHubRococo, vec![ + // Burned the fee RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { asset_id: *asset_id == ASSET_ID, owner: *owner == para_sovereign_account, balance: *balance == fee_amount, }, - RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, .. }) => { - asset_id: *asset_id == ASSET_ID, + // Asset created + RuntimeEvent::Assets(pallet_assets::Event::Created { asset_id, creator, owner }) => { + asset_id: *asset_id == new_asset_id, + creator: *creator == para_sovereign_account.clone(), + owner: *owner == para_sovereign_account, }, ] ); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs index 8eeac93072943..98cb0138b0297 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs @@ -129,6 +129,8 @@ fn swap_locally_on_chain_using_foreign_assets() { ]); AssetHubRococo::execute_with(|| { + // 0: No need to create foreign asset as it exists in genesis. + // // 1: Mint foreign asset on asset_hub_rococo: // // (While it might be nice to use batch, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 131c7a196624e..278486808bdaf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -591,6 +591,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { sender.clone(), fee_amount_to_send, ); + // No need to create the asset (only mint) as it exists in genesis. PenpalA::mint_asset( ::RuntimeOrigin::signed(asset_owner.clone()), asset_id_on_penpal, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs index f90f9d3b17573..87d612df21ef0 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs @@ -28,8 +28,92 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() { ) } -/// Parachain should be able to send XCM paying its fee with sufficient asset -/// in the System Parachain +/// We tests two things here: +/// - Parachain should be able to send XCM paying its fee with system asset +/// in the System Parachain +/// - Parachain should be able to create a new Foreign Asset in the System Parachain +#[test] +fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { + let para_sovereign_account = AssetHubWestend::sovereign_account_id_of( + AssetHubWestend::sibling_location_of(PenpalA::para_id()), + ); + let asset_location_on_penpal = v3::Location::new( + 0, + [v3::Junction::PalletInstance(ASSETS_PALLET_ID), v3::Junction::GeneralIndex(ASSET_ID.into())] + ); + let foreign_asset_at_asset_hub = + v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + .appended_with(asset_location_on_penpal) + .unwrap(); + + // Encoded `create_asset` call to be executed in AssetHub + let call = AssetHubWestend::create_foreign_asset_call( + foreign_asset_at_asset_hub, + ASSET_MIN_BALANCE, + para_sovereign_account.clone(), + ); + + let origin_kind = OriginKind::Xcm; + let fee_amount = ASSET_HUB_WESTEND_ED * 1000000; + let system_asset = + (Parent, fee_amount).into(); + + let root_origin = ::RuntimeOrigin::root(); + let system_para_destination = PenpalA::sibling_location_of(AssetHubWestend::para_id()).into(); + let xcm = xcm_transact_paid_execution( + call, + origin_kind, + system_asset, + para_sovereign_account.clone(), + ); + + // SA-of-Penpal-on-AHR needs to have balance to pay for fees and asset creation deposit + AssetHubWestend::fund_accounts(vec![(para_sovereign_account.clone().into(), ASSET_HUB_WESTEND_ED * 10000000000)]); + + PenpalA::execute_with(|| { + assert_ok!(::PolkadotXcm::send( + root_origin, + bx!(system_para_destination), + bx!(xcm), + )); + + PenpalA::assert_xcm_pallet_sent(); + }); + + AssetHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + AssetHubWestend::assert_xcmp_queue_success(Some(Weight::from_parts( + 15_594_564_000, + 562_893, + ))); + + assert_expected_events!( + AssetHubWestend, + vec![ + // Burned the fee + RuntimeEvent::Balances(pallet_balances::Event::Burned { who, amount }) => { + who: *who == para_sovereign_account, + amount: *amount == fee_amount, + }, + // Foreign Asset created + RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { asset_id, creator, owner }) => { + asset_id: *asset_id == foreign_asset_at_asset_hub.clone(), + creator: *creator == para_sovereign_account.clone(), + owner: *owner == para_sovereign_account, + }, + ] + ); + + type ForeignAssets = ::ForeignAssets; + assert!(ForeignAssets::asset_exists(foreign_asset_at_asset_hub)); + }); +} + +/// We tests two things here: +/// - Parachain should be able to send XCM paying its fee with system assets +/// in the System Parachain +/// - Parachain should be able to create a new Asset in the System Parachain #[test] fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { let para_sovereign_account = AssetHubWestend::sovereign_account_id_of( @@ -46,18 +130,19 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { ASSET_MIN_BALANCE * 1000000000, ); - // We just need a call that can pass the `SafeCallFilter` - // Call values are not relevant - let call = AssetHubWestend::force_create_asset_call( - ASSET_ID, - para_sovereign_account.clone(), - true, + // Just a different `asset_id`` that does not exist yet + let new_asset_id = ASSET_ID + 1; + + // Encoded `create_asset` call to be executed in AssetHub + let call = AssetHubWestend::create_asset_call( + new_asset_id, ASSET_MIN_BALANCE, + para_sovereign_account.clone(), ); let origin_kind = OriginKind::SovereignAccount; let fee_amount = ASSET_MIN_BALANCE * 1000000; - let native_asset = + let asset = ([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into(); let root_origin = ::RuntimeOrigin::root(); @@ -65,10 +150,13 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { let xcm = xcm_transact_paid_execution( call, origin_kind, - native_asset, + asset, para_sovereign_account.clone(), ); + // SA-of-Penpal-on-AHR needs to have balance to pay for asset creation deposit + AssetHubWestend::fund_accounts(vec![(para_sovereign_account.clone().into(), ASSET_HUB_WESTEND_ED * 10000000000)]); + PenpalA::execute_with(|| { assert_ok!(::PolkadotXcm::send( root_origin, @@ -90,13 +178,17 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { assert_expected_events!( AssetHubWestend, vec![ + // Burned the fee RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { asset_id: *asset_id == ASSET_ID, owner: *owner == para_sovereign_account, balance: *balance == fee_amount, }, - RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, .. }) => { - asset_id: *asset_id == ASSET_ID, + // Asset created + RuntimeEvent::Assets(pallet_assets::Event::Created { asset_id, creator, owner }) => { + asset_id: *asset_id == new_asset_id, + creator: *creator == para_sovereign_account.clone(), + owner: *owner == para_sovereign_account, }, ] ); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index db93b47531e8c..f5daf50c5f3dc 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -128,6 +128,8 @@ fn swap_locally_on_chain_using_foreign_assets() { ]); AssetHubWestend::execute_with(|| { + // 0: No need to create foreign asset as it exists in genesis. + // // 1: Mint foreign asset on asset_hub_westend: // // (While it might be nice to use batch, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index ed66132437912..08c2d98a4c948 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -591,6 +591,7 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { sender.clone(), fee_amount_to_send, ); + // No need to create the asset (only mint) as it exists in genesis. PenpalA::mint_asset( ::RuntimeOrigin::signed(asset_owner.clone()), asset_id_on_penpal, From ecc8968b73d0f4e41e1ec9b04685f4536a755596 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 4 Mar 2024 14:33:34 +0000 Subject: [PATCH 13/18] ".git/.scripts/commands/fmt/fmt.sh" --- .../assets/asset-hub-rococo/src/tests/send.rs | 31 ++++++++++--------- .../asset-hub-westend/src/tests/send.rs | 31 ++++++++++--------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs index 65a6153f1b992..49f43114f7328 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs @@ -29,8 +29,7 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() { } /// We tests two things here: -/// - Parachain should be able to send XCM paying its fee with system asset -/// in the System Parachain +/// - Parachain should be able to send XCM paying its fee with system asset in the System Parachain /// - Parachain should be able to create a new Foreign Asset in the System Parachain #[test] fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { @@ -39,7 +38,10 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { ); let asset_location_on_penpal = v3::Location::new( 0, - [v3::Junction::PalletInstance(ASSETS_PALLET_ID), v3::Junction::GeneralIndex(ASSET_ID.into())] + [ + v3::Junction::PalletInstance(ASSETS_PALLET_ID), + v3::Junction::GeneralIndex(ASSET_ID.into()), + ], ); let foreign_asset_at_asset_hub = v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) @@ -55,8 +57,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { let origin_kind = OriginKind::Xcm; let fee_amount = ASSET_HUB_ROCOCO_ED * 1000000; - let system_asset = - (Parent, fee_amount).into(); + let system_asset = (Parent, fee_amount).into(); let root_origin = ::RuntimeOrigin::root(); let system_para_destination = PenpalA::sibling_location_of(AssetHubRococo::para_id()).into(); @@ -68,7 +69,10 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { ); // SA-of-Penpal-on-AHR needs to have balance to pay for fees and asset creation deposit - AssetHubRococo::fund_accounts(vec![(para_sovereign_account.clone().into(), ASSET_HUB_ROCOCO_ED * 10000000000)]); + AssetHubRococo::fund_accounts(vec![( + para_sovereign_account.clone().into(), + ASSET_HUB_ROCOCO_ED * 10000000000, + )]); PenpalA::execute_with(|| { assert_ok!(::PolkadotXcm::send( @@ -111,8 +115,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { } /// We tests two things here: -/// - Parachain should be able to send XCM paying its fee with system assets -/// in the System Parachain +/// - Parachain should be able to send XCM paying its fee with system assets in the System Parachain /// - Parachain should be able to create a new Asset in the System Parachain #[test] fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { @@ -147,15 +150,13 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { let root_origin = ::RuntimeOrigin::root(); let system_para_destination = PenpalA::sibling_location_of(AssetHubRococo::para_id()).into(); - let xcm = xcm_transact_paid_execution( - call, - origin_kind, - asset, - para_sovereign_account.clone(), - ); + let xcm = xcm_transact_paid_execution(call, origin_kind, asset, para_sovereign_account.clone()); // SA-of-Penpal-on-AHR needs to have balance to pay for asset creation deposit - AssetHubRococo::fund_accounts(vec![(para_sovereign_account.clone().into(), ASSET_HUB_ROCOCO_ED * 10000000000)]); + AssetHubRococo::fund_accounts(vec![( + para_sovereign_account.clone().into(), + ASSET_HUB_ROCOCO_ED * 10000000000, + )]); PenpalA::execute_with(|| { assert_ok!(::PolkadotXcm::send( diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs index 87d612df21ef0..2b5850eeaf4bf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs @@ -29,8 +29,7 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() { } /// We tests two things here: -/// - Parachain should be able to send XCM paying its fee with system asset -/// in the System Parachain +/// - Parachain should be able to send XCM paying its fee with system asset in the System Parachain /// - Parachain should be able to create a new Foreign Asset in the System Parachain #[test] fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { @@ -39,7 +38,10 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { ); let asset_location_on_penpal = v3::Location::new( 0, - [v3::Junction::PalletInstance(ASSETS_PALLET_ID), v3::Junction::GeneralIndex(ASSET_ID.into())] + [ + v3::Junction::PalletInstance(ASSETS_PALLET_ID), + v3::Junction::GeneralIndex(ASSET_ID.into()), + ], ); let foreign_asset_at_asset_hub = v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) @@ -55,8 +57,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { let origin_kind = OriginKind::Xcm; let fee_amount = ASSET_HUB_WESTEND_ED * 1000000; - let system_asset = - (Parent, fee_amount).into(); + let system_asset = (Parent, fee_amount).into(); let root_origin = ::RuntimeOrigin::root(); let system_para_destination = PenpalA::sibling_location_of(AssetHubWestend::para_id()).into(); @@ -68,7 +69,10 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { ); // SA-of-Penpal-on-AHR needs to have balance to pay for fees and asset creation deposit - AssetHubWestend::fund_accounts(vec![(para_sovereign_account.clone().into(), ASSET_HUB_WESTEND_ED * 10000000000)]); + AssetHubWestend::fund_accounts(vec![( + para_sovereign_account.clone().into(), + ASSET_HUB_WESTEND_ED * 10000000000, + )]); PenpalA::execute_with(|| { assert_ok!(::PolkadotXcm::send( @@ -111,8 +115,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { } /// We tests two things here: -/// - Parachain should be able to send XCM paying its fee with system assets -/// in the System Parachain +/// - Parachain should be able to send XCM paying its fee with system assets in the System Parachain /// - Parachain should be able to create a new Asset in the System Parachain #[test] fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { @@ -147,15 +150,13 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() { let root_origin = ::RuntimeOrigin::root(); let system_para_destination = PenpalA::sibling_location_of(AssetHubWestend::para_id()).into(); - let xcm = xcm_transact_paid_execution( - call, - origin_kind, - asset, - para_sovereign_account.clone(), - ); + let xcm = xcm_transact_paid_execution(call, origin_kind, asset, para_sovereign_account.clone()); // SA-of-Penpal-on-AHR needs to have balance to pay for asset creation deposit - AssetHubWestend::fund_accounts(vec![(para_sovereign_account.clone().into(), ASSET_HUB_WESTEND_ED * 10000000000)]); + AssetHubWestend::fund_accounts(vec![( + para_sovereign_account.clone().into(), + ASSET_HUB_WESTEND_ED * 10000000000, + )]); PenpalA::execute_with(|| { assert_ok!(::PolkadotXcm::send( From 4590d3e683a648bfb95341b48ea388caed4a0413 Mon Sep 17 00:00:00 2001 From: NachoPal Date: Mon, 4 Mar 2024 16:30:21 +0100 Subject: [PATCH 14/18] make clippy happy --- .../emulated/tests/assets/asset-hub-rococo/src/tests/send.rs | 2 +- .../emulated/tests/assets/asset-hub-westend/src/tests/send.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs index 65a6153f1b992..e96dddcd5059d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs @@ -98,7 +98,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { }, // Foreign Asset created RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { asset_id, creator, owner }) => { - asset_id: *asset_id == foreign_asset_at_asset_hub.clone(), + asset_id: *asset_id == foreign_asset_at_asset_hub, creator: *creator == para_sovereign_account.clone(), owner: *owner == para_sovereign_account, }, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs index 87d612df21ef0..9c9b9306c2da1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs @@ -98,7 +98,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { }, // Foreign Asset created RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { asset_id, creator, owner }) => { - asset_id: *asset_id == foreign_asset_at_asset_hub.clone(), + asset_id: *asset_id == foreign_asset_at_asset_hub, creator: *creator == para_sovereign_account.clone(), owner: *owner == para_sovereign_account, }, From 176f63ef994710093305655d02b92d63df0942a9 Mon Sep 17 00:00:00 2001 From: NachoPal Date: Mon, 11 Mar 2024 17:58:12 +0100 Subject: [PATCH 15/18] address comments --- Cargo.lock | 2 +- .../parachains/testing/penpal/Cargo.toml | 3 + .../parachains/testing/penpal/src/genesis.rs | 9 ++- .../tests/assets/asset-hub-rococo/src/lib.rs | 6 +- .../src/tests/reserve_transfer.rs | 46 ++++++------ .../assets/asset-hub-rococo/src/tests/swap.rs | 5 +- .../asset-hub-rococo/src/tests/teleport.rs | 9 ++- .../tests/assets/asset-hub-westend/src/lib.rs | 6 +- .../src/tests/reserve_transfer.rs | 46 ++++++------ .../asset-hub-westend/src/tests/swap.rs | 5 +- .../asset-hub-westend/src/tests/teleport.rs | 9 ++- .../assets/asset-hub-rococo/src/xcm_config.rs | 18 +++-- .../assets/asset-hub-rococo/tests/tests.rs | 14 ++-- .../asset-hub-westend/src/xcm_config.rs | 18 +++-- .../assets/asset-hub-westend/tests/tests.rs | 10 +-- .../runtimes/assets/common/Cargo.toml | 3 - .../runtimes/assets/common/src/lib.rs | 19 +---- .../runtimes/testing/penpal/src/lib.rs | 6 +- .../runtimes/testing/penpal/src/xcm_config.rs | 75 +++++-------------- 19 files changed, 133 insertions(+), 176 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 949bdecd217f2..52278f269b412 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1095,7 +1095,6 @@ dependencies = [ "impl-trait-for-tuples", "log", "pallet-asset-conversion", - "pallet-assets", "pallet-xcm", "parachains-common", "parity-scale-codec", @@ -11766,6 +11765,7 @@ dependencies = [ "parachains-common", "penpal-runtime", "sp-core", + "staging-xcm", ] [[package]] diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml index ba6996107c98f..f47350b00eb18 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/Cargo.toml @@ -16,6 +16,9 @@ workspace = true sp-core = { path = "../../../../../../../../substrate/primitives/core", default-features = false } frame-support = { path = "../../../../../../../../substrate/frame/support", default-features = false } +# Polkadot +xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false } + # Cumulus parachains-common = { path = "../../../../../../../parachains/common" } cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index 1d4a92a6a9d04..fcd847cdb8531 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -16,12 +16,15 @@ // Substrate use frame_support::parameter_types; use sp_core::{sr25519, storage::Storage}; + +// Polkadot +use xcm::v3::Location; // Cumulus use emulated_integration_tests_common::{ accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION, }; use parachains_common::{AccountId, Balance}; -use penpal_runtime::xcm_config::{LocalReservableFromAssetHubV3, RelayLocationV3}; +use penpal_runtime::xcm_config::{LocalReservableFromAssetHub, RelayLocation}; // Penpal pub const PARA_ID_A: u32 = 2000; pub const PARA_ID_B: u32 = 2001; @@ -76,9 +79,9 @@ pub fn genesis(para_id: u32) -> Storage { foreign_assets: penpal_runtime::ForeignAssetsConfig { assets: vec![ // Relay Native asset representation - (RelayLocationV3::get(), PenpalAssetOwner::get(), true, ED), + (Location::try_from(RelayLocation::get()).expect("conversion works"), PenpalAssetOwner::get(), true, ED), // Sufficient AssetHub asset representation - (LocalReservableFromAssetHubV3::get(), PenpalAssetOwner::get(), true, ED), + (Location::try_from(LocalReservableFromAssetHub::get()).expect("conversion works"), PenpalAssetOwner::get(), true, ED), ], ..Default::default() }, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs index d307cc5faf02d..21d858f1fe514 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs @@ -63,12 +63,12 @@ mod imports { // Runtimes pub use asset_hub_rococo_runtime::xcm_config::{ - TokenLocationV3 as RelayLocationV3, UniversalLocation as AssetHubRococoUniversalLocation, + TokenLocation as RelayLocation, UniversalLocation as AssetHubRococoUniversalLocation, XcmConfig as AssetHubRococoXcmConfig, }; pub use penpal_runtime::xcm_config::{ - LocalReservableFromAssetHubV3 as PenpalLocalReservableFromAssetHubV3, - LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3, + LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub, + LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub, UniversalLocation as PenpalUniversalLocation, XcmConfig as PenpalRococoXcmConfig, }; pub use rococo_runtime::xcm_config::{ diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 3b6f242bbec16..7c4a64ea21165 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -47,7 +47,7 @@ fn para_to_relay_sender_assertions(t: ParaToRelayTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == RelayLocationV3::get(), + asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -87,7 +87,7 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); @@ -112,7 +112,7 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == RelayLocationV3::get(), + asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -211,8 +211,9 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = RelayLocationV3::get(); - let reservable_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let reservable_asset_location + = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); assert_expected_events!( PenpalA, @@ -242,13 +243,13 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let system_para_asset_location = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == RelayLocationV3::get(), + asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), owner: *owner == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { @@ -300,7 +301,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == RelayLocationV3::get(), + asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), owner: *owner == t.receiver.account_id, }, RuntimeEvent::MessageQueue( @@ -313,7 +314,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { fn para_to_para_through_relay_sender_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = RelayLocationV3::get(); + let relay_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcm_pallet_attempted_complete(None); // XCM sent to relay reserve @@ -366,7 +367,7 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = RelayLocationV3::get(); + let relay_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalB::assert_xcmp_queue_success(None); @@ -521,7 +522,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let assets: Assets = (Here, amount_to_send).into(); // Init values fot Parachain - let relay_native_asset_location = RelayLocationV3::get(); + let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let receiver = PenpalAReceiver::get(); // Init Test @@ -580,7 +581,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { let amount_to_send: Balance = ROCOCO_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); let asset_owner = PenpalAssetOwner::get(); - let relay_native_asset_location = RelayLocationV3::get(); + let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); // fund Parachain's sender account PenpalA::mint_foreign_asset( @@ -665,7 +666,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let assets: Assets = (Parent, amount_to_send).into(); // Init values for Parachain - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let receiver = PenpalAReceiver::get(); // Init Test @@ -731,7 +732,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let asset_owner = PenpalAssetOwner::get(); // fund Parachain's sender account @@ -845,8 +846,9 @@ fn reserve_transfer_assets_from_system_para_to_para() { // Init values for Parachain let receiver = PenpalAReceiver::get(); - let system_para_native_asset_location = RelayLocationV3::get(); - let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_foreign_asset_location + = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); // Init Test let para_test_args = TestContext { @@ -930,9 +932,10 @@ fn reserve_transfer_assets_from_para_to_system_para() { let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 10000; let penpal_asset_owner = PenpalAssetOwner::get(); let penpal_asset_owner_signer = ::RuntimeOrigin::signed(penpal_asset_owner); - let asset_location_on_penpal = PenpalLocalReservableFromAssetHubV3::get(); + let asset_location_on_penpal + = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); - let system_asset_location_on_penpal = RelayLocationV3::get(); + let system_asset_location_on_penpal = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), (asset_location_on_penpal_latest, asset_amount_to_send).into(), @@ -962,8 +965,9 @@ fn reserve_transfer_assets_from_para_to_system_para() { let receiver = AssetHubRococoReceiver::get(); let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr); - let system_para_native_asset_location = RelayLocationV3::get(); - let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_foreign_asset_location + = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); let ah_asset_owner = AssetHubRococoAssetOwner::get(); let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); @@ -1058,7 +1062,7 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { let amount_to_send: Balance = ROCOCO_ED * 10000; let asset_owner = PenpalAssetOwner::get(); let assets = (Parent, amount_to_send).into(); - let relay_native_asset_location = RelayLocationV3::get(); + let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let sender_as_seen_by_relay = Rococo::child_location_of(PenpalA::para_id()); let sov_of_sender_on_relay = Rococo::sovereign_account_id_of(sender_as_seen_by_relay); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs index 98cb0138b0297..5f7f0f513091b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs @@ -112,8 +112,9 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new(RelayLocationV3::get()); - let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); + let asset_native = Box::new(v3::Location::try_from(RelayLocation::get()).expect("conversion works")); + let asset_location_on_penpal + = v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); let foreign_asset_at_asset_hub_rococo = v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 278486808bdaf..66a62cc15c278 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -110,7 +110,7 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); @@ -203,7 +203,7 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let checking_account = ::PolkadotXcm::check_account(); - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); @@ -561,14 +561,15 @@ fn teleport_to_other_system_parachains_works() { fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { // Init values for Parachain let fee_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; - let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); + let asset_location_on_penpal + = v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); let asset_id_on_penpal = match asset_location_on_penpal.last() { Some(v3::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 1000; let asset_owner = PenpalAssetOwner::get(); - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let sender = PenpalASender::get(); let penpal_check_account = ::PolkadotXcm::check_account(); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id()); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs index 5d53edc1a86b4..5bd5a126fc3b3 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs @@ -68,11 +68,11 @@ mod imports { // Runtimes pub use asset_hub_westend_runtime::xcm_config::{ UniversalLocation as AssetHubWestendUniversalLocation, - WestendLocationV3 as RelayLocationV3, XcmConfig as AssetHubWestendXcmConfig, + WestendLocation as RelayLocation, XcmConfig as AssetHubWestendXcmConfig, }; pub use penpal_runtime::xcm_config::{ - LocalReservableFromAssetHubV3 as PenpalLocalReservableFromAssetHubV3, - LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3, + LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub, + LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub, UniversalLocation as PenpalUniversalLocation, XcmConfig as PenpalWestendXcmConfig, }; pub use westend_runtime::xcm_config::{ diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index 4116bacd99740..e271efd1e6837 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -47,7 +47,7 @@ fn para_to_relay_sender_assertions(t: ParaToRelayTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == RelayLocationV3::get(), + asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -87,7 +87,7 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); @@ -112,7 +112,7 @@ fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { RuntimeEvent::ForeignAssets( pallet_assets::Event::Burned { asset_id, owner, balance, .. } ) => { - asset_id: *asset_id == RelayLocationV3::get(), + asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), owner: *owner == t.sender.account_id, balance: *balance == t.args.amount, }, @@ -211,8 +211,9 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = RelayLocationV3::get(); - let reservable_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let reservable_asset_location + = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("coversion works"); PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); assert_expected_events!( PenpalA, @@ -242,13 +243,13 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let system_para_asset_location = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("coversion works"); PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == RelayLocationV3::get(), + asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), owner: *owner == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { @@ -300,7 +301,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == RelayLocationV3::get(), + asset_id: *asset_id == v3::Location::try_from(RelayLocation::get()).expect("conversion works"), owner: *owner == t.receiver.account_id, }, RuntimeEvent::MessageQueue( @@ -313,7 +314,7 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { fn para_to_para_through_relay_sender_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = RelayLocationV3::get(); + let relay_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcm_pallet_attempted_complete(None); // XCM sent to relay reserve @@ -366,7 +367,7 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = RelayLocationV3::get(); + let relay_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalB::assert_xcmp_queue_success(None); @@ -521,7 +522,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let assets: Assets = (Here, amount_to_send).into(); // Init values fot Parachain - let relay_native_asset_location = RelayLocationV3::get(); + let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let receiver = PenpalAReceiver::get(); // Init Test @@ -580,7 +581,7 @@ fn reserve_transfer_native_asset_from_para_to_relay() { let amount_to_send: Balance = WESTEND_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); let asset_owner = PenpalAssetOwner::get(); - let relay_native_asset_location = RelayLocationV3::get(); + let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); // fund Parachain's sender account PenpalA::mint_foreign_asset( @@ -665,7 +666,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let assets: Assets = (Parent, amount_to_send).into(); // Init values for Parachain - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let receiver = PenpalAReceiver::get(); // Init Test @@ -731,7 +732,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let asset_owner = PenpalAssetOwner::get(); // fund Parachain's sender account @@ -846,8 +847,9 @@ fn reserve_transfer_assets_from_system_para_to_para() { // Init values for Parachain let receiver = PenpalAReceiver::get(); - let system_para_native_asset_location = RelayLocationV3::get(); - let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_foreign_asset_location + = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); // Init Test let para_test_args = TestContext { @@ -931,9 +933,10 @@ fn reserve_transfer_assets_from_para_to_system_para() { let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; let penpal_asset_owner = PenpalAssetOwner::get(); let penpal_asset_owner_signer = ::RuntimeOrigin::signed(penpal_asset_owner); - let asset_location_on_penpal = PenpalLocalReservableFromAssetHubV3::get(); + let asset_location_on_penpal + = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); - let system_asset_location_on_penpal = RelayLocationV3::get(); + let system_asset_location_on_penpal = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), (asset_location_on_penpal_latest, asset_amount_to_send).into(), @@ -964,8 +967,9 @@ fn reserve_transfer_assets_from_para_to_system_para() { let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); - let system_para_native_asset_location = RelayLocationV3::get(); - let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHubV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_foreign_asset_location + = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); let ah_asset_owner = AssetHubWestendAssetOwner::get(); let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); @@ -1060,7 +1064,7 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { let amount_to_send: Balance = WESTEND_ED * 10000; let asset_owner = PenpalAssetOwner::get(); let assets = (Parent, amount_to_send).into(); - let relay_native_asset_location = RelayLocationV3::get(); + let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let sender_as_seen_by_relay = Westend::child_location_of(PenpalA::para_id()); let sov_of_sender_on_relay = Westend::sovereign_account_id_of(sender_as_seen_by_relay); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index f5daf50c5f3dc..89acbe096e1a1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -111,8 +111,9 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new(RelayLocationV3::get()); - let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); + let asset_native = Box::new(v3::Location::try_from(RelayLocation::get()).expect("conversion works")); + let asset_location_on_penpal + = v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion_works"); let foreign_asset_at_asset_hub_westend = v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 08c2d98a4c948..849fbb9730576 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -110,7 +110,7 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); @@ -203,7 +203,7 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let checking_account = ::PolkadotXcm::check_account(); - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); @@ -561,14 +561,15 @@ fn teleport_to_other_system_parachains_works() { fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { // Init values for Parachain let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 100; - let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get(); + let asset_location_on_penpal + = v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); let asset_id_on_penpal = match asset_location_on_penpal.last() { Some(v3::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; let asset_owner = PenpalAssetOwner::get(); - let system_para_native_asset_location = RelayLocationV3::get(); + let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let sender = PenpalASender::get(); let penpal_check_account = ::PolkadotXcm::check_account(); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubWestend::para_id()); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 177880a51f237..2584dbdf31062 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -22,7 +22,7 @@ use super::{ }; use assets_common::{ matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset}, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, TrustBackedAssetsAsLocation, + TrustBackedAssetsAsLocation, }; use frame_support::{ parameter_types, @@ -520,6 +520,15 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; +/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. +pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = + AssetFeeAsExistentialDepositMultiplier< + Runtime, + WeightToFee, + pallet_assets::BalanceToAssetBalance, + ForeignAssetsInstance, + >; + /// Locations that will not be charged fees in the executor, /// either execution or delivery. /// We only waive fees for system functions, which these locations represent. @@ -590,12 +599,7 @@ impl xcm_executor::Config for XcmConfig { // `pallet_assets` instance - `ForeignAssets`. cumulus_primitives_utility::TakeFirstAssetTrader< AccountId, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger< - Runtime, - WeightToFee, - Balances, - ForeignAssetsInstance, - >, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignAssetsConvertedConcreteId, ForeignAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index eeba95df1dcdc..45d230c4ac346 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -23,7 +23,7 @@ use asset_hub_rococo_runtime::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, ForeignCreatorsSovereignAccountOf, LocationToAccountId, StakingPot, TokenLocation, TokenLocationV3, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, - XcmConfig, + XcmConfig, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger }, AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, @@ -34,7 +34,6 @@ use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder, SlotDurations, }; -use assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger; use codec::{Decode, Encode}; use cumulus_primitives_utility::ChargeWeightInFungibles; use frame_support::{ @@ -528,12 +527,11 @@ fn test_foreign_asset_xcm_take_first_trader() { let bought = Weight::from_parts(4_000_000_000u64, 0); // Lets calculate amount needed - let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::< - Runtime, - WeightToFee, - Balances, - ForeignAssetsInstance, - >::charge_weight_in_fungibles(foreign_location, bought) + let asset_amount_needed + = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles( + foreign_location, + bought + ) .expect("failed to compute"); // Lets pay with: asset_amount_needed + asset_amount_extra diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 7d64598f3de40..50865c0006117 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -22,7 +22,7 @@ use super::{ }; use assets_common::{ matching::{FromSiblingParachain, IsForeignConcreteAsset}, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, TrustBackedAssetsAsLocation, + TrustBackedAssetsAsLocation, }; use frame_support::{ parameter_types, @@ -543,6 +543,15 @@ pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentia TrustBackedAssetsInstance, >; +/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. +pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = + AssetFeeAsExistentialDepositMultiplier< + Runtime, + WeightToFee, + pallet_assets::BalanceToAssetBalance, + ForeignAssetsInstance, + >; + /// Locations that will not be charged fees in the executor, /// either execution or delivery. /// We only waive fees for system functions, which these locations represent. @@ -612,12 +621,7 @@ impl xcm_executor::Config for XcmConfig { // `pallet_assets` instance - `ForeignAssets`. cumulus_primitives_utility::TakeFirstAssetTrader< AccountId, - ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger< - Runtime, - WeightToFee, - Balances, - ForeignAssetsInstance, - >, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignAssetsConvertedConcreteId, ForeignAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index 3a3ff3d2b6652..a26e511fa633a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -23,7 +23,7 @@ use asset_hub_westend_runtime::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, ForeignCreatorsSovereignAccountOf, LocationToAccountId, StakingPot, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, WestendLocation, - WestendLocationV3, XcmConfig, + WestendLocationV3, XcmConfig, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger }, AllPalletsWithoutSystem, Assets, Balances, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, @@ -35,7 +35,6 @@ use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder, SlotDurations, }; -use assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger; use codec::{Decode, Encode}; use cumulus_primitives_utility::ChargeWeightInFungibles; use frame_support::{ @@ -528,12 +527,7 @@ fn test_foreign_asset_xcm_take_first_trader() { let bought = Weight::from_parts(4_000_000_000u64, 0); // Lets calculate amount needed - let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::< - Runtime, - WeightToFee, - Balances, - ForeignAssetsInstance, - >::charge_weight_in_fungibles(foreign_location, bought) + let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles(foreign_location, bought) .expect("failed to compute"); // Lets pay with: asset_amount_needed + asset_amount_extra diff --git a/cumulus/parachains/runtimes/assets/common/Cargo.toml b/cumulus/parachains/runtimes/assets/common/Cargo.toml index 8f6d28b82d91f..c9252375cfbf0 100644 --- a/cumulus/parachains/runtimes/assets/common/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/common/Cargo.toml @@ -21,7 +21,6 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-std = { path = "../../../../../substrate/primitives/std", default-features = false } sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false } pallet-asset-conversion = { path = "../../../../../substrate/frame/asset-conversion", default-features = false } -pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false } # Polkadot pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features = false } @@ -44,7 +43,6 @@ std = [ "frame-support/std", "log/std", "pallet-asset-conversion/std", - "pallet-assets/std", "pallet-xcm/std", "parachains-common/std", "scale-info/std", @@ -60,7 +58,6 @@ runtime-benchmarks = [ "cumulus-primitives-core/runtime-benchmarks", "frame-support/runtime-benchmarks", "pallet-asset-conversion/runtime-benchmarks", - "pallet-assets/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index c3fa5656a7074..fa2752179eb6f 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -25,11 +25,7 @@ pub mod runtime_api; use crate::matching::{LocalLocationPattern, ParentLocation}; use frame_support::traits::{Equals, EverythingBut}; -use parachains_common::{ - xcm_config::AssetFeeAsExistentialDepositMultiplier, AssetIdForTrustBackedAssets, CollectionId, - ItemId, -}; -use sp_runtime::traits::ConvertInto; +use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId}; use xcm_builder::{ AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, V4V3LocationConverter, }; @@ -129,19 +125,6 @@ pub type PoolAssetsConvertedConcreteId = JustTry, >; -/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. -pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger< - Runtime, - WeightToFee, - Balances, - ForeignAssetsInstance, -> = AssetFeeAsExistentialDepositMultiplier< - Runtime, - WeightToFee, - pallet_assets::BalanceToAssetBalance, - ForeignAssetsInstance, ->; - #[cfg(test)] mod tests { use super::*; diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 0030287edb3b6..bdba7b7873f80 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -53,7 +53,7 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; +use parachains_common::{impls::{AssetsToBlockAuthor, NonZeroIssuance}, message_queue::{NarrowOriginToSibling, ParaIdToSibling}}; use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use smallvec::smallvec; use sp_api::impl_runtime_apis; @@ -70,7 +70,7 @@ use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use xcm_config::{AssetsToBlockAuthor, XcmOriginToTransactDispatchOrigin}; +use xcm_config::XcmOriginToTransactDispatchOrigin; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -618,7 +618,7 @@ impl pallet_asset_tx_payment::Config for Runtime { ConvertInto, pallet_assets::Instance1, >, - AssetsToBlockAuthor, + AssetsToBlockAuthor, >; } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index f14bd5fdb2c2d..ced57f275238c 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -26,23 +26,21 @@ use super::{ AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Assets, Authorship, Balance, Balances, ForeignAssets, ForeignAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + NonZeroIssuance, }; use core::marker::PhantomData; use frame_support::{ parameter_types, traits::{ - fungibles::{self, Balanced, Credit}, ConstU32, Contains, ContainsPair, Everything, EverythingBut, Get, Nothing, }, weights::Weight, }; use frame_system::EnsureRoot; -use pallet_asset_tx_payment::HandleCredit; -use pallet_assets::Instance1; use pallet_xcm::XcmPassthrough; +use parachains_common::xcm_config::AssetFeeAsExistentialDepositMultiplier; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; -use sp_runtime::traits::Zero; use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork; use xcm::latest::prelude::*; use xcm_builder::{ @@ -55,10 +53,13 @@ use xcm_builder::{ TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::{traits::JustTry, XcmExecutor}; +use sp_runtime::traits::ConvertInto; + parameter_types! { pub const RelayLocation: Location = Location::parent(); - pub const NativeCurrency: Location = Location::here(); + // Local native currency which is stored in `pallet_balances`` + pub const PenpalNativeCurrency: Location = Location::here(); pub const RelayNetwork: Option = None; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = [Parachain(ParachainInfo::parachain_id().into())].into(); @@ -81,7 +82,7 @@ pub type CurrencyTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, + IsConcrete, // Do a simple punn to convert an AccountId32 Location into a native chain account ID: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -193,13 +194,6 @@ impl Contains for ParentOrParentsExecutivePlurality { } } -pub struct CommonGoodAssetsParachain; -impl Contains for CommonGoodAssetsParachain { - fn contains(location: &Location) -> bool { - matches!(location.unpack(), (1, [Parachain(ASSET_HUB_ID)])) - } -} - pub type Barrier = TrailingSetTopicAsId<( TakeWeightCredit, // Expected responses are OK. @@ -249,34 +243,6 @@ impl> ContainsPair for NativeAssetFrom { } } -/// Allow checking in assets that have issuance > 0. -pub struct NonZeroIssuance(PhantomData<(AccountId, Assets)>); -impl Contains<>::AssetId> - for NonZeroIssuance -where - Assets: fungibles::Inspect, -{ - fn contains(id: &>::AssetId) -> bool { - !Assets::total_issuance(id.clone()).is_zero() - } -} - -/// A `HandleCredit` implementation that naively transfers the fees to the block author. -/// Will drop and burn the assets in case the transfer fails. -pub struct AssetsToBlockAuthor(PhantomData); -impl HandleCredit, pallet_assets::Pallet> for AssetsToBlockAuthor -where - R: pallet_authorship::Config + pallet_assets::Config, - AccountIdOf: From + Into, -{ - fn handle_credit(credit: Credit, pallet_assets::Pallet>) { - if let Some(author) = pallet_authorship::Pallet::::author() { - // In case of error: Will drop the result triggering the `OnDrop` of the imbalance. - let _ = pallet_assets::Pallet::::resolve(&author, credit); - } - } -} - // This asset can be added to AH as Asset and reserved transfer between Penpal and AH pub const RESERVABLE_ASSET_ID: u32 = 1; // This asset can be added to AH as ForeignAsset and teleported between Penpal and AH @@ -288,9 +254,6 @@ pub const ASSET_HUB_ID: u32 = 1000; parameter_types! { /// The location that this chain recognizes as the Relay network's Asset Hub. pub SystemAssetHubLocation: Location = Location::new(1, [Parachain(ASSET_HUB_ID)]); - pub SystemAssetHubLocationV3: xcm::v3::Location = xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(ASSET_HUB_ID)]); - pub RelayLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); - // ALWAYS ensure that the index in PalletInstance stays up-to-date with // the Relay Chain's Asset Hub's Assets pallet index pub SystemAssetHubAssetsPalletLocation: Location = Location::new(1, [Parachain(ASSET_HUB_ID), PalletInstance(ASSETS_PALLET_ID)]); @@ -301,18 +264,10 @@ parameter_types! { 0, [PalletInstance(ASSETS_PALLET_ID), GeneralIndex(TELEPORTABLE_ASSET_ID.into())] ); - pub LocalTeleportableToAssetHubV3: xcm::v3::Location = xcm::v3::Location::new( - 0, - [xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), xcm::v3::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into())] - ); pub LocalReservableFromAssetHub: Location = Location::new( 1, [Parachain(ASSET_HUB_ID), PalletInstance(ASSETS_PALLET_ID), GeneralIndex(RESERVABLE_ASSET_ID.into())] ); - pub LocalReservableFromAssetHubV3: xcm::v3::Location = xcm::v3::Location::new( - 1, - [xcm::v3::Junction::Parachain(ASSET_HUB_ID), xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), xcm::v3::Junction::GeneralIndex(RESERVABLE_ASSET_ID.into())] - ); pub EthereumLocation: Location = Location::new(2, [GlobalConsensus(EthereumNetwork::get())]); } @@ -356,12 +311,7 @@ impl xcm_executor::Config for XcmConfig { // `pallet_assets` instance - `ForeignAssets`. cumulus_primitives_utility::TakeFirstAssetTrader< AccountId, - assets_common::ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger< - Runtime, - WeightToFee, - Balances, - ForeignAssetsInstance, - >, + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignAssetsConvertedConcreteId, ForeignAssets, cumulus_primitives_utility::XcmFeesTo32ByteAccount< @@ -388,6 +338,15 @@ impl xcm_executor::Config for XcmConfig { type TransactionalProcessor = FrameTransactionalProcessor; } +/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance. +pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger = + AssetFeeAsExistentialDepositMultiplier< + Runtime, + WeightToFee, + pallet_assets::BalanceToAssetBalance, + ForeignAssetsInstance, + >; + /// No local origins on this chain are allowed to dispatch XCM sends/executions. pub type LocalOriginToLocation = SignedToAccountId32; From e9614a3a812dead24bd53e9c8092746190414006 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 11 Mar 2024 17:09:49 +0000 Subject: [PATCH 16/18] ".git/.scripts/commands/fmt/fmt.sh" --- .../parachains/testing/penpal/src/genesis.rs | 15 ++++- .../src/tests/reserve_transfer.rs | 55 ++++++++++++------- .../assets/asset-hub-rococo/src/tests/swap.rs | 7 ++- .../asset-hub-rococo/src/tests/teleport.rs | 13 +++-- .../tests/assets/asset-hub-westend/src/lib.rs | 4 +- .../src/tests/reserve_transfer.rs | 55 ++++++++++++------- .../asset-hub-westend/src/tests/swap.rs | 7 ++- .../asset-hub-westend/src/tests/teleport.rs | 13 +++-- .../assets/asset-hub-rococo/tests/tests.rs | 6 +- .../assets/asset-hub-westend/tests/tests.rs | 6 +- .../runtimes/testing/penpal/src/lib.rs | 5 +- .../runtimes/testing/penpal/src/xcm_config.rs | 14 ++--- 12 files changed, 122 insertions(+), 78 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index fcd847cdb8531..48901647fd052 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -79,9 +79,20 @@ pub fn genesis(para_id: u32) -> Storage { foreign_assets: penpal_runtime::ForeignAssetsConfig { assets: vec![ // Relay Native asset representation - (Location::try_from(RelayLocation::get()).expect("conversion works"), PenpalAssetOwner::get(), true, ED), + ( + Location::try_from(RelayLocation::get()).expect("conversion works"), + PenpalAssetOwner::get(), + true, + ED, + ), // Sufficient AssetHub asset representation - (Location::try_from(LocalReservableFromAssetHub::get()).expect("conversion works"), PenpalAssetOwner::get(), true, ED), + ( + Location::try_from(LocalReservableFromAssetHub::get()) + .expect("conversion works"), + PenpalAssetOwner::get(), + true, + ED, + ), ], ..Default::default() }, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 7c4a64ea21165..705c9613b647a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -87,7 +87,8 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); @@ -211,9 +212,10 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let reservable_asset_location - = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let reservable_asset_location = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); assert_expected_events!( PenpalA, @@ -243,7 +245,8 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_asset_location = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_asset_location = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( PenpalA, @@ -314,7 +317,8 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { fn para_to_para_through_relay_sender_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcm_pallet_attempted_complete(None); // XCM sent to relay reserve @@ -367,7 +371,8 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalB::assert_xcmp_queue_success(None); @@ -522,7 +527,8 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let assets: Assets = (Here, amount_to_send).into(); // Init values fot Parachain - let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let receiver = PenpalAReceiver::get(); // Init Test @@ -581,7 +587,8 @@ fn reserve_transfer_native_asset_from_para_to_relay() { let amount_to_send: Balance = ROCOCO_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); let asset_owner = PenpalAssetOwner::get(); - let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); // fund Parachain's sender account PenpalA::mint_foreign_asset( @@ -666,7 +673,8 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let assets: Assets = (Parent, amount_to_send).into(); // Init values for Parachain - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let receiver = PenpalAReceiver::get(); // Init Test @@ -732,7 +740,8 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let asset_owner = PenpalAssetOwner::get(); // fund Parachain's sender account @@ -846,9 +855,10 @@ fn reserve_transfer_assets_from_system_para_to_para() { // Init values for Parachain let receiver = PenpalAReceiver::get(); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let system_para_foreign_asset_location - = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_foreign_asset_location = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); // Init Test let para_test_args = TestContext { @@ -932,10 +942,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 10000; let penpal_asset_owner = PenpalAssetOwner::get(); let penpal_asset_owner_signer = ::RuntimeOrigin::signed(penpal_asset_owner); - let asset_location_on_penpal - = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let asset_location_on_penpal = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); - let system_asset_location_on_penpal = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_asset_location_on_penpal = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), (asset_location_on_penpal_latest, asset_amount_to_send).into(), @@ -965,9 +976,10 @@ fn reserve_transfer_assets_from_para_to_system_para() { let receiver = AssetHubRococoReceiver::get(); let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let system_para_foreign_asset_location - = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_foreign_asset_location = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); let ah_asset_owner = AssetHubRococoAssetOwner::get(); let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); @@ -1062,7 +1074,8 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { let amount_to_send: Balance = ROCOCO_ED * 10000; let asset_owner = PenpalAssetOwner::get(); let assets = (Parent, amount_to_send).into(); - let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let sender_as_seen_by_relay = Rococo::child_location_of(PenpalA::para_id()); let sov_of_sender_on_relay = Rococo::sovereign_account_id_of(sender_as_seen_by_relay); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs index 5f7f0f513091b..87f0b3d9f90a6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs @@ -112,9 +112,10 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new(v3::Location::try_from(RelayLocation::get()).expect("conversion works")); - let asset_location_on_penpal - = v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); + let asset_native = + Box::new(v3::Location::try_from(RelayLocation::get()).expect("conversion works")); + let asset_location_on_penpal = + v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); let foreign_asset_at_asset_hub_rococo = v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 66a62cc15c278..0cc5ddb9f64d3 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -110,7 +110,8 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); @@ -203,7 +204,8 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let checking_account = ::PolkadotXcm::check_account(); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); @@ -561,15 +563,16 @@ fn teleport_to_other_system_parachains_works() { fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { // Init values for Parachain let fee_amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000; - let asset_location_on_penpal - = v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); + let asset_location_on_penpal = + v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); let asset_id_on_penpal = match asset_location_on_penpal.last() { Some(v3::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 1000; let asset_owner = PenpalAssetOwner::get(); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let sender = PenpalASender::get(); let penpal_check_account = ::PolkadotXcm::check_account(); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id()); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs index 5bd5a126fc3b3..3f899d1dbdbcb 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs @@ -67,8 +67,8 @@ mod imports { // Runtimes pub use asset_hub_westend_runtime::xcm_config::{ - UniversalLocation as AssetHubWestendUniversalLocation, - WestendLocation as RelayLocation, XcmConfig as AssetHubWestendXcmConfig, + UniversalLocation as AssetHubWestendUniversalLocation, WestendLocation as RelayLocation, + XcmConfig as AssetHubWestendXcmConfig, }; pub use penpal_runtime::xcm_config::{ LocalReservableFromAssetHub as PenpalLocalReservableFromAssetHub, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index e271efd1e6837..8c836132b5469 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -87,7 +87,8 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) { fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); @@ -211,9 +212,10 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let reservable_asset_location - = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("coversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let reservable_asset_location = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("coversion works"); PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); assert_expected_events!( PenpalA, @@ -243,7 +245,8 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { fn system_para_to_para_assets_receiver_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_asset_location = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("coversion works"); + let system_para_asset_location = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("coversion works"); PenpalA::assert_xcmp_queue_success(None); assert_expected_events!( PenpalA, @@ -314,7 +317,8 @@ fn relay_to_para_assets_receiver_assertions(t: RelayToParaTest) { fn para_to_para_through_relay_sender_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcm_pallet_attempted_complete(None); // XCM sent to relay reserve @@ -367,7 +371,8 @@ fn para_to_para_relay_hop_assertions(t: ParaToParaThroughRelayTest) { fn para_to_para_through_relay_receiver_assertions(t: ParaToParaThroughRelayTest) { type RuntimeEvent = ::RuntimeEvent; - let relay_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalB::assert_xcmp_queue_success(None); @@ -522,7 +527,8 @@ fn reserve_transfer_native_asset_from_relay_to_para() { let assets: Assets = (Here, amount_to_send).into(); // Init values fot Parachain - let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let receiver = PenpalAReceiver::get(); // Init Test @@ -581,7 +587,8 @@ fn reserve_transfer_native_asset_from_para_to_relay() { let amount_to_send: Balance = WESTEND_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); let asset_owner = PenpalAssetOwner::get(); - let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); // fund Parachain's sender account PenpalA::mint_foreign_asset( @@ -666,7 +673,8 @@ fn reserve_transfer_native_asset_from_system_para_to_para() { let assets: Assets = (Parent, amount_to_send).into(); // Init values for Parachain - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let receiver = PenpalAReceiver::get(); // Init Test @@ -732,7 +740,8 @@ fn reserve_transfer_native_asset_from_para_to_system_para() { let sender = PenpalASender::get(); let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000; let assets: Assets = (Parent, amount_to_send).into(); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let asset_owner = PenpalAssetOwner::get(); // fund Parachain's sender account @@ -847,9 +856,10 @@ fn reserve_transfer_assets_from_system_para_to_para() { // Init values for Parachain let receiver = PenpalAReceiver::get(); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let system_para_foreign_asset_location - = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_foreign_asset_location = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); // Init Test let para_test_args = TestContext { @@ -933,10 +943,11 @@ fn reserve_transfer_assets_from_para_to_system_para() { let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; let penpal_asset_owner = PenpalAssetOwner::get(); let penpal_asset_owner_signer = ::RuntimeOrigin::signed(penpal_asset_owner); - let asset_location_on_penpal - = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let asset_location_on_penpal = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap(); - let system_asset_location_on_penpal = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_asset_location_on_penpal = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let assets: Assets = vec![ (Parent, fee_amount_to_send).into(), (asset_location_on_penpal_latest, asset_amount_to_send).into(), @@ -967,9 +978,10 @@ fn reserve_transfer_assets_from_para_to_system_para() { let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let system_para_foreign_asset_location - = v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_foreign_asset_location = + v3::Location::try_from(PenpalLocalReservableFromAssetHub::get()).expect("conversion works"); let ah_asset_owner = AssetHubWestendAssetOwner::get(); let ah_asset_owner_signer = ::RuntimeOrigin::signed(ah_asset_owner); @@ -1064,7 +1076,8 @@ fn reserve_transfer_native_asset_from_para_to_para_trough_relay() { let amount_to_send: Balance = WESTEND_ED * 10000; let asset_owner = PenpalAssetOwner::get(); let assets = (Parent, amount_to_send).into(); - let relay_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let relay_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let sender_as_seen_by_relay = Westend::child_location_of(PenpalA::para_id()); let sov_of_sender_on_relay = Westend::sovereign_account_id_of(sender_as_seen_by_relay); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index 89acbe096e1a1..04740d3115834 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -111,9 +111,10 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new(v3::Location::try_from(RelayLocation::get()).expect("conversion works")); - let asset_location_on_penpal - = v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion_works"); + let asset_native = + Box::new(v3::Location::try_from(RelayLocation::get()).expect("conversion works")); + let asset_location_on_penpal = + v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion_works"); let foreign_asset_at_asset_hub_westend = v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 849fbb9730576..61f547fe7c5ec 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -110,7 +110,8 @@ fn para_dest_assertions(t: RelayToSystemParaTest) { fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let expected_asset_id = t.args.asset_id.unwrap(); let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); @@ -203,7 +204,8 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { let (_, expected_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); let checking_account = ::PolkadotXcm::check_account(); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); PenpalA::assert_xcmp_queue_success(None); @@ -561,15 +563,16 @@ fn teleport_to_other_system_parachains_works() { fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() { // Init values for Parachain let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 100; - let asset_location_on_penpal - = v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); + let asset_location_on_penpal = + v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works"); let asset_id_on_penpal = match asset_location_on_penpal.last() { Some(v3::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100; let asset_owner = PenpalAssetOwner::get(); - let system_para_native_asset_location = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); + let system_para_native_asset_location = + v3::Location::try_from(RelayLocation::get()).expect("conversion works"); let sender = PenpalASender::get(); let penpal_check_account = ::PolkadotXcm::check_account(); let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubWestend::para_id()); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index 45d230c4ac346..5fa7455ad2a0b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -21,9 +21,9 @@ use asset_hub_rococo_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignCreatorsSovereignAccountOf, LocationToAccountId, StakingPot, TokenLocation, - TokenLocationV3, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, - XcmConfig, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf, + LocationToAccountId, StakingPot, TokenLocation, TokenLocationV3, + TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, XcmConfig, }, AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index a26e511fa633a..3ba9b9587d888 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -21,9 +21,9 @@ use asset_hub_westend_runtime::{ xcm_config, xcm_config::{ bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignCreatorsSovereignAccountOf, LocationToAccountId, StakingPot, - TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, WestendLocation, - WestendLocationV3, XcmConfig, ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger + ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf, + LocationToAccountId, StakingPot, TrustBackedAssetsPalletLocation, + TrustBackedAssetsPalletLocationV3, WestendLocation, WestendLocationV3, XcmConfig, }, AllPalletsWithoutSystem, Assets, Balances, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index a6ddb58cce2a4..8ca6cac4d0c08 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -53,7 +53,10 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -use parachains_common::{impls::{AssetsToBlockAuthor, NonZeroIssuance}, message_queue::{NarrowOriginToSibling, ParaIdToSibling}}; +use parachains_common::{ + impls::{AssetsToBlockAuthor, NonZeroIssuance}, + message_queue::{NarrowOriginToSibling, ParaIdToSibling}, +}; use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use smallvec::smallvec; use sp_api::impl_runtime_apis; diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index 2a50217353405..0471e2bad54f6 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -24,16 +24,14 @@ //! soon. use super::{ AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Assets, Authorship, Balance, - Balances, ForeignAssets, ForeignAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, - NonZeroIssuance, + Balances, ForeignAssets, ForeignAssetsInstance, NonZeroIssuance, ParachainInfo, + ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, + XcmpQueue, }; use core::marker::PhantomData; use frame_support::{ parameter_types, - traits::{ - ConstU32, Contains, ContainsPair, Everything, EverythingBut, Get, Nothing, - }, + traits::{ConstU32, Contains, ContainsPair, Everything, EverythingBut, Get, Nothing}, weights::Weight, }; use frame_system::EnsureRoot; @@ -41,8 +39,8 @@ use pallet_xcm::XcmPassthrough; use parachains_common::xcm_config::AssetFeeAsExistentialDepositMultiplier; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; +use sp_runtime::traits::{ConvertInto, Zero}; use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork; -use sp_runtime::traits::Zero; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, @@ -54,8 +52,6 @@ use xcm_builder::{ TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::{traits::JustTry, XcmExecutor}; -use sp_runtime::traits::ConvertInto; - parameter_types! { pub const RelayLocation: Location = Location::parent(); From 30f80ad566ecba7286bfc37222b93e49615669db Mon Sep 17 00:00:00 2001 From: NachoPal Date: Mon, 11 Mar 2024 18:27:12 +0100 Subject: [PATCH 17/18] fix --- cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs index 0471e2bad54f6..bc1aa05a61774 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs @@ -39,8 +39,7 @@ use pallet_xcm::XcmPassthrough; use parachains_common::xcm_config::AssetFeeAsExistentialDepositMultiplier; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; -use sp_runtime::traits::{ConvertInto, Zero}; -use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork; +use sp_runtime::traits::ConvertInto; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, From 3af08a5046afb5206e2bf13ae01386719b4afb34 Mon Sep 17 00:00:00 2001 From: NachoPal Date: Mon, 11 Mar 2024 20:02:42 +0100 Subject: [PATCH 18/18] clippy --- .../emulated/chains/parachains/testing/penpal/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs index c12dad68c740a..651b3a5230676 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs @@ -16,8 +16,7 @@ mod genesis; pub use genesis::{genesis, PenpalAssetOwner, PenpalSudoAcccount, ED, PARA_ID_A, PARA_ID_B}; pub use penpal_runtime::xcm_config::{ - CustomizableAssetFromSystemAssetHub, LocalTeleportableToAssetHub, - LocalTeleportableToAssetHubV3, XcmConfig, + CustomizableAssetFromSystemAssetHub, LocalTeleportableToAssetHub, XcmConfig, }; // Substrate