pallet_dap/
benchmarking.rs1use super::*;
21use frame_benchmarking::v2::*;
22use frame_system::RawOrigin;
23use sp_staking::budget::BudgetRecipientList;
24
25#[benchmarks(where T: pallet_timestamp::Config<Moment = u64>)]
26mod benchmarks {
27 use super::*;
28
29 fn build_even_allocation<T: Config>() -> BudgetAllocationMap {
32 let recipients = T::BudgetRecipients::recipients();
33 let count = recipients.len() as u32;
34 let mut allocations = BudgetAllocationMap::new();
35
36 for (i, (key, _)) in recipients.into_iter().enumerate() {
37 let perbill = if i as u32 == count - 1 {
38 let used: u32 = allocations.values().map(|p| p.deconstruct()).sum();
39 Perbill::from_parts(Perbill::one().deconstruct().saturating_sub(used))
40 } else {
41 Perbill::from_rational(1u32, count)
42 };
43 allocations.try_insert(key, perbill).expect("bounded by MAX_BUDGET_RECIPIENTS");
44 }
45
46 allocations
47 }
48
49 #[benchmark]
50 fn set_budget_allocation() {
51 let allocations = build_even_allocation::<T>();
52
53 #[extrinsic_call]
54 _(RawOrigin::Root, allocations.clone());
55
56 assert_eq!(BudgetAllocation::<T>::get(), allocations);
57 }
58
59 #[benchmark]
60 fn drip_issuance() {
61 let allocations = build_even_allocation::<T>();
62 BudgetAllocation::<T>::put(allocations);
63
64 let now: u64 = 1_000_000;
66 pallet_timestamp::Now::<T>::put(now);
67 let past = now.saturating_sub(T::IssuanceCadence::get() + 1);
68 LastIssuanceTimestamp::<T>::put(past);
69
70 #[block]
71 {
72 Pallet::<T>::drip_issuance();
73 }
74
75 assert!(LastIssuanceTimestamp::<T>::get() > past);
76 }
77}