cumulus_pallet_weight_reclaim/
benchmarks.rs1#![cfg(feature = "runtime-benchmarks")]
18
19use super::*;
20use frame_support::pallet_prelude::{DispatchClass, Pays};
21use frame_system::RawOrigin;
22use sp_runtime::traits::{AsTransactionAuthorizedOrigin, DispatchTransaction};
23
24#[frame_benchmarking::v2::benchmarks(
25 where T: Send + Sync,
26 <T as frame_system::Config>::RuntimeCall:
27 Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
28 <T as frame_system::Config>::RuntimeOrigin: AsTransactionAuthorizedOrigin,
29)]
30mod bench {
31 use super::*;
32 use frame_benchmarking::impl_test_function;
33
34 #[benchmark]
35 fn storage_weight_reclaim() {
36 let ext = StorageWeightReclaim::<T, ()>::new(());
37
38 let origin = RawOrigin::Root.into();
39 let call = T::RuntimeCall::from(frame_system::Call::remark { remark: alloc::vec![] });
40
41 let overestimate = 10_000;
42 let info = DispatchInfo {
43 call_weight: Weight::zero().add_proof_size(overestimate),
44 extension_weight: Weight::zero(),
45 class: DispatchClass::Normal,
46 pays_fee: Pays::No,
47 };
48
49 let post_info = PostDispatchInfo { actual_weight: None, pays_fee: Pays::No };
50
51 let mut block_weight = frame_system::ConsumedWeight::default();
52 block_weight.accrue(Weight::from_parts(0, overestimate), info.class);
53
54 frame_system::BlockWeight::<T>::put(block_weight);
55
56 #[block]
57 {
58 assert!(ext.test_run(origin, &call, &info, 0, 0, |_| Ok(post_info)).unwrap().is_ok());
59 }
60
61 let final_block_proof_size =
62 frame_system::BlockWeight::<T>::get().get(info.class).proof_size();
63
64 assert!(
65 final_block_proof_size < overestimate,
66 "The proof size measured should be less than {overestimate}"
67 );
68 }
69
70 impl_benchmark_test_suite!(Pallet, crate::tests::setup_test_ext_default(), crate::tests::Test);
71}