Skip to content

Commit 855703f

Browse files
[stable2412] Backport #7013 (#7017)
Backport #7013 into `stable2412` from bkchr. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 98f8334 commit 855703f

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

prdoc/pr_7013.prdoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: 'pallet-bounties: Fix benchmarks for 0 ED'
2+
doc:
3+
- audience: Runtime Dev
4+
description: 'Closes: https://github.com/paritytech/polkadot-sdk/issues/7009'
5+
crates:
6+
- name: pallet-bounties
7+
bump: patch

substrate/frame/bounties/src/benchmarking.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18-
//! bounties pallet benchmarking.
19-
20-
#![cfg(feature = "runtime-benchmarks")]
18+
//! Bounties pallet benchmarking.
2119
2220
use super::*;
2321

@@ -37,6 +35,16 @@ fn set_block_number<T: Config<I>, I: 'static>(n: BlockNumberFor<T>) {
3735
<T as pallet_treasury::Config<I>>::BlockNumberProvider::set_block_number(n);
3836
}
3937

38+
fn minimum_balance<T: Config<I>, I: 'static>() -> BalanceOf<T, I> {
39+
let minimum_balance = T::Currency::minimum_balance();
40+
41+
if minimum_balance.is_zero() {
42+
1u32.into()
43+
} else {
44+
minimum_balance
45+
}
46+
}
47+
4048
// Create bounties that are approved for use in `on_initialize`.
4149
fn create_approved_bounties<T: Config<I>, I: 'static>(n: u32) -> Result<(), BenchmarkError> {
4250
for i in 0..n {
@@ -62,12 +70,10 @@ fn setup_bounty<T: Config<I>, I: 'static>(
6270
let fee = value / 2u32.into();
6371
let deposit = T::BountyDepositBase::get() +
6472
T::DataDepositPerByte::get() * T::MaximumReasonLength::get().into();
65-
let _ = T::Currency::make_free_balance_be(&caller, deposit + T::Currency::minimum_balance());
73+
let _ = T::Currency::make_free_balance_be(&caller, deposit + minimum_balance::<T, I>());
6674
let curator = account("curator", u, SEED);
67-
let _ = T::Currency::make_free_balance_be(
68-
&curator,
69-
fee / 2u32.into() + T::Currency::minimum_balance(),
70-
);
75+
let _ =
76+
T::Currency::make_free_balance_be(&curator, fee / 2u32.into() + minimum_balance::<T, I>());
7177
let reason = vec![0; d as usize];
7278
(caller, curator, fee, value, reason)
7379
}
@@ -91,7 +97,7 @@ fn create_bounty<T: Config<I>, I: 'static>(
9197

9298
fn setup_pot_account<T: Config<I>, I: 'static>() {
9399
let pot_account = Bounties::<T, I>::account_id();
94-
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into());
100+
let value = minimum_balance::<T, I>().saturating_mul(1_000_000_000u32.into());
95101
let _ = T::Currency::make_free_balance_be(&pot_account, value);
96102
}
97103

substrate/frame/bounties/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
8585
#![cfg_attr(not(feature = "std"), no_std)]
8686

87+
#[cfg(feature = "runtime-benchmarks")]
8788
mod benchmarking;
8889
pub mod migrations;
8990
mod tests;

0 commit comments

Comments
 (0)