Skip to content

Commit 1f6b1bb

Browse files
committed
pallet-bounties: refactor unassign_curator benchmark to always perform worst case even if BountyUpdatePeriod is max
1 parent e254cec commit 1f6b1bb

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

substrate/frame/bounties/src/benchmarking.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ benchmarks_instance_pallet! {
146146
);
147147
}
148148

149-
// Worst case when curator is inactive and any sender unassigns the curator.
149+
// Worst case when curator is inactive and any sender unassigns the curator,
150+
// or if `BountyUpdatePeriod` is large enough and `RejectOrigin` executes the call.
150151
unassign_curator {
151152
setup_pot_account::<T, I>();
152153
let (curator_lookup, bounty_id) = create_bounty::<T, I>()?;
@@ -155,18 +156,15 @@ benchmarks_instance_pallet! {
155156
let bounty_update_period = T::BountyUpdatePeriod::get();
156157
let inactivity_timeout = T::SpendPeriod::get().saturating_add(bounty_update_period);
157158
set_block_number::<T, I>(inactivity_timeout.saturating_add(2u32.into()));
158-
let caller = whitelisted_caller();
159-
}: {
160-
let res = Pallet::<T, I>::unassign_curator(RawOrigin::Signed(caller).into(), bounty_id);
161159

162-
// If `BountyUpdatePeriod` overflowed the inactivity timeout, the call will fail (which is fine)
163-
// but we need to handle it.
164-
if Pallet::<T, I>::treasury_block_number() <= inactivity_timeout {
165-
assert!(res.is_err());
160+
// If `BountyUpdatePeriod` overflows the inactivity timeout the benchmark still executes the slash
161+
let origin = if Pallet::<T, I>::treasury_block_number() <= inactivity_timeout {
162+
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?
166163
} else {
167-
res?;
168-
}
169-
}
164+
let caller: T::AccountId = whitelisted_caller();
165+
RawOrigin::Signed(caller.clone()).into()
166+
};
167+
}: _<T::RuntimeOrigin>(origin, bounty_id)
170168

171169
accept_curator {
172170
setup_pot_account::<T, I>();

substrate/frame/child-bounties/src/benchmarking.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ mod benchmarks {
267267
Ok(())
268268
}
269269

270-
// Worst case when curator is inactive and any sender un-assigns the curator.
270+
// Worst case when curator is inactive and any sender un-assigns the curator,
271+
// or if `BountyUpdatePeriod` is large enough and `RejectOrigin` executes the call.
271272
#[benchmark]
272273
fn unassign_curator() -> Result<(), BenchmarkError> {
273274
setup_pot_account::<T>();
@@ -276,24 +277,21 @@ mod benchmarks {
276277
let bounty_update_period = T::BountyUpdatePeriod::get();
277278
let inactivity_timeout = T::SpendPeriod::get().saturating_add(bounty_update_period);
278279
set_block_number::<T>(inactivity_timeout.saturating_add(1u32.into()));
279-
let caller: T::AccountId = whitelisted_caller();
280-
281-
#[block]
282-
{
283-
let res = Pallet::<T>::unassign_curator(
284-
RawOrigin::Signed(caller).into(),
285-
bounty_setup.bounty_id,
286-
bounty_setup.child_bounty_id,
287-
);
288-
289-
// If `BountyUpdatePeriod` overflowed the inactivity timeout, the call will fail (which
290-
// is fine) but we need to handle it.
291-
if Pallet::<T>::treasury_block_number() <= inactivity_timeout {
292-
assert!(res.is_err());
293-
} else {
294-
assert_ok!(res);
295-
}
296-
}
280+
281+
// If `BountyUpdatePeriod` overflows the inactivity timeout the benchmark still executes the slash
282+
let origin = if Pallet::<T>::treasury_block_number() <= inactivity_timeout {
283+
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?
284+
} else {
285+
let caller: T::AccountId = whitelisted_caller();
286+
RawOrigin::Signed(caller.clone()).into()
287+
};
288+
289+
#[extrinsic_call]
290+
_(
291+
origin as T::RuntimeOrigin,
292+
bounty_setup.bounty_id,
293+
bounty_setup.child_bounty_id,
294+
);
297295

298296
Ok(())
299297
}

0 commit comments

Comments
 (0)