Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Pallets: Treasury spend() should use Pay trait #13607

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a027594
pallet_treasury: implement treasury pallet over the pay trait in pall…
tonyalaribe Mar 15, 2023
29194c3
update the new spend logic to exist parallel to original spend logic
tonyalaribe Mar 15, 2023
11cd988
clean up imports diffs
tonyalaribe Mar 16, 2023
57aacbe
switch to using the pay trait in frame support
tonyalaribe Mar 16, 2023
67b9f7a
remove the changes to the build genesis config method
tonyalaribe Mar 16, 2023
2b20924
fix some type errors
tonyalaribe Mar 16, 2023
3602844
add a test for the new spend workflow
tonyalaribe Mar 16, 2023
dd99d7c
implement initial tests for the new spend workflow
tonyalaribe Mar 16, 2023
5f52015
remove unneeded Balance type from Confg
tonyalaribe Mar 16, 2023
1925806
Update lib.rs
tonyalaribe Mar 22, 2023
f94e20a
introduce a unit implementation for BalanceConversion which behaves a…
tonyalaribe Mar 22, 2023
293552f
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe Mar 22, 2023
a88fb24
Merge branch 'master' into aa/multi-asset-support-in-treasury
tonyalaribe Mar 22, 2023
3aaed66
fix rebase introduced error
tonyalaribe Mar 22, 2023
a33d4dc
fix broken tests due to rebase
tonyalaribe Mar 22, 2023
414e8e2
fix tests in tips and bounties
tonyalaribe Mar 22, 2023
2f60a1b
fix lint error for unused fn argument in Pay trait
tonyalaribe Mar 22, 2023
182c733
fix tests in child-bounties pallet
tonyalaribe Mar 22, 2023
0916aff
remove unneeded DummyBalanceConverter
tonyalaribe Mar 22, 2023
fdcd66a
Update frame/bounties/src/tests.rs
tonyalaribe Mar 23, 2023
5673e79
Update frame/bounties/src/tests.rs
tonyalaribe Mar 23, 2023
c6f9c5a
Update frame/treasury/src/lib.rs
tonyalaribe Mar 23, 2023
bb372a2
tiny cleanups
tonyalaribe Mar 27, 2023
a56897d
rename asset_id to asset_kind and proposal
tonyalaribe Mar 27, 2023
69cc489
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe Mar 27, 2023
e07ee86
Update frame/treasury/src/lib.rs
tonyalaribe Mar 27, 2023
304f536
implememt PR feedback
tonyalaribe Mar 27, 2023
e7ecdbf
update doc comments
tonyalaribe Mar 27, 2023
e689272
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe Mar 27, 2023
3cd5760
include correct weight funchtion
tonyalaribe Mar 27, 2023
d97886d
add spend_local to weight.rs
tonyalaribe Mar 27, 2023
805d595
benchmarking updates
tonyalaribe Mar 27, 2023
bbf83fa
rename Treasury1Account to TreasuryAccount1
tonyalaribe Mar 30, 2023
8aa1c3c
update PendingPayment storage comment
tonyalaribe Mar 30, 2023
aabfadf
update PendingPayment storage comment
tonyalaribe Mar 30, 2023
592b81b
adjust naming of Events to not mix PendingPayment and Proposal concepts
tonyalaribe Mar 30, 2023
b295ea7
adjust tests to check more cases
tonyalaribe Mar 30, 2023
1e85a67
benchmarking update
tonyalaribe Apr 3, 2023
eb4b2fe
make benchmarks pass
tonyalaribe Apr 4, 2023
1fdccb7
Merge remote-tracking branch 'origin/master' into aa/multi-asset-supp…
Apr 4, 2023
310578d
update BalanceConverter to use ConversionFromAssetBalance trait
tonyalaribe Apr 4, 2023
22e43a1
Add BenchmarkHelper to runtimes in dependent pallets
tonyalaribe Apr 4, 2023
d96d541
Update frame/treasury/src/lib.rs
tonyalaribe Apr 4, 2023
dc891cb
Update frame/treasury/src/lib.rs
tonyalaribe Apr 4, 2023
3bd3c8e
add benchmark helper to tips
tonyalaribe Apr 5, 2023
1018464
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe Apr 5, 2023
c04955d
add From<u32> for ()
tonyalaribe Apr 5, 2023
b5b5d0e
introduce NilBenchmarkHelper for unit asset ids
tonyalaribe Apr 5, 2023
65c71a0
remove comment
tonyalaribe Apr 5, 2023
62b0901
Merge remote-tracking branch 'origin/master' into aa/multi-asset-supp…
Apr 14, 2023
5750f0b
add debug log for pay errors; Pay trait should support an error type
tonyalaribe Apr 20, 2023
e26dee6
add error associated type to Salary pallet test pay impl
tonyalaribe Apr 20, 2023
0739c29
fix fmt error
tonyalaribe Apr 21, 2023
ac27c84
Merge remote-tracking branch 'origin/master' into aa/multi-asset-supp…
Apr 21, 2023
87b905c
Trigger CI
tonyalaribe Apr 21, 2023
5bc0af9
Trigger CI
tonyalaribe Apr 21, 2023
1fca0e9
add a debug log for when Paymaster::check_payment returns failure
tonyalaribe Apr 28, 2023
7d712e2
add payment_id to events
tonyalaribe Apr 28, 2023
db02823
Merge remote-tracking branch 'origin/master' into aa/multi-asset-supp…
May 5, 2023
415561d
Trigger companion CI
tonyalaribe May 5, 2023
449d484
Trigger companion CI
tonyalaribe May 5, 2023
4741037
Trigger Companion CI
tonyalaribe May 5, 2023
9cad108
Trigger Companion CI
tonyalaribe May 5, 2023
b644329
Trigger Companion CI
tonyalaribe May 5, 2023
8a9903b
Trigger Companion CI
tonyalaribe May 5, 2023
f07e8b0
Trigger Companion CI
tonyalaribe May 5, 2023
34c859b
support vector of assets for treasury spend
tonyalaribe May 30, 2023
9237568
Merge branch 'master' into aa/multi-asset-support-in-treasury
tonyalaribe May 30, 2023
1ecd8cc
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe May 30, 2023
c029123
fix types on child-bounties and tips
tonyalaribe May 30, 2023
83a2097
switch node template to use SimpleAsset
tonyalaribe May 30, 2023
d79cab0
Merge branch 'master' into aa/multi-asset-support-in-treasury
gavofyork Jun 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use frame_support::{
parameter_types,
traits::{
fungible::ItemOf,
tokens::{nonfungibles_v2::Inspect, GetSalary, PayFromAccount},
tokens::{nonfungibles_v2::Inspect, GetSalary, PayFromAccount, PayFungibles},
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse,
EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem,
LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote, WithdrawReasons,
Expand Down Expand Up @@ -1106,6 +1106,10 @@ parameter_types! {

impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type AssetId = u32;
type AssetKind = pallet_treasury::SimpleAsset<u32, u128>;
type Paymaster = PayFungibles<Assets, TreasuryAccount>;
type BalanceConverter = ();
type Currency = Balances;
type ApproveOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
Expand All @@ -1127,6 +1131,9 @@ impl pallet_treasury::Config for Runtime {
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type MaxApprovals = MaxApprovals;
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
type MaxPaymentRetries = ConstU32<3>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

impl pallet_asset_rate::Config for Runtime {
Expand Down
22 changes: 21 additions & 1 deletion frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use frame_support::{
assert_noop, assert_ok,
pallet_prelude::GenesisBuild,
parameter_types,
traits::{ConstU32, ConstU64, OnInitialize},
traits::{tokens::PayFromAccount, ConstU32, ConstU64, OnInitialize},
PalletId,
};

Expand Down Expand Up @@ -59,6 +59,8 @@ frame_support::construct_runtime!(

parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub TreasuryAccount: u128 = Treasury::account_id();
pub TreasuryAccount1: u128 = Treasury1::account_id();
}

type Balance = u64;
Expand Down Expand Up @@ -114,8 +116,19 @@ parameter_types! {
pub static SpendLimit1: Balance = u64::MAX;
}

pub struct NilBenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
impl<AssetKind: From<()>> pallet_treasury::BenchmarkHelper<AssetKind> for NilBenchmarkHelper {
fn create_asset_kind(_id: u32) -> AssetKind {
().into()
}
}

impl pallet_treasury::Config for Test {
type PalletId = TreasuryPalletId;
type AssetKind = ();
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type BalanceConverter = ();
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
Expand All @@ -131,10 +144,15 @@ impl pallet_treasury::Config for Test {
type SpendFunds = Bounties;
type MaxApprovals = ConstU32<100>;
type SpendOrigin = frame_system::EnsureRootWithSuccess<Self::AccountId, SpendLimit>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = NilBenchmarkHelper;
}

impl pallet_treasury::Config<Instance1> for Test {
type PalletId = TreasuryPalletId2;
type AssetKind = ();
type Paymaster = PayFromAccount<Balances, TreasuryAccount1>;
type BalanceConverter = ();
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
Expand All @@ -150,6 +168,8 @@ impl pallet_treasury::Config<Instance1> for Test {
type SpendFunds = Bounties1;
type MaxApprovals = ConstU32<100>;
type SpendOrigin = frame_system::EnsureRootWithSuccess<Self::AccountId, SpendLimit1>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = NilBenchmarkHelper;
}

parameter_types! {
Expand Down
11 changes: 9 additions & 2 deletions frame/child-bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ use frame_support::{
assert_noop, assert_ok,
pallet_prelude::GenesisBuild,
parameter_types,
traits::{ConstU32, ConstU64, OnInitialize},
traits::{tokens::PayFromAccount, ConstU32, ConstU64, OnInitialize},
weights::Weight,
PalletId,
};

use sp_core::H256;
use sp_runtime::{
testing::Header,
Expand Down Expand Up @@ -113,10 +112,15 @@ parameter_types! {
pub const Burn: Permill = Permill::from_percent(50);
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const SpendLimit: Balance = u64::MAX;
pub TreasuryAccount: u128 = Treasury::account_id();
}

impl pallet_treasury::Config for Test {
type PalletId = TreasuryPalletId;
type AssetId = ();
type AssetKind = u64;
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type BalanceConverter = ();
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
Expand All @@ -132,6 +136,9 @@ impl pallet_treasury::Config for Test {
type SpendFunds = Bounties;
type MaxApprovals = ConstU32<100>;
type SpendOrigin = frame_system::EnsureRootWithSuccess<Self::AccountId, SpendLimit>;
type MaxPaymentRetries = ConstU32<3>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = pallet_treasury::NilBenchmarkHelper;
}
parameter_types! {
// This will be 50% of the bounty fee.
Expand Down
4 changes: 3 additions & 1 deletion frame/support/src/traits/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ pub trait EnsureOriginWithArg<OuterOrigin, Argument> {
///
/// ** Should be used for benchmarking only!!! **
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(a: &Argument) -> Result<OuterOrigin, ()>;
fn try_successful_origin(a: &Argument) -> Result<OuterOrigin, ()>{
Err(())
}
}

pub struct AsEnsureOriginWithArg<EO>(sp_std::marker::PhantomData<EO>);
Expand Down
2 changes: 1 addition & 1 deletion frame/support/src/traits/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ pub use misc::{
ConvertRank, DepositConsequence, ExistenceRequirement, Fortitude, GetSalary, Locker, Precision,
Preservation, Provenance, Restriction, WithdrawConsequence, WithdrawReasons,
};
pub use pay::{Pay, PayFromAccount, PaymentStatus};
pub use pay::{Pay, PayFromAccount, PayFungibles, PaymentStatus};
12 changes: 12 additions & 0 deletions frame/support/src/traits/tokens/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ pub trait ConversionFromAssetBalance<AssetBalance, AssetId, OutBalance> {
) -> Result<OutBalance, Self::Error>;
}

impl<InBalance, AssetId, OutBalance: core::convert::From<InBalance>>
ConversionFromAssetBalance<InBalance, AssetId, OutBalance> for ()
{
type Error = ();
fn from_asset_balance(
balance: InBalance,
_asset_id: AssetId,
) -> Result<OutBalance, Self::Error> {
Ok(balance.into())
}
}

/// Trait to handle NFT locking mechanism to ensure interactions with the asset can be implemented
/// downstream to extend logic of Uniques/Nfts current functionality.
pub trait Locker<CollectionId, ItemId> {
Expand Down
28 changes: 27 additions & 1 deletion frame/support/src/traits/tokens/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sp_core::{RuntimeDebug, TypedGet};
use sp_runtime::DispatchError;
use sp_std::fmt::Debug;

use super::{fungible, Balance, Preservation::Expendable};
use super::{fungible, fungibles, Balance, Preservation::Expendable};

/// Can be implemented by `PayFromAccount` using a `fungible` impl, but can also be implemented with
/// XCM/MultiAsset and made generic over assets.
Expand Down Expand Up @@ -107,3 +107,29 @@ impl<A: TypedGet, F: fungible::Mutate<A::Type>> Pay for PayFromAccount<F, A> {
#[cfg(feature = "runtime-benchmarks")]
fn ensure_concluded(_: Self::Id) {}
}

pub struct PayFungibles<F, A>(sp_std::marker::PhantomData<(F, A)>);
impl<A: TypedGet, F: fungibles::Mutate<A::Type> + fungibles::Inspect<A::Type>> Pay
for PayFungibles<F, A>
{
type Balance = F::Balance;
type Beneficiary = A::Type;
type AssetKind = F::AssetId;
type Id = ();
type Error = DispatchError;
fn pay(
who: &Self::Beneficiary,
asset_id: Self::AssetKind,
amount: Self::Balance,
) -> Result<Self::Id, Self::Error> {
<F as fungibles::Mutate<_>>::transfer(asset_id, &A::get(), who, amount, Expendable)?;
Ok(())
}
fn check_payment(_: ()) -> PaymentStatus {
PaymentStatus::Success
}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_successful(_: &Self::Beneficiary, _: Self::Balance) {}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_concluded(_: Self::Id) {}
}
19 changes: 18 additions & 1 deletion frame/tips/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use frame_support::{
pallet_prelude::GenesisBuild,
parameter_types,
storage::StoragePrefixedMap,
traits::{ConstU32, ConstU64, SortedMembers, StorageVersion},
traits::{tokens::PayFromAccount, ConstU32, ConstU64, SortedMembers, StorageVersion},
PalletId,
};

Expand All @@ -59,6 +59,8 @@ frame_support::construct_runtime!(

parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub TreasuryAccount: u128 = Treasury::account_id();
pub TreasuryAccount1: u128 = Treasury1::account_id();
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
Expand Down Expand Up @@ -132,8 +134,13 @@ parameter_types! {
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const TreasuryPalletId2: PalletId = PalletId(*b"py/trsr2");
}

impl pallet_treasury::Config for Test {
type PalletId = TreasuryPalletId;
type AssetId = ();
type AssetKind = u64;
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type BalanceConverter = ();
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
Expand All @@ -149,10 +156,17 @@ impl pallet_treasury::Config for Test {
type SpendFunds = ();
type MaxApprovals = ConstU32<100>;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u64>;
type MaxPaymentRetries = ConstU32<3>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = pallet_treasury::NilBenchmarkHelper;
}

impl pallet_treasury::Config<Instance1> for Test {
type PalletId = TreasuryPalletId2;
type AssetId = ();
type AssetKind = u64;
type Paymaster = PayFromAccount<Balances, TreasuryAccount1>;
type BalanceConverter = ();
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
Expand All @@ -168,6 +182,9 @@ impl pallet_treasury::Config<Instance1> for Test {
type SpendFunds = ();
type MaxApprovals = ConstU32<100>;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u64>;
type MaxPaymentRetries = ConstU32<3>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = pallet_treasury::NilBenchmarkHelper;
}

parameter_types! {
Expand Down
2 changes: 2 additions & 0 deletions frame/treasury/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
pallet-balances = { version = "4.0.0-dev", default-features = false, path = "../balances" }
pallet-assets = { version = "4.0.0-dev", default-features = false, path = "../assets" }
sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" }

Expand All @@ -40,6 +41,7 @@ std = [
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"pallet-assets/std",
"scale-info/std",
"serde",
"sp-runtime/std",
Expand Down
56 changes: 54 additions & 2 deletions frame/treasury/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ use frame_system::RawOrigin;

const SEED: u32 = 0;

fn default_asset_kind<T: Config<I>, I: 'static>() -> T::AssetKind {
T::BenchmarkHelper::create_asset_kind(0)
}

// Create the pre-requisite information needed to create a treasury `propose_spend`.
fn setup_proposal<T: Config<I>, I: 'static>(
u: u32,
Expand All @@ -43,6 +47,19 @@ fn setup_proposal<T: Config<I>, I: 'static>(
(caller, value, beneficiary_lookup)
}

// Create the pre-requisite information needed to create a treasury `spend` call.
fn setup_spend_call<T: Config<I>, I: 'static>(
u: u32,
) -> (T::AssetKind, T::AccountId, PayBalanceOf<T, I>, AccountIdLookupOf<T>) {
let caller = account("caller", u, SEED);

let value: PayBalanceOf<T, I> = SEED.into();
let beneficiary = account("beneficiary", u, SEED);
let beneficiary_lookup = T::Lookup::unlookup(beneficiary);
let asset_kind = default_asset_kind::<T, I>();
(asset_kind, caller, value, beneficiary_lookup)
}

// Create proposals that are approved for use in `on_initialize`.
fn create_approved_proposals<T: Config<I>, I: 'static>(n: u32) -> Result<(), &'static str> {
for i in 0..n {
Expand All @@ -55,6 +72,16 @@ fn create_approved_proposals<T: Config<I>, I: 'static>(n: u32) -> Result<(), &'s
Ok(())
}

// Create pending payments that are approved for use in `on_initialize`.
fn create_pending_payments<T: Config<I>, I: 'static>(n: u32) -> Result<(), &'static str> {
for i in 0..n {
let (asset_kind, _, value, lookup) = setup_spend_call::<T, I>(i);
Treasury::<T, I>::spend(RawOrigin::Root.into(), asset_kind, value, lookup)?;
}
ensure!(<PendingPayments<T, I>>::count() == n, "Enpty pending payments storage");
Ok(())
}

fn setup_pot_account<T: Config<I>, I: 'static>() {
let pot_account = Treasury::<T, I>::account_id();
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into());
Expand All @@ -68,11 +95,11 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::
benchmarks_instance_pallet! {
// This benchmark is short-circuited if `SpendOrigin` cannot provide
// a successful origin, in which case `spend` is un-callable and can use weight=0.
spend {
spend_local {
let (_, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
let origin = T::SpendOrigin::try_successful_origin();
let beneficiary = T::Lookup::lookup(beneficiary_lookup.clone()).unwrap();
let call = Call::<T, I>::spend { amount: value, beneficiary: beneficiary_lookup };
let call = Call::<T, I>::spend_local { amount: value, beneficiary: beneficiary_lookup };
}: {
if let Ok(origin) = origin.clone() {
call.dispatch_bypass_filter(origin)?;
Expand All @@ -84,6 +111,24 @@ benchmarks_instance_pallet! {
}
}

// This benchmark is short-circuited if `SpendOrigin` cannot provide
// a successful origin, in which case `spend` is un-callable and can use weight=0.
spend {
let (asset_kind, _, value, beneficiary_lookup) = setup_spend_call::<T, I>(SEED);
let origin = T::SpendOrigin::try_successful_origin();
let beneficiary: T::AccountId = T::Lookup::lookup(beneficiary_lookup.clone()).unwrap();
let call = Call::<T, I>::spend { asset_kind, amount: value, beneficiary: beneficiary_lookup };
}: {
if let Ok(origin) = origin.clone() {
call.dispatch_bypass_filter(origin)?;
}
}
verify {
if origin.is_ok() {
assert_last_event::<T, I>(Event::PaymentQueued{ pending_payment_index: 0, asset_kind, amount: value, beneficiary }.into())
}
}

propose_spend {
let (caller, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
// Whitelist caller account from further DB operations.
Expand Down Expand Up @@ -138,5 +183,12 @@ benchmarks_instance_pallet! {
Treasury::<T, _>::on_initialize(T::BlockNumber::zero());
}

on_initialize_pending_payments {
let p in 0 .. T::MaxApprovals::get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaxApprovals limit is not enforced for pending payments

create_pending_payments::<T,_>(p)?;
}: {
Treasury::<T, _>::on_initialize(T::BlockNumber::zero());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need some check here that pay was executed


impl_benchmark_test_suite!(Treasury, crate::tests::new_test_ext(), crate::tests::Test);
}
Loading