This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 365
Runtime: Allow unpaid execution for Treasury Pallet on AssetHubs #2902
Open
muharem
wants to merge
10
commits into
master
Choose a base branch
from
muharem-multi-asset-treasury
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f3f8bec
use ext_wrapper instead execute_with (#2893)
muharem 73012fe
allow unpaid for treasury pallet
muharem 03b7486
approve and claim a treasury spend test
muharem 95018cd
Update parachains/integration-tests/emulated/assets/asset-hub-polkado…
muharem bda8747
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem f45da03
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
7fed2e9
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
25fa658
upgrade to new api
muharem fbb3315
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem 452bdea
asset kind rename
muharem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,4 @@ | |
| mod reserve_transfer; | ||
| mod teleport; | ||
| mod transact; | ||
| mod treasury; | ||
123 changes: 123 additions & 0 deletions
123
parachains/integration-tests/emulated/assets/asset-hub-kusama/src/tests/treasury.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Copyright 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 <http://www.gnu.org/licenses/>. | ||
|
|
||
| use crate::*; | ||
| use frame_support::traits::fungibles::{Create, Inspect, Mutate}; | ||
| use xcm_builder::LocatableAssetId; | ||
| use xcm_executor::traits::ConvertLocation; | ||
|
|
||
| #[test] | ||
| fn create_and_claim_treasury_spend() { | ||
| const ASSET_ID: u32 = 1984; | ||
| const SPEND_AMOUNT: u128 = 1_000_000; | ||
| // treasury location from a sibling parachain. | ||
| let treasury_location: MultiLocation = MultiLocation::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 = MultiLocation::new(0, Parachain(AssetHubKusama::para_id().into())); | ||
| let root = <Kusama as Relay>::RuntimeOrigin::root(); | ||
| // asset kind to be spend from the treasury. | ||
| let asset_kind = LocatableAssetId::new( | ||
| AssetId::Concrete((PalletInstance(50), GeneralIndex(ASSET_ID.into())).into()), | ||
| asset_hub_location, | ||
| ); | ||
| // treasury spend beneficiary. | ||
| let alice: AccountId = Kusama::account_id_of(ALICE); | ||
| let bob: AccountId = Kusama::account_id_of(BOB); | ||
| let bob_signed = <Kusama as Relay>::RuntimeOrigin::signed(bob.clone()); | ||
|
|
||
| AssetHubKusama::execute_with(|| { | ||
| type Assets = <AssetHubKusama as AssetHubKusamaPallet>::Assets; | ||
|
|
||
| // create an asset class and mint some assets to the treasury account. | ||
| assert_ok!(<Assets as Create<_>>::create( | ||
| ASSET_ID, | ||
| treasury_account.clone(), | ||
| true, | ||
| SPEND_AMOUNT / 2 | ||
| )); | ||
| assert_ok!(<Assets as Mutate<_>>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4)); | ||
| // beneficiary has zero balance. | ||
| assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), 0u128,); | ||
| }); | ||
|
|
||
| Kusama::execute_with(|| { | ||
| type RuntimeEvent = <Kusama as Relay>::RuntimeEvent; | ||
| type Treasury = <Kusama as KusamaPallet>::Treasury; | ||
| type AssetRate = <Kusama as KusamaPallet>::AssetRate; | ||
|
|
||
| // create a conversion rate from `asset_kind` to the native currency. | ||
| assert_ok!(AssetRate::create(root.clone(), asset_kind.clone(), 2.into())); | ||
|
|
||
| // create and approve a treasury spend. | ||
| assert_ok!(Treasury::spend( | ||
| root, | ||
| asset_kind, | ||
| SPEND_AMOUNT, | ||
| MultiLocation::new(0, Into::<[u8; 32]>::into(alice.clone())), | ||
| 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 = <AssetHubKusama as Para>::RuntimeEvent; | ||
| type Assets = <AssetHubKusama as AssetHubKusamaPallet>::Assets; | ||
|
|
||
| // assets transferred, response sent back via UMP. | ||
| 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::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward { outcome: Outcome::Complete(..) ,.. }) => {}, | ||
| ] | ||
| ); | ||
| // beneficiary received the assets from the treasury. | ||
| assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,); | ||
| }); | ||
|
|
||
| Kusama::execute_with(|| { | ||
| type RuntimeEvent = <Kusama as Relay>::RuntimeEvent; | ||
| type Treasury = <Kusama as KusamaPallet>::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 { .. }) => {}, | ||
| ] | ||
| ); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,4 @@ | |
| mod reserve_transfer; | ||
| mod teleport; | ||
| mod transact; | ||
| mod treasury; | ||
123 changes: 123 additions & 0 deletions
123
parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/tests/treasury.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Copyright 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 <http://www.gnu.org/licenses/>. | ||
|
|
||
| use crate::*; | ||
| use frame_support::traits::fungibles::{Create, Inspect, Mutate}; | ||
| use xcm_builder::LocatableAssetId; | ||
| use xcm_executor::traits::ConvertLocation; | ||
|
|
||
| #[test] | ||
| fn create_and_claim_treasury_spend() { | ||
| const ASSET_ID: u32 = 1984; | ||
| const SPEND_AMOUNT: u128 = 1_000_000; | ||
| // treasury location from a sibling parachain. | ||
| let treasury_location: MultiLocation = MultiLocation::new(1, PalletInstance(19)); | ||
| // treasury account on a sibling parachain. | ||
| let treasury_account = | ||
| asset_hub_polkadot_runtime::xcm_config::LocationToAccountId::convert_location( | ||
| &treasury_location, | ||
| ) | ||
| .unwrap(); | ||
| let asset_hub_location = MultiLocation::new(0, Parachain(AssetHubPolkadot::para_id().into())); | ||
| let root = <Polkadot as Relay>::RuntimeOrigin::root(); | ||
| // asset kind to be spend from the treasury. | ||
| let asset_kind = LocatableAssetId::new( | ||
| AssetId::Concrete((PalletInstance(50), GeneralIndex(ASSET_ID.into())).into()), | ||
| asset_hub_location, | ||
| ); | ||
| // treasury spend beneficiary. | ||
| let alice: AccountId = Polkadot::account_id_of(ALICE); | ||
| let bob: AccountId = Polkadot::account_id_of(BOB); | ||
| let bob_signed = <Polkadot as Relay>::RuntimeOrigin::signed(bob.clone()); | ||
|
|
||
| AssetHubPolkadot::execute_with(|| { | ||
| type Assets = <AssetHubPolkadot as AssetHubPolkadotPallet>::Assets; | ||
|
|
||
| // create an asset class and mint some assets to the treasury account. | ||
| assert_ok!(<Assets as Create<_>>::create( | ||
| ASSET_ID, | ||
| treasury_account.clone(), | ||
| true, | ||
| SPEND_AMOUNT / 2 | ||
| )); | ||
| assert_ok!(<Assets as Mutate<_>>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4)); | ||
| // beneficiary has zero balance. | ||
| assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), 0u128,); | ||
| }); | ||
|
|
||
| Polkadot::execute_with(|| { | ||
| type RuntimeEvent = <Polkadot as Relay>::RuntimeEvent; | ||
| type Treasury = <Polkadot as PolkadotPallet>::Treasury; | ||
| type AssetRate = <Polkadot as PolkadotPallet>::AssetRate; | ||
|
|
||
| // create a conversion rate from `asset_kind` to the native currency. | ||
| assert_ok!(AssetRate::create(root.clone(), asset_kind.clone(), 2.into())); | ||
|
|
||
| // create and approve a treasury spend. | ||
| assert_ok!(Treasury::spend( | ||
| root, | ||
| asset_kind, | ||
| SPEND_AMOUNT, | ||
| MultiLocation::new(0, Into::<[u8; 32]>::into(alice.clone())), | ||
| None, | ||
| )); | ||
| // claim the spend. | ||
| assert_ok!(Treasury::payout(bob_signed.clone(), 0)); | ||
|
|
||
| assert_expected_events!( | ||
| Polkadot, | ||
| vec![ | ||
| RuntimeEvent::Treasury(pallet_treasury::Event::Paid { .. }) => {}, | ||
| ] | ||
| ); | ||
| }); | ||
|
|
||
| AssetHubPolkadot::execute_with(|| { | ||
| type RuntimeEvent = <AssetHubPolkadot as Para>::RuntimeEvent; | ||
| type Assets = <AssetHubPolkadot as AssetHubPolkadotPallet>::Assets; | ||
|
|
||
| // assets transferred, response sent back via UMP. | ||
| assert_expected_events!( | ||
| AssetHubPolkadot, | ||
| 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::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward { outcome: Outcome::Complete(..) ,.. }) => {}, | ||
| ] | ||
| ); | ||
| // beneficiary received the assets from the treasury. | ||
| assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,); | ||
| }); | ||
|
|
||
| Polkadot::execute_with(|| { | ||
| type RuntimeEvent = <Polkadot as Relay>::RuntimeEvent; | ||
| type Treasury = <Polkadot as PolkadotPallet>::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!( | ||
| Polkadot, | ||
| vec![ | ||
| RuntimeEvent::Treasury(pallet_treasury::Event::SpendProcessed { .. }) => {}, | ||
| ] | ||
| ); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.