From fc8bcb0f7d8aad88dc710c36efea88c7006f3e96 Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 11 Mar 2024 17:05:14 +0100 Subject: [PATCH 01/14] balance conversion implementation for native asset --- relay/kusama/src/impls.rs | 53 +++++++++++++++++++ relay/kusama/src/lib.rs | 4 +- relay/polkadot/src/impls.rs | 53 +++++++++++++++++++ relay/polkadot/src/lib.rs | 4 +- .../src/fellowship/mod.rs | 2 +- .../collectives-polkadot/src/impls.rs | 52 +++++++++++++++++- 6 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 relay/kusama/src/impls.rs create mode 100644 relay/polkadot/src/impls.rs diff --git a/relay/kusama/src/impls.rs b/relay/kusama/src/impls.rs new file mode 100644 index 0000000000..3d582565fd --- /dev/null +++ b/relay/kusama/src/impls.rs @@ -0,0 +1,53 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +use super::*; +use core::marker::PhantomData; +use frame_support::traits::{tokens::ConversionFromAssetBalance, Contains}; +use primitives::Id as ParaId; +use xcm_builder::IsChildSystemParachain; + +/// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without +/// conversion; otherwise, delegates to the implementation specified by `I`. +pub struct NativeOnSystemParachain(PhantomData); +impl ConversionFromAssetBalance + for NativeOnSystemParachain +where + I: ConversionFromAssetBalance, +{ + type Error = (); + fn from_asset_balance( + balance: Balance, + asset_kind: VersionedLocatableAsset, + ) -> Result { + use VersionedLocatableAsset::*; + let (location, asset_id) = match asset_kind.clone() { + V3 { location, asset_id } => (location.try_into()?, asset_id.try_into()?), + V4 { location, asset_id } => (location, asset_id), + }; + if asset_id.0.contains_parents_only(1) && + IsChildSystemParachain::::contains(&location) + { + Ok(balance) + } else { + I::from_asset_balance(balance, asset_kind).map_err(|_| ()) + } + } + #[cfg(feature = "runtime-benchmarks")] + fn ensure_successful(asset_kind: VersionedLocatableAsset) { + I::ensure_successful(asset_kind) + } +} diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index e8e1a0b0a0..fedcef25db 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -142,6 +142,8 @@ use governance::{ Treasurer, TreasurySpender, }; +pub mod impls; + #[cfg(test)] mod tests; @@ -808,7 +810,7 @@ impl pallet_treasury::Config for Runtime { LocatableAssetConverter, VersionedLocationConverter, >; - type BalanceConverter = AssetRate; + type BalanceConverter = impls::NativeOnSystemParachain; type PayoutPeriod = PayoutSpendPeriod; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = runtime_common::impls::benchmarks::TreasuryArguments; diff --git a/relay/polkadot/src/impls.rs b/relay/polkadot/src/impls.rs new file mode 100644 index 0000000000..3d582565fd --- /dev/null +++ b/relay/polkadot/src/impls.rs @@ -0,0 +1,53 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +use super::*; +use core::marker::PhantomData; +use frame_support::traits::{tokens::ConversionFromAssetBalance, Contains}; +use primitives::Id as ParaId; +use xcm_builder::IsChildSystemParachain; + +/// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without +/// conversion; otherwise, delegates to the implementation specified by `I`. +pub struct NativeOnSystemParachain(PhantomData); +impl ConversionFromAssetBalance + for NativeOnSystemParachain +where + I: ConversionFromAssetBalance, +{ + type Error = (); + fn from_asset_balance( + balance: Balance, + asset_kind: VersionedLocatableAsset, + ) -> Result { + use VersionedLocatableAsset::*; + let (location, asset_id) = match asset_kind.clone() { + V3 { location, asset_id } => (location.try_into()?, asset_id.try_into()?), + V4 { location, asset_id } => (location, asset_id), + }; + if asset_id.0.contains_parents_only(1) && + IsChildSystemParachain::::contains(&location) + { + Ok(balance) + } else { + I::from_asset_balance(balance, asset_kind).map_err(|_| ()) + } + } + #[cfg(feature = "runtime-benchmarks")] + fn ensure_successful(asset_kind: VersionedLocatableAsset) { + I::ensure_successful(asset_kind) + } +} diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index f46ec66e4c..d7493e23ad 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -125,7 +125,7 @@ use governance::{ pallet_custom_origins, AuctionAdmin, FellowshipAdmin, GeneralAdmin, LeaseAdmin, StakingAdmin, Treasurer, TreasurySpender, }; - +pub mod impls; pub mod xcm_config; pub const LOG_TARGET: &'static str = "runtime::polkadot"; @@ -891,7 +891,7 @@ impl pallet_treasury::Config for Runtime { LocatableAssetConverter, VersionedLocationConverter, >; - type BalanceConverter = AssetRate; + type BalanceConverter = impls::NativeOnSystemParachain; type PayoutPeriod = PayoutSpendPeriod; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = runtime_common::impls::benchmarks::TreasuryArguments; diff --git a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs index 3505587d19..67994efdd8 100644 --- a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -352,7 +352,7 @@ impl pallet_treasury::Config for Runtime { type Paymaster = FellowshipTreasuryPaymaster; #[cfg(feature = "runtime-benchmarks")] type Paymaster = PayWithEnsure>>; - type BalanceConverter = AssetRate; + type BalanceConverter = crate::impls::NativeOnSiblingParachain; type PayoutPeriod = ConstU32<{ 30 * DAYS }>; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = polkadot_runtime_common::impls::benchmarks::TreasuryArguments< diff --git a/system-parachains/collectives/collectives-polkadot/src/impls.rs b/system-parachains/collectives/collectives-polkadot/src/impls.rs index d4f1fd8ecc..9426c3648d 100644 --- a/system-parachains/collectives/collectives-polkadot/src/impls.rs +++ b/system-parachains/collectives/collectives-polkadot/src/impls.rs @@ -13,15 +13,20 @@ // See the License for the specific language governing permissions and // limitations under the License. +use super::*; use crate::OriginCaller; use frame_support::{ dispatch::DispatchResultWithPostInfo, - traits::{Currency, Get, Imbalance, OnUnbalanced, OriginTrait, PrivilegeCmp}, + traits::{ + tokens::ConversionFromAssetBalance, Contains, Currency, Get, Imbalance, OnUnbalanced, + OriginTrait, PrivilegeCmp, + }, weights::Weight, }; use log; use pallet_alliance::{ProposalIndex, ProposalProvider}; use parachains_common::impls::NegativeImbalance; +use polkadot_parachain_primitives::primitives::{Id as ParaId, IsSystem}; use sp_runtime::DispatchError; use sp_std::{cmp::Ordering, marker::PhantomData, prelude::*}; use xcm::latest::{Fungibility, Junction, Junctions::Here, Location, Parent, WeightLimit}; @@ -159,6 +164,51 @@ impl PrivilegeCmp for EqualOrGreatestRootCmp { } } +/// Contains a system-level sibling parachain. +pub struct IsSiblingSystemParachain(PhantomData); +impl> Contains for IsSiblingSystemParachain { + fn contains(l: &Location) -> bool { + matches!( + l.interior().as_slice(), + [Junction::Parachain(id)] + if ParaId::from(*id).is_system() && l.parent_count() == 1, + ) + } +} + +/// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without +/// conversion; otherwise, delegates to the implementation specified by `I`. +pub struct NativeOnSiblingParachain(PhantomData); +impl ConversionFromAssetBalance + for NativeOnSiblingParachain +where + I: ConversionFromAssetBalance, +{ + type Error = (); + fn from_asset_balance( + balance: Balance, + asset_kind: VersionedLocatableAsset, + ) -> Result { + use VersionedLocatableAsset::*; + let (location, asset_id) = match asset_kind.clone() { + V3 { location, asset_id } => (location.try_into()?, asset_id.try_into()?), + V4 { location, asset_id } => (location, asset_id), + }; + + if asset_id.0.contains_parents_only(1) && + IsSiblingSystemParachain::::contains(&location) + { + Ok(balance) + } else { + I::from_asset_balance(balance, asset_kind).map_err(|_| ()) + } + } + #[cfg(feature = "runtime-benchmarks")] + fn ensure_successful(asset_kind: VersionedLocatableAsset) { + I::ensure_successful(asset_kind) + } +} + #[cfg(feature = "runtime-benchmarks")] pub mod benchmarks { use super::*; From f64b6da0b08aa5dd00a38909e8a1891f84472960 Mon Sep 17 00:00:00 2001 From: muharem Date: Sat, 9 Mar 2024 11:52:52 +0100 Subject: [PATCH 02/14] fellowship treasury spend test --- .../workflows/integration-tests-matrix.json | 4 + Cargo.lock | 32 ++ Cargo.toml | 1 + .../collectives-polkadot/Cargo.toml | 44 +++ .../collectives-polkadot/src/lib.rs | 81 +++++ .../src/tests/fellowship_treasury.rs | 285 ++++++++++++++++++ .../collectives-polkadot/src/tests/mod.rs | 16 + 7 files changed, 463 insertions(+) create mode 100644 integration-tests/emulated/tests/collectives/collectives-polkadot/Cargo.toml create mode 100644 integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs create mode 100644 integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs create mode 100644 integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/mod.rs diff --git a/.github/workflows/integration-tests-matrix.json b/.github/workflows/integration-tests-matrix.json index f16c7f0f3a..7fe0ba89e7 100644 --- a/.github/workflows/integration-tests-matrix.json +++ b/.github/workflows/integration-tests-matrix.json @@ -14,5 +14,9 @@ { "name": "bridge-hub-polkadot", "package": "bridge-hub-polkadot-integration-tests" + }, + { + "name": "collectives-polkadot", + "package": "collectives-polkadot-integration-tests" } ] diff --git a/Cargo.lock b/Cargo.lock index 325aa0bbac..7cba47c3ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1984,6 +1984,38 @@ dependencies = [ "sp-core", ] +[[package]] +name = "collectives-polkadot-integration-tests" +version = "1.0.0" +dependencies = [ + "assert_matches", + "asset-hub-polkadot-runtime", + "asset-test-utils", + "collectives-polkadot-runtime", + "cumulus-pallet-parachain-system", + "cumulus-pallet-xcmp-queue", + "emulated-integration-tests-common", + "frame-support", + "integration-tests-helpers", + "pallet-asset-rate", + "pallet-assets", + "pallet-balances", + "pallet-message-queue", + "pallet-treasury", + "pallet-utility", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "polkadot-runtime", + "polkadot-runtime-common", + "polkadot-runtime-constants", + "polkadot-system-emulated-network", + "sp-runtime", + "staging-xcm", + "staging-xcm-executor", + "system-parachains-constants", +] + [[package]] name = "collectives-polkadot-runtime" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 7c4f766baa..3502fdfc79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ members = [ "integration-tests/emulated/tests/assets/asset-hub-polkadot", "integration-tests/emulated/tests/bridges/bridge-hub-kusama", "integration-tests/emulated/tests/bridges/bridge-hub-polkadot", + "integration-tests/emulated/tests/collectives/collectives-polkadot", ] [profile.release] diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/Cargo.toml b/integration-tests/emulated/tests/collectives/collectives-polkadot/Cargo.toml new file mode 100644 index 0000000000..ee15b60abe --- /dev/null +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "collectives-polkadot-integration-tests" +version.workspace = true +authors.workspace = true +edition.workspace = true +license = "Apache-2.0" +description = "Collectives Polkadot runtime integration tests with xcm-emulator" +publish = false + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.6.9" } +assert_matches = "1.5.0" + +# Substrate +sp-runtime = { version = "32.0.0" } +frame-support = { version = "29.0.0" } +pallet-balances = { version = "29.0.0" } +pallet-asset-rate = { version = "8.0.0" } +pallet-assets = { version = "30.0.0" } +pallet-treasury = { version = "28.0.0" } +pallet-message-queue = { version = "32.0.0" } +pallet-utility = { version = "29.0.0" } + +# Polkadot +polkadot-runtime-common = { version = "8.0.1" } +xcm = { package = "staging-xcm", version = "8.0.1" } +pallet-xcm = { version = "8.0.2" } +xcm-executor = { package = "staging-xcm-executor", version = "8.0.1" } + +# Cumulus +asset-test-utils = { version = "8.0.1" } +emulated-integration-tests-common = { version = "4.0.0" } +parachains-common = { version = "8.0.0" } +cumulus-pallet-xcmp-queue = { version = "0.8.0" } +cumulus-pallet-parachain-system = { features = ["parameterized-consensus-hook"], version = "0.8.1" } + +# Local +asset-hub-polkadot-runtime = { path = "../../../../../system-parachains/asset-hubs/asset-hub-polkadot" } +collectives-polkadot-runtime = { path = "../../../../../system-parachains/collectives/collectives-polkadot" } +integration-tests-helpers = { path = "../../../helpers" } +polkadot-runtime = { path = "../../../../../relay/polkadot" } +polkadot-runtime-constants = { path = "../../../../../relay/polkadot/constants" } +polkadot-system-emulated-network = { path = "../../../networks/polkadot-system" } +system-parachains-constants = { path = "../../../../../system-parachains/constants" } diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs new file mode 100644 index 0000000000..b72b0baa38 --- /dev/null +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs @@ -0,0 +1,81 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// 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. + +pub use codec::Encode; + +// Substrate +pub use frame_support::{ + assert_err, assert_ok, + instances::Instance1, + 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::Polkadot as PolkadotId}, +}; + +// Cumulus +pub use asset_test_utils::xcm_helpers; +pub use emulated_integration_tests_common::{ + 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 integration_tests_helpers::test_parachain_is_trusted_teleporter; +pub use parachains_common::{AccountId, Balance}; +pub use polkadot_system_emulated_network::{ + asset_hub_polkadot_emulated_chain::{ + genesis::ED as ASSET_HUB_POLKADOT_ED, AssetHubPolkadotParaPallet as AssetHubPolkadotPallet, + }, + collectives_polkadot_emulated_chain::{ + genesis::ED as COLLECTIVES_POLKADOT_ED, + CollectivesPolkadotParaPallet as CollectivesPolkadotPallet, + }, + penpal_emulated_chain::PenpalBParaPallet as PenpalBPallet, + polkadot_emulated_chain::{genesis::ED as POLKADOT_ED, PolkadotRelayPallet as PolkadotPallet}, + AssetHubPolkadotPara as AssetHubPolkadot, + AssetHubPolkadotParaReceiver as AssetHubPolkadotReceiver, + AssetHubPolkadotParaSender as AssetHubPolkadotSender, + BridgeHubPolkadotPara as BridgeHubPolkadot, + BridgeHubPolkadotParaReceiver as BridgeHubPolkadotReceiver, + CollectivesPolkadotPara as CollectivesPolkadot, PenpalAPara as PenpalA, + PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender, + PenpalBPara as PenpalB, PenpalBParaReceiver as PenpalBReceiver, + PenpalBParaSender as PenpalBSender, PolkadotRelay as Polkadot, + PolkadotRelayReceiver as PolkadotReceiver, PolkadotRelaySender as PolkadotSender, +}; + +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; + +#[cfg(test)] +mod tests; diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs new file mode 100644 index 0000000000..be333e32e2 --- /dev/null +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs @@ -0,0 +1,285 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// 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 asset_hub_polkadot_runtime::xcm_config::LocationToAccountId as AssetHubLocationToAccountId; +use emulated_integration_tests_common::accounts::ALICE; +use frame_support::{ + dispatch::RawOrigin, sp_runtime::traits::Dispatchable, traits::fungible::Inspect, +}; +use polkadot_runtime::OriginCaller; +use polkadot_runtime_common::impls::VersionedLocatableAsset; +use polkadot_runtime_constants::currency::UNITS; +use xcm_executor::traits::ConvertLocation; + +// Fund Fellowship Treasury from Polkadot Treasury and spend from Fellowship Treasury. +#[test] +fn fellowship_treasury_spend() { + // initial treasury balance on Asset Hub in DOTs. + let treasury_balance = 20_000_000 * UNITS; + // target fellowship balance on Asset Hub in DOTs. + let fellowship_treasury_balance = 1_000_000 * UNITS; + // fellowship first spend balance in DOTs. + let fellowship_spend_balance = 10_000 * UNITS; + + let init_alice_balance = AssetHubPolkadot::execute_with(|| { + <::Balances as Inspect<_>>::balance( + &Polkadot::account_id_of(ALICE), + ) + }); + + Polkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type RuntimeCall = ::RuntimeCall; + type Runtime = ::Runtime; + type Balances = ::Balances; + type Treasury = ::Treasury; + + // Fund Treasury account on Asset Hub with DOTs. + + let root = ::RuntimeOrigin::root(); + let treasury_account = Treasury::account_id(); + + // Mist assets to Treasury account on Relay Chain. + assert_ok!(Balances::force_set_balance( + root.clone(), + treasury_account.clone().into(), + treasury_balance * 2, + )); + + let native_asset = Location::here(); + let asset_hub_location: Location = [Parachain(1000)].into(); + let treasury_location_on_asset_hub: Location = (Parent, PalletInstance(19)).into(); + + let teleport_call = RuntimeCall::Utility(pallet_utility::Call::::dispatch_as { + as_origin: bx!(OriginCaller::system(RawOrigin::Signed(treasury_account))), + call: bx!(RuntimeCall::XcmPallet(pallet_xcm::Call::::teleport_assets { + dest: bx!(VersionedLocation::V4(asset_hub_location.clone())), + beneficiary: bx!(VersionedLocation::V4(treasury_location_on_asset_hub)), + assets: bx!(VersionedAssets::V4( + Asset { id: native_asset.clone().into(), fun: treasury_balance.into() }.into() + )), + fee_asset_item: 0, + })), + }); + + // Dispatched from Root to `despatch_as` `Signed(treasury_account)`. + assert_ok!(teleport_call.dispatch(root)); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + Polkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type RuntimeCall = ::RuntimeCall; + type RuntimeOrigin = ::RuntimeOrigin; + type Runtime = ::Runtime; + + // Set up an asset rate for the assets that will be spent. + // TODO: Ensure asset rate identifies relative native asset locations and maintains a 1:1 + // rate without the need to set up a rate. + + let treasury_origin: RuntimeOrigin = + polkadot_runtime::governance::pallet_custom_origins::Origin::Treasurer.into(); + + let asset_hub_location: Location = [Parachain(1000)].into(); + let native_asset_on_asset_hub = Location::parent(); + + let asset_rate_call = RuntimeCall::AssetRate(pallet_asset_rate::Call::::create { + asset_kind: bx!(VersionedLocatableAsset::V4 { + location: asset_hub_location.clone(), + asset_id: native_asset_on_asset_hub.into(), + }), + rate: 1.into(), + }); + + assert_ok!(asset_rate_call.dispatch(treasury_origin)); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::AssetRate(pallet_asset_rate::Event::AssetRateCreated { .. }) => {}, + ] + ); + }); + + Polkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type RuntimeCall = ::RuntimeCall; + type RuntimeOrigin = ::RuntimeOrigin; + type Runtime = ::Runtime; + type Treasury = ::Treasury; + + // Fund Fellowship Treasury from Polkadot Treasury. + + let treasury_origin: RuntimeOrigin = + polkadot_runtime::governance::pallet_custom_origins::Origin::Treasurer.into(); + let fellowship_treasury_location: Location = + Location::new(1, [Parachain(1001), PalletInstance(65)]); + let asset_hub_location: Location = [Parachain(1000)].into(); + let native_asset_on_asset_hub = Location::parent(); + + let treasury_spend_call = RuntimeCall::Treasury(pallet_treasury::Call::::spend { + asset_kind: bx!(VersionedLocatableAsset::V4 { + location: asset_hub_location.clone(), + asset_id: native_asset_on_asset_hub.into(), + }), + amount: fellowship_treasury_balance, + beneficiary: bx!(VersionedLocation::V4(fellowship_treasury_location)), + valid_from: None, + }); + + assert_ok!(treasury_spend_call.dispatch(treasury_origin)); + + // Claim the spend. + + let alice_signed = RuntimeOrigin::signed(Polkadot::account_id_of(ALICE)); + assert_ok!(Treasury::payout(alice_signed.clone(), 0)); + + assert_expected_events!( + Polkadot, + vec![ + RuntimeEvent::Treasury(pallet_treasury::Event::AssetSpendApproved { .. }) => {}, + RuntimeEvent::Treasury(pallet_treasury::Event::Paid { .. }) => {}, + ] + ); + }); + + AssetHubPolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type Balances = ::Balances; + + // Ensure that the funds deposited to the Fellowship Treasury account. + + let fellowship_treasury_location: Location = + Location::new(1, [Parachain(1001), PalletInstance(65)]); + let fellowship_treasury_account = + AssetHubLocationToAccountId::convert_location(&fellowship_treasury_location).unwrap(); + + assert_eq!( + >::balance(&fellowship_treasury_account), + fellowship_treasury_balance + ); + + // Assert events triggered by xcm pay program: + // 1. treasury asset transferred to spend beneficiary; + // 2. response to Relay Chain Treasury pallet instance sent back; + // 3. XCM program completed; + assert_expected_events!( + AssetHubPolkadot, + vec![ + RuntimeEvent::Balances(pallet_balances::Event::Transfer { .. }) => {}, + RuntimeEvent::ParachainSystem(cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true ,.. }) => {}, + ] + ); + }); + + CollectivesPolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type RuntimeCall = ::RuntimeCall; + type RuntimeOrigin = ::RuntimeOrigin; + type Runtime = ::Runtime; + type FellowshipTreasury = + ::FellowshipTreasury; + + // Spend assets from Fellowship Treasury. + + let fellows_origin: RuntimeOrigin = + collectives_polkadot_runtime::fellowship::pallet_fellowship_origins::Origin::Fellows + .into(); + + // Set up an asset rate for the assets that will be spent. + // TODO: Ensure asset rate identifies relative native asset locations and maintains a 1:1 + // rate without the need to set up a rate. + + let asset_hub_location: Location = (Parent, Parachain(1000)).into(); + let native_asset_on_asset_hub = Location::parent(); + + let asset_rate_call = RuntimeCall::AssetRate(pallet_asset_rate::Call::::create { + asset_kind: bx!(VersionedLocatableAsset::V4 { + location: asset_hub_location.clone(), + asset_id: native_asset_on_asset_hub.clone().into(), + }), + rate: 1.into(), + }); + + assert_ok!(asset_rate_call.dispatch(fellows_origin.clone())); + + // Fund Alice account from Fellowship Treasury. + + let alice_location: Location = + [Junction::AccountId32 { network: None, id: Polkadot::account_id_of(ALICE).into() }] + .into(); + + let fellowship_treasury_spend_call = + RuntimeCall::FellowshipTreasury(pallet_treasury::Call::::spend { + asset_kind: bx!(VersionedLocatableAsset::V4 { + location: asset_hub_location, + asset_id: native_asset_on_asset_hub.into(), + }), + amount: fellowship_spend_balance, + beneficiary: bx!(VersionedLocation::V4(alice_location)), + valid_from: None, + }); + + assert_ok!(fellowship_treasury_spend_call.dispatch(fellows_origin)); + + // Claim the spend. + + let alice_signed = RuntimeOrigin::signed(Polkadot::account_id_of(ALICE)); + assert_ok!(FellowshipTreasury::payout(alice_signed.clone(), 0)); + + assert_expected_events!( + CollectivesPolkadot, + vec![ + RuntimeEvent::AssetRate(pallet_asset_rate::Event::AssetRateCreated { .. }) => {}, + RuntimeEvent::FellowshipTreasury(pallet_treasury::Event::AssetSpendApproved { .. }) => {}, + RuntimeEvent::FellowshipTreasury(pallet_treasury::Event::Paid { .. }) => {}, + ] + ); + }); + + AssetHubPolkadot::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type Balances = ::Balances; + + // Ensure that the funds deposited to Alice account. + + let alice_account = Polkadot::account_id_of(ALICE); + assert_eq!( + >::balance(&alice_account), + fellowship_spend_balance + init_alice_balance + ); + + // Assert events triggered by xcm pay program: + // 1. treasury asset transferred to spend beneficiary; + // 2. response to Relay Chain Treasury pallet instance sent back; + // 3. XCM program completed; + assert_expected_events!( + AssetHubPolkadot, + vec![ + RuntimeEvent::Balances(pallet_balances::Event::Transfer { .. }) => {}, + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true ,.. }) => {}, + ] + ); + }); +} diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/mod.rs b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/mod.rs new file mode 100644 index 0000000000..a9f65df34b --- /dev/null +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/mod.rs @@ -0,0 +1,16 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// 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. + +mod fellowship_treasury; From fa5136f0789ba454479b34ab17037a5f5875e032 Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 11 Mar 2024 17:54:55 +0100 Subject: [PATCH 03/14] kusama tests --- Cargo.lock | 4 + .../emulated/chains/relays/kusama/src/lib.rs | 2 + .../tests/assets/asset-hub-kusama/Cargo.toml | 4 + .../assets/asset-hub-kusama/src/tests/mod.rs | 1 + .../asset-hub-kusama/src/tests/treasury.rs | 269 ++++++++++++++++++ .../src/tests/fellowship_treasury.rs | 54 +--- 6 files changed, 281 insertions(+), 53 deletions(-) create mode 100644 integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs diff --git a/Cargo.lock b/Cargo.lock index 7cba47c3ce..015b532adb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -445,14 +445,18 @@ dependencies = [ "emulated-integration-tests-common", "frame-support", "integration-tests-helpers", + "kusama-runtime-constants", "kusama-system-emulated-network", "pallet-asset-conversion", "pallet-assets", "pallet-balances", "pallet-message-queue", + "pallet-treasury", + "pallet-utility", "pallet-xcm", "parachains-common", "parity-scale-codec", + "polkadot-runtime-common", "sp-runtime", "staging-kusama-runtime", "staging-xcm", diff --git a/integration-tests/emulated/chains/relays/kusama/src/lib.rs b/integration-tests/emulated/chains/relays/kusama/src/lib.rs index b3718e69cc..ac053b22d8 100644 --- a/integration-tests/emulated/chains/relays/kusama/src/lib.rs +++ b/integration-tests/emulated/chains/relays/kusama/src/lib.rs @@ -37,6 +37,8 @@ decl_test_relay_chains! { Balances: kusama_runtime::Balances, Hrmp: kusama_runtime::Hrmp, Identity: kusama_runtime::Identity, + Treasury: kusama_runtime::Treasury, + AssetRate: kusama_runtime::AssetRate, } }, } diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/Cargo.toml b/integration-tests/emulated/tests/assets/asset-hub-kusama/Cargo.toml index 14228e387d..4840141fc1 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/Cargo.toml +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/Cargo.toml @@ -17,12 +17,15 @@ frame-support = { version = "29.0.0" } pallet-assets = { version = "30.0.0" } pallet-balances = { version = "29.0.0" } pallet-asset-conversion = { version = "11.0.0" } +pallet-treasury = { version = "28.0.0" } pallet-message-queue = { version = "32.0.0" } +pallet-utility = { version = "29.0.0" } # Polkadot xcm = { package = "staging-xcm", version = "8.0.1" } xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "8.0.1" } pallet-xcm = { version = "8.0.2" } +runtime-common = { package = "polkadot-runtime-common", default-features = false, version = "8.0.1" } # Cumulus parachains-common = { version = "8.0.0" } @@ -36,3 +39,4 @@ integration-tests-helpers = { path = "../../../helpers" } kusama-runtime = { package = "staging-kusama-runtime", path = "../../../../../relay/kusama" } kusama-system-emulated-network = { path = "../../../networks/kusama-system" } system-parachains-constants = { path = "../../../../../system-parachains/constants" } +kusama-runtime-constants = { path = "../../../../../relay/kusama/constants" } diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/mod.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/mod.rs index 3bded12dd1..7e60ad90b2 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/mod.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/mod.rs @@ -19,6 +19,7 @@ mod send; mod set_xcm_versions; mod swap; mod teleport; +mod treasury; use crate::*; emulated_integration_tests_common::include_penpal_create_foreign_asset_on_asset_hub!( diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs new file mode 100644 index 0000000000..cb29df713a --- /dev/null +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs @@ -0,0 +1,269 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// 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 emulated_integration_tests_common::accounts::{ALICE, BOB}; +use frame_support::{ + dispatch::RawOrigin, + sp_runtime::traits::Dispatchable, + traits::{ + fungible::Inspect, + fungibles::{Create, Inspect as FungiblesInspect, Mutate}, + }, +}; +use kusama_runtime::OriginCaller; +use kusama_runtime_constants::currency::GRAND; +use runtime_common::impls::VersionedLocatableAsset; +use xcm_executor::traits::ConvertLocation; + +// Fund Treasury account on Asset Hub from Treasury account on Relay Chain with KSMs. +#[test] +fn spend_ksm_on_asset_hub() { + // initial treasury balance on Asset Hub in KSMs. + let treasury_balance = 9_000 * GRAND; + // the balance spend on Asset Hub. + let treasury_spend_balance = 1_000 * GRAND; + + let init_alice_balance = AssetHubKusama::execute_with(|| { + <::Balances as Inspect<_>>::balance( + &Kusama::account_id_of(ALICE), + ) + }); + + Kusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type RuntimeCall = ::RuntimeCall; + type Runtime = ::Runtime; + type Balances = ::Balances; + type Treasury = ::Treasury; + + // Fund Treasury account on Asset Hub with KSMs. + + let root = ::RuntimeOrigin::root(); + let treasury_account = Treasury::account_id(); + + // Mist assets to Treasury account on Relay Chain. + assert_ok!(Balances::force_set_balance( + root.clone(), + treasury_account.clone().into(), + treasury_balance * 2, + )); + + let native_asset = Location::here(); + let asset_hub_location: Location = [Parachain(1000)].into(); + let treasury_location_on_asset_hub: Location = (Parent, PalletInstance(18)).into(); + + let teleport_call = RuntimeCall::Utility(pallet_utility::Call::::dispatch_as { + as_origin: bx!(OriginCaller::system(RawOrigin::Signed(treasury_account))), + call: bx!(RuntimeCall::XcmPallet(pallet_xcm::Call::::teleport_assets { + dest: bx!(VersionedLocation::V4(asset_hub_location.clone())), + beneficiary: bx!(VersionedLocation::V4(treasury_location_on_asset_hub)), + assets: bx!(VersionedAssets::V4( + Asset { id: native_asset.clone().into(), fun: treasury_balance.into() }.into() + )), + fee_asset_item: 0, + })), + }); + + // Dispatched from Root to `despatch_as` `Signed(treasury_account)`. + assert_ok!(teleport_call.dispatch(root)); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + Kusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type RuntimeCall = ::RuntimeCall; + type RuntimeOrigin = ::RuntimeOrigin; + type Runtime = ::Runtime; + type Treasury = ::Treasury; + + // Fund Alice account from Kusama Treasury account on Asset Hub. + + let treasury_origin: RuntimeOrigin = + kusama_runtime::governance::pallet_custom_origins::Origin::Treasurer.into(); + + let alice_location: Location = + [Junction::AccountId32 { network: None, id: Kusama::account_id_of(ALICE).into() }] + .into(); + let asset_hub_location: Location = [Parachain(1000)].into(); + let native_asset_on_asset_hub = Location::parent(); + + let treasury_spend_call = RuntimeCall::Treasury(pallet_treasury::Call::::spend { + asset_kind: bx!(VersionedLocatableAsset::V4 { + location: asset_hub_location.clone(), + asset_id: native_asset_on_asset_hub.into(), + }), + amount: treasury_spend_balance, + beneficiary: bx!(VersionedLocation::V4(alice_location)), + valid_from: None, + }); + + assert_ok!(treasury_spend_call.dispatch(treasury_origin)); + + // Claim the spend. + + let bob_signed = RuntimeOrigin::signed(Kusama::account_id_of(BOB)); + assert_ok!(Treasury::payout(bob_signed.clone(), 0)); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::Treasury(pallet_treasury::Event::AssetSpendApproved { .. }) => {}, + RuntimeEvent::Treasury(pallet_treasury::Event::Paid { .. }) => {}, + ] + ); + }); + + AssetHubKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type Balances = ::Balances; + + // Ensure that the funds deposited to Alice account. + + let alice_account = Kusama::account_id_of(ALICE); + assert_eq!( + >::balance(&alice_account), + treasury_spend_balance + init_alice_balance + ); + + // Assert events triggered by xcm pay program: + // 1. treasury asset transferred to spend beneficiary; + // 2. response to Relay Chain Treasury pallet instance sent back; + // 3. XCM program completed; + assert_expected_events!( + AssetHubKusama, + vec![ + RuntimeEvent::Balances(pallet_balances::Event::Transfer { .. }) => {}, + RuntimeEvent::ParachainSystem(cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true ,.. }) => {}, + ] + ); + }); +} + +#[test] +fn create_and_claim_treasury_spend_in_usdt() { + const ASSET_ID: u32 = 1984; + const SPEND_AMOUNT: u128 = 1_000_000; + // treasury location from a sibling parachain. + let treasury_location: Location = Location::new(1, PalletInstance(18)); + // treasury account on a sibling parachain. + let treasury_account = + asset_hub_kusama_runtime::xcm_config::LocationToAccountId::convert_location( + &treasury_location, + ) + .unwrap(); + let asset_hub_location = + v3::Location::new(0, v3::Junction::Parachain(AssetHubKusama::para_id().into())); + let root = ::RuntimeOrigin::root(); + // asset kind to be spend from the treasury. + let asset_kind = VersionedLocatableAsset::V3 { + location: asset_hub_location, + asset_id: v3::AssetId::Concrete( + (v3::Junction::PalletInstance(50), v3::Junction::GeneralIndex(ASSET_ID.into())).into(), + ), + }; + // treasury spend beneficiary. + let alice: AccountId = Kusama::account_id_of(ALICE); + let bob: AccountId = Kusama::account_id_of(BOB); + let bob_signed = ::RuntimeOrigin::signed(bob.clone()); + + AssetHubKusama::execute_with(|| { + type Assets = ::Assets; + + // create an asset class and mint some assets to the treasury account. + assert_ok!(>::create( + ASSET_ID, + treasury_account.clone(), + true, + SPEND_AMOUNT / 2 + )); + assert_ok!(>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4)); + // beneficiary has zero balance. + assert_eq!(>::balance(ASSET_ID, &alice,), 0u128,); + }); + + Kusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type Treasury = ::Treasury; + type AssetRate = ::AssetRate; + + // create a conversion rate from `asset_kind` to the native currency. + assert_ok!(AssetRate::create(root.clone(), Box::new(asset_kind.clone()), 2.into())); + + // create and approve a treasury spend. + assert_ok!(Treasury::spend( + root, + Box::new(asset_kind), + SPEND_AMOUNT, + Box::new(Location::new(0, Into::<[u8; 32]>::into(alice.clone())).into()), + None, + )); + // claim the spend. + assert_ok!(Treasury::payout(bob_signed.clone(), 0)); + + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::Treasury(pallet_treasury::Event::Paid { .. }) => {}, + ] + ); + }); + + AssetHubKusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type Assets = ::Assets; + + // assert events triggered by xcm pay program + // 1. treasury asset transferred to spend beneficiary + // 2. response to Relay Chain treasury pallet instance sent back + // 3. XCM program completed + assert_expected_events!( + AssetHubKusama, + vec![ + RuntimeEvent::Assets(pallet_assets::Event::Transferred { asset_id: id, from, to, amount }) => { + id: id == &ASSET_ID, + from: from == &treasury_account, + to: to == &alice, + amount: amount == &SPEND_AMOUNT, + }, + RuntimeEvent::ParachainSystem(cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true ,.. }) => {}, + ] + ); + // beneficiary received the assets from the treasury. + assert_eq!(>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,); + }); + + Kusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type Treasury = ::Treasury; + + // check the payment status to ensure the response from the AssetHub was received. + assert_ok!(Treasury::check_status(bob_signed, 0)); + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::Treasury(pallet_treasury::Event::SpendProcessed { .. }) => {}, + ] + ); + }); +} diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs index be333e32e2..c451f74dda 100644 --- a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs @@ -86,40 +86,6 @@ fn fellowship_treasury_spend() { ); }); - Polkadot::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - type RuntimeCall = ::RuntimeCall; - type RuntimeOrigin = ::RuntimeOrigin; - type Runtime = ::Runtime; - - // Set up an asset rate for the assets that will be spent. - // TODO: Ensure asset rate identifies relative native asset locations and maintains a 1:1 - // rate without the need to set up a rate. - - let treasury_origin: RuntimeOrigin = - polkadot_runtime::governance::pallet_custom_origins::Origin::Treasurer.into(); - - let asset_hub_location: Location = [Parachain(1000)].into(); - let native_asset_on_asset_hub = Location::parent(); - - let asset_rate_call = RuntimeCall::AssetRate(pallet_asset_rate::Call::::create { - asset_kind: bx!(VersionedLocatableAsset::V4 { - location: asset_hub_location.clone(), - asset_id: native_asset_on_asset_hub.into(), - }), - rate: 1.into(), - }); - - assert_ok!(asset_rate_call.dispatch(treasury_origin)); - - assert_expected_events!( - Polkadot, - vec![ - RuntimeEvent::AssetRate(pallet_asset_rate::Event::AssetRateCreated { .. }) => {}, - ] - ); - }); - Polkadot::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; type RuntimeCall = ::RuntimeCall; @@ -200,31 +166,14 @@ fn fellowship_treasury_spend() { type FellowshipTreasury = ::FellowshipTreasury; - // Spend assets from Fellowship Treasury. + // Fund Alice account from Fellowship Treasury. let fellows_origin: RuntimeOrigin = collectives_polkadot_runtime::fellowship::pallet_fellowship_origins::Origin::Fellows .into(); - - // Set up an asset rate for the assets that will be spent. - // TODO: Ensure asset rate identifies relative native asset locations and maintains a 1:1 - // rate without the need to set up a rate. - let asset_hub_location: Location = (Parent, Parachain(1000)).into(); let native_asset_on_asset_hub = Location::parent(); - let asset_rate_call = RuntimeCall::AssetRate(pallet_asset_rate::Call::::create { - asset_kind: bx!(VersionedLocatableAsset::V4 { - location: asset_hub_location.clone(), - asset_id: native_asset_on_asset_hub.clone().into(), - }), - rate: 1.into(), - }); - - assert_ok!(asset_rate_call.dispatch(fellows_origin.clone())); - - // Fund Alice account from Fellowship Treasury. - let alice_location: Location = [Junction::AccountId32 { network: None, id: Polkadot::account_id_of(ALICE).into() }] .into(); @@ -250,7 +199,6 @@ fn fellowship_treasury_spend() { assert_expected_events!( CollectivesPolkadot, vec![ - RuntimeEvent::AssetRate(pallet_asset_rate::Event::AssetRateCreated { .. }) => {}, RuntimeEvent::FellowshipTreasury(pallet_treasury::Event::AssetSpendApproved { .. }) => {}, RuntimeEvent::FellowshipTreasury(pallet_treasury::Event::Paid { .. }) => {}, ] From 1cb4f6d786c956c44c541156ebea290db8de783f Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 13 Mar 2024 11:50:16 +0100 Subject: [PATCH 04/14] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c57fa0ef99..88c03a2505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Bump parachains runtime API to v9 in Kusama to enable the `node_features` function [polkadot-fellows/runtimes#194](https://github.com/polkadot-fellows/runtimes/pull/194) - Bump parachains runtime API to v10 in Kusama to enable the `approval-voting-params` function [polkadot-fellows/runtimes#204](https://github.com/polkadot-fellows/runtimes/pull/204) - Use Relay Chain's Treasury Pallet account as a destination for XCM fees on System Parachain ([polkadot-fellows/runtimes#191](https://github.com/polkadot-fellows/runtimes/pull/191)) +- Treasury Spend detects relative locations of the native asset ([polkadot-fellows/runtimes#233](https://github.com/polkadot-fellows/runtimes/pull/233)) ### Removed From 81a0a864131dc9ac7e33e2f2cbf0b11b5c51fa36 Mon Sep 17 00:00:00 2001 From: Muharem Date: Wed, 13 Mar 2024 17:48:44 +0100 Subject: [PATCH 05/14] Apply suggestions from code review Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- .../collectives-polkadot/src/tests/fellowship_treasury.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs index c451f74dda..8cea61f32c 100644 --- a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs @@ -52,7 +52,7 @@ fn fellowship_treasury_spend() { let root = ::RuntimeOrigin::root(); let treasury_account = Treasury::account_id(); - // Mist assets to Treasury account on Relay Chain. + // Mint assets to Treasury account on Relay Chain. assert_ok!(Balances::force_set_balance( root.clone(), treasury_account.clone().into(), From 8094c440263d3334442ef89ac3948f7d53369397 Mon Sep 17 00:00:00 2001 From: muharem Date: Mon, 18 Mar 2024 15:44:53 +0100 Subject: [PATCH 06/14] review fixes --- .../collectives-polkadot/src/lib.rs | 2 -- .../collectives-polkadot/src/fellowship/mod.rs | 9 +++++---- .../collectives-polkadot/src/impls.rs | 18 +++++++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs index b72b0baa38..7fc5004fb3 100644 --- a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs @@ -65,8 +65,6 @@ pub use polkadot_system_emulated_network::{ PolkadotRelayReceiver as PolkadotReceiver, PolkadotRelaySender as PolkadotSender, }; -pub const ASSET_ID: u32 = 1; -pub const ASSET_MIN_BALANCE: u128 = 1000; // `Assets` pallet index pub const ASSETS_PALLET_ID: u8 = 50; diff --git a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs index 67994efdd8..401cd6f427 100644 --- a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -23,10 +23,10 @@ use crate::{ weights, xcm_config::{LocationToAccountId, TreasurerBodyId}, AccountId, AssetRate, Balance, Balances, FellowshipReferenda, GovernanceLocation, - PolkadotTreasuryAccount, Preimage, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - Scheduler, DAYS, FELLOWSHIP_TREASURY_PALLET_ID, + ParachainInfo, PolkadotTreasuryAccount, Preimage, Runtime, RuntimeCall, RuntimeEvent, + RuntimeOrigin, Scheduler, DAYS, FELLOWSHIP_TREASURY_PALLET_ID, }; -use cumulus_primitives_core::Junction::GeneralIndex; +use cumulus_primitives_core::{Junction::GeneralIndex, ParaId}; use frame_support::{ parameter_types, traits::{ @@ -274,6 +274,7 @@ parameter_types! { // pallet instance. pub FellowshipTreasuryInteriorLocation: InteriorLocation = PalletInstance(::index() as u8).into(); + pub SelfParaId: ParaId = ParachainInfo::parachain_id(); } #[cfg(feature = "runtime-benchmarks")] @@ -352,7 +353,7 @@ impl pallet_treasury::Config for Runtime { type Paymaster = FellowshipTreasuryPaymaster; #[cfg(feature = "runtime-benchmarks")] type Paymaster = PayWithEnsure>>; - type BalanceConverter = crate::impls::NativeOnSiblingParachain; + type BalanceConverter = crate::impls::NativeOnSiblingParachain; type PayoutPeriod = ConstU32<{ 30 * DAYS }>; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = polkadot_runtime_common::impls::benchmarks::TreasuryArguments< diff --git a/system-parachains/collectives/collectives-polkadot/src/impls.rs b/system-parachains/collectives/collectives-polkadot/src/impls.rs index 9426c3648d..eaeec76acf 100644 --- a/system-parachains/collectives/collectives-polkadot/src/impls.rs +++ b/system-parachains/collectives/collectives-polkadot/src/impls.rs @@ -165,24 +165,28 @@ impl PrivilegeCmp for EqualOrGreatestRootCmp { } /// Contains a system-level sibling parachain. -pub struct IsSiblingSystemParachain(PhantomData); -impl> Contains for IsSiblingSystemParachain { +pub struct IsSiblingSystemParachain(PhantomData<(ParaId, SelfParaId)>); +impl + Eq, SelfParaId: Get> Contains + for IsSiblingSystemParachain +{ fn contains(l: &Location) -> bool { matches!( l.interior().as_slice(), [Junction::Parachain(id)] - if ParaId::from(*id).is_system() && l.parent_count() == 1, + if SelfParaId::get() != ParaId::from(*id) + && ParaId::from(*id).is_system() && l.parent_count() == 1, ) } } /// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without /// conversion; otherwise, delegates to the implementation specified by `I`. -pub struct NativeOnSiblingParachain(PhantomData); -impl ConversionFromAssetBalance - for NativeOnSiblingParachain +pub struct NativeOnSiblingParachain(PhantomData<(I, SelfParaId)>); +impl ConversionFromAssetBalance + for NativeOnSiblingParachain where I: ConversionFromAssetBalance, + SelfParaId: Get, { type Error = (); fn from_asset_balance( @@ -196,7 +200,7 @@ where }; if asset_id.0.contains_parents_only(1) && - IsSiblingSystemParachain::::contains(&location) + IsSiblingSystemParachain::::contains(&location) { Ok(balance) } else { From 562a18d0a97b80a433530527b53ee83de94311cb Mon Sep 17 00:00:00 2001 From: Muharem Date: Mon, 18 Mar 2024 16:57:20 +0100 Subject: [PATCH 07/14] Update system-parachains/collectives/collectives-polkadot/src/impls.rs Co-authored-by: Branislav Kontur --- .../collectives/collectives-polkadot/src/impls.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/system-parachains/collectives/collectives-polkadot/src/impls.rs b/system-parachains/collectives/collectives-polkadot/src/impls.rs index eaeec76acf..c9fddcdff7 100644 --- a/system-parachains/collectives/collectives-polkadot/src/impls.rs +++ b/system-parachains/collectives/collectives-polkadot/src/impls.rs @@ -171,10 +171,8 @@ impl + Eq, SelfParaId: Get> Contains bool { matches!( - l.interior().as_slice(), - [Junction::Parachain(id)] - if SelfParaId::get() != ParaId::from(*id) - && ParaId::from(*id).is_system() && l.parent_count() == 1, + l.unpack(), + (1, [Parachain(id)]) if ParaId::from(*id).is_system() && SelfParaId::get() != ParaId::from(*id), ) } } From 239880accabf3591c20adbb85ca9dc52f3e17c79 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 19 Mar 2024 12:40:43 +0100 Subject: [PATCH 08/14] minor docs and naming fixes --- .../assets/asset-hub-kusama/src/tests/treasury.rs | 12 +++++++----- .../src/tests/fellowship_treasury.rs | 4 ++-- relay/kusama/src/impls.rs | 7 +++++++ relay/polkadot/src/impls.rs | 7 +++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs index cb29df713a..88cc4a5e6a 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//! Tests concerning the Polkadot Treasury. + use crate::*; use emulated_integration_tests_common::accounts::{ALICE, BOB}; use frame_support::{ @@ -38,7 +40,7 @@ fn spend_ksm_on_asset_hub() { let init_alice_balance = AssetHubKusama::execute_with(|| { <::Balances as Inspect<_>>::balance( - &Kusama::account_id_of(ALICE), + &AssetHubKusama::account_id_of(ALICE), ) }); @@ -54,7 +56,7 @@ fn spend_ksm_on_asset_hub() { let root = ::RuntimeOrigin::root(); let treasury_account = Treasury::account_id(); - // Mist assets to Treasury account on Relay Chain. + // Mint assets to Treasury account on Relay Chain. assert_ok!(Balances::force_set_balance( root.clone(), treasury_account.clone().into(), @@ -63,13 +65,13 @@ fn spend_ksm_on_asset_hub() { let native_asset = Location::here(); let asset_hub_location: Location = [Parachain(1000)].into(); - let treasury_location_on_asset_hub: Location = (Parent, PalletInstance(18)).into(); + let treasury_location: Location = (Parent, PalletInstance(18)).into(); let teleport_call = RuntimeCall::Utility(pallet_utility::Call::::dispatch_as { as_origin: bx!(OriginCaller::system(RawOrigin::Signed(treasury_account))), call: bx!(RuntimeCall::XcmPallet(pallet_xcm::Call::::teleport_assets { dest: bx!(VersionedLocation::V4(asset_hub_location.clone())), - beneficiary: bx!(VersionedLocation::V4(treasury_location_on_asset_hub)), + beneficiary: bx!(VersionedLocation::V4(treasury_location)), assets: bx!(VersionedAssets::V4( Asset { id: native_asset.clone().into(), fun: treasury_balance.into() }.into() )), @@ -138,7 +140,7 @@ fn spend_ksm_on_asset_hub() { // Ensure that the funds deposited to Alice account. - let alice_account = Kusama::account_id_of(ALICE); + let alice_account = AssetHubKusama::account_id_of(ALICE); assert_eq!( >::balance(&alice_account), treasury_spend_balance + init_alice_balance diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs index 8cea61f32c..7a867faf32 100644 --- a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs @@ -61,13 +61,13 @@ fn fellowship_treasury_spend() { let native_asset = Location::here(); let asset_hub_location: Location = [Parachain(1000)].into(); - let treasury_location_on_asset_hub: Location = (Parent, PalletInstance(19)).into(); + let treasury_location: Location = (Parent, PalletInstance(19)).into(); let teleport_call = RuntimeCall::Utility(pallet_utility::Call::::dispatch_as { as_origin: bx!(OriginCaller::system(RawOrigin::Signed(treasury_account))), call: bx!(RuntimeCall::XcmPallet(pallet_xcm::Call::::teleport_assets { dest: bx!(VersionedLocation::V4(asset_hub_location.clone())), - beneficiary: bx!(VersionedLocation::V4(treasury_location_on_asset_hub)), + beneficiary: bx!(VersionedLocation::V4(treasury_location)), assets: bx!(VersionedAssets::V4( Asset { id: native_asset.clone().into(), fun: treasury_balance.into() }.into() )), diff --git a/relay/kusama/src/impls.rs b/relay/kusama/src/impls.rs index 0f29d9a2f1..bdbd530408 100644 --- a/relay/kusama/src/impls.rs +++ b/relay/kusama/src/impls.rs @@ -184,6 +184,13 @@ where /// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without /// conversion; otherwise, delegates to the implementation specified by `I`. +/// Example where the `asset_kind` represents the native asset: +/// ``` +/// `asset_kind`: VersionedLocatableAsset: { +/// `location`: (0, Parachain(1000)), // location of a Parachain +/// `asset_id`: (1, Here), // the asset id in the context of `asset_kind.location` +/// } +/// ``` pub struct NativeOnSystemParachain(PhantomData); impl ConversionFromAssetBalance for NativeOnSystemParachain diff --git a/relay/polkadot/src/impls.rs b/relay/polkadot/src/impls.rs index 3d582565fd..f9df578b51 100644 --- a/relay/polkadot/src/impls.rs +++ b/relay/polkadot/src/impls.rs @@ -22,6 +22,13 @@ use xcm_builder::IsChildSystemParachain; /// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without /// conversion; otherwise, delegates to the implementation specified by `I`. +/// Example where the `asset_kind` represents the native asset: +/// ``` +/// `asset_kind`: VersionedLocatableAsset: { +/// `location`: (1, Parachain(1000)), // location of a Sibling Parachain +/// `asset_id`: (1, Here), // the asset id in the context of `asset_kind.location` +/// } +/// ``` pub struct NativeOnSystemParachain(PhantomData); impl ConversionFromAssetBalance for NativeOnSystemParachain From a041dc82cd843a1c69f7a370250da7ac41aedf28 Mon Sep 17 00:00:00 2001 From: Muharem Date: Tue, 19 Mar 2024 14:36:31 +0100 Subject: [PATCH 09/14] Apply suggestions from code review Co-authored-by: Branislav Kontur --- .../collectives/collectives-polkadot/src/fellowship/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs index 401cd6f427..0f1c5fd815 100644 --- a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -26,7 +26,7 @@ use crate::{ ParachainInfo, PolkadotTreasuryAccount, Preimage, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, DAYS, FELLOWSHIP_TREASURY_PALLET_ID, }; -use cumulus_primitives_core::{Junction::GeneralIndex, ParaId}; +use cumulus_primitives_core::Junction::GeneralIndex; use frame_support::{ parameter_types, traits::{ @@ -274,7 +274,6 @@ parameter_types! { // pallet instance. pub FellowshipTreasuryInteriorLocation: InteriorLocation = PalletInstance(::index() as u8).into(); - pub SelfParaId: ParaId = ParachainInfo::parachain_id(); } #[cfg(feature = "runtime-benchmarks")] @@ -353,7 +352,7 @@ impl pallet_treasury::Config for Runtime { type Paymaster = FellowshipTreasuryPaymaster; #[cfg(feature = "runtime-benchmarks")] type Paymaster = PayWithEnsure>>; - type BalanceConverter = crate::impls::NativeOnSiblingParachain; + type BalanceConverter = crate::impls::NativeOnSiblingParachain; type PayoutPeriod = ConstU32<{ 30 * DAYS }>; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = polkadot_runtime_common::impls::benchmarks::TreasuryArguments< From 470a444756f32a58463971ff5e5d638cd2d95f40 Mon Sep 17 00:00:00 2001 From: Muharem Date: Tue, 19 Mar 2024 14:37:41 +0100 Subject: [PATCH 10/14] Apply suggestions from code review Co-authored-by: Branislav Kontur --- .../tests/assets/asset-hub-kusama/src/tests/treasury.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs index 88cc4a5e6a..0bf533a613 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/treasury.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Tests concerning the Polkadot Treasury. +//! Tests concerning the Kusama Treasury. use crate::*; use emulated_integration_tests_common::accounts::{ALICE, BOB}; @@ -79,7 +79,7 @@ fn spend_ksm_on_asset_hub() { })), }); - // Dispatched from Root to `despatch_as` `Signed(treasury_account)`. + // Dispatched from Root to `dispatch_as` `Signed(treasury_account)`. assert_ok!(teleport_call.dispatch(root)); assert_expected_events!( From 4e922b8b4893b32c6e6d956062e7345421b5fde8 Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 20 Mar 2024 14:39:15 +0100 Subject: [PATCH 11/14] TODOs --- relay/kusama/src/impls.rs | 1 + relay/polkadot/src/impls.rs | 1 + system-parachains/collectives/collectives-polkadot/src/impls.rs | 2 ++ 3 files changed, 4 insertions(+) diff --git a/relay/kusama/src/impls.rs b/relay/kusama/src/impls.rs index bdbd530408..f6b73f03fb 100644 --- a/relay/kusama/src/impls.rs +++ b/relay/kusama/src/impls.rs @@ -182,6 +182,7 @@ where } } +// TODO: replace by types from polkadot-sdk https://github.com/paritytech/polkadot-sdk/pull/3659 /// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without /// conversion; otherwise, delegates to the implementation specified by `I`. /// Example where the `asset_kind` represents the native asset: diff --git a/relay/polkadot/src/impls.rs b/relay/polkadot/src/impls.rs index f9df578b51..836c2216ca 100644 --- a/relay/polkadot/src/impls.rs +++ b/relay/polkadot/src/impls.rs @@ -20,6 +20,7 @@ use frame_support::traits::{tokens::ConversionFromAssetBalance, Contains}; use primitives::Id as ParaId; use xcm_builder::IsChildSystemParachain; +// TODO: replace by types from polkadot-sdk https://github.com/paritytech/polkadot-sdk/pull/3659 /// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without /// conversion; otherwise, delegates to the implementation specified by `I`. /// Example where the `asset_kind` represents the native asset: diff --git a/system-parachains/collectives/collectives-polkadot/src/impls.rs b/system-parachains/collectives/collectives-polkadot/src/impls.rs index c9fddcdff7..02086c0adb 100644 --- a/system-parachains/collectives/collectives-polkadot/src/impls.rs +++ b/system-parachains/collectives/collectives-polkadot/src/impls.rs @@ -164,6 +164,7 @@ impl PrivilegeCmp for EqualOrGreatestRootCmp { } } +// TODO: replace by types from polkadot-sdk https://github.com/paritytech/polkadot-sdk/pull/3659 /// Contains a system-level sibling parachain. pub struct IsSiblingSystemParachain(PhantomData<(ParaId, SelfParaId)>); impl + Eq, SelfParaId: Get> Contains @@ -177,6 +178,7 @@ impl + Eq, SelfParaId: Get> Contains(PhantomData<(I, SelfParaId)>); From f87c0e9f480093cffc374d2c623f5b14db779c75 Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 20 Mar 2024 15:09:37 +0100 Subject: [PATCH 12/14] remove unused imports --- .../collectives-polkadot/src/lib.rs | 63 +++---------------- .../src/tests/fellowship_treasury.rs | 3 +- 2 files changed, 10 insertions(+), 56 deletions(-) diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs index 7fc5004fb3..605d817598 100644 --- a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/lib.rs @@ -13,67 +13,20 @@ // 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, - instances::Instance1, - 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::Polkadot as PolkadotId}, -}; +pub use xcm::{prelude::*, v3}; // Cumulus -pub use asset_test_utils::xcm_helpers; -pub use emulated_integration_tests_common::{ - 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 emulated_integration_tests_common::xcm_emulator::{ + assert_expected_events, bx, Chain, RelayChain as Relay, TestExt, }; -pub use integration_tests_helpers::test_parachain_is_trusted_teleporter; -pub use parachains_common::{AccountId, Balance}; pub use polkadot_system_emulated_network::{ - asset_hub_polkadot_emulated_chain::{ - genesis::ED as ASSET_HUB_POLKADOT_ED, AssetHubPolkadotParaPallet as AssetHubPolkadotPallet, - }, - collectives_polkadot_emulated_chain::{ - genesis::ED as COLLECTIVES_POLKADOT_ED, - CollectivesPolkadotParaPallet as CollectivesPolkadotPallet, - }, - penpal_emulated_chain::PenpalBParaPallet as PenpalBPallet, - polkadot_emulated_chain::{genesis::ED as POLKADOT_ED, PolkadotRelayPallet as PolkadotPallet}, - AssetHubPolkadotPara as AssetHubPolkadot, - AssetHubPolkadotParaReceiver as AssetHubPolkadotReceiver, - AssetHubPolkadotParaSender as AssetHubPolkadotSender, - BridgeHubPolkadotPara as BridgeHubPolkadot, - BridgeHubPolkadotParaReceiver as BridgeHubPolkadotReceiver, - CollectivesPolkadotPara as CollectivesPolkadot, PenpalAPara as PenpalA, - PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender, - PenpalBPara as PenpalB, PenpalBParaReceiver as PenpalBReceiver, - PenpalBParaSender as PenpalBSender, PolkadotRelay as Polkadot, - PolkadotRelayReceiver as PolkadotReceiver, PolkadotRelaySender as PolkadotSender, + asset_hub_polkadot_emulated_chain::AssetHubPolkadotParaPallet as AssetHubPolkadotPallet, + collectives_polkadot_emulated_chain::CollectivesPolkadotParaPallet as CollectivesPolkadotPallet, + polkadot_emulated_chain::PolkadotRelayPallet as PolkadotPallet, + AssetHubPolkadotPara as AssetHubPolkadot, CollectivesPolkadotPara as CollectivesPolkadot, + PolkadotRelay as Polkadot, }; -// `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; - #[cfg(test)] mod tests; diff --git a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs index 7a867faf32..03adf3dbbc 100644 --- a/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs +++ b/integration-tests/emulated/tests/collectives/collectives-polkadot/src/tests/fellowship_treasury.rs @@ -17,7 +17,8 @@ use crate::*; use asset_hub_polkadot_runtime::xcm_config::LocationToAccountId as AssetHubLocationToAccountId; use emulated_integration_tests_common::accounts::ALICE; use frame_support::{ - dispatch::RawOrigin, sp_runtime::traits::Dispatchable, traits::fungible::Inspect, + assert_ok, dispatch::RawOrigin, instances::Instance1, sp_runtime::traits::Dispatchable, + traits::fungible::Inspect, }; use polkadot_runtime::OriginCaller; use polkadot_runtime_common::impls::VersionedLocatableAsset; From a97e959295fb7b79e06f14aa7bba3a71e56947e5 Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 20 Mar 2024 15:38:00 +0100 Subject: [PATCH 13/14] empty commit From 744591a14db2c99f971c0d39589d7ba30835cdc9 Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 21 Mar 2024 15:54:27 +0100 Subject: [PATCH 14/14] fix docs --- relay/kusama/src/impls.rs | 9 +++------ relay/polkadot/src/impls.rs | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/relay/kusama/src/impls.rs b/relay/kusama/src/impls.rs index f6b73f03fb..23e63b637c 100644 --- a/relay/kusama/src/impls.rs +++ b/relay/kusama/src/impls.rs @@ -185,13 +185,10 @@ where // TODO: replace by types from polkadot-sdk https://github.com/paritytech/polkadot-sdk/pull/3659 /// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without /// conversion; otherwise, delegates to the implementation specified by `I`. +/// /// Example where the `asset_kind` represents the native asset: -/// ``` -/// `asset_kind`: VersionedLocatableAsset: { -/// `location`: (0, Parachain(1000)), // location of a Parachain -/// `asset_id`: (1, Here), // the asset id in the context of `asset_kind.location` -/// } -/// ``` +/// - location: (1, Parachain(1000)), // location of a Sibling Parachain; +/// - asset_id: (1, Here), // the asset id in the context of `asset_kind.location`; pub struct NativeOnSystemParachain(PhantomData); impl ConversionFromAssetBalance for NativeOnSystemParachain diff --git a/relay/polkadot/src/impls.rs b/relay/polkadot/src/impls.rs index 836c2216ca..3e13683348 100644 --- a/relay/polkadot/src/impls.rs +++ b/relay/polkadot/src/impls.rs @@ -23,13 +23,10 @@ use xcm_builder::IsChildSystemParachain; // TODO: replace by types from polkadot-sdk https://github.com/paritytech/polkadot-sdk/pull/3659 /// Determines if the given `asset_kind` is a native asset. If it is, returns the balance without /// conversion; otherwise, delegates to the implementation specified by `I`. +/// /// Example where the `asset_kind` represents the native asset: -/// ``` -/// `asset_kind`: VersionedLocatableAsset: { -/// `location`: (1, Parachain(1000)), // location of a Sibling Parachain -/// `asset_id`: (1, Here), // the asset id in the context of `asset_kind.location` -/// } -/// ``` +/// - location: (1, Parachain(1000)), // location of a Sibling Parachain; +/// - asset_id: (1, Here), // the asset id in the context of `asset_kind.location`; pub struct NativeOnSystemParachain(PhantomData); impl ConversionFromAssetBalance for NativeOnSystemParachain