pallet_asset_tx_payment/
benchmarking.rs1extern crate alloc;
21
22use super::*;
23use crate::Pallet;
24use frame_benchmarking::v2::*;
25use frame_support::{
26 dispatch::{DispatchInfo, PostDispatchInfo},
27 pallet_prelude::*,
28};
29use frame_system::RawOrigin;
30use sp_runtime::traits::{
31 AsSystemOriginSigner, AsTransactionAuthorizedOrigin, DispatchTransaction, Dispatchable,
32};
33
34#[benchmarks(where
35 T::RuntimeOrigin: AsTransactionAuthorizedOrigin,
36 T::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
37 AssetBalanceOf<T>: Send + Sync,
38 BalanceOf<T>: Send + Sync + From<u64> + IsType<ChargeAssetBalanceOf<T>>,
39 ChargeAssetIdOf<T>: Send + Sync,
40 <T::RuntimeCall as Dispatchable>::RuntimeOrigin: AsSystemOriginSigner<T::AccountId> + Clone,
41 Credit<T::AccountId, T::Fungibles>: IsType<ChargeAssetLiquidityOf<T>>,
42)]
43mod benchmarks {
44 use super::*;
45
46 #[benchmark]
47 fn charge_asset_tx_payment_zero() {
48 let caller: T::AccountId = account("caller", 0, 0);
49 let ext: ChargeAssetTxPayment<T> = ChargeAssetTxPayment::from(0u32.into(), None);
50 let inner = frame_system::Call::remark { remark: alloc::vec![] };
51 let call = T::RuntimeCall::from(inner);
52 let info = DispatchInfo {
53 call_weight: Weight::zero(),
54 extension_weight: Weight::zero(),
55 class: DispatchClass::Normal,
56 pays_fee: Pays::No,
57 };
58 let post_info = PostDispatchInfo { actual_weight: None, pays_fee: Pays::No };
59 #[block]
60 {
61 assert!(ext
62 .test_run(RawOrigin::Signed(caller).into(), &call, &info, 0, 0, |_| Ok(post_info))
63 .unwrap()
64 .is_ok());
65 }
66 }
67
68 #[benchmark]
69 fn charge_asset_tx_payment_native() {
70 let caller: T::AccountId = account("caller", 0, 0);
71 let (fun_asset_id, _) = <T as Config>::BenchmarkHelper::create_asset_id_parameter(1);
72 <T as Config>::BenchmarkHelper::setup_balances_and_pool(fun_asset_id, caller.clone());
73 let ext: ChargeAssetTxPayment<T> = ChargeAssetTxPayment::from(10u32.into(), None);
74 let inner = frame_system::Call::remark { remark: alloc::vec![] };
75 let call = T::RuntimeCall::from(inner);
76 let info = DispatchInfo {
77 call_weight: Weight::from_parts(10, 0),
78 extension_weight: Weight::zero(),
79 class: DispatchClass::Operational,
80 pays_fee: Pays::Yes,
81 };
82 let post_info = PostDispatchInfo {
83 actual_weight: Some(Weight::from_parts(10, 0)),
84 pays_fee: Pays::Yes,
85 };
86
87 #[block]
88 {
89 assert!(ext
90 .test_run(RawOrigin::Signed(caller).into(), &call, &info, 0, 0, |_| Ok(post_info))
91 .unwrap()
92 .is_ok());
93 }
94 }
95
96 #[benchmark]
97 fn charge_asset_tx_payment_asset() {
98 let caller: T::AccountId = account("caller", 0, 0);
99 let (fun_asset_id, asset_id) = <T as Config>::BenchmarkHelper::create_asset_id_parameter(1);
100 <T as Config>::BenchmarkHelper::setup_balances_and_pool(
101 fun_asset_id.clone(),
102 caller.clone(),
103 );
104 let tip = 10u32.into();
105 let ext: ChargeAssetTxPayment<T> = ChargeAssetTxPayment::from(tip, Some(asset_id));
106 let inner = frame_system::Call::remark { remark: alloc::vec![] };
107 let call = T::RuntimeCall::from(inner);
108 let info = DispatchInfo {
109 call_weight: Weight::from_parts(10, 0),
110 extension_weight: Weight::zero(),
111 class: DispatchClass::Operational,
112 pays_fee: Pays::Yes,
113 };
114 let post_info = PostDispatchInfo {
115 actual_weight: Some(Weight::from_parts(10, 0)),
116 pays_fee: Pays::Yes,
117 };
118
119 #[block]
120 {
121 assert!(ext
122 .test_run(RawOrigin::Signed(caller.clone()).into(), &call, &info, 0, 0, |_| Ok(
123 post_info
124 ))
125 .unwrap()
126 .is_ok());
127 }
128 }
129
130 impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime);
131}